]> git.sven.stormbind.net Git - sven/vym.git/blob - mainwindow.cpp
7a53f53ca4f2e3ca8c4fa7618055d46f835a933f
[sven/vym.git] / mainwindow.cpp
1 #include "mainwindow.h"
2
3 #include <iostream>
4 #include <typeinfo>
5
6 #ifndef Q_OS_WIN
7 #include <unistd.h>
8 #endif
9
10 #if defined(VYM_DBUS)
11 #include "adaptorvym.h"
12 #endif
13
14 #include <QColorDialog>
15 #include <QDockWidget>
16 #include <QFontDialog>
17 #include <QInputDialog>
18 #include <QMenuBar>
19 #include <QPrinter>
20 #include <QStatusBar>
21 #include <QTextStream>
22
23 #include "aboutdialog.h"
24 #include "branchpropeditor.h"
25 #include "branchitem.h"
26 #include "command.h"
27 #include "downloadagent.h"
28 #include "exportoofiledialog.h"
29 #include "exports.h"
30 #include "file.h"
31 #include "findresultwidget.h"
32 #include "findresultmodel.h"
33 #include "flagrow.h"
34 #include "headingeditor.h"
35 #include "historywindow.h"
36 #include "imports.h"
37 #include "lineeditdialog.h"
38 #include "macros.h"
39 #include "mapeditor.h"
40 #include "misc.h"
41 #include "options.h"
42 #include "vymprocess.h"
43 #include "scripteditor.h"
44 #include "settings.h"
45 #include "shortcuts.h"
46 #include "noteeditor.h"
47 #include "task.h"
48 #include "taskeditor.h"
49 #include "taskmodel.h"
50 #include "treeeditor.h"
51 #include "version.h"
52 #include "warningdialog.h"
53 #include "xlinkitem.h"
54
55 QPrinter *printer;
56
57 //#include <modeltest.h>    
58
59 #if defined(VYM_DBUS)
60 #include <QDBusConnection>
61 #endif
62
63 extern NoteEditor    *noteEditor;
64 extern HeadingEditor *headingEditor;
65 extern ScriptEditor  *scriptEditor;
66 extern Main *mainWindow;
67 extern FindResultWidget *findResultWidget;  
68 extern TaskEditor *taskEditor;
69 extern TaskModel *taskModel;
70 extern Macros macros;
71 extern QString tmpVymDir;
72 extern QString clipboardDir;
73 extern QString clipboardFile;
74 extern bool clipboardEmpty;
75 extern int statusbarTime;
76 extern FlagRow *standardFlagsMaster;    
77 extern FlagRow *systemFlagsMaster;
78 extern QString vymName;
79 extern QString vymVersion;
80 extern QString vymPlatform;
81 extern QString vymBuildDate;
82 extern QString localeName;
83 extern bool debug;
84 extern bool testmode;
85 extern QTextStream vout;
86 extern bool bugzillaClientAvailable;
87 extern Switchboard switchboard;
88
89
90 extern QList <Command*> modelCommands;
91
92 QMenu* branchAddContextMenu;
93 QMenu* branchContextMenu;
94 QMenu* branchLinksContextMenu;
95 QMenu* branchRemoveContextMenu;
96 QMenu* branchXLinksContextMenuEdit;
97 QMenu* branchXLinksContextMenuFollow;
98 QMenu* canvasContextMenu;
99 QMenu* floatimageContextMenu;
100 QMenu* targetsContextMenu;
101 QMenu* taskContextMenu;
102 QMenu* fileLastMapsMenu;
103 QMenu* fileImportMenu;
104 QMenu* fileExportMenu;
105
106 extern Settings settings;
107 extern Options options;
108 extern ImageIO imageIO;
109
110 extern QDir vymBaseDir;
111 extern QDir lastImageDir;
112 extern QDir lastMapDir;
113 #if defined(Q_OS_WIN32)
114 extern QDir vymInstallDir;
115 #endif
116 extern QString zipToolPath;
117
118 Main::Main(QWidget* parent, Qt::WindowFlags f) : QMainWindow(parent,f)
119 {
120     mainWindow = this;
121
122     setWindowTitle ("VYM - View Your Mind");
123
124     shortcutScope = tr("Main window","Shortcut scope");
125
126     // Load window settings
127     #if defined(Q_OS_WIN32)
128     if (settings.value("/mainwindow/geometry/maximized", false).toBool())
129     {
130         setWindowState(Qt::WindowMaximized);
131     }
132     else
133     #endif
134     {
135         resize (settings.value("/mainwindow/geometry/size", QSize (1024,900)).toSize());
136         move   (settings.value("/mainwindow/geometry/pos",  QPoint(50,50)).toPoint());
137     }
138
139     // Sometimes we may need to remember old selections
140     prevSelection="";
141
142     // Default color
143     currentColor=Qt::black;
144
145     // Create unique temporary directory
146     bool ok;
147     tmpVymDir=makeTmpDir (ok,"vym");
148     if (!ok)
149     {
150         qWarning ("Mainwindow: Could not create temporary directory, failed to start vym");
151         exit (1);
152     }
153     if (debug) qDebug ()<<"tmpDir="<<tmpVymDir;
154
155     // Create direcctory for clipboard
156     clipboardDir=tmpVymDir+"/clipboard";
157     clipboardFile="map.xml";
158     QDir d(clipboardDir);
159     d.mkdir (clipboardDir);
160     makeSubDirs (clipboardDir);
161     clipboardEmpty=true;
162
163     // Remember PID of our friendly webbrowser
164     browserPID=new qint64;
165     *browserPID=0;
166
167     // Define commands in API (used globally)
168     setupAPI();
169
170     // Initialize some settings, which are platform dependant
171     QString p,s;
172
173         // application to open URLs
174         p="/system/readerURL";
175         #if defined(Q_OS_WIN)
176             // Assume that system has been set up so that
177             // Explorer automagically opens up the URL
178             // in the user's preferred browser.
179             s=settings.value (p,"explorer").toString();
180         #elif defined(Q_OS_MACX)
181             s=settings.value (p,"/usr/bin/open").toString();
182         #else
183             s=settings.value (p,"xdg-open").toString();
184         #endif
185         settings.setValue( p,s);
186
187         // application to open PDFs
188         p="/system/readerPDF";
189         #if defined(Q_OS_WIN)
190             s=settings.value (p,"explorer").toString();
191         #elif defined(Q_OS_MACX)
192             s=settings.value (p,"/usr/bin/open").toString();
193         #else
194             s=settings.value (p,"xdg-open").toString();
195         #endif
196         settings.setValue( p,s);
197
198     // width of xLinksMenu
199     xLinkMenuWidth=60;
200
201     // Create Layout
202     QWidget* centralWidget = new QWidget (this);
203     QVBoxLayout *layout=new QVBoxLayout (centralWidget);
204     setCentralWidget(centralWidget);    
205
206     // Create tab widget which holds the maps
207     tabWidget= new QTabWidget (centralWidget);
208     connect(tabWidget, SIGNAL( currentChanged( int  ) ), 
209             this, SLOT( editorChanged( ) ) );
210
211     // Allow closing of tabs (introduced in Qt 4.5)
212     tabWidget->setTabsClosable( true ); 
213     connect(tabWidget, SIGNAL(tabCloseRequested(int)), 
214             this, SLOT( fileCloseMap(int) ));
215
216     layout->addWidget (tabWidget);
217
218     switchboard.addGroup("MainWindow",tr("Main window","Shortcut group"));
219     switchboard.addGroup("MapEditor",tr("Map Editors","Shortcut group"));
220     switchboard.addGroup("TextEditor",tr("Text Editors","Shortcut group"));
221
222     // Setup actions
223     setupFileActions();
224     setupEditActions();
225     setupSelectActions();
226     setupFormatActions();
227     setupViewActions();
228     setupModeActions();
229     setupNetworkActions();
230     setupSettingsActions();
231     setupContextMenus();
232     setupMacros();
233     setupToolbars();
234     setupFlagActions();
235
236     // Dock widgets ///////////////////////////////////////////////
237     QDockWidget *dw;
238     dw = new QDockWidget ();
239     dw->setWidget (noteEditor);
240     dw->setObjectName ("NoteEditor");
241     dw->setWindowTitle(noteEditor->getEditorTitle() );
242     dw->hide();
243     noteEditorDW=dw;
244     addDockWidget (Qt::LeftDockWidgetArea,dw);
245
246     dw = new QDockWidget ();
247     dw->setWidget (headingEditor);
248     dw->setObjectName ("HeadingEditor");
249     dw->setWindowTitle(headingEditor->getEditorTitle() );
250     dw->hide();
251     headingEditorDW=dw;
252     addDockWidget (Qt::BottomDockWidgetArea,dw);
253
254     dw = new QDockWidget (tr("Script Editor"));
255     dw->setWidget (scriptEditor);
256     dw->setObjectName ("ScriptEditor");
257     dw->hide();
258     scriptEditorDW=dw;
259     addDockWidget (Qt::LeftDockWidgetArea,dw);
260
261     findResultWidget=new FindResultWidget ();
262     dw= new QDockWidget (tr ("Search results list","FindResultWidget"));
263     dw->setWidget (findResultWidget);
264     dw->setObjectName ("FindResultWidget");
265     dw->hide(); 
266     addDockWidget (Qt::RightDockWidgetArea,dw);
267     connect (
268         findResultWidget, SIGNAL (noteSelected (QString, int)),
269         this, SLOT (selectInNoteEditor (QString, int)));
270     connect (
271         findResultWidget, SIGNAL (findPressed (QString) ), 
272         this, SLOT (editFindNext(QString) ) );
273
274     scriptEditor = new ScriptEditor(this);
275     dw= new QDockWidget (tr ("Script Editor","ScriptEditor"));
276     dw->setWidget (scriptEditor);
277     dw->setObjectName ("ScriptEditor");
278     dw->hide(); 
279     addDockWidget (Qt::LeftDockWidgetArea,dw);
280
281     branchPropertyEditor = new BranchPropertyEditor();
282     dw = new QDockWidget (tr("Property Editor","PropertyEditor"));
283     dw->setWidget (branchPropertyEditor);
284     dw->setObjectName ("PropertyEditor");
285     dw->hide();
286     addDockWidget (Qt::LeftDockWidgetArea,dw);
287
288     historyWindow=new HistoryWindow();
289     dw = new QDockWidget (tr("History window","HistoryWidget"));
290     dw->setWidget (historyWindow);
291     dw->setObjectName ("HistoryWidget");
292     dw->hide();
293     addDockWidget (Qt::RightDockWidgetArea,dw);
294     connect (dw, SIGNAL (visibilityChanged(bool ) ), this, SLOT (updateActions()));
295
296     // Connect NoteEditor, so that we can update flags if text changes
297     connect (noteEditor, SIGNAL (textHasChanged() ), this, SLOT (updateNoteFlag()));
298     connect (noteEditor, SIGNAL (windowClosed() ), this, SLOT (updateActions()));
299
300     // Connect heading editor
301     connect (headingEditor, SIGNAL (textHasChanged() ), this, SLOT (updateHeading()));
302
303     connect( scriptEditor, SIGNAL( runScript ( QString ) ),  this, SLOT( execute( QString ) ) );
304
305     // Switch back  to MapEditor using Esc 
306     QAction* a = new QAction(this);
307     a->setShortcut (Qt::Key_Escape);
308     a->setShortcutContext (Qt::ApplicationShortcut);
309     a->setCheckable(false);
310     a->setEnabled (true);
311     addAction(a);
312     connect (a , SIGNAL (triggered() ), this, SLOT (setFocusMapEditor()));
313     
314     // Create TaskEditor after setting up above actions, allow cloning 
315     taskEditor = new TaskEditor ();
316     dw= new QDockWidget (tr ("Task list","TaskEditor"));
317     dw->setWidget (taskEditor);
318     dw->setObjectName ("TaskEditor");
319     dw->hide();
320     addDockWidget (Qt::TopDockWidgetArea,dw);
321     connect (dw, SIGNAL (visibilityChanged(bool ) ), this, SLOT (updateActions()));
322     //FIXME -0 connect (taskEditor, SIGNAL (focusReleased() ), this, SLOT (setFocusMapEditor()));
323
324     if (options.isOn("shortcutsLaTeX")) switchboard.printLaTeX();
325
326     if (settings.value( "/mainwindow/showTestMenu",false).toBool()) setupTestActions();
327     setupHelpActions();
328
329     // Status bar and progress bar there
330     statusBar();
331     progressMax=0;
332     progressCounter=0;
333     progressCounterTotal=0;
334
335     progressDialog.setAutoReset(false);
336     progressDialog.setAutoClose(false);
337     progressDialog.setMinimumWidth (600);
338     //progressDialog.setWindowModality (Qt::WindowModal);   // That forces mainwindo to update and slows down
339     progressDialog.setCancelButton (NULL);
340
341     restoreState (settings.value("/mainwindow/state",0).toByteArray());
342
343     // Global Printer
344     printer=new QPrinter (QPrinter::HighResolution );   
345
346     // Enable testmenu
347     //settings.setValue( "mainwindow/showTestMenu", true);
348     updateGeometry();
349
350 #if defined(VYM_DBUS)
351     // Announce myself on DBUS
352     new AdaptorVym (this);    // Created and not deleted as documented in Qt
353     if (!QDBusConnection::sessionBus().registerObject ("/vym",this))
354         qWarning ("MainWindow: Couldn't register DBUS object!");
355 #endif    
356
357 }
358
359 Main::~Main()
360 {
361     // qDebug()<<"Destr Mainwindow"<<flush;
362
363     // Save Settings
364
365     if (!testmode) 
366     {
367         #if defined(Q_OS_WIN32)
368         settings.setValue ("/mainwindow/geometry/maximized", isMaximized());
369         #endif
370         settings.setValue ("/mainwindow/geometry/size", size());
371         settings.setValue ("/mainwindow/geometry/pos", pos());
372         settings.setValue ("/mainwindow/state",saveState(0));
373
374         settings.setValue ("/mainwindow/view/AntiAlias",actionViewToggleAntiAlias->isChecked());
375         settings.setValue ("/mainwindow/view/SmoothPixmapTransform",actionViewToggleSmoothPixmapTransform->isChecked());
376         settings.setValue( "/system/autosave/use",actionSettingsToggleAutosave->isChecked() );
377         settings.setValue ("/system/autosave/ms", settings.value("/system/autosave/ms",60000)); 
378         settings.setValue ("/mainwindow/autoLayout/use",actionSettingsToggleAutoLayout->isChecked() );
379         settings.setValue( "/mapeditor/editmode/autoSelectNewBranch",actionSettingsAutoSelectNewBranch->isChecked() );
380         settings.setValue( "/system/writeBackupFile",actionSettingsWriteBackupFile->isChecked() );
381
382         settings.setValue("/system/printerName",printer->printerName());
383         settings.setValue("/system/printerFormat",printer->outputFormat());
384         settings.setValue("/system/printerFileName",printer->outputFileName());
385         settings.setValue( "/mapeditor/editmode/autoSelectText",actionSettingsAutoSelectText->isChecked() );
386         settings.setValue( "/mapeditor/editmode/autoEditNewBranch",actionSettingsAutoEditNewBranch->isChecked() );
387         settings.setValue( "/mapeditor/editmode/useFlagGroups",actionSettingsUseFlagGroups->isChecked() );
388         settings.setValue( "/export/useHideExport",actionSettingsUseHideExport->isChecked() );
389         settings.setValue( "/system/version", vymVersion );
390         settings.setValue( "/system/builddate", vymBuildDate );
391     }
392     //
393     // call the destructors
394     delete noteEditorDW;
395     delete historyWindow;
396     delete branchPropertyEditor;
397
398     // Remove temporary directory
399     removeDir (QDir(tmpVymDir));
400 }
401
402 void Main::loadCmdLine()
403 {
404     QStringList flist=options.getFileList();
405     QStringList::Iterator it=flist.begin();
406
407     initProgressCounter (flist.count());
408     while (it !=flist.end() )
409     {
410         FileType type=getMapType (*it);
411         fileLoad (*it, NewMap,type);
412         *it++;
413     }   
414     removeProgressCounter();
415 }
416
417
418 void Main::statusMessage(const QString &s)
419 {
420     // Surpress messages while progressdialog during 
421     // load is active
422     statusBar()->showMessage( s,statusbarTime);
423 }
424
425 void Main::setProgressMaximum (int max) {
426     if (progressCounter==0)
427     {
428         // Init range only on first time, when progressCounter still 0
429         // Normalize range to 1000
430         progressDialog.setRange (0,1000);
431         progressDialog.setValue (1);
432     }
433     progressCounter++;  // Another map is loaded
434
435     progressMax=max*1000;
436     QApplication::processEvents();
437 }
438
439 void Main::addProgressValue (float v) 
440
441 {
442     int progress_value= (v + progressCounter -1)*1000/progressCounterTotal;
443 /*
444     qDebug() << "addVal v="<<v
445          <<"  cur="<<progressDialog.value()
446          <<"  pCounter="<<progressCounter
447          <<"  pCounterTotal="<<progressCounterTotal
448          <<"  newv="<< progress_value
449          ;
450          */
451
452     // Make sure the progress dialog shows, even if value == 0
453     if (progress_value < 1) progress_value = 1; 
454     progressDialog.setValue ( progress_value );
455     if (progress_value == 1) QApplication::processEvents();
456 }
457
458 void Main::initProgressCounter(uint n)
459 {
460     progressCounterTotal=n;
461 }
462
463 void Main::removeProgressCounter()
464 {
465     // Hide dialog again
466     progressCounter=0;
467     progressCounterTotal=0;
468     progressDialog.reset();
469     progressDialog.hide();
470 }
471
472 void Main::closeEvent (QCloseEvent* event)
473 {
474     if (fileExitVYM())
475         event->ignore();
476     else        
477         event->accept();
478 }
479
480 // Define commands for models
481 void Main::setupAPI()
482 {
483     Command *c = new Command ("addBranch",Command::Branch);
484     c->addPar (Command::Int, true, "Index of new branch");
485     modelCommands.append(c);
486
487     c=new Command ("addBranchBefore",Command::Branch);
488     modelCommands.append(c);
489
490     c=new Command ("addMapCenter",Command::Any);
491     c->addPar (Command::Double,false, "Position x");
492     c->addPar (Command::Double,false, "Position y");
493     modelCommands.append(c);
494
495     c=new Command ("addMapInsert",Command::Any);
496     c->addPar (Command::String,false, "Filename of map to load");
497     c->addPar (Command::Int,true, "Index where map is inserted");
498     c->addPar (Command::Int,true, "Content filter");
499     modelCommands.append(c);
500
501     c=new Command ("addMapReplace",Command::Branch);
502     c->addPar (Command::String,false, "Filename of map to load");
503     modelCommands.append(c);
504
505     c=new Command ("addSlide",Command::Branch);
506     modelCommands.append(c);
507
508     c=new Command ("addXLink",Command::BranchLike);
509     c->addPar (Command::String, false, "Begin of XLink");
510     c->addPar (Command::String, false, "End of XLink");
511     c->addPar (Command::Int,    true, "Width of XLink");
512     c->addPar (Command::Color,  true, "Color of XLink");
513     c->addPar (Command::String, true, "Penstyle of XLink");
514     modelCommands.append(c);
515
516     c=new Command ("branchCount",Command::Any);
517     modelCommands.append(c);
518
519     c=new Command ("centerCount",Command::BranchLike);
520     modelCommands.append(c);
521
522     c=new Command ("centerOnID",Command::Any);
523     c->addPar (Command::String,false, "UUID of object to center on");
524     modelCommands.append(c);
525
526     c=new Command ("clearFlags",Command::BranchLike);
527     modelCommands.append(c);
528
529     c=new Command ("colorBranch",Command::Branch);
530     c->addPar (Command::Color,true, "New color");
531     modelCommands.append(c);
532
533     c=new Command ("colorSubtree",Command::Branch);
534     c->addPar (Command::Color,true, "New color");
535     modelCommands.append(c);
536
537     c=new Command ("copy",Command::BranchOrImage);
538     modelCommands.append(c);
539
540     c=new Command ("cut",Command::BranchOrImage);
541     modelCommands.append(c);
542
543     c=new Command ("cycleTask",Command::BranchOrImage);
544     c->addPar (Command::Bool,true, "True, if cycling in reverse order");
545     modelCommands.append(c);
546
547     c=new Command ("delete",Command::TreeItem);
548     modelCommands.append(c);
549
550     c=new Command ("deleteChildren",Command::Branch);
551     modelCommands.append(c);
552
553     c=new Command ("deleteKeepChildren",Command::Branch);
554     modelCommands.append(c);
555
556     c=new Command ("deleteSlide",Command::Any);
557     c->addPar (Command::Int,false,"Index of slide to delete");
558     modelCommands.append(c);
559
560     c=new Command ("exportAO",Command::Any);
561     c->addPar (Command::String,false,"Filename for export");
562     modelCommands.append(c);
563
564     c=new Command ("exportASCII",Command::Any);
565     c->addPar (Command::String,false,"Filename for export");
566     c->addPar (Command::Bool,false,"Flag, if tasks should be appended");
567     modelCommands.append(c);
568
569     c=new Command ("exportCSV",Command::Any);
570     c->addPar (Command::String,false,"Filename for export");
571     modelCommands.append(c);
572
573     c=new Command ("exportHTML",Command::Any);
574     c->addPar (Command::String,false,"Path used for export");
575     c->addPar (Command::String,false,"Filename for export");
576     modelCommands.append(c);
577
578     c=new Command ("exportImage",Command::Any);
579     c->addPar (Command::String,false,"Filename for export");
580     c->addPar (Command::String,true,"Image format");
581     modelCommands.append(c);
582
583     c=new Command ("exportImpress",Command::Any);
584     c->addPar (Command::String,false,"Filename for export");
585     c->addPar (Command::String,false,"Configuration file for export");
586     modelCommands.append(c);
587
588     c=new Command ("exportLast",Command::Any);
589     modelCommands.append(c);
590
591     c=new Command ("exportLaTeX",Command::Any);
592     c->addPar (Command::String,false,"Filename for export");
593     modelCommands.append(c);
594
595     c=new Command ("exportOrgMode",Command::Any);
596     c->addPar (Command::String,false,"Filename for export");
597     modelCommands.append(c);
598
599     modelCommands.append(c);
600
601     c=new Command ("exportPDF",Command::Any);
602     c->addPar (Command::String,false,"Filename for export");
603     modelCommands.append(c);
604
605     c=new Command ("exportPDF",Command::Any);
606     c->addPar (Command::String,false,"Filename for export");
607     modelCommands.append(c);
608
609     c=new Command ("exportSVG",Command::Any);
610     c->addPar (Command::String,false,"Filename for export");
611     modelCommands.append(c);
612
613     c=new Command ("exportXML",Command::Any);
614     c->addPar (Command::String,false,"Path used for export");
615     c->addPar (Command::String,false,"Filename for export");
616     modelCommands.append(c);
617
618     c=new Command ("getDestPath",Command::Any);
619     modelCommands.append(c);
620
621     c=new Command ("getFileDir",Command::Any);
622     modelCommands.append(c);
623
624     c=new Command ("getFrameType",Command::Branch);
625     modelCommands.append(c);
626
627     c=new Command ("getHeadingPlainText",Command::TreeItem);
628     modelCommands.append(c);
629
630     c=new Command ("getHeadingXML",Command::TreeItem);
631     modelCommands.append(c);
632
633     c=new Command ("getMapAuthor",Command::Any);
634     modelCommands.append(c);
635
636     c=new Command ("getMapComment",Command::Any);
637     modelCommands.append(c);
638
639     c=new Command ("getMapTitle",Command::Any);
640     modelCommands.append(c);
641
642     c=new Command ("getNotePlainText",Command::TreeItem);
643     modelCommands.append(c);
644
645     c=new Command ("getNoteXML",Command::TreeItem);
646     modelCommands.append(c);
647
648     c=new Command ("getSelectString",Command::TreeItem);
649     modelCommands.append(c);
650
651     c=new Command ("getTaskSleepDays",Command::Branch);
652     modelCommands.append(c);
653
654     c=new Command ("getURL",Command::TreeItem); 
655     modelCommands.append(c);
656
657     c=new Command ("getVymLink",Command::Branch); 
658     modelCommands.append(c);
659
660     c=new Command ("getXLinkColor",Command::XLink);
661     modelCommands.append(c);
662
663     c=new Command ("getXLinkWidth",Command::XLink);
664     modelCommands.append(c);
665
666     c=new Command ("getXLinkPenStyle",Command::XLink);
667     modelCommands.append(c);
668
669     c=new Command ("getXLinkStyleBegin",Command::XLink);
670     modelCommands.append(c);
671
672     c=new Command ("getXLinkStyleEnd",Command::XLink);
673     modelCommands.append(c);
674
675     c=new Command ("hasActiveFlag",Command::TreeItem);
676     c->addPar (Command::String,false,"Name of flag");
677     modelCommands.append(c);
678
679     c=new Command ("hasNote",Command::Branch); 
680     modelCommands.append(c);
681
682     c=new Command ("hasRichTextNote",Command::Branch); 
683     modelCommands.append(c);
684
685     c=new Command ("hasTask",Command::Branch); 
686     modelCommands.append(c);
687
688     c=new Command ("importDir",Command::Branch);
689     c->addPar (Command::String,false,"Directory name to import");
690     modelCommands.append(c);
691
692     c=new Command ("isScrolled",Command::Branch); 
693     modelCommands.append(c);
694
695     c=new Command ("loadImage",Command::Branch); 
696     c->addPar (Command::String,false,"Filename of image");
697     modelCommands.append(c);
698
699     c=new Command ("loadNote",Command::Branch); 
700     c->addPar (Command::String,false,"Filename of note");
701     modelCommands.append(c);
702
703     c=new Command ("moveDown",Command::Branch); 
704     modelCommands.append(c);
705
706     c=new Command ("moveUp",Command::Branch); 
707     modelCommands.append(c);
708
709     c=new Command ("moveSlideDown",Command::Any); 
710     modelCommands.append(c);
711
712     c=new Command ("moveSlideUp",Command::Any); 
713     modelCommands.append(c);
714
715     c=new Command ("move",Command::BranchOrImage); 
716     c->addPar (Command::Double,false,"Position x");
717     c->addPar (Command::Double,false,"Position y");
718     modelCommands.append(c);
719
720     c=new Command ("moveRel",Command::BranchOrImage); 
721     c->addPar (Command::Double,false,"Position x");
722     c->addPar (Command::Double,false,"Position y");
723     modelCommands.append(c);
724
725     c=new Command ("nop",Command::Any); 
726     modelCommands.append(c);
727
728     c=new Command ("note2URLs",Command::Branch); 
729     modelCommands.append(c);
730
731     //internally required for undo/redo of changing VymText:
732     c=new Command ("parseVymText",Command::Branch);
733     c->addPar (Command::String,false,"parse XML of VymText, e.g for Heading or VymNote");
734     modelCommands.append(c);
735
736     c=new Command ("paste",Command::Branch);
737     modelCommands.append(c);
738
739     c=new Command ("redo",Command::Any); 
740     modelCommands.append(c);
741
742     c=new Command ("relinkTo",Command::TreeItem);   // FIXME different number of parameters for Image or Branch
743     c->addPar (Command::String,false,"Selection string of parent");
744     c->addPar (Command::Int,false,"Index position");
745     c->addPar (Command::Double,true,"Position x");
746     c->addPar (Command::Double,true,"Position y");
747     modelCommands.append(c);
748
749     c=new Command ("saveImage",Command::Image); 
750     c->addPar (Command::String,false,"Filename of image to save");
751     c->addPar (Command::String,false,"Format of image to save");
752     modelCommands.append(c);
753
754     c=new Command ("saveNote",Command::Branch); 
755     c->addPar (Command::String,false,"Filename of note to save");
756     modelCommands.append(c);
757
758     c=new Command ("scroll",Command::Branch); 
759     modelCommands.append(c);
760
761     c=new Command ("select",Command::Any); 
762     c->addPar (Command::String,false,"Selection string");
763     modelCommands.append(c);
764
765     c=new Command ("selectID",Command::Any); 
766     c->addPar (Command::String,false,"Unique ID");
767     modelCommands.append(c);
768
769     c=new Command ("selectLastBranch",Command::Branch); 
770     modelCommands.append(c);
771
772     c=new Command ("selectLastImage",Command::Branch); 
773     modelCommands.append(c);
774
775     c=new Command ("selectLatestAdded",Command::Any); 
776     modelCommands.append(c);
777
778     c=new Command ("selectParent",Command::Branch); 
779     modelCommands.append(c);
780
781     c=new Command ("setFlag",Command::TreeItem); 
782     c->addPar (Command::String,false,"Name of flag");
783     modelCommands.append(c);
784
785     c=new Command ("setTaskSleep",Command::Branch); 
786     c->addPar (Command::String,false,"Days to sleep");
787     modelCommands.append(c);
788
789     c=new Command ("setFrameIncludeChildren",Command::BranchOrImage); 
790     c->addPar (Command::Bool,false,"Include or don't include children in frame");
791     modelCommands.append(c);
792
793     c=new Command ("setFrameType",Command::BranchOrImage); 
794     c->addPar (Command::String,false,"Type of frame");
795     modelCommands.append(c);
796
797     c=new Command ("setFramePenColor",Command::BranchOrImage); 
798     c->addPar (Command::Color,false,"Color of frame border line");
799     modelCommands.append(c);
800
801     c=new Command ("setFrameBrushColor",Command::BranchOrImage); 
802     c->addPar (Command::Color,false,"Color of frame background");
803     modelCommands.append(c);
804
805     c=new Command ("setFramePadding",Command::BranchOrImage); 
806     c->addPar (Command::Int,false,"Padding around frame");
807     modelCommands.append(c);
808
809     c=new Command ("setFrameBorderWidth",Command::BranchOrImage); 
810     c->addPar (Command::Int,false,"Width of frame borderline");
811     modelCommands.append(c);
812
813     c=new Command ("setHeadingPlainText",Command::TreeItem); 
814     c->addPar (Command::String,false,"New heading");
815     modelCommands.append(c);
816
817     c=new Command ("setHideExport",Command::BranchOrImage); 
818     c->addPar (Command::Bool,false,"Set if item should be visible in export");
819     modelCommands.append(c);
820
821     c=new Command ("setIncludeImagesHorizontally",Command::Branch); 
822     c->addPar (Command::Bool,false,"Set if images should be included horizontally in parent branch");
823     modelCommands.append(c);
824
825     c=new Command ("setIncludeImagesVertically",Command::Branch); 
826     c->addPar (Command::Bool,false,"Set if images should be included vertically in parent branch");
827     modelCommands.append(c);
828
829     c=new Command ("setHideLinksUnselected",Command::BranchOrImage); 
830     c->addPar (Command::Bool,false,"Set if links of items should be visible for unselected items");
831     modelCommands.append(c);
832
833     c=new Command ("setMapAnimCurve",Command::Any); 
834     c->addPar (Command::Int,false,"EasingCurve used in animation in MapEditor");
835     modelCommands.append(c);
836
837     c=new Command ("setMapAuthor",Command::Any); 
838     c->addPar (Command::String,false,"");
839     modelCommands.append(c);
840
841     c=new Command ("setMapAnimDuration",Command::Any); 
842     c->addPar (Command::Int,false,"Duration of animation in MapEditor in milliseconds");
843     modelCommands.append(c);
844
845     c=new Command ("setMapBackgroundColor",Command::Any); 
846     c->addPar (Command::Color,false,"Color of map background");
847     modelCommands.append(c);
848
849     c=new Command ("setMapComment",Command::Any); 
850     c->addPar (Command::String,false,"");
851     modelCommands.append(c);
852
853     c=new Command ("setMapTitle",Command::Any); 
854     c->addPar (Command::String,false,"");
855     modelCommands.append(c);
856
857     c=new Command ("setMapDefLinkColor",Command::Any); 
858     c->addPar (Command::Color,false,"Default color of links");
859     modelCommands.append(c);
860
861     c=new Command ("setMapLinkStyle",Command::Any); 
862     c->addPar (Command::String,false,"Link style in map");
863     modelCommands.append(c);
864
865     c=new Command ("setMapRotation",Command::Any); 
866     c->addPar (Command::Double,false,"Rotation of map");
867     modelCommands.append(c);
868
869     c=new Command ("setMapTitle",Command::Any); 
870     c->addPar (Command::String,false,"");
871     modelCommands.append(c);
872
873     c=new Command ("setMapZoom",Command::Any); 
874     c->addPar (Command::Double,false,"Zoomfactor of map");
875     modelCommands.append(c);
876
877     c=new Command ("setNotePlainText",Command::Branch); 
878     c->addPar (Command::String,false,"Note of branch");
879     modelCommands.append(c);
880
881     c=new Command ("setScale",Command::Image); 
882     c->addPar (Command::Double,false,"Scale image x");
883     c->addPar (Command::Double,false,"Scale image y");
884     modelCommands.append(c);
885
886     c=new Command ("setSelectionColor",Command::Any); 
887     c->addPar (Command::Color,false,"Color of selection box");
888     modelCommands.append(c);
889
890     c=new Command ("setURL",Command::TreeItem); 
891     c->addPar (Command::String,false,"URL of TreeItem");
892     modelCommands.append(c);
893
894     c=new Command ("setVymLink",Command::Branch); 
895     c->addPar (Command::String,false,"Vymlink of branch");
896     modelCommands.append(c);
897
898     c=new Command ("setXLinkColor", Command::XLink); 
899     c->addPar (Command::String,false,"Color of xlink");
900     modelCommands.append(c);
901
902     c=new Command ("setXLinkLineStyle", Command::XLink); 
903     c->addPar (Command::String,false,"Style of xlink");
904     modelCommands.append(c);
905
906     c=new Command ("setXLinkStyleBegin", Command::XLink); 
907     c->addPar (Command::String,false,"Style of xlink begin");
908     modelCommands.append(c);
909
910     c=new Command ("setXLinkStyleEnd", Command::XLink); 
911     c->addPar (Command::String,false,"Style of xlink end");
912     modelCommands.append(c);
913
914     c=new Command ("setXLinkWidth", Command::XLink); 
915     c->addPar (Command::Int,false,"Width of xlink");
916     modelCommands.append(c);
917
918     c=new Command ("sleep",Command::Any); 
919     c->addPar (Command::Int,false,"Sleep (seconds)");
920     modelCommands.append(c);
921
922     c=new Command ("sortChildren",Command::Branch); 
923     c->addPar (Command::Bool,true,"Sort children of branch in revers order if set");
924     modelCommands.append(c);
925
926     c=new Command ("toggleFlag",Command::Branch); 
927     c->addPar (Command::String,false,"Name of flag to toggle");
928     modelCommands.append(c);
929
930     c=new Command ("toggleFrameIncludeChildren",Command::Branch); 
931     modelCommands.append(c);
932
933     c=new Command ("toggleScroll",Command::Branch); 
934     modelCommands.append(c);
935
936     c=new Command ("toggleTarget",Command::Branch); 
937     modelCommands.append(c);
938
939     c=new Command ("toggleTask",Command::Branch); 
940     modelCommands.append(c);
941
942     c=new Command ("undo",Command::Any); 
943     modelCommands.append(c);
944
945     c=new Command ("unscroll",Command::Branch); 
946     modelCommands.append(c);
947
948     c=new Command ("unscrollChildren",Command::Branch); 
949     modelCommands.append(c);
950
951     c=new Command ("unselectAll",Command::Any); 
952     modelCommands.append(c);
953
954     c=new Command ("unsetFlag",Command::Branch); 
955     c->addPar (Command::String,false,"Name of flag to unset");
956     modelCommands.append(c);
957 }
958
959 void Main::cloneActionMapEditor( QAction *a, QKeySequence ks)
960 {
961     a->setShortcut ( ks );
962     a->setShortcutContext ( Qt::WidgetShortcut );
963     mapEditorActions.append ( a );
964 }
965
966 // File Actions
967 void Main::setupFileActions()
968 {
969     QString tag = tr ("&Map","Menu for file actions");
970     QMenu *fileMenu = menuBar()->addMenu ( tag );
971
972     QAction *a;
973     a = new QAction(QPixmap( ":/filenew.png"), tr( "&New map","File menu" ),this);
974     switchboard.addSwitch ("fileMapNew", shortcutScope, a, tag);
975     connect( a, SIGNAL( triggered() ), this, SLOT( fileNew() ) );
976     cloneActionMapEditor( a, Qt::CTRL + Qt::Key_N);
977     fileMenu->addAction(a);
978     actionFileNew=a;
979
980     a = new QAction(QPixmap( ":/filenewcopy.png"), tr( "&Copy to new map","File menu" ),this);
981     switchboard.addSwitch ("fileMapNewCopy", shortcutScope, a, tag);
982     connect( a, SIGNAL( triggered() ), this, SLOT( fileNewCopy() ) );
983     cloneActionMapEditor( a, Qt::CTRL + Qt::SHIFT + Qt::Key_C);
984     fileMenu->addAction(a);
985     actionFileNewCopy=a;
986
987     a = new QAction( QPixmap( ":/fileopen.png"), tr( "&Open..." ,"File menu"),this);
988     switchboard.addSwitch ("fileMapOpen", shortcutScope, a, tag);
989     connect( a, SIGNAL( triggered() ), this, SLOT( fileLoad() ) );
990     cloneActionMapEditor( a, Qt::CTRL + Qt::Key_L);
991     fileMenu->addAction(a);
992     actionFileOpen=a;
993
994     a = new QAction(tr( "&Restore last session","Edit menu" ), this);
995     a->setShortcut (Qt::ALT + Qt::Key_R );
996     switchboard.addSwitch ("fileMapRestore", shortcutScope, a, tag);
997     connect( a, SIGNAL( triggered() ), this, SLOT( fileRestoreSession() ) );
998     fileMenu->addAction(a);
999     actionListFiles.append(a);   
1000     actionCopy=a;
1001
1002     fileLastMapsMenu = fileMenu->addMenu (tr("Open Recent","File menu"));
1003     fileMenu->addSeparator();
1004
1005     a = new QAction( QPixmap( ":/filesave.png"), tr( "&Save...","File menu" ), this);
1006     switchboard.addSwitch ("fileMapSave", shortcutScope, a, tag);
1007     cloneActionMapEditor( a, Qt::CTRL + Qt::Key_S);
1008     fileMenu->addAction(a);
1009     restrictedMapActions.append( a );
1010     connect( a, SIGNAL( triggered() ), this, SLOT( fileSave() ) );
1011     actionFileSave=a;
1012
1013     a = new QAction( QPixmap(":/filesaveas.png"), tr( "Save &As...","File menu" ), this);
1014     fileMenu->addAction(a);
1015     connect( a, SIGNAL( triggered() ), this, SLOT( fileSaveAs() ) );
1016
1017     fileMenu->addSeparator();
1018
1019     fileImportMenu = fileMenu->addMenu (tr("Import","File menu"));
1020
1021     if (settings.value( "/mainwindow/showTestMenu",false).toBool()) 
1022     {
1023         a = new QAction( QPixmap(), tr("Firefox Bookmarks","Import filters"),this);
1024         connect( a, SIGNAL( triggered() ), this, SLOT( fileImportFirefoxBookmarks() ) );
1025         fileImportMenu->addAction(a);
1026     }
1027
1028     a = new QAction("Freemind...",this);
1029     connect( a, SIGNAL( triggered() ), this, SLOT( fileImportFreemind() ) );
1030     fileImportMenu->addAction(a);
1031
1032     a = new QAction("Mind Manager...",this);
1033     connect( a, SIGNAL( triggered() ), this, SLOT( fileImportMM() ) );
1034     fileImportMenu->addAction(a);
1035
1036     a = new QAction( tr( "Import Dir%1","Import Filters").arg("..." + tr("(still experimental)") ), this);
1037     connect( a, SIGNAL( triggered() ), this, SLOT( fileImportDir() ) );
1038     fileImportMenu->addAction(a);
1039
1040     fileExportMenu = fileMenu->addMenu (tr("Export","File menu"));
1041
1042     a = new QAction( QPixmap(":/file-document-export.png"),tr("Repeat last export (%1)").arg("-"), this);
1043     switchboard.addSwitch ("fileExportLast", shortcutScope, a, tag);
1044     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportLast() ) );
1045     cloneActionMapEditor( a, Qt::ALT + Qt::Key_E );
1046     fileExportMenu->addAction(a);
1047     actionFileExportLast=a;
1048
1049     a = new QAction(  tr("Webpage (HTML)...","File export menu"),this );
1050     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportHTML() ) );
1051     fileExportMenu->addAction(a);
1052
1053     a = new QAction( tr("Text (ASCII)...","File export menu"), this);
1054     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportASCII() ) );
1055     fileExportMenu->addAction(a);
1056
1057     a = new QAction( tr("Text with tasks","File export menu") + " (ASCII)... "  + tr("(still experimental)"), this);
1058     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportASCIITasks() ) );
1059     fileExportMenu->addAction(a);
1060
1061     a = new QAction( tr("Text (A&O report)...","Export format"), this);
1062     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportAO() ) );
1063     fileExportMenu->addAction(a);
1064
1065     a = new QAction( tr("Image%1","File export menu").arg("..."), this);
1066     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportImage() ) );
1067     fileExportMenu->addAction(a);
1068
1069     a = new QAction( tr("PDF%1","File export menu").arg("..."), this);
1070     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportPDF() ) );
1071     fileExportMenu->addAction(a);
1072
1073     a = new QAction( tr("SVG%1","File export menu").arg("..."), this);
1074     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportSVG() ) );
1075     fileExportMenu->addAction(a);
1076
1077     a = new QAction( "LibreOffice...", this);
1078     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportImpress() ) );
1079     fileExportMenu->addAction(a);
1080
1081     a = new QAction( "XML..." , this );
1082     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportXML() ) );
1083     fileExportMenu->addAction(a);
1084
1085     a = new QAction( tr("Spreadsheet") + " (CSV)... " + tr("(still experimental)"), this);
1086     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportCSV() ) );
1087     fileExportMenu->addAction(a);
1088
1089     a = new QAction( "Taskjuggler... " + tr("(still experimental)"), this );
1090     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportTaskjuggler() ) );
1091     fileExportMenu->addAction(a);
1092
1093     a = new QAction( "OrgMode... " + tr("(still experimental)"), this);
1094     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportOrgMode() ) );
1095     fileExportMenu->addAction(a);
1096
1097     a = new QAction( "LaTeX... " + tr("(still experimental)"), this);
1098     connect( a, SIGNAL( triggered() ), this, SLOT( fileExportLaTeX() ) );
1099     fileExportMenu->addAction(a);
1100
1101     fileMenu->addSeparator();
1102
1103     a = new QAction( tr( "Properties"), this);
1104     switchboard.addSwitch ("editMapProperties", shortcutScope, a, tag);
1105     connect( a, SIGNAL( triggered() ), this, SLOT( editMapProperties() ) );
1106     fileMenu->addAction(a);
1107     actionListFiles.append (a);   
1108     actionMapProperties = a;
1109
1110     fileMenu->addSeparator();
1111
1112     a = new QAction(QPixmap( ":/fileprint.png"), tr( "&Print")+QString("..."), this);
1113     a->setShortcut ( Qt::CTRL + Qt::Key_P);
1114     switchboard.addSwitch ("fileMapPrint", shortcutScope, a, tag);
1115     connect( a, SIGNAL( triggered() ), this, SLOT( filePrint() ) );
1116     fileMenu->addAction(a);
1117     unrestrictedMapActions.append (a);
1118     actionFilePrint=a;
1119
1120     a = new QAction( QPixmap(":/fileclose.png"), tr( "&Close Map","File menu" ), this);
1121     a->setShortcut (Qt::CTRL + Qt::Key_W );      
1122     switchboard.addSwitch ("fileMapClose", shortcutScope, a, tag);
1123     connect( a, SIGNAL( triggered() ), this, SLOT( fileCloseMap() ) );
1124     fileMenu->addAction(a);
1125
1126     a = new QAction(QPixmap(":/exit.png"), tr( "E&xit","File menu"), this);
1127     a->setShortcut (Qt::CTRL + Qt::Key_Q );       
1128     switchboard.addSwitch ("fileExit", shortcutScope, a, tag);
1129     connect( a, SIGNAL( triggered() ), this, SLOT( fileExitVYM() ) );
1130     fileMenu->addAction(a);
1131 }
1132
1133
1134 //Edit Actions
1135 void Main::setupEditActions()
1136 {
1137     QString tag = tr("E&dit","Edit menu") ;
1138     QMenu *editMenu = menuBar()->addMenu( tag );
1139
1140     QAction *a;
1141     a = new QAction( QPixmap( ":/undo.png"), tr( "&Undo","Edit menu" ),this);
1142     a->setShortcut (Qt::CTRL + Qt::Key_Z);
1143     a->setShortcutContext (Qt::WidgetShortcut);
1144     a->setEnabled (false);
1145     editMenu->addAction(a);
1146     mapEditorActions.append( a );
1147     restrictedMapActions.append( a );
1148     switchboard.addSwitch ("mapUndo", shortcutScope, a, tag);
1149     connect( a, SIGNAL( triggered() ), this, SLOT( editUndo() ) );
1150     actionUndo=a;
1151
1152     a = new QAction( QPixmap( ":/redo.png"), tr( "&Redo","Edit menu" ), this); 
1153     a->setShortcut (Qt::CTRL + Qt::Key_Y);
1154     a->setShortcutContext (Qt::WidgetShortcut);
1155     editMenu->addAction(a);
1156     restrictedMapActions.append( a );
1157     mapEditorActions.append( a );
1158     switchboard.addSwitch ("mapRedo", shortcutScope, a, tag);
1159     connect( a, SIGNAL( triggered() ), this, SLOT( editRedo() ) );
1160     actionRedo=a;
1161
1162     editMenu->addSeparator();
1163     a = new QAction(QPixmap( ":/editcopy.png"), tr( "&Copy","Edit menu" ), this);
1164     a->setShortcut (Qt::CTRL + Qt::Key_C );
1165     a->setShortcutContext (Qt::WidgetShortcut);
1166     a->setEnabled (false);
1167     editMenu->addAction(a);
1168     unrestrictedMapActions.append ( a );
1169     mapEditorActions.append( a );
1170     switchboard.addSwitch ("mapCopy", shortcutScope, a, tag);
1171     connect( a, SIGNAL( triggered() ), this, SLOT( editCopy() ) );
1172     actionCopy=a;
1173
1174     a = new QAction(QPixmap( ":/editcut.png" ), tr( "Cu&t","Edit menu" ), this);
1175     a->setShortcut (Qt::CTRL + Qt::Key_X );
1176     a->setEnabled (false);
1177     a->setShortcutContext (Qt::WidgetShortcut);
1178     editMenu->addAction(a);
1179     restrictedMapActions.append( a );
1180     mapEditorActions.append( a );
1181     restrictedMapActions.append( a );
1182     switchboard.addSwitch ("mapCut", shortcutScope, a, tag);
1183     connect( a, SIGNAL( triggered() ), this, SLOT( editCut() ) );
1184     addAction (a);
1185     actionCut=a;
1186
1187     a = new QAction(QPixmap( ":/editpaste.png"), tr( "&Paste","Edit menu" ),this);
1188     connect( a, SIGNAL( triggered() ), this, SLOT( editPaste() ) );
1189     a->setShortcut (Qt::CTRL + Qt::Key_V );
1190     a->setShortcutContext (Qt::WidgetShortcut);
1191     a->setEnabled (false);
1192     editMenu->addAction(a);
1193     restrictedMapActions.append( a );
1194     mapEditorActions.append( a );
1195     switchboard.addSwitch ("mapPaste", shortcutScope, a, tag);
1196     actionPaste=a;
1197
1198     // Shortcut to delete selection
1199     a = new QAction( tr( "Delete Selection","Edit menu" ),this);
1200     a->setShortcut ( Qt::Key_Delete);            
1201     a->setShortcutContext (Qt::WindowShortcut);
1202     switchboard.addSwitch ("mapDelete", shortcutScope, a, tag);
1203     addAction (a);
1204     connect( a, SIGNAL( triggered() ), this, SLOT( editDeleteSelection() ) );
1205     editMenu->addAction(a);
1206     actionListItems.append (a);
1207     actionDelete=a;
1208
1209     // Shortcut to add attribute
1210     a= new QAction(tr( "Add attribute" ), this);
1211     if (settings.value( "/mainwindow/showTestMenu",false).toBool() )
1212     {
1213         //a->setShortcut ( Qt::Key_Q);  
1214         a->setShortcutContext (Qt::WindowShortcut);
1215         switchboard.addSwitch ("mapAddAttribute", shortcutScope, a, tag);
1216     }
1217     connect( a, SIGNAL( triggered() ), this, SLOT( editAddAttribute() ) );
1218     editMenu->addAction(a);
1219     actionAddAttribute= a;
1220
1221
1222     // Shortcut to add mapcenter
1223     a= new QAction(QPixmap(":/newmapcenter.png"),tr( "Add mapcenter","Canvas context menu" ), this);
1224     a->setShortcut ( Qt::Key_C);    
1225     a->setShortcutContext (Qt::WindowShortcut);
1226     switchboard.addSwitch ("mapAddCenter", shortcutScope, a, tag);
1227     connect( a, SIGNAL( triggered() ), this, SLOT( editAddMapCenter() ) );
1228     editMenu->addAction(a);
1229     actionListFiles.append (a);
1230     actionAddMapCenter = a;
1231
1232
1233     // Shortcut to add branch
1234     a = new QAction(QPixmap(":/newbranch.png"), tr( "Add branch as child","Edit menu" ), this);
1235     switchboard.addSwitch ("mapEditNewBranch", shortcutScope, a, tag);
1236     connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranch() ) );
1237     cloneActionMapEditor( a, Qt::Key_A );
1238     taskEditorActions.append( a );
1239     actionListBranches.append(a);
1240     actionAddBranch=a;
1241
1242
1243     // Add branch by inserting it at selection
1244     a = new QAction(tr( "Add branch (insert)","Edit menu" ),this);
1245     a->setShortcut ( Qt::ALT + Qt::Key_A );      
1246     a->setShortcutContext (Qt::WindowShortcut);
1247     switchboard.addSwitch ("mapEditAddBranchBefore", shortcutScope, a, tag);
1248     connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBefore() ) );
1249     editMenu->addAction(a);
1250     actionListBranches.append(a);
1251     actionAddBranchBefore=a;
1252
1253     // Add branch above
1254     a = new QAction(tr( "Add branch above","Edit menu" ), this);
1255     a->setShortcut (Qt::SHIFT+Qt::Key_Insert );   
1256     a->setShortcutContext (Qt::WindowShortcut);
1257     switchboard.addSwitch ("mapEditAddBranchAbove", shortcutScope, a, tag);
1258     addAction (a);
1259     connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchAbove() ) );
1260     a->setEnabled (false);
1261     actionListBranches.append(a);
1262     actionAddBranchAbove=a;
1263
1264     a = new QAction(tr( "Add branch above","Edit menu" ), this);
1265     a->setShortcut (Qt::SHIFT+Qt::Key_A );       
1266     a->setShortcutContext (Qt::WindowShortcut);
1267     switchboard.addSwitch ("mapEditAddBranchAboveAlt", shortcutScope, a, tag);
1268     addAction (a);
1269     connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchAbove() ) );
1270     actionListBranches.append(a);
1271     editMenu->addAction(a);
1272
1273     // Add branch below 
1274     a = new QAction(tr( "Add branch below","Edit menu" ), this);
1275     a->setShortcut (Qt::CTRL +Qt::Key_Insert );   
1276     a->setShortcutContext (Qt::WindowShortcut);
1277     switchboard.addSwitch ("mapEditAddBranchBelow", shortcutScope, a, tag);
1278     addAction (a);
1279     connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBelow() ) );
1280     a->setEnabled (false);
1281     actionListBranches.append(a);
1282
1283     a = new QAction(tr( "Add branch below","Edit menu" ), this);
1284     a->setShortcut (Qt::CTRL +Qt::Key_A );       
1285     a->setShortcutContext (Qt::WindowShortcut);
1286     switchboard.addSwitch ("mapEditAddBranchBelowAlt", shortcutScope, a, tag);
1287     addAction (a);
1288     connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBelow() ) );
1289     actionListBranches.append(a);
1290     actionAddBranchBelow=a; 
1291
1292     a = new QAction(QPixmap(":/up.png" ), tr( "Move branch up","Edit menu" ), this);
1293     a->setShortcut (Qt::Key_PageUp );           
1294     a->setShortcutContext (Qt::WidgetShortcut);
1295     //a->setEnabled (false);
1296     mapEditorActions.append( a );
1297     taskEditorActions.append( a );
1298     restrictedMapActions.append( a );
1299     actionListBranches.append (a);
1300     editMenu->addAction(a);
1301     switchboard.addSwitch ("mapEditMoveBranchUp", shortcutScope, a, tag);
1302     connect( a, SIGNAL( triggered() ), this, SLOT( editMoveUp() ) );
1303     actionMoveUp=a;
1304
1305     a = new QAction( QPixmap( ":/down.png"), tr( "Move branch down","Edit menu" ),this);
1306     a->setShortcut ( Qt::Key_PageDown );          
1307     a->setShortcutContext (Qt::WidgetShortcut);
1308     //a->setEnabled (false);
1309     mapEditorActions.append( a );
1310     taskEditorActions.append( a );
1311     restrictedMapActions.append( a );
1312     actionListBranches.append (a);
1313     editMenu->addAction(a);
1314     switchboard.addSwitch ("mapEditMoveBranchDown", shortcutScope, a, tag);
1315     connect( a, SIGNAL( triggered() ), this, SLOT( editMoveDown() ) );
1316     actionMoveDown=a;
1317
1318     a = new QAction(QPixmap(), tr( "&Detach","Context menu" ),this);
1319     a->setStatusTip ( tr( "Detach branch and use as mapcenter","Context menu" ) );
1320     a->setShortcut ( Qt::Key_D );                
1321     switchboard.addSwitch ("mapDetachBranch", shortcutScope, a, tag);
1322     connect( a, SIGNAL( triggered() ), this, SLOT( editDetach() ) );
1323     editMenu->addAction(a);
1324     actionListBranches.append (a);
1325     actionDetach=a;
1326
1327     a = new QAction( QPixmap(":/editsort.png" ), tr( "Sort children","Edit menu" ), this );
1328     a->setEnabled (true);
1329     a->setShortcut ( Qt::Key_O );                 
1330     switchboard.addSwitch ("mapSortBranches", shortcutScope, a, tag);
1331     connect( a, SIGNAL( triggered() ), this, SLOT( editSortChildren() ) );
1332     editMenu->addAction(a);
1333     actionListBranches.append (a);
1334     actionSortChildren=a;
1335
1336     a = new QAction( QPixmap(":/editsortback.png" ), tr( "Sort children backwards","Edit menu" ), this );
1337     a->setEnabled (true);
1338     a->setShortcut ( Qt::SHIFT + Qt::Key_O );           
1339     switchboard.addSwitch ("mapSortBranchesReverse", shortcutScope, a, tag);
1340     connect( a, SIGNAL( triggered() ), this, SLOT( editSortBackChildren() ) );
1341     editMenu->addAction(a);
1342     actionListBranches.append (a);
1343     actionSortBackChildren=a;   
1344
1345     a = new QAction( QPixmap(":/flag-scrolled-right.png"), tr( "Scroll branch","Edit menu" ), this);
1346     a->setShortcut ( Qt::Key_S );                 
1347     switchboard.addSwitch ("mapToggleScroll", shortcutScope, a, tag);
1348     connect( a, SIGNAL( triggered() ), this, SLOT( editToggleScroll() ) );
1349     editMenu->addAction(a);
1350     actionListBranches.append (a);
1351     a->setEnabled (false);
1352     a->setCheckable(true);
1353     addAction (a);
1354     actionListBranches.append(a);
1355     actionToggleScroll=a;
1356
1357     a = new QAction( tr( "Unscroll children","Edit menu" ), this);
1358     editMenu->addAction(a);
1359     connect( a, SIGNAL( triggered() ), this, SLOT( editUnscrollChildren() ) );
1360     actionListBranches.append (a);
1361
1362     a = new QAction( tr( "Grow selection","Edit menu" ), this);
1363     a->setShortcut ( Qt::CTRL + Qt::Key_Plus);    
1364     switchboard.addSwitch ("mapGrowSelection", shortcutScope, a, tag);
1365     connect( a, SIGNAL( triggered() ), this, SLOT( editGrowSelectionSize() ) );
1366     editMenu->addAction(a);
1367     actionListBranches.append (a);
1368     actionListItems.append (a);
1369     actionGrowSelectionSize=a;
1370
1371     a = new QAction( tr( "Shrink selection","Edit menu" ), this);
1372     a->setShortcut ( Qt::CTRL + Qt::Key_Minus);    
1373     switchboard.addSwitch ("mapShrinkSelection", shortcutScope, a, tag);
1374     connect( a, SIGNAL( triggered() ), this, SLOT( editShrinkSelectionSize() ) );
1375     editMenu->addAction(a);
1376     actionListBranches.append (a);
1377     actionListItems.append (a);
1378     actionShrinkSelectionSize=a;
1379
1380     a = new QAction( tr( "Reset selection size","Edit menu" ), this);
1381     a->setShortcut ( Qt::CTRL + Qt::Key_0);         
1382     switchboard.addSwitch ("mapResetSelectionSize", shortcutScope, a, tag);
1383     connect( a, SIGNAL( triggered() ), this, SLOT( editResetSelectionSize() ) );
1384     editMenu->addAction(a);
1385     actionListBranches.append (a);
1386     actionListItems.append (a);
1387     actionResetSelectionSize=a;
1388
1389     editMenu->addSeparator();
1390
1391     a = new QAction( QPixmap(), "TE: " + tr( "Collapse one level","Edit menu" ), this);
1392     a->setShortcut ( Qt::Key_Less + Qt::CTRL);  
1393     switchboard.addSwitch ("mapCollapseOneLevel", shortcutScope, a, tag);
1394     connect( a, SIGNAL( triggered() ), this, SLOT( editCollapseOneLevel() ) );
1395     editMenu->addAction(a);
1396     a->setEnabled (false);
1397     a->setCheckable(false);
1398     actionListBranches.append(a);
1399     addAction (a);
1400     actionCollapseOneLevel=a;  
1401
1402     a = new QAction( QPixmap(), "TE: " + tr( "Collapse unselected levels","Edit menu" ), this);
1403     a->setShortcut ( Qt::Key_Less);       
1404     switchboard.addSwitch ("mapCollapseUnselectedLevels", shortcutScope, a, tag);
1405     connect( a, SIGNAL( triggered() ), this, SLOT( editCollapseUnselected() ) );
1406     editMenu->addAction(a);
1407     a->setEnabled (false);
1408     a->setCheckable(false);
1409     actionListBranches.append(a);
1410     addAction (a);
1411     actionCollapseUnselected=a;
1412
1413     a = new QAction( QPixmap(), tr( "Expand all branches","Edit menu" ), this);
1414     connect( a, SIGNAL( triggered() ), this, SLOT( editExpandAll() ) );
1415     actionExpandAll=a;
1416     actionExpandAll->setEnabled (false);
1417     actionExpandAll->setCheckable(false);
1418     actionListBranches.append(actionExpandAll);
1419     addAction (a);
1420
1421     a = new QAction( QPixmap(), tr( "Expand one level","Edit menu" ), this);
1422     a->setShortcut ( Qt::Key_Greater );     
1423     switchboard.addSwitch ("mapExpandOneLevel", shortcutScope, a, tag);
1424     connect( a, SIGNAL( triggered() ), this, SLOT( editExpandOneLevel() ) );
1425     a->setEnabled (false);
1426     a->setCheckable(false);
1427     addAction (a);
1428     actionListBranches.append(a);
1429     actionExpandOneLevel=a;
1430
1431     tag = tr("References Context menu","Shortcuts");
1432     a = new QAction( QPixmap(":/flag-url.png"), tr( "Open URL","Edit menu" ), this);
1433     a->setShortcut (Qt::SHIFT + Qt::Key_U );
1434     switchboard.addSwitch ("mapOpenUrl", shortcutScope, a, tag);
1435     addAction(a);
1436     connect( a, SIGNAL( triggered() ), this, SLOT( editOpenURL() ) );
1437     actionListBranches.append (a);
1438     actionOpenURL=a;
1439
1440     a = new QAction( tr( "Open URL in new tab","Edit menu" ), this);
1441     //a->setShortcut (Qt::CTRL+Qt::Key_U );
1442     switchboard.addSwitch ("mapOpenUrlTab", shortcutScope, a, tag);
1443     addAction(a);
1444     connect( a, SIGNAL( triggered() ), this, SLOT( editOpenURLTab() ) );
1445     actionListBranches.append (a);
1446     actionOpenURLTab=a;
1447
1448     a = new QAction( tr( "Open all URLs in subtree (including scrolled branches)","Edit menu" ), this);
1449     a->setShortcut ( Qt::CTRL + Qt::Key_U );
1450     switchboard.addSwitch ("mapOpenUrlsSubTree", shortcutScope, a, tag);
1451     addAction(a);
1452     connect( a, SIGNAL( triggered() ), this, SLOT( editOpenMultipleVisURLTabs() ) );
1453     actionListBranches.append(a);
1454     actionOpenMultipleVisURLTabs=a;
1455
1456     a = new QAction( tr( "Open all URLs in subtree","Edit menu" ), this);
1457     switchboard.addSwitch ("mapOpenMultipleUrlTabs", shortcutScope, a, tag);
1458     addAction(a);
1459     connect( a, SIGNAL( triggered() ), this, SLOT( editOpenMultipleURLTabs() ) );
1460     actionListBranches.append(a);
1461     actionOpenMultipleURLTabs=a;
1462
1463     a = new QAction(QPixmap(), tr( "Extract URLs from note","Edit menu"), this);
1464     a->setShortcut ( Qt::SHIFT + Qt::Key_N );
1465     a->setShortcutContext (Qt::WindowShortcut);
1466     switchboard.addSwitch ("mapUrlsFromNote", shortcutScope, a, tag);
1467     addAction(a);
1468     connect( a, SIGNAL( triggered() ), this, SLOT( editNote2URLs() ) );
1469     actionListBranches.append(a);
1470     actionGetURLsFromNote=a;
1471
1472     a = new QAction(QPixmap(":/flag-urlnew.png"), tr( "Edit URL...","Edit menu"), this);
1473     a->setShortcut ( Qt::Key_U );
1474     a->setShortcutContext (Qt::WindowShortcut);
1475     switchboard.addSwitch ("mapEditURL", shortcutScope, a, tag);
1476     addAction(a);
1477     connect( a, SIGNAL( triggered() ), this, SLOT( editURL() ) );
1478     actionListBranches.append(a);
1479     actionURLNew=a;
1480
1481     a = new QAction(QPixmap(), tr( "Edit local URL...","Edit menu"), this);
1482     //a->setShortcut (Qt::SHIFT +  Qt::Key_U );
1483     a->setShortcutContext (Qt::WindowShortcut);
1484     switchboard.addSwitch ("mapEditLocalURL", shortcutScope, a, tag);
1485     addAction(a);
1486     connect( a, SIGNAL( triggered() ), this, SLOT( editLocalURL() ) );
1487     actionListBranches.append(a);
1488     actionLocalURL=a;
1489
1490     a = new QAction( tr( "Use heading for URL","Edit menu" ), this);
1491     a->setShortcut ( Qt::ALT + Qt::Key_U );
1492     a->setShortcutContext (Qt::ApplicationShortcut);
1493     a->setEnabled (false);
1494     switchboard.addSwitch ("mapHeading2URL", shortcutScope, a, tag);
1495     addAction(a);
1496     connect( a, SIGNAL( triggered() ), this, SLOT( editHeading2URL() ) );
1497     actionListBranches.append(a);
1498     actionHeading2URL=a;
1499
1500     tag = tr("Bugzilla handling","Shortcuts");
1501     a = new QAction(tr( "Create URL to SUSE Bugzilla","Edit menu" ), this);
1502     a->setEnabled (false);
1503     actionListBranches.append(a);
1504     a->setShortcut ( Qt::Key_B );
1505     a->setShortcutContext (Qt::WindowShortcut);
1506     switchboard.addSwitch ("mapUseHeadingForURL", shortcutScope, a, tag);
1507     addAction(a);
1508     connect( a, SIGNAL( triggered() ), this, SLOT( editBugzilla2URL() ) );
1509     actionListBranches.append(a);
1510     actionBugzilla2URL=a;
1511
1512     a = new QAction(tr( "Get data from SUSE Bugzilla","Edit menu" ), this);
1513     a->setShortcut ( Qt::Key_B + Qt::SHIFT);
1514     a->setShortcutContext (Qt::WindowShortcut);
1515     switchboard.addSwitch ("mapUpdateFromBugzilla", shortcutScope, a, tag);
1516     addAction(a);
1517     connect( a, SIGNAL( triggered() ), this, SLOT( getBugzillaData() ) );
1518     actionListBranches.append(a);
1519     actionGetBugzillaData=a;
1520
1521     a = new QAction(tr( "Get data from SUSE Bugzilla for subtree","Edit menu" ), this);
1522     a->setShortcut ( Qt::Key_B + Qt::CTRL);
1523     a->setShortcutContext (Qt::WindowShortcut);
1524     switchboard.addSwitch ("mapUpdateSubTreeFromBugzilla", shortcutScope, a, tag);
1525     addAction(a);
1526     connect( a, SIGNAL( triggered() ), this, SLOT( getBugzillaDataSubtree() ) );
1527     actionListBranches.append(a);
1528     actionGetBugzillaDataSubtree=a;
1529
1530     tag = tr("SUSE Fate tool handling","Shortcuts");
1531     a = new QAction(tr( "Create URL to SUSE FATE tool","Edit menu" ), this);
1532     a->setEnabled (false);
1533     switchboard.addSwitch ("mapFate2URL", shortcutScope, a, tag);
1534     actionListBranches.append(a);
1535     connect( a, SIGNAL( triggered() ), this, SLOT( editFATE2URL() ) );
1536     actionListBranches.append(a);
1537     actionFATE2URL=a;
1538
1539     tag = tr("vymlinks - linking maps","Shortcuts");
1540     a = new QAction(QPixmap(":/flag-vymlink.png"), tr( "Open linked map","Edit menu" ), this);
1541     a->setEnabled (false);
1542     switchboard.addSwitch ("mapOpenVymLink", shortcutScope, a, tag);
1543     connect( a, SIGNAL( triggered() ), this, SLOT( editOpenVymLink() ) );
1544     actionListBranches.append (a);
1545     actionOpenVymLink=a;
1546
1547     a = new QAction(QPixmap(":/flag-vymlink.png"), tr( "Open linked map in background tab","Edit menu" ), this);
1548     a->setEnabled (false);
1549     switchboard.addSwitch ("mapOpenVymLink", shortcutScope, a, tag);
1550     connect( a, SIGNAL( triggered() ), this, SLOT( editOpenVymLinkBackground() ) );
1551     actionListBranches.append (a);
1552     actionOpenVymLinkBackground=a;
1553
1554     a = new QAction(QPixmap(), tr( "Open all vym links in subtree","Edit menu" ), this);
1555     a->setEnabled (false);
1556     switchboard.addSwitch ("mapOpenMultipleVymLinks", shortcutScope, a, tag);
1557     connect( a, SIGNAL( triggered() ), this, SLOT( editOpenMultipleVymLinks() ) );
1558     actionListBranches.append(a);
1559     actionOpenMultipleVymLinks=a;
1560
1561
1562     a = new QAction(QPixmap(":/flag-vymlinknew.png"), tr( "Edit vym link...","Edit menu" ), this);
1563     a->setEnabled (false);
1564     switchboard.addSwitch ("mapEditVymLink", shortcutScope, a, tag);
1565     connect( a, SIGNAL( triggered() ), this, SLOT( editVymLink() ) );
1566     actionListBranches.append(a);
1567     actionEditVymLink=a;
1568
1569     a = new QAction(tr( "Delete vym link","Edit menu" ),this);
1570     a->setEnabled (false);
1571     switchboard.addSwitch ("mapDeleteVymLink", shortcutScope, a, tag);
1572     connect( a, SIGNAL( triggered() ), this, SLOT( editDeleteVymLink() ) );
1573     actionListBranches.append(a);
1574     actionDeleteVymLink=a;
1575
1576     tag = tr("Exports","Shortcuts");
1577     a = new QAction(QPixmap(":/flag-hideexport.png"), tr( "Hide in exports","Edit menu" ), this);
1578     a->setShortcut (Qt::Key_H );
1579     a->setShortcutContext (Qt::WindowShortcut);
1580     a->setCheckable(true);
1581     a->setEnabled (false);
1582     addAction(a);
1583     switchboard.addSwitch ("mapToggleHideExport", shortcutScope, a, tag);
1584     connect( a, SIGNAL( triggered() ), this, SLOT( editToggleHideExport() ) );
1585     actionListItems.append (a);
1586     actionToggleHideExport=a;
1587
1588     tag = tr("Tasks","Shortcuts");
1589     a = new QAction(QPixmap(":/flag-task.png"), tr( "Toggle task","Edit menu" ), this);
1590     a->setShortcut (Qt::Key_W + Qt::SHIFT);
1591     a->setShortcutContext (Qt::WindowShortcut);
1592     a->setCheckable(true);
1593     a->setEnabled (false);
1594     addAction(a);
1595     switchboard.addSwitch ("mapToggleTask", shortcutScope, a, tag);
1596     connect( a, SIGNAL( triggered() ), this, SLOT( editToggleTask() ) );
1597     actionListBranches.append (a);
1598     actionToggleTask=a;
1599
1600     a = new QAction(QPixmap(), tr( "Cycle task status","Edit menu" ), this);
1601     a->setShortcut (Qt::Key_W );
1602     a->setShortcutContext (Qt::WindowShortcut);
1603     a->setCheckable(false);
1604     a->setEnabled (false);
1605     addAction(a);
1606     switchboard.addSwitch ("mapCycleTaskStatus", shortcutScope, a, tag);
1607     connect( a, SIGNAL( triggered() ), this, SLOT( editCycleTaskStatus() ) );
1608     actionListBranches.append (a);
1609     actionCycleTaskStatus=a;
1610
1611     a = new QAction(QPixmap(), tr( "Reset sleep","Task sleep" ), this);
1612     a->setShortcutContext (Qt::WindowShortcut);
1613     a->setCheckable(false);
1614     a->setEnabled (false);
1615     a->setData (0);
1616     addAction(a);
1617     switchboard.addSwitch ("mapResetSleep", shortcutScope, a, tag);
1618     connect( a, SIGNAL( triggered() ), this, SLOT( editTaskSleepN() ) );
1619     actionListBranches.append (a);
1620     actionTaskSleep0=a;
1621
1622     a = new QAction(QPixmap(), tr( "Sleep %1 days","Task sleep" ).arg("n")+"...", this);
1623     a->setShortcutContext (Qt::WindowShortcut);
1624     a->setShortcut (Qt::Key_Q + Qt::SHIFT);
1625     a->setCheckable(false);
1626     a->setEnabled (false);
1627     a->setData (-1);
1628     addAction(a);
1629     switchboard.addSwitch ("mapTaskSleepN", shortcutScope, a, tag);
1630     connect( a, SIGNAL( triggered() ), this, SLOT( editTaskSleepN() ) );
1631     actionListBranches.append (a);
1632     actionTaskSleepN=a;
1633
1634     a = new QAction(QPixmap(), tr( "Sleep %1 day","Task sleep" ).arg(1), this);
1635     a->setShortcutContext (Qt::WindowShortcut);
1636     a->setCheckable(false);
1637     a->setEnabled (false);
1638     a->setData (1);
1639     addAction(a);
1640     switchboard.addSwitch ("mapTaskSleep1", shortcutScope, a, tag);
1641     connect( a, SIGNAL( triggered() ), this, SLOT( editTaskSleepN() ) );
1642     actionListBranches.append (a);
1643     actionTaskSleep1=a;
1644
1645     a = new QAction(QPixmap(), tr( "Sleep %1 days","Task sleep" ).arg(2), this);
1646     a->setShortcutContext (Qt::WindowShortcut);
1647     a->setCheckable(false);
1648     a->setEnabled (false);
1649     a->setData (2);
1650     addAction(a);
1651     switchboard.addSwitch ("mapTaskSleep2", shortcutScope, a, tag);
1652     connect( a, SIGNAL( triggered() ), this, SLOT( editTaskSleepN() ) );
1653     actionListBranches.append (a);
1654     actionTaskSleep2=a;
1655
1656     a = new QAction(QPixmap(), tr( "Sleep %1 days","Task sleep" ).arg(3), this);
1657     a->setShortcutContext (Qt::WindowShortcut);
1658     a->setCheckable(false);
1659     a->setEnabled (false);
1660     a->setData (3);
1661     addAction(a);
1662     switchboard.addSwitch ("mapTaskSleep3", shortcutScope, a, tag);
1663     connect( a, SIGNAL( triggered() ), this, SLOT( editTaskSleepN() ) );
1664     actionListBranches.append (a);
1665     actionTaskSleep3=a;
1666
1667     a = new QAction(QPixmap(), tr( "Sleep %1 days","Task sleep" ).arg(5), this); 
1668     a->setShortcutContext (Qt::WindowShortcut);
1669     a->setCheckable(false);
1670     a->setEnabled (false);
1671     a->setData (5);
1672     addAction(a);
1673     switchboard.addSwitch ("mapTaskSleep5", shortcutScope, a, tag);
1674     connect( a, SIGNAL( triggered() ), this, SLOT( editTaskSleepN() ) );
1675     actionListBranches.append (a);
1676     actionTaskSleep5=a;
1677
1678     a = new QAction(QPixmap(), tr( "Sleep %1 days","Task sleep" ).arg(7), this);
1679     a->setShortcutContext (Qt::WindowShortcut);
1680     a->setCheckable(false);
1681     a->setEnabled (false);
1682     a->setData (7);
1683     addAction(a);
1684     switchboard.addSwitch ("mapTaskSleep7", shortcutScope, a, tag);
1685     connect( a, SIGNAL( triggered() ), this, SLOT( editTaskSleepN() ) );
1686     actionListBranches.append (a);
1687     actionTaskSleep7=a;
1688
1689     a = new QAction(QPixmap(), tr( "Sleep %1 weeks","Task sleep" ).arg(2), this);
1690     a->setShortcutContext (Qt::WindowShortcut);
1691     a->setCheckable(false);
1692     a->setEnabled (false);
1693     a->setData (14);
1694     addAction(a);
1695     switchboard.addSwitch ("mapTaskSleep14", shortcutScope, a, tag);
1696     connect( a, SIGNAL( triggered() ), this, SLOT( editTaskSleepN() ) );
1697     actionListBranches.append (a);
1698     actionTaskSleep14=a;
1699
1700     a = new QAction(QPixmap(), tr( "Sleep %1 weeks","Task sleep" ).arg(4), this);
1701     a->setShortcutContext (Qt::WindowShortcut);
1702     a->setCheckable(false);
1703     a->setEnabled (false);
1704     a->setData (28);
1705     addAction(a);
1706     switchboard.addSwitch ("mapTaskSleep28", shortcutScope, a, tag);
1707     connect( a, SIGNAL( triggered() ), this, SLOT( editTaskSleepN() ) );
1708     actionListBranches.append (a);
1709     actionTaskSleep28=a;
1710
1711     // Import at selection (adding to selection)
1712     a = new QAction( tr( "Add map (insert)","Edit menu" ),this);
1713     connect( a, SIGNAL( triggered() ), this, SLOT( editImportAdd() ) );
1714     a->setEnabled (false);
1715     actionListBranches.append(a);
1716     actionImportAdd=a;
1717
1718     // Import at selection (replacing selection)
1719     a = new QAction( tr( "Add map (replace)","Edit menu" ), this);
1720     connect( a, SIGNAL( triggered() ), this, SLOT( editImportReplace() ) );
1721     a->setEnabled (false);
1722     actionListBranches.append(a);
1723     actionImportReplace=a;
1724
1725     // Save selection 
1726     a = new QAction( tr( "Save selection","Edit menu" ), this);
1727     connect( a, SIGNAL( triggered() ), this, SLOT( editSaveBranch() ) );
1728     a->setEnabled (false);
1729     actionListBranches.append(a);
1730     actionSaveBranch=a;
1731
1732     tag = tr("Removing parts of a map","Shortcuts");
1733
1734     // Only remove branch, not its children
1735     a = new QAction(tr( "Remove only branch and keep its children ","Edit menu" ), this);
1736     a->setShortcut (Qt::ALT + Qt::Key_X );
1737     connect( a, SIGNAL( triggered() ), this, SLOT( editDeleteKeepChildren() ) );
1738     a->setEnabled (false);
1739     addAction(a);
1740     switchboard.addSwitch ("mapDeleteKeepChildren", shortcutScope, a, tag);
1741     actionListBranches.append(a);
1742     actionDeleteKeepChildren=a;
1743
1744     // Only remove children of a branch
1745     a = new QAction( tr( "Remove children","Edit menu" ), this);
1746     a->setShortcut (Qt::SHIFT + Qt::Key_X );
1747     addAction(a);
1748     switchboard.addSwitch ("mapDeleteChildren", shortcutScope, a, tag);
1749     connect( a, SIGNAL( triggered() ), this, SLOT( editDeleteChildren() ) );
1750     a->setEnabled (false);
1751     addAction (a);
1752     actionListBranches.append(a);
1753     actionDeleteChildren=a;
1754
1755     tag = tr("Various","Shortcuts");
1756     a = new QAction(tr( "Add timestamp","Edit menu" ), this);
1757     a->setEnabled (false);
1758     actionListBranches.append(a);
1759     a->setShortcut ( Qt::Key_T ); 
1760     a->setShortcutContext (Qt::WindowShortcut);
1761     addAction(a);
1762     switchboard.addSwitch ("mapAddTimestamp", shortcutScope, a, tag);
1763     connect( a, SIGNAL( triggered() ), this, SLOT( editAddTimestamp() ) );
1764     actionListBranches.append (a);
1765     actionAddTimestamp=a;
1766
1767     a = new QAction(tr( "Map properties...","Edit menu" ),this);
1768     a->setEnabled (true);
1769     connect( a, SIGNAL( triggered() ), this, SLOT( editMapProperties() ) );
1770     actionListFiles.append (a);
1771     actionMapInfo=a;
1772
1773     a = new QAction( tr( "Add   ...","Edit menu" ), this);
1774     a->setShortcutContext (Qt::WindowShortcut);
1775     a->setShortcut (Qt::Key_I + Qt::SHIFT);    
1776     addAction(a);
1777     switchboard.addSwitch ("mapLoadImage", shortcutScope, a, tag);
1778     connect( a, SIGNAL( triggered() ), this, SLOT( editLoadImage() ) );
1779     actionLoadImage=a;
1780
1781     a = new QAction( tr( "Property window","Dialog to edit properties of selection" )+QString ("..."), this);
1782     a->setShortcut ( Qt::Key_P );        
1783     a->setShortcutContext (Qt::WindowShortcut);
1784     a->setCheckable (true);
1785     addAction(a);
1786     switchboard.addSwitch ("mapTogglePropertEditor", shortcutScope, a, tag);
1787     connect( a, SIGNAL( triggered() ), this, SLOT( windowToggleProperty() ) );
1788     actionViewTogglePropertyEditor=a;
1789 }
1790
1791 // Select Actions
1792 void Main::setupSelectActions()
1793 {
1794     QString tag = tr("Selections","Shortcuts");
1795     QMenu *selectMenu = menuBar()->addMenu( tr("Select","Select menu") );
1796     QAction *a;
1797     a = new QAction( QPixmap(":/flag-target.png"), tr( "Toggle target...","Edit menu"), this);
1798     a->setShortcut (Qt::SHIFT + Qt::Key_T );            
1799     a->setCheckable(true);
1800     selectMenu->addAction(a);
1801     switchboard.addSwitch ("mapToggleTarget", shortcutScope, a, tag);
1802     connect( a, SIGNAL( triggered() ), this, SLOT( editToggleTarget() ) );
1803     actionListBranches.append (a);
1804     actionToggleTarget=a;
1805
1806     a = new QAction( QPixmap(":/flag-target.png"), tr( "Goto target...","Edit menu"), this);
1807     a->setShortcut (Qt::Key_G );                
1808     selectMenu->addAction(a);
1809     switchboard.addSwitch ("mapGotoTarget", shortcutScope, a, tag);
1810     connect( a, SIGNAL( triggered() ), this, SLOT( editGoToTarget() ) );
1811     actionListBranches.append (a);
1812     actionGoToTarget=a;
1813
1814     a = new QAction( QPixmap(":/flag-target.png"), tr( "Move to target...","Edit menu"), this);
1815     a->setShortcut (Qt::Key_M );                
1816     selectMenu->addAction(a);
1817     switchboard.addSwitch ("mapMoveToTarget", shortcutScope, a, tag);
1818     connect( a, SIGNAL( triggered() ), this, SLOT( editMoveToTarget() ) );
1819     actionListBranches.append (a);
1820     actionMoveToTarget=a;
1821
1822     a = new QAction( QPixmap(":/selectprevious.png"), tr( "Select previous","Edit menu"), this);
1823     a->setShortcut (Qt::CTRL+ Qt::Key_O );      
1824     a->setShortcutContext (Qt::WidgetShortcut);
1825     selectMenu->addAction(a);
1826     actionListFiles.append (a);
1827     mapEditorActions.append ( a );
1828     switchboard.addSwitch ("mapSelectPrevious", shortcutScope, a, tag);
1829     connect( a, SIGNAL( triggered() ), this, SLOT( editSelectPrevious() ) );
1830     actionSelectPrevious=a;
1831
1832     a = new QAction( QPixmap(":/selectnext.png"), tr( "Select next","Edit menu"), this);
1833     a->setShortcut (Qt::CTRL + Qt::Key_I );
1834     a->setShortcutContext (Qt::WidgetShortcut);
1835     selectMenu->addAction(a);
1836     actionListFiles.append (a);
1837     mapEditorActions.append ( a );
1838     switchboard.addSwitch ("mapSelectNext", shortcutScope, a, tag);
1839     connect( a, SIGNAL( triggered() ), this, SLOT( editSelectNext() ) );
1840     actionSelectNext=a;
1841
1842     a = new QAction( tr( "Unselect all","Edit menu"), this);
1843     //a->setShortcut (Qt::CTRL + Qt::Key_I );
1844     selectMenu->addAction(a);
1845     switchboard.addSwitch ("mapSelectNothing", shortcutScope, a, tag);
1846     connect( a, SIGNAL( triggered() ), this, SLOT( editSelectNothing() ) );
1847     actionListFiles.append (a);
1848     actionSelectNothing=a;
1849
1850     tag = tr("Search functions","Shortcuts");
1851     a = new QAction( QPixmap(":/find.png"), tr( "Find...","Edit menu"), this);
1852     a->setShortcut (Qt::CTRL + Qt::Key_F );     
1853     selectMenu->addAction(a);
1854     switchboard.addSwitch ("mapFind", shortcutScope, a, tag);
1855     connect( a, SIGNAL( triggered() ), this, SLOT( editOpenFindResultWidget() ) );
1856     actionListFiles.append(a);
1857     actionFind=a;
1858
1859     a = new QAction( QPixmap(":/find.png"), tr( "Find...","Edit menu"), this);
1860     a->setShortcut (Qt::Key_Slash );    
1861     selectMenu->addAction(a);
1862     switchboard.addSwitch ("mapFindAlt", shortcutScope, a, tag);
1863     connect( a, SIGNAL( triggered() ), this, SLOT( editOpenFindResultWidget() ) );
1864     actionListFiles.append(a);
1865
1866     a = new QAction( tr( "Find duplicate URLs","Edit menu"), this);
1867     a->setShortcut (Qt::SHIFT + Qt::Key_F);     
1868     switchboard.addSwitch ("mapFindDuplicates", shortcutScope, a, tag);
1869     if (settings.value( "/mainwindow/showTestMenu",false).toBool() ) 
1870         selectMenu->addAction (a);
1871     connect( a, SIGNAL( triggered() ), this, SLOT( editFindDuplicateURLs() ) );
1872
1873 }
1874
1875 // Format Actions
1876 void Main::setupFormatActions()
1877 {
1878     QMenu *formatMenu = menuBar()->addMenu (tr ("F&ormat","Format menu"));
1879
1880     QString tag = tr("Formatting","Shortcuts");
1881
1882     QAction *a;
1883     QPixmap pix( 16,16);
1884     pix.fill (Qt::black);
1885     a= new QAction(pix, tr( "Set &Color" )+QString("..."), this);
1886     formatMenu->addAction(a);
1887     switchboard.addSwitch ("mapFormatColor", shortcutScope, a, tag);
1888     connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectColor() ) );
1889     actionFormatColor=a;
1890
1891     a= new QAction( QPixmap(":/formatcolorpicker.png"), tr( "Pic&k color","Edit menu" ), this);
1892     a->setShortcut (Qt::CTRL + Qt::Key_K );
1893     formatMenu->addAction(a);
1894     switchboard.addSwitch ("mapFormatColorPicker", shortcutScope, a, tag);
1895     connect( a, SIGNAL( triggered() ), this, SLOT( formatPickColor() ) );
1896     a->setEnabled (false);
1897     actionListBranches.append(a);
1898     actionFormatPickColor=a;
1899
1900     a= new QAction(QPixmap(":/formatcolorbranch.png"), tr( "Color &branch","Edit menu" ), this);
1901     //a->setShortcut (Qt::CTRL + Qt::Key_B + Qt::SHIFT);
1902     formatMenu->addAction(a);
1903     switchboard.addSwitch ("mapFormatColorBranch", shortcutScope, a, tag);
1904     connect( a, SIGNAL( triggered() ), this, SLOT( formatColorBranch() ) );
1905     a->setEnabled (false);
1906     actionListBranches.append(a);
1907     actionFormatColorBranch=a;
1908
1909     a= new QAction(QPixmap(":/formatcolorsubtree.png"), tr( "Color sub&tree","Edit menu" ), this);
1910     //a->setShortcut (Qt::CTRL + Qt::Key_B);    // Color subtree
1911     formatMenu->addAction(a);
1912     switchboard.addSwitch ("mapFormatColorSubtree", shortcutScope, a, tag);
1913     connect( a, SIGNAL( triggered() ), this, SLOT( formatColorSubtree() ) );
1914     a->setEnabled (false);
1915     actionListBranches.append(a);
1916     actionFormatColorSubtree=a;
1917
1918     formatMenu->addSeparator();
1919
1920     a= new QAction( tr( "Select default font","Branch attribute" )+"...",  this);
1921     a->setCheckable(false);
1922     connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectFont() ) );
1923     formatMenu->addAction (a);
1924     actionFormatFont=a;
1925
1926     formatMenu->addSeparator();
1927
1928     actionGroupFormatLinkStyles=new QActionGroup ( this);
1929     actionGroupFormatLinkStyles->setExclusive (true);
1930     a= new QAction( tr( "Linkstyle Line" ), actionGroupFormatLinkStyles);
1931     a->setCheckable(true);
1932     restrictedMapActions.append( a );
1933     formatMenu->addAction (a);
1934     connect( a, SIGNAL( triggered() ), this, SLOT( formatLinkStyleLine() ) );
1935     actionFormatLinkStyleLine=a;
1936
1937     a= new QAction( tr( "Linkstyle Curve" ), actionGroupFormatLinkStyles);
1938     a->setCheckable(true);
1939     restrictedMapActions.append( a );
1940     formatMenu->addAction (a);
1941     connect( a, SIGNAL( triggered() ), this, SLOT( formatLinkStyleParabel() ) );
1942     actionFormatLinkStyleParabel=a;
1943
1944     a= new QAction( tr( "Linkstyle Thick Line" ), actionGroupFormatLinkStyles );
1945     a->setCheckable(true);
1946     restrictedMapActions.append( a );
1947     formatMenu->addAction (a);
1948     connect( a, SIGNAL( triggered() ), this, SLOT( formatLinkStylePolyLine() ) );
1949     actionFormatLinkStylePolyLine=a;
1950
1951     a= new QAction( tr( "Linkstyle Thick Curve" ), actionGroupFormatLinkStyles);
1952     a->setCheckable(true);
1953     a->setChecked (true);
1954     restrictedMapActions.append( a );
1955     formatMenu->addAction (a);
1956     formatMenu->addSeparator();
1957     connect( a, SIGNAL( triggered() ), this, SLOT( formatLinkStylePolyParabel() ) );
1958     actionFormatLinkStylePolyParabel=a;
1959
1960     a = new QAction( tr( "Hide link if object is not selected","Branch attribute" ), this);
1961     a->setCheckable(true);
1962     connect( a, SIGNAL( triggered() ), this, SLOT( formatHideLinkUnselected() ) );
1963     actionListBranches.append (a);
1964     actionFormatHideLinkUnselected=a;
1965
1966     a= new QAction( tr( "&Use color of heading for link","Branch attribute" ),  this);
1967     a->setCheckable(true);
1968     connect( a, SIGNAL( triggered() ), this, SLOT( formatToggleLinkColorHint() ) );
1969     formatMenu->addAction (a);
1970     actionFormatLinkColorHint=a;
1971
1972     pix.fill (Qt::white);
1973     a= new QAction( pix, tr( "Set &Link Color")+"..." , this  );
1974     formatMenu->addAction (a);
1975     connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectLinkColor() ) );
1976     actionFormatLinkColor=a;
1977
1978     a= new QAction( pix, tr( "Set &Selection Color")+"...", this  );
1979     formatMenu->addAction (a);
1980     connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectSelectionColor() ) );
1981     actionFormatSelectionColor=a;
1982
1983     a= new QAction( pix, tr( "Set &Background Color" )+"...", this );
1984     formatMenu->addAction (a);
1985     connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectBackColor() ) );
1986     actionFormatBackColor=a;
1987
1988     a= new QAction( pix, tr( "Set &Background image" )+"...", this );
1989     formatMenu->addAction (a);
1990     connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectBackImage() ) );
1991     actionFormatBackImage=a;
1992 }
1993
1994 // View Actions
1995 void Main::setupViewActions()
1996 {
1997     QMenu *viewMenu = menuBar()->addMenu ( tr( "&View" ));
1998     toolbarsMenu=viewMenu->addMenu (tr("Toolbars","Toolbars overview in view menu") );
1999     QString tag = tr("Views","Shortcuts");
2000
2001     viewMenu->addSeparator();   
2002
2003     QAction *a;
2004     a = new QAction( QPixmap(":/viewmag+.png"), tr( "Zoom in","View action" ), this);
2005     a->setShortcut(Qt::Key_Plus);
2006     viewMenu->addAction (a);
2007     switchboard.addSwitch ("mapZoomIn", shortcutScope, a, tag);
2008     connect( a, SIGNAL( triggered() ), this, SLOT(viewZoomIn() ) );
2009     actionListFiles.append (a);
2010     actionZoomIn=a;
2011
2012     a = new QAction( QPixmap(":/viewmag-.png"), tr( "Zoom out","View action" ), this);
2013     a->setShortcut(Qt::Key_Minus);
2014     viewMenu->addAction (a);
2015     switchboard.addSwitch ("mapZoomOut", shortcutScope, a, tag);
2016     connect( a, SIGNAL( triggered() ), this, SLOT( viewZoomOut() ) );
2017     actionListFiles.append (a);
2018     actionZoomOut=a;
2019
2020     a = new QAction( QPixmap(":/rotate-ccw.png"), tr( "Rotate counterclockwise","View action" ), this);
2021     a->setShortcut( Qt::SHIFT + Qt::Key_R);
2022     viewMenu->addAction (a);
2023     switchboard.addSwitch ("mapRotateCounterClockwise", shortcutScope, a, tag);
2024     connect( a, SIGNAL( triggered() ), this, SLOT( viewRotateCounterClockwise() ) );
2025     actionListFiles.append (a);
2026     actionRotateCounterClockwise=a;
2027
2028     a = new QAction( QPixmap(":/rotate-cw.png"), tr( "Rotate rclockwise","View action" ), this);
2029     a->setShortcut(Qt::Key_R);
2030     viewMenu->addAction (a);
2031     switchboard.addSwitch ("mapRotateClockwise", shortcutScope, a, tag);
2032     connect( a, SIGNAL( triggered() ), this, SLOT( viewRotateClockwise() ) );
2033     actionListFiles.append (a);
2034     actionRotateClockwise=a;
2035
2036     a = new QAction(QPixmap(":/viewmag-reset.png"), tr( "reset Zoom","View action" ), this);
2037     a->setShortcut (Qt::Key_Comma);
2038     switchboard.addSwitch ("mapZoomReset", shortcutScope, a, tag);
2039     viewMenu->addAction (a);
2040     connect( a, SIGNAL( triggered() ), this, SLOT(viewZoomReset() ) );
2041     actionListFiles.append (a);
2042     actionZoomReset=a;
2043
2044     a = new QAction( QPixmap(":/viewshowsel.png"), tr( "Center on selection","View action" ), this);
2045     a->setShortcut(Qt::Key_Period);
2046     viewMenu->addAction (a);
2047     switchboard.addSwitch ("mapCenterOn", shortcutScope, a, tag);
2048     connect( a, SIGNAL( triggered() ), this, SLOT( viewCenter() ) );
2049     actionListFiles.append (a);
2050     actionCenterOn=a;
2051
2052     viewMenu->addSeparator();   
2053
2054     //a=noteEditorDW->toggleViewAction();
2055     a = new QAction(QPixmap(":/flag-note.png"), tr( "Note editor","View action" ),this);
2056     a->setShortcut ( Qt::Key_N );
2057     a->setShortcutContext (Qt::WidgetShortcut);
2058     a->setCheckable(true);
2059     viewMenu->addAction (a);
2060     mapEditorActions.append( a );
2061     switchboard.addSwitch ("mapToggleNoteEditor", shortcutScope, a, tag);
2062     connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleNoteEditor() ) );
2063     actionViewToggleNoteEditor=a;
2064
2065     //a=headingEditorDW->toggleViewAction();
2066     a = new QAction(QPixmap(":/headingeditor.png"), tr( "Heading editor","View action" ),this);
2067     a->setCheckable(true);
2068     a->setIcon (QPixmap(":/headingeditor.png"));
2069     a->setShortcut ( Qt::Key_E );
2070     a->setShortcutContext (Qt::WidgetShortcut);
2071     mapEditorActions.append( a );
2072     viewMenu->addAction (a);
2073     switchboard.addSwitch ("mapToggleHeadingEditor", shortcutScope, a, tag);
2074     connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleHeadingEditor() ) );
2075     actionViewToggleHeadingEditor=a;
2076
2077     // Original icon is "category" from KDE
2078     a = new QAction(QPixmap(":/treeeditor.png"), tr( "Tree editor","View action" ),this);
2079     a->setShortcut ( Qt::CTRL + Qt::Key_T );
2080     a->setCheckable(true);
2081     viewMenu->addAction (a);
2082     switchboard.addSwitch ("mapToggleTreeEditor", shortcutScope, a, tag);
2083     connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleTreeEditor() ) );
2084     actionViewToggleTreeEditor=a;
2085
2086     a = new QAction(QPixmap(":/taskeditor.png"), tr( "Task editor","View action" ),this);
2087     a->setCheckable(true);
2088     a->setShortcut ( Qt::Key_Q );
2089     a->setShortcutContext (Qt::WidgetShortcut);
2090     mapEditorActions.append( a );
2091     viewMenu->addAction (a);
2092     switchboard.addSwitch ("mapToggleTaskEditor", shortcutScope, a, tag);
2093     connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleTaskEditor() ) );
2094     actionViewToggleTaskEditor=a;
2095
2096     a = new QAction(QPixmap(":/slideeditor.png"), tr( "Slide editor","View action" ),this);
2097     a->setShortcut ( Qt::SHIFT + Qt::Key_S );
2098     a->setCheckable(true);
2099     viewMenu->addAction (a);
2100     switchboard.addSwitch ("mapToggleSlideEditor", shortcutScope, a, tag);
2101     connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleSlideEditor() ) );
2102     actionViewToggleSlideEditor=a;
2103
2104     a = new QAction(QPixmap(":/scripteditor.png"), tr("Script editor","View action"), this);
2105     a->setShortcut ( Qt::ALT + Qt::Key_S );
2106     a->setCheckable(true);
2107     viewMenu->addAction (a);
2108     switchboard.addSwitch ("mapToggleScriptEditor", shortcutScope, a, tag);
2109     connect( a, SIGNAL( triggered() ), this, SLOT( windowToggleScriptEditor() ) );
2110     actionViewToggleScriptEditor=a;
2111
2112     a = new QAction(QPixmap(":/history.png"),  tr( "History Window","View action" ),this );
2113     a->setShortcut ( Qt::CTRL + Qt::Key_H  );
2114     a->setShortcutContext (Qt::WidgetShortcut);
2115     a->setCheckable(true);
2116     viewMenu->addAction (a);
2117     mapEditorActions.append( a );
2118     switchboard.addSwitch ("mapToggleHistoryWindow", shortcutScope, a, tag);
2119     connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleHistory() ) );
2120     actionViewToggleHistoryWindow=a;
2121
2122     viewMenu->addAction (actionViewTogglePropertyEditor);
2123
2124     viewMenu->addSeparator();   
2125
2126     a = new QAction(tr( "Antialiasing","View action" ),this );
2127     a->setCheckable(true);
2128     a->setChecked (settings.value("/mainwindow/view/AntiAlias",true).toBool());
2129     viewMenu->addAction (a);
2130     connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleAntiAlias() ) );
2131     actionViewToggleAntiAlias=a;
2132
2133     a = new QAction(tr( "Smooth pixmap transformations","View action" ),this );
2134     a->setStatusTip (a->text());
2135     a->setCheckable(true);
2136     a->setChecked (settings.value("/mainwindow/view/SmoothPixmapTransformation",true).toBool());
2137     viewMenu->addAction (a);
2138     connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleSmoothPixmap() ) );
2139     actionViewToggleSmoothPixmapTransform=a;
2140
2141     a = new QAction(tr( "Next Map","View action" ), this);
2142     a->setStatusTip (a->text());
2143     a->setShortcut (Qt::SHIFT+ Qt::Key_Right );
2144     viewMenu->addAction (a);
2145     switchboard.addSwitch ("mapPrevious", shortcutScope, a, tag);
2146     connect( a, SIGNAL( triggered() ), this, SLOT(windowNextEditor() ) );
2147
2148     a = new QAction (tr( "Previous Map","View action" ), this );
2149     a->setStatusTip (a->text());
2150     a->setShortcut (Qt::SHIFT+ Qt::Key_Left );
2151     viewMenu->addAction (a);
2152     switchboard.addSwitch ("mapNext", shortcutScope, a, tag);
2153     connect( a, SIGNAL( triggered() ), this, SLOT(windowPreviousEditor() ) );
2154
2155     a = new QAction (tr( "Next slide","View action" ), this );
2156     a->setStatusTip (a->text());
2157     a->setShortcut (Qt::Key_Space);
2158     viewMenu->addAction (a);
2159     switchboard.addSwitch ("mapNextSlide", shortcutScope, a, tag);
2160     connect( a, SIGNAL( triggered() ), this, SLOT(nextSlide() ) );
2161
2162     a = new QAction (tr( "Previous slide","View action" ), this );
2163     a->setStatusTip (a->text());
2164     a->setShortcut (Qt::Key_Backspace);
2165     viewMenu->addAction (a);
2166     switchboard.addSwitch ("mapPreviousSlide", shortcutScope, a, tag);
2167     connect( a, SIGNAL( triggered() ), this, SLOT(previousSlide() ) );
2168 }
2169
2170 // Mode Actions
2171 void Main::setupModeActions()
2172 {
2173     //QPopupMenu *menu = new QPopupMenu( this );
2174     //menuBar()->insertItem( tr( "&Mode (using modifiers)" ), menu );
2175
2176     QString tag = tr("Modifier modes","Shortcuts");
2177     QAction *a;
2178     actionGroupModModes=new QActionGroup ( this);
2179     actionGroupModModes->setExclusive (true);
2180     a= new QAction( QPixmap(":/modecolor.png"), tr( "Use modifier to color branches","Mode modifier" ), actionGroupModModes);
2181     a->setShortcut (Qt::Key_J);
2182     addAction(a);
2183     switchboard.addSwitch ("mapModModeColor", shortcutScope, a, tag);
2184     a->setCheckable(true);
2185     a->setChecked(true);
2186     actionListFiles.append (a);
2187     actionModModeColor=a;
2188
2189     a->setShortcut( Qt::Key_K); 
2190     addAction(a);
2191     switchboard.addSwitch ("mapModModeCopy", shortcutScope, a, tag);
2192     a->setCheckable(true);
2193     actionListFiles.append (a);
2194     actionModModeCopy=a;
2195
2196     a= new QAction(QPixmap(":/modelink.png"), tr( "Use modifier to draw xLinks","Mode modifier" ), actionGroupModModes );
2197     a->setShortcut (Qt::Key_L);
2198     addAction(a);
2199     switchboard.addSwitch ("mapModModeXLink", shortcutScope, a, tag);
2200     a->setCheckable(true);
2201     actionListFiles.append (a);
2202     actionModModeXLink=a;
2203 }
2204
2205 // Flag Actions
2206 void Main::setupFlagActions()
2207 {
2208     // Create System Flags
2209     Flag *flag;
2210
2211     // Tasks
2212     // Origin: ./share/icons/oxygen/48x48/status/task-reject.png
2213     flag=new Flag(":/flag-task-new.png");
2214     flag->setGroup("system-tasks");
2215     setupFlag (flag,NULL,"system-task-new",tr("Note","SystemFlag"));
2216     flag=new Flag(":/flag-task-new-morning.png");
2217     flag->setGroup("system-tasks");
2218     setupFlag (flag,NULL,"system-task-new-morning",tr("Note","SystemFlag"));
2219     flag=new Flag(":/flag-task-new-sleeping.png");
2220     flag->setGroup("system-tasks");
2221     setupFlag (flag,NULL,"system-task-new-sleeping",tr("Note","SystemFlag"));
2222     // Origin: ./share/icons/oxygen/48x48/status/task-reject.png
2223     flag=new Flag(":/flag-task-wip.png");
2224     flag->setGroup("system-tasks");
2225     setupFlag (flag,NULL,"system-task-wip",tr("Note","SystemFlag"));
2226     flag=new Flag(":/flag-task-wip-morning.png");
2227     flag->setGroup("system-tasks");
2228     setupFlag (flag,NULL,"system-task-wip-morning",tr("Note","SystemFlag"));
2229     flag=new Flag(":/flag-task-wip-sleeping.png");
2230     flag->setGroup("system-tasks");
2231     setupFlag (flag,NULL,"system-task-wip-sleeping",tr("Note","SystemFlag"));
2232     // Origin: ./share/icons/oxygen/48x48/status/task-complete.png
2233     flag=new Flag(":/flag-task-finished.png");
2234     flag->setGroup("system-tasks");
2235     setupFlag (flag,NULL,"system-task-finished",tr("Note","SystemFlag"));
2236
2237     flag=new Flag(":/flag-note.png");
2238     setupFlag (flag,NULL,"system-note",tr("Note","SystemFlag"));
2239
2240     flag=new Flag(":/flag-url.png");
2241     setupFlag (flag,NULL,"system-url",tr("URL to Document ","SystemFlag"));
2242
2243     flag=new Flag(":/flag-url-bugzilla-novell.png");
2244     setupFlag (flag,NULL,"system-url-bugzilla-novell",tr("URL to Bugzilla ","SystemFlag"));
2245
2246     flag=new Flag(":/flag-url-bugzilla-novell-closed.png");
2247     setupFlag (flag,NULL,"system-url-bugzilla-novell-closed",tr("URL to Bugzilla ","SystemFlag"));
2248
2249     flag=new Flag(":/flag-target.png");
2250     setupFlag (flag,NULL,"system-target",tr("Map target","SystemFlag"));
2251
2252     flag=new Flag(":/flag-vymlink.png");
2253     setupFlag (flag,NULL,"system-vymLink",tr("Link to another vym map","SystemFlag"));
2254
2255     flag=new Flag(":/flag-scrolled-right.png");
2256     setupFlag (flag,NULL,"system-scrolledright",tr("subtree is scrolled","SystemFlag"));
2257
2258     flag=new Flag(":/flag-tmpUnscrolled-right.png");
2259     setupFlag (flag,NULL,"system-tmpUnscrolledRight",tr("subtree is temporary scrolled","SystemFlag"));
2260
2261     flag=new Flag(":/flag-hideexport.png");
2262     setupFlag (flag,NULL,"system-hideInExport",tr("Hide object in exported maps","SystemFlag"));
2263
2264     addToolBarBreak();
2265
2266     // Create Standard Flags
2267     standardFlagsToolbar=addToolBar (tr ("Standard Flags toolbar","Standard Flag Toolbar"));
2268     standardFlagsToolbar->setObjectName ("standardFlagTB");
2269     standardFlagsMaster->setToolBar (standardFlagsToolbar);
2270
2271     // Add entry now, to avoid chicken and egg problem and position toolbar 
2272     // after all others:
2273     toolbarsMenu->addAction (standardFlagsToolbar->toggleViewAction() );
2274
2275     flag=new Flag(":/flag-stopsign.png");
2276     setupFlag (flag,standardFlagsToolbar,"stopsign",tr("This won't work!","Standardflag"),Qt::Key_1);
2277     flag->unsetGroup();
2278
2279     flag=new Flag(":/flag-hook-green.png");
2280     flag->setGroup("standard-status");
2281     setupFlag (flag,standardFlagsToolbar,"hook-green",tr("Status - ok,done","Standardflag"),Qt::Key_2);
2282
2283     flag=new Flag(":/flag-wip.png");
2284     flag->setGroup("standard-status");
2285     setupFlag (flag,standardFlagsToolbar,"wip",tr("Status - work in progress","Standardflag"),Qt::Key_3);
2286
2287     flag=new Flag(":/flag-cross-red.png");
2288     flag->setGroup("standard-status");
2289     setupFlag (flag,standardFlagsToolbar,"cross-red",tr("Status - missing, not started","Standardflag"),Qt::Key_4);
2290
2291     flag=new Flag(":/flag-exclamationmark.png");
2292     flag->setGroup("standard-mark");
2293     setupFlag (flag,standardFlagsToolbar,"exclamationmark",tr("Take care!","Standardflag"),Qt::Key_Exclam);
2294
2295     flag=new Flag(":/flag-questionmark.png");
2296     flag->setGroup("standard-mark");
2297     setupFlag (flag,standardFlagsToolbar,"questionmark",tr("Really?","Standardflag"),Qt::Key_Question);
2298
2299     flag=new Flag(":/flag-smiley-good.png");
2300     flag->setGroup("standard-smiley");
2301     setupFlag (flag,standardFlagsToolbar,"smiley-good",tr("Good","Standardflag"),Qt::Key_ParenRight);
2302
2303     flag=new Flag(":/flag-smiley-sad.png");
2304     flag->setGroup("standard-smiley");
2305     setupFlag (flag,standardFlagsToolbar,"smiley-sad",tr("Bad","Standardflag"),Qt::Key_ParenLeft);
2306
2307     flag=new Flag(":/flag-smiley-omb.png");
2308     flag->setGroup("standard-smiley");
2309     setupFlag (flag,standardFlagsToolbar,"smiley-omb",tr("Oh no!","Standardflag"));
2310     // Original omg.png (in KDE emoticons)
2311     flag->unsetGroup();
2312
2313     flag=new Flag(":/flag-clock.png");
2314     setupFlag (flag,standardFlagsToolbar,"clock",tr("Time critical","Standardflag"));
2315
2316     flag=new Flag(":/flag-phone.png");
2317     setupFlag (flag,standardFlagsToolbar,"phone",tr("Call...","Standardflag"));
2318
2319     flag=new Flag(":/flag-lamp.png");
2320     setupFlag (flag,standardFlagsToolbar,"lamp",tr("Idea!","Standardflag"),Qt::Key_Asterisk);
2321
2322     flag=new Flag(":/flag-arrow-up.png");
2323     flag->setGroup("standard-arrow");
2324     setupFlag (flag,standardFlagsToolbar,"arrow-up",tr("Important","Standardflag"),Qt::SHIFT + Qt::Key_PageUp);
2325
2326     flag=new Flag(":/flag-arrow-down.png");
2327     flag->setGroup("standard-arrow");
2328     setupFlag (flag,standardFlagsToolbar,"arrow-down",tr("Unimportant","Standardflag"),Qt::SHIFT + Qt::Key_PageDown);
2329
2330     flag=new Flag(":/flag-2arrow-up.png");
2331     flag->setGroup("standard-arrow");
2332     setupFlag (flag,standardFlagsToolbar,"2arrow-up",tr("Very important!","Standardflag"),Qt::SHIFT + +Qt::CTRL + Qt::Key_PageUp);
2333
2334     flag=new Flag(":/flag-2arrow-down.png");
2335     flag->setGroup("standard-arrow");
2336     setupFlag (flag,standardFlagsToolbar,"2arrow-down",tr("Very unimportant!","Standardflag"),Qt::SHIFT + Qt::CTRL + Qt::Key_PageDown);
2337     flag->unsetGroup();
2338
2339     flag=new Flag(":/flag-thumb-up.png");
2340     flag->setGroup("standard-thumb");
2341     setupFlag (flag,standardFlagsToolbar,"thumb-up",tr("I like this","Standardflag"));
2342
2343     flag=new Flag(":/flag-thumb-down.png");
2344     flag->setGroup("standard-thumb");
2345     setupFlag (flag,standardFlagsToolbar,"thumb-down",tr("I do not like this","Standardflag"));
2346     flag->unsetGroup();
2347
2348     flag=new Flag(":/flag-rose.png");
2349     setupFlag (flag,standardFlagsToolbar,"rose",tr("Rose","Standardflag"));
2350
2351     flag=new Flag(":/flag-heart.png");
2352     setupFlag (flag,standardFlagsToolbar,"heart",tr("I just love...","Standardflag"));
2353
2354     flag=new Flag(":/flag-present.png");
2355     setupFlag (flag,standardFlagsToolbar,"present",tr("Surprise!","Standardflag"));
2356
2357     flag=new Flag(":/flag-flash.png");
2358     setupFlag (flag,standardFlagsToolbar,"flash",tr("Dangerous","Standardflag"));
2359
2360     // Original: xsldbg_output.png
2361     flag=new Flag(":/flag-info.png");
2362     setupFlag (flag,standardFlagsToolbar,"info",tr("Info","Standardflag"),Qt::Key_I);
2363
2364     // Original khelpcenter.png
2365     flag=new Flag(":/flag-lifebelt.png");
2366     setupFlag (flag,standardFlagsToolbar,"lifebelt",tr("This will help","Standardflag"));
2367
2368     // Freemind flags
2369     flag=new Flag(":/freemind/warning.png");
2370     flag->setVisible(false);
2371     setupFlag (flag,standardFlagsToolbar,  "freemind-warning",tr("Important","Freemind-Flag"));
2372
2373     for (int i=1; i<8; i++)
2374     {
2375         flag=new Flag(QString(":/freemind/priority-%1.png").arg(i));
2376         flag->setVisible(false);
2377         flag->setGroup ("Freemind-priority");
2378         setupFlag (flag,standardFlagsToolbar, QString("freemind-priority-%1").arg(i),tr("Priority","Freemind-Flag"));
2379     }
2380
2381     flag=new Flag(":/freemind/back.png");
2382     flag->setVisible(false);
2383     setupFlag (flag,standardFlagsToolbar,"freemind-back",tr("Back","Freemind-Flag"));
2384
2385     flag=new Flag(":/freemind/forward.png");
2386     flag->setVisible(false);
2387     setupFlag (flag,standardFlagsToolbar,"freemind-forward",tr("forward","Freemind-Flag"));
2388
2389     flag=new Flag(":/freemind/attach.png");
2390     flag->setVisible(false);
2391     setupFlag (flag,standardFlagsToolbar,"freemind-attach",tr("Look here","Freemind-Flag"));
2392
2393     flag=new Flag(":/freemind/clanbomber.png");
2394     flag->setVisible(false);
2395     setupFlag (flag,standardFlagsToolbar,"freemind-clanbomber",tr("Dangerous","Freemind-Flag"));
2396
2397     flag=new Flag(":/freemind/desktopnew.png");
2398     flag->setVisible(false);
2399     setupFlag (flag,standardFlagsToolbar,"freemind-desktopnew",tr("Don't flagrget","Freemind-Flag"));
2400
2401     flag=new Flag(":/freemind/flag.png");
2402     flag->setVisible(false);
2403     setupFlag (flag,standardFlagsToolbar,"freemind-flag",tr("Flag","Freemind-Flag"));
2404
2405
2406     flag=new Flag(":/freemind/gohome.png");
2407     flag->setVisible(false);
2408     setupFlag (flag,standardFlagsToolbar,"freemind-gohome",tr("Home","Freemind-Flag"));
2409
2410     flag=new Flag(":/freemind/kaddressbook.png");
2411     flag->setVisible(false);
2412     setupFlag (flag,standardFlagsToolbar,"freemind-kaddressbook",tr("Telephone","Freemind-Flag"));
2413
2414     flag=new Flag(":/freemind/knotify.png");
2415     flag->setVisible(false);
2416     setupFlag (flag,standardFlagsToolbar,"freemind-knotify",tr("Music","Freemind-Flag"));
2417
2418     flag=new Flag(":/freemind/korn.png");
2419     flag->setVisible(false);
2420     setupFlag (flag,standardFlagsToolbar,"freemind-korn",tr("Mailbox","Freemind-Flag"));
2421
2422     flag=new Flag(":/freemind/mail.png");
2423     flag->setVisible(false);
2424     setupFlag (flag,standardFlagsToolbar,"freemind-mail",tr("Maix","Freemind-Flag"));
2425
2426     flag=new Flag(":/freemind/password.png");
2427     flag->setVisible(false);
2428     setupFlag (flag,standardFlagsToolbar,"freemind-password",tr("Password","Freemind-Flag"));
2429
2430     flag=new Flag(":/freemind/pencil.png");
2431     flag->setVisible(false);
2432     setupFlag (flag,standardFlagsToolbar,"freemind-pencil",tr("To be improved","Freemind-Flag"));
2433
2434     flag=new Flag(":/freemind/stop.png");
2435     flag->setVisible(false);
2436     setupFlag (flag,standardFlagsToolbar,"freemind-stop",tr("Stop","Freemind-Flag"));
2437
2438     flag=new Flag(":/freemind/wizard.png");
2439     flag->setVisible(false);
2440     setupFlag (flag,standardFlagsToolbar,"freemind-wizard",tr("Magic","Freemind-Flag"));
2441
2442     flag=new Flag(":/freemind/xmag.png");
2443     flag->setVisible(false);
2444     setupFlag (flag,standardFlagsToolbar,"freemind-xmag",tr("To be discussed","Freemind-Flag"));
2445
2446     flag=new Flag(":/freemind/bell.png");
2447     flag->setVisible(false);
2448     setupFlag (flag,standardFlagsToolbar,"freemind-bell",tr("Reminder","Freemind-Flag"));
2449
2450     flag=new Flag(":/freemind/bookmark.png");
2451     flag->setVisible(false);
2452     setupFlag (flag,standardFlagsToolbar,"freemind-bookmark",tr("Excellent","Freemind-Flag"));
2453
2454     flag= new Flag(":/freemind/penguin.png");
2455     flag->setVisible(false);
2456     setupFlag (flag,standardFlagsToolbar,"freemind-penguin",tr("Linux","Freemind-Flag"));
2457
2458     flag=new Flag (":/freemind/licq.png");
2459     flag->setVisible(false);
2460     setupFlag (flag,standardFlagsToolbar,"freemind-licq",tr("Sweet","Freemind-Flag"));
2461 }
2462
2463 void Main::setupFlag (Flag *flag, QToolBar *tb, const QString &name, const QString &tooltip, const QKeySequence &keyseq)
2464 {
2465     flag->setName(name);
2466     flag->setToolTip (tooltip);
2467     QAction *a;
2468     if (tb)
2469     {
2470         a=new QAction (flag->getPixmap(),name,this);
2471         // StandardFlag
2472         flag->setAction (a);
2473         a->setVisible (flag->isVisible());
2474         a->setCheckable(true);
2475         a->setObjectName(name);
2476         a->setToolTip(tooltip);
2477         if (keyseq != 0)
2478         {
2479             a->setShortcut (keyseq);
2480             a->setShortcutContext (Qt::WidgetShortcut);
2481
2482             // Allow mapEditors to actually trigger this action
2483             mapEditorActions.append( a );
2484             taskEditorActions.append( a );
2485         }
2486
2487         tb->addAction(a);
2488         connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
2489         standardFlagsMaster->addFlag (flag);
2490     } else
2491     {
2492         // SystemFlag
2493         systemFlagsMaster->addFlag (flag);
2494     }
2495 }
2496
2497 // Network Actions
2498 void Main::setupNetworkActions()
2499 {
2500     if (!settings.value( "/mainwindow/showTestMenu",false).toBool() ) return;
2501
2502     QAction *a;
2503
2504     a = new QAction(  "Start TCPserver for MapEditor",this);
2505     //a->setShortcut ( Qt::ALT + Qt::Key_T );    
2506     connect( a, SIGNAL( triggered() ), this, SLOT( networkStartServer() ) );
2507
2508     a = new QAction(  "Connect MapEditor to server",this);
2509     //a->setShortcut ( Qt::ALT + Qt::Key_C );
2510     connect( a, SIGNAL( triggered() ), this, SLOT( networkConnect() ) );
2511 }
2512
2513 // Settings Actions
2514 void Main::setupSettingsActions()
2515 {
2516     QMenu *settingsMenu = menuBar()->addMenu( tr( "Settings" ));
2517
2518     QAction *a;
2519
2520     a = new QAction( tr( "Check for release notes and updates","Settings action"), this);
2521     a->setCheckable(true);
2522     a->setChecked ( settings.value ("/downloads/enabled",true).toBool());
2523     connect( a, SIGNAL( triggered() ), this, SLOT( settingsToggleDownloads() ) );
2524     settingsMenu->addAction (a);
2525     actionSettingsToggleDownloads = a;
2526
2527     a = new QAction( tr( "Set author for new maps","Settings action"), this);
2528     connect( a, SIGNAL( triggered() ), this, SLOT( settingsDefaultMapAuthor() ) );
2529     settingsMenu->addAction (a);
2530
2531     settingsMenu->addSeparator();
2532
2533     a = new QAction( tr( "Set application to open pdf files","Settings action"), this);
2534     connect( a, SIGNAL( triggered() ), this, SLOT( settingsPDF() ) );
2535     settingsMenu->addAction (a);
2536
2537     a = new QAction( tr( "Set application to open external links","Settings action"), this);
2538     connect( a, SIGNAL( triggered() ), this, SLOT( settingsURL() ) );
2539     settingsMenu->addAction (a);
2540
2541     a = new QAction( tr( "Set application to zip/unzip files","Settings action"), this);
2542     connect( a, SIGNAL( triggered() ), this, SLOT( settingsZipTool() ) );
2543     settingsMenu->addAction (a);
2544
2545     a = new QAction( tr( "Set path for macros","Settings action")+"...", this);
2546     connect( a, SIGNAL( triggered() ), this, SLOT( settingsMacroDir() ) );
2547     settingsMenu->addAction (a);
2548
2549     a = new QAction( tr( "Set number of undo levels","Settings action")+"...", this);
2550     connect( a, SIGNAL( triggered() ), this, SLOT( settingsUndoLevels() ) );
2551     settingsMenu->addAction (a);
2552
2553     settingsMenu->addSeparator();
2554
2555     a = new QAction( tr( "Autosave","Settings action"), this);
2556     a->setCheckable(true);
2557     a->setChecked ( settings.value ("/system/autosave/use",true).toBool());
2558     settingsMenu->addAction (a);
2559     actionSettingsToggleAutosave=a;
2560
2561     a = new QAction( tr( "Autosave time","Settings action")+"...", this);
2562     connect( a, SIGNAL( triggered() ), this, SLOT( settingsAutosaveTime() ) );
2563     settingsMenu->addAction (a);
2564     actionSettingsAutosaveTime=a;
2565
2566     // Disable certain actions during testing
2567     if (testmode)
2568     {
2569         actionSettingsToggleAutosave->setChecked (false);
2570         actionSettingsToggleAutosave->setEnabled (false);
2571         actionSettingsAutosaveTime->setEnabled (false);
2572     }
2573
2574     a = new QAction( tr( "Write backup file on save","Settings action"), this);
2575     a->setCheckable(true);
2576     a->setChecked ( settings.value ("/system/writeBackupFile",false).toBool());
2577     connect( a, SIGNAL( triggered() ), this, SLOT( settingsToggleWriteBackupFile() ) );
2578     settingsMenu->addAction (a);
2579     actionSettingsWriteBackupFile=a;
2580
2581     settingsMenu->addSeparator();
2582
2583     a = new QAction( tr( "Edit branch after adding it","Settings action" ), this );
2584     a->setCheckable(true);
2585     a->setChecked ( settings.value ("/mapeditor/editmode/autoEditNewBranch",true).toBool());
2586     settingsMenu->addAction (a);
2587     actionSettingsAutoEditNewBranch=a;
2588
2589     a= new QAction( tr( "Select branch after adding it","Settings action" ), this );
2590     a->setCheckable(true);
2591     a->setChecked ( settings.value ("/mapeditor/editmode/autoSelectNewBranch",false).toBool() );
2592     settingsMenu->addAction (a);
2593     actionSettingsAutoSelectNewBranch=a;
2594
2595     a= new QAction(tr( "Select existing heading","Settings action" ), this);
2596     a->setCheckable(true);
2597     a->setChecked ( settings.value ("/mapeditor/editmode/autoSelectText",true).toBool() );
2598     settingsMenu->addAction (a);
2599     actionSettingsAutoSelectText=a;
2600
2601     a= new QAction( tr( "Exclusive flags","Settings action" ), this);
2602     a->setCheckable(true);
2603     a->setChecked ( settings.value ("/mapeditor/editmode/useFlagGroups",true).toBool() );
2604     settingsMenu->addAction (a);
2605     actionSettingsUseFlagGroups=a;
2606
2607     a= new QAction( tr( "Use hide flags","Settings action" ), this);
2608     a->setCheckable(true);
2609     a->setChecked ( settings.value ("/export/useHideExport",true).toBool() );
2610     settingsMenu->addAction (a);
2611     actionSettingsUseHideExport=a;
2612
2613     settingsMenu->addSeparator();
2614
2615     a = new QAction( tr( "Number of visible parents in task editor","Settings action"), this); 
2616     connect( a, SIGNAL( triggered() ), this, SLOT( settingsShowParentsLevelTasks() ) );
2617     settingsMenu->addAction (a);
2618     actionSettingsShowParentsLevelTasks=a;
2619
2620     a = new QAction( tr( "Number of visible parents in find results window","Settings action"), this); 
2621     connect( a, SIGNAL( triggered() ), this, SLOT( settingsShowParentsLevelFindResults() ) );
2622     settingsMenu->addAction (a);
2623     actionSettingsShowParentsLevelFindResults=a;
2624
2625     a = new QAction( tr( "Animation","Settings action"), this);
2626     a->setCheckable(true);
2627     a->setChecked (settings.value("/animation/use",true).toBool() );
2628     connect( a, SIGNAL( triggered() ), this, SLOT( settingsToggleAnimation() ) );
2629     settingsMenu->addAction (a);
2630     actionSettingsUseAnimation=a;
2631
2632     a = new QAction( tr( "Automatic layout","Settings action"), this);
2633     a->setCheckable(true);
2634     a->setChecked ( settings.value ("/mainwindow/autoLayout/use",true).toBool());
2635     connect( a, SIGNAL( triggered() ), this, SLOT( settingsToggleAutoLayout() ) );
2636     settingsMenu->addAction (a);
2637     actionSettingsToggleAutoLayout=a;
2638 }
2639
2640 // Test Actions
2641 void Main::setupTestActions()
2642 {
2643     QMenu *testMenu = menuBar()->addMenu( tr( "Test" ));
2644
2645     QString tag = "Testing";
2646     QAction *a;
2647     a = new QAction( "Test function 1" , this);
2648     a->setShortcut (Qt::ALT + Qt::Key_T); 
2649     testMenu->addAction(a);
2650     switchboard.addSwitch ("mapTest1", shortcutScope, a, tag);
2651     connect( a, SIGNAL( triggered() ), this, SLOT( testFunction1() ) );
2652
2653     a = new QAction( "Test function 2" , this);
2654     testMenu->addAction(a);
2655     connect( a, SIGNAL( triggered() ), this, SLOT( testFunction2() ) );
2656
2657     a = new QAction( "Toggle hide export mode" , this);
2658     a->setCheckable (true);
2659     a->setChecked (false);
2660     testMenu->addAction(a);
2661     connect( a, SIGNAL( triggered() ), this, SLOT( toggleHideExport() ) );
2662     actionToggleHideMode=a;
2663
2664     a = new QAction( "Toggle winter mode" , this);
2665     a->setShortcut (Qt::ALT + Qt::Key_Asterisk); 
2666     testMenu->addAction(a);
2667     switchboard.addSwitch ("mapWinterMode", shortcutScope, a, tag);
2668     connect( a, SIGNAL( triggered() ), this, SLOT( toggleWinter() ) );
2669     actionToggleWinter=a;
2670 }
2671
2672 // Help Actions
2673 void Main::setupHelpActions()
2674 {
2675     QMenu *helpMenu = menuBar()->addMenu ( tr( "&Help","Help menubar entry" ));
2676
2677     QAction *a;
2678     a = new QAction(  tr( "Open VYM Documentation (pdf) ","Help action" ), this );
2679     helpMenu->addAction(a);
2680     connect( a, SIGNAL( triggered() ), this, SLOT( helpDoc() ) );
2681
2682     a = new QAction(  tr( "Open VYM example maps ","Help action" ), this );
2683     helpMenu->addAction(a);
2684     connect( a, SIGNAL( triggered() ), this, SLOT( helpDemo() ) );
2685     helpMenu->addSeparator();
2686
2687     a = new QAction(  tr( "Download and show release notes","Help action" ), this );
2688     helpMenu->addAction(a);
2689     connect( a, SIGNAL( triggered() ), this, SLOT( checkReleaseNotes() ) );
2690
2691     a = new QAction(  tr( "Check, if updates are available","Help action" ), this );
2692     helpMenu->addAction(a);
2693     connect( a, SIGNAL( triggered() ), this, SLOT( checkUpdates() ) );
2694     helpMenu->addSeparator();
2695
2696     a = new QAction(  tr( "Show keyboard shortcuts","Help action" ), this );
2697     helpMenu->addAction(a);
2698     connect( a, SIGNAL( triggered() ), this, SLOT( helpShortcuts() ) );
2699
2700     a = new QAction( tr("Debug info","Option to show debugging info") , this);  
2701     helpMenu->addAction(a);
2702     connect( a, SIGNAL( triggered() ), this, SLOT( debugInfo() ) );
2703
2704     a = new QAction( tr( "About VYM","Help action" ), this);
2705     connect( a, SIGNAL( triggered() ), this, SLOT( helpAbout() ) );
2706     helpMenu->addAction (a);
2707
2708     a = new QAction( tr( "About QT","Help action" ), this);
2709     connect( a, SIGNAL( triggered() ), this, SLOT( helpAboutQT() ) );
2710     helpMenu->addAction (a);
2711 }
2712
2713 // Context Menus
2714 void Main::setupContextMenus()
2715 {
2716     // Context menu for goto/move targets  (populated on demand)
2717     targetsContextMenu = new QMenu (this);
2718
2719     // Context Menu for branch or mapcenter
2720     branchContextMenu =new QMenu (this);
2721     branchContextMenu->addAction (actionViewTogglePropertyEditor);
2722     branchContextMenu->addSeparator();  
2723
2724         // Submenu "Add"
2725         branchAddContextMenu =branchContextMenu->addMenu (tr("Add"));
2726         branchAddContextMenu->addAction (actionPaste );
2727         branchAddContextMenu->addAction ( actionAddMapCenter );
2728         branchAddContextMenu->addAction ( actionAddBranch );
2729         branchAddContextMenu->addAction ( actionAddBranchBefore );
2730         branchAddContextMenu->addAction ( actionAddBranchAbove);
2731         branchAddContextMenu->addAction ( actionAddBranchBelow );
2732         branchAddContextMenu->addSeparator();   
2733         branchAddContextMenu->addAction ( actionImportAdd );
2734         branchAddContextMenu->addAction ( actionImportReplace );
2735
2736         // Submenu "Remove"
2737         branchRemoveContextMenu =branchContextMenu->addMenu (tr ("Remove","Context menu name"));
2738         branchRemoveContextMenu->addAction (actionCut);
2739         branchRemoveContextMenu->addAction ( actionDelete );
2740         branchRemoveContextMenu->addAction ( actionDeleteKeepChildren );
2741         branchRemoveContextMenu->addAction ( actionDeleteChildren );
2742         
2743
2744     branchContextMenu->addAction(actionSaveBranch);
2745     branchContextMenu->addAction( actionFileNewCopy);
2746     branchContextMenu->addAction(actionDetach);
2747
2748     branchContextMenu->addSeparator();  
2749     branchContextMenu->addAction ( actionLoadImage);
2750     if (settings.value( "/mainwindow/showTestMenu",false).toBool() )
2751         branchContextMenu->addAction ( actionAddAttribute);
2752
2753
2754     branchContextMenu->addSeparator();  
2755
2756     // Context menu for tasks
2757     taskContextMenu = branchContextMenu->addMenu (tr("Tasks","Context menu"));
2758         taskContextMenu->addAction (actionToggleTask);
2759         taskContextMenu->addAction (actionCycleTaskStatus);
2760         taskContextMenu->addSeparator();
2761         taskContextMenu->addAction (actionTaskSleep0);
2762         taskContextMenu->addAction (actionTaskSleepN);
2763         taskContextMenu->addAction (actionTaskSleep1);
2764         taskContextMenu->addAction (actionTaskSleep2);
2765         taskContextMenu->addAction (actionTaskSleep3);
2766         taskContextMenu->addAction (actionTaskSleep5);
2767         taskContextMenu->addAction (actionTaskSleep7);
2768         taskContextMenu->addAction (actionTaskSleep14);
2769         taskContextMenu->addAction (actionTaskSleep28);
2770
2771     // Submenu for Links (URLs, vymLinks)
2772     branchLinksContextMenu =new QMenu (this);
2773
2774         branchLinksContextMenu=branchContextMenu->addMenu(tr("References (URLs, vymLinks, ...)","Context menu name"));  
2775         branchLinksContextMenu->addAction ( actionOpenURL );
2776         branchLinksContextMenu->addAction ( actionOpenURLTab );
2777         branchLinksContextMenu->addAction ( actionOpenMultipleVisURLTabs );
2778         branchLinksContextMenu->addAction ( actionOpenMultipleURLTabs );
2779         branchLinksContextMenu->addAction ( actionURLNew );
2780         branchLinksContextMenu->addAction ( actionLocalURL );
2781         branchLinksContextMenu->addAction ( actionGetURLsFromNote );
2782         branchLinksContextMenu->addAction ( actionHeading2URL );
2783         branchLinksContextMenu->addAction ( actionBugzilla2URL );
2784         branchLinksContextMenu->addAction ( actionGetBugzillaData );
2785         branchLinksContextMenu->addAction ( actionGetBugzillaDataSubtree );
2786         if (settings.value( "/mainwindow/showTestMenu",false).toBool() )
2787             branchLinksContextMenu->addAction ( actionFATE2URL );
2788         branchLinksContextMenu->addSeparator(); 
2789         branchLinksContextMenu->addAction ( actionOpenVymLink );
2790         branchLinksContextMenu->addAction ( actionOpenVymLinkBackground );
2791         branchLinksContextMenu->addAction ( actionOpenMultipleVymLinks );
2792         branchLinksContextMenu->addAction ( actionEditVymLink );
2793         branchLinksContextMenu->addAction ( actionDeleteVymLink );
2794         
2795
2796     // Context Menu for XLinks in a branch menu
2797     // This will be populated "on demand" in updateActions
2798     QString tag = tr ("XLinks","Menu for file actions");
2799     branchContextMenu->addSeparator();  
2800     branchXLinksContextMenuEdit =branchContextMenu->addMenu (tr ("Edit XLink","Context menu name"));
2801     connect( 
2802         branchXLinksContextMenuEdit, SIGNAL( triggered(QAction *) ), 
2803         this, SLOT( editEditXLink(QAction * ) ) );
2804     QAction *a;
2805     a = new QAction( tr("Follow XLink","Context menu") , this);
2806     a->setShortcut (Qt::Key_F); 
2807     addAction(a);
2808     switchboard.addSwitch ("mapFollowXLink", shortcutScope, a, tag);
2809     connect( a, SIGNAL( triggered() ), this, SLOT( popupFollowXLink() ) );
2810
2811     branchXLinksContextMenuFollow =branchContextMenu->addMenu (tr ("Follow XLink","Context menu name"));
2812     connect( 
2813         branchXLinksContextMenuFollow, SIGNAL( triggered(QAction *) ), 
2814         this, SLOT( editFollowXLink(QAction * ) ) );
2815
2816
2817
2818     // Context menu for floatimage
2819     floatimageContextMenu =new QMenu (this);
2820     a= new QAction (tr ("Save image","Context action"),this);
2821     connect (a, SIGNAL (triggered()), this, SLOT (editSaveImage()));
2822     floatimageContextMenu->addAction (a);
2823
2824     floatimageContextMenu->addSeparator();  
2825     floatimageContextMenu->addAction(actionCopy);
2826     floatimageContextMenu->addAction(actionCut);
2827
2828     floatimageContextMenu->addSeparator();  
2829     floatimageContextMenu->addAction ( actionFormatHideLinkUnselected );
2830
2831     // Context menu for canvas
2832     canvasContextMenu =new QMenu (this);
2833
2834     canvasContextMenu->addAction (actionAddMapCenter);
2835
2836     canvasContextMenu->addSeparator();   
2837
2838     canvasContextMenu->addAction(actionMapProperties);
2839     canvasContextMenu->addAction(actionFormatFont);
2840
2841     canvasContextMenu->addSeparator();   
2842
2843     canvasContextMenu->addActions(actionGroupFormatLinkStyles->actions() );
2844
2845     canvasContextMenu->addSeparator();   
2846
2847     canvasContextMenu->addAction(actionFormatLinkColorHint);
2848
2849     canvasContextMenu->addSeparator();   
2850
2851     canvasContextMenu->addAction(actionFormatLinkColor);
2852     canvasContextMenu->addAction(actionFormatSelectionColor);
2853     canvasContextMenu->addAction(actionFormatBackColor);
2854     //if (settings.value( "/mainwindow/showTestMenu",false).toBool() )
2855     //    canvasContextMenu->addAction( actionFormatBackImage );  //FIXME-3 makes vym too slow: postponed for later version 
2856
2857
2858     // Menu for last opened files
2859     // Create actions
2860     for (int i = 0; i < MaxRecentFiles; ++i) 
2861     {
2862         recentFileActions[i] = new QAction(this);
2863         recentFileActions[i]->setVisible(false);
2864         fileLastMapsMenu->addAction(recentFileActions[i]);
2865         connect(recentFileActions[i], SIGNAL(triggered()),
2866                 this, SLOT(fileLoadRecent()));
2867     }
2868     setupRecentMapsMenu();
2869 }
2870
2871 void Main::setupRecentMapsMenu()
2872 {
2873     QStringList files = settings.value("/mainwindow/recentFileList").toStringList();
2874
2875     int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles);
2876
2877     for (int i = 0; i < numRecentFiles; ++i) {
2878         QString text = QString("&%1 %2").arg(i + 1).arg(files[i]);
2879         recentFileActions[i]->setText(text);
2880         recentFileActions[i]->setData(files[i]);
2881         recentFileActions[i]->setVisible(true);
2882     }
2883     for (int j = numRecentFiles; j < MaxRecentFiles; ++j)
2884         recentFileActions[j]->setVisible(false);
2885 }
2886
2887 void Main::setupMacros()
2888 {
2889     for (int i = 0; i <= 12; i++) 
2890     {
2891         macroActions[i] = new QAction(this);
2892         macroActions[i]->setData(i);
2893         addAction (macroActions[i]);
2894         connect(macroActions[i], SIGNAL(triggered()), this, SLOT(callMacro()));
2895     }           
2896     macroActions[0]->setShortcut ( Qt::Key_F1 );
2897     macroActions[1]->setShortcut ( Qt::Key_F2 );
2898     macroActions[2]->setShortcut ( Qt::Key_F3 );
2899     macroActions[3]->setShortcut ( Qt::Key_F4 );
2900     macroActions[4]->setShortcut ( Qt::Key_F5 );
2901     macroActions[5]->setShortcut ( Qt::Key_F6 );
2902     macroActions[6]->setShortcut ( Qt::Key_F7 );
2903     macroActions[7]->setShortcut ( Qt::Key_F8 );
2904     macroActions[8]->setShortcut ( Qt::Key_F9 );
2905     macroActions[9]->setShortcut ( Qt::Key_F10 );
2906     macroActions[10]->setShortcut ( Qt::Key_F11 );
2907     macroActions[11]->setShortcut ( Qt::Key_F12 );
2908
2909     macroActions[12]->setShortcut ( Qt::Key_F1 + Qt::SHIFT);
2910 }
2911
2912 void Main::setupToolbars()
2913 {
2914     // File actions
2915     fileToolbar = addToolBar( tr ("File actions toolbar","Toolbar for file actions"));
2916     fileToolbar->setObjectName ("fileTB");
2917     fileToolbar->addAction(actionFileNew);
2918     fileToolbar->addAction(actionFileOpen);
2919     fileToolbar->addAction(actionFileSave);
2920     fileToolbar->addAction(actionFileExportLast);
2921     fileToolbar->addAction(actionFilePrint);
2922
2923     // Undo/Redo and clipboard
2924     clipboardToolbar =addToolBar( tr ("Undo and clipboard toolbar","Toolbar for redo/undo and clipboard"));
2925     clipboardToolbar->setObjectName ("clipboard toolbar");
2926     clipboardToolbar->addAction (actionUndo);
2927     clipboardToolbar->addAction (actionRedo);
2928     clipboardToolbar->addAction (actionCopy);
2929     clipboardToolbar->addAction (actionCut);
2930     clipboardToolbar->addAction (actionPaste);
2931
2932     // Basic edits
2933     editActionsToolbar = addToolBar( tr ("Edit actions toolbar","Toolbar name") );
2934     editActionsToolbar->setObjectName ("basic edit actions TB");
2935     editActionsToolbar->addAction (actionAddMapCenter);
2936     editActionsToolbar->addAction (actionAddBranch);
2937     editActionsToolbar->addAction (actionMoveUp);
2938     editActionsToolbar->addAction (actionMoveDown);
2939     editActionsToolbar->addAction (actionSortChildren);
2940     editActionsToolbar->addAction (actionSortBackChildren);
2941     editActionsToolbar->addAction (actionToggleScroll);
2942     editActionsToolbar->addAction (actionToggleHideExport);
2943     editActionsToolbar->addAction (actionToggleTask);
2944     //editActionsToolbar->addAction (actionExpandAll);
2945     //editActionsToolbar->addAction (actionExpandOneLevel);
2946     //editActionsToolbar->addAction (actionCollapseOneLevel);
2947     //editActionsToolbar->addAction (actionCollapseUnselected);
2948
2949     // Selections
2950     selectionToolbar = addToolBar( tr ("Selection toolbar","Toolbar name") );
2951     selectionToolbar->setObjectName ("toolbar for selecting items");
2952     selectionToolbar->addAction (actionToggleTarget);
2953     selectionToolbar->addAction (actionSelectPrevious);
2954     selectionToolbar->addAction (actionSelectNext);
2955     selectionToolbar->addAction (actionFind);
2956
2957     // URLs and vymLinks
2958     referencesToolbar=addToolBar( tr ("URLs and vymLinks toolbar","Toolbar for URLs and vymlinks"));
2959     referencesToolbar->setObjectName ("URLs and vymlinks toolbar");
2960     //referencesToolbar->addAction (actionOpenURL); //FIXME-4 removed 2015-06-22
2961     referencesToolbar->addAction (actionURLNew);
2962     //referencesToolbar->addAction (actionOpenVymLink)//FIXME-4 removed 2015-06-22;
2963     referencesToolbar->addAction (actionEditVymLink);
2964
2965     // Format and colors
2966     colorsToolbar = addToolBar( tr("Colors toolbar","Colors toolbar name"));
2967     colorsToolbar->setObjectName ("colorsTB");
2968     colorsToolbar->addAction(actionFormatColor);
2969     colorsToolbar->addAction(actionFormatPickColor);
2970     colorsToolbar->addAction(actionFormatColorBranch);
2971     colorsToolbar->addAction(actionFormatColorSubtree);
2972
2973     // Zoom
2974     zoomToolbar = addToolBar( tr("Zoom toolbar","View Toolbar name") );
2975     zoomToolbar->setObjectName ("viewTB");
2976     zoomToolbar->addAction(actionZoomIn);
2977     zoomToolbar->addAction(actionZoomOut);
2978     zoomToolbar->addAction(actionZoomReset);
2979     zoomToolbar->addAction(actionCenterOn);
2980     zoomToolbar->addAction(actionRotateCounterClockwise);
2981     zoomToolbar->addAction(actionRotateClockwise);
2982
2983     // Editors
2984     editorsToolbar = addToolBar( tr("Editors toolbar","Editor Toolbar name") );
2985     editorsToolbar->setObjectName ("editorsTB");
2986     editorsToolbar->addAction (actionViewToggleNoteEditor);
2987     editorsToolbar->addAction (actionViewToggleHeadingEditor);
2988     editorsToolbar->addAction (actionViewToggleTreeEditor);
2989     editorsToolbar->addAction (actionViewToggleTaskEditor);
2990     editorsToolbar->addAction (actionViewToggleSlideEditor);
2991     editorsToolbar->addAction (actionViewToggleScriptEditor);
2992     editorsToolbar->addAction (actionViewToggleHistoryWindow);
2993
2994
2995     // Modifier modes
2996     modModesToolbar = addToolBar( tr ("Modifier modes toolbar","Modifier Toolbar name") );
2997     modModesToolbar->setObjectName ("modesTB");
2998     modModesToolbar->addAction(actionModModeColor);
2999     modModesToolbar->addAction(actionModModeCopy);
3000     modModesToolbar->addAction(actionModModeXLink);
3001     
3002     // Add all toolbars to View menu
3003     toolbarsMenu->addAction (fileToolbar->toggleViewAction() );
3004     toolbarsMenu->addAction (clipboardToolbar->toggleViewAction() );
3005     toolbarsMenu->addAction (editActionsToolbar->toggleViewAction() );
3006     toolbarsMenu->addAction (selectionToolbar->toggleViewAction() );
3007     toolbarsMenu->addAction (colorsToolbar->toggleViewAction() );
3008     toolbarsMenu->addAction (zoomToolbar->toggleViewAction() );
3009     toolbarsMenu->addAction (modModesToolbar->toggleViewAction() );
3010     toolbarsMenu->addAction (referencesToolbar->toggleViewAction() );
3011     toolbarsMenu->addAction (editorsToolbar->toggleViewAction() );
3012
3013     // Default visibility to not overload new users
3014     fileToolbar->show();
3015     clipboardToolbar->show();
3016     editActionsToolbar->show();
3017     selectionToolbar->hide();
3018     colorsToolbar->show();
3019     zoomToolbar->show();
3020     modModesToolbar->hide();
3021     referencesToolbar->hide();
3022     editorsToolbar->hide();
3023
3024 }
3025
3026 VymView* Main::currentView() const
3027 {
3028     if ( tabWidget->currentWidget() )
3029     {
3030         int i=tabWidget->currentIndex();
3031         if (i>=0 && i< vymViews.count() ) return vymViews.at(i);
3032     }
3033     return NULL;
3034 }
3035
3036 MapEditor* Main::currentMapEditor() const
3037 {
3038     if ( tabWidget->currentWidget())
3039         return vymViews.at(tabWidget->currentIndex())->getMapEditor();
3040     return NULL;    
3041 }
3042
3043 uint  Main::currentModelID() const
3044 {
3045     VymModel *m=currentModel();
3046     if (m)
3047         return m->getModelID();
3048     else
3049         return 0;    
3050 }
3051
3052 VymModel* Main::currentModel() const
3053 {
3054     VymView *vv=currentView();
3055     if (vv) 
3056         return vv->getModel();
3057     else
3058         return NULL;    
3059 }
3060
3061 VymModel* Main::getModel(uint id) const 
3062 {
3063     if (id <=0) return NULL;
3064
3065     // Used in BugAgent
3066     for (int i=0; i<vymViews.count();i++)
3067         if (vymViews.at(i)->getModel()->getModelID()==id)
3068             return vymViews.at(i)->getModel();
3069     return NULL;    
3070 }
3071
3072 void Main::gotoModel (VymModel *m)
3073 {
3074     for (int i=0; i<vymViews.count();i++)
3075         if (vymViews.at(i)->getModel()==m)
3076         {
3077             tabWidget->setCurrentIndex (i);
3078             return;
3079         }
3080 }
3081
3082 int Main::modelCount()
3083 {
3084     return vymViews.count();
3085 }
3086
3087 void Main::updateTabName( VymModel *vm)
3088 {
3089     for( int i = 0; i < vymViews.count(); i++)
3090     {
3091         if (vymViews.at(i)->getModel() == vm )
3092         {
3093             if ( vm->isReadOnly() )
3094                 tabWidget->setTabText( i, vm->getFileName() + " " + tr("(readonly)") );
3095             else
3096                 tabWidget->setTabText( i, vm->getFileName() );
3097             break;
3098         }
3099     }
3100 }
3101
3102 void Main::editorChanged()
3103 {
3104     VymModel *vm=currentModel();
3105     if (vm) 
3106     {   
3107         updateNoteEditor (vm->getSelectedIndex() );
3108         updateQueries (vm);
3109
3110         taskEditor->setMapName (vm->getMapName() );
3111     }   
3112
3113     // Update actions to in menus and toolbars according to editor
3114     updateActions();
3115 }
3116
3117 void Main::fileNew()
3118 {
3119     VymModel *vm=new VymModel;
3120
3121     /////////////////////////////////////
3122 //  new ModelTest(vm, this);    
3123     /////////////////////////////////////
3124
3125     VymView *vv=new VymView (vm);
3126     vymViews.append (vv);
3127
3128     tabWidget->addTab (vv,tr("unnamed","MainWindow: name for new and empty file"));
3129     tabWidget->setCurrentIndex (vymViews.count() );
3130     vv->initFocus();
3131
3132     // Create MapCenter for empty map
3133     vm->addMapCenter(false);
3134     vm->makeDefault();
3135
3136     // For the very first map we do not have flagrows yet...
3137     vm->select("mc:");
3138
3139     // Switch to new tab
3140     tabWidget->setCurrentIndex (tabWidget->count() -1);
3141 }
3142
3143 void Main::fileNewCopy() 
3144 {
3145     QString fn="unnamed";
3146     VymModel *srcModel=currentModel();
3147     if (srcModel)
3148     {
3149         srcModel->copy();
3150         fileNew();
3151         VymModel *dstModel=vymViews.last()->getModel();
3152         if (dstModel->select("mc:0"))
3153             dstModel->loadMap (clipboardDir+"/"+clipboardFile,ImportReplace);
3154         else
3155             qWarning ()<<"Main::fileNewCopy couldn't select mapcenter";
3156     }
3157 }
3158
3159 File::ErrorCode Main::fileLoad(QString fn, const LoadMode &lmode, const FileType &ftype) 
3160 {
3161     File::ErrorCode err=File::Success;
3162
3163     // fn is usually the archive, mapfile the file after uncompressing
3164     QString mapfile;
3165
3166     // Make fn absolute (needed for unzip)
3167     fn=QDir (fn).absolutePath();
3168
3169     VymModel *vm;
3170
3171     if (lmode==NewMap)
3172     {
3173         // Check, if map is already loaded
3174         int i=0;
3175         while (i<=tabWidget->count() -1)
3176         {
3177             if (vymViews.at(i)->getModel()->getFilePath() == fn)
3178             {
3179                 // Already there, ask for confirmation
3180                 QMessageBox mb( vymName,
3181                     tr("The map %1\nis already opened."
3182                     "Opening the same map in multiple editors may lead \n"
3183                     "to confusion when finishing working with vym."
3184                     "Do you want to").arg(fn),
3185                     QMessageBox::Warning,
3186                     QMessageBox::Yes | QMessageBox::Default,
3187                     QMessageBox::Cancel | QMessageBox::Escape,
3188                     QMessageBox::NoButton);
3189                 mb.setButtonText( QMessageBox::Yes, tr("Open anyway") );
3190                 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
3191                 switch( mb.exec() ) 
3192                 {
3193                     case QMessageBox::Yes:
3194                         // end loop and load anyway
3195                         i=tabWidget->count();
3196                         break;
3197                     case QMessageBox::Cancel:
3198                         // do nothing
3199                         return File::Aborted;
3200                         break;
3201                 }
3202             }
3203             i++;
3204         }
3205     }
3206
3207
3208     // Try to load map
3209     if ( !fn.isEmpty() )
3210     {
3211         vm = currentModel();
3212         // Check first, if mapeditor exists
3213         // If it is not default AND we want a new map, 
3214         // create a new mapeditor in a new tab
3215         if ( lmode==NewMap && (!vm || !vm->isDefault() )  )
3216         {
3217             vm=new VymModel;
3218             VymView *vv=new VymView (vm);
3219             vymViews.append (vv);
3220
3221             tabWidget->addTab (vv,fn);
3222             vv->initFocus();
3223         }
3224         
3225         // Check, if file exists (important for creating new files
3226         // from command line
3227         if (!QFile(fn).exists() )
3228         {
3229             QMessageBox mb( vymName,
3230                 tr("This map does not exist:\n  %1\nDo you want to create a new one?").arg(fn),
3231                 QMessageBox::Question,
3232                 QMessageBox::Yes ,
3233                 QMessageBox::Cancel | QMessageBox::Default,
3234                 QMessageBox::NoButton );
3235
3236             mb.setButtonText( QMessageBox::Yes, tr("Create"));
3237             mb.setButtonText( QMessageBox::No, tr("Cancel"));
3238
3239             VymModel *vm = currentMapEditor()->getModel();
3240             switch( mb.exec() ) 
3241             {
3242                 case QMessageBox::Yes:
3243                     // Create new map
3244                     vm->setFilePath(fn);
3245                     updateTabName( vm );
3246                     statusBar()->showMessage( "Created " + fn , statusbarTime );
3247                     return File::Success;
3248                         
3249                 case QMessageBox::Cancel:
3250                     // don't create new map
3251                     statusBar()->showMessage( "Loading " + fn + " failed!", statusbarTime );
3252                     int cur=tabWidget->currentIndex();
3253                     tabWidget->setCurrentIndex (tabWidget->count()-1);
3254                     fileCloseMap();
3255                     tabWidget->setCurrentIndex (cur);
3256                     return File::Aborted;
3257             }
3258         }   
3259
3260         if (err!=File::Aborted)
3261         {
3262             // Save existing filename in case  we import
3263             QString fn_org = vm->getFilePath();
3264
3265             // Finally load map into mapEditor
3266             progressDialog.setLabelText (tr("Loading: %1","Progress dialog while loading maps").arg(fn));
3267             vm->setFilePath (fn);
3268             vm->saveStateBeforeLoad (lmode,fn);
3269             err = vm->loadMap(fn,lmode,ftype);
3270
3271             // Restore old (maybe empty) filepath, if this is an import
3272             if (lmode != NewMap)
3273                 vm->setFilePath (fn_org);
3274         }   
3275
3276         // Finally check for errors and go home
3277         if (err == File::Aborted) 
3278         {
3279             if (lmode == NewMap) fileCloseMap();
3280             statusBar()->showMessage( "Could not load " + fn, statusbarTime );
3281         } else 
3282         {
3283             if (lmode == NewMap)
3284             {
3285                 vm->setFilePath (fn);
3286                 updateTabName( vm );
3287                 actionFilePrint->setEnabled (true);
3288             }   
3289             editorChanged();
3290             vm->emitShowSelection();
3291             addRecentMap( fn );
3292             statusBar()->showMessage( "Loaded " + fn, statusbarTime );
3293         }   
3294     }
3295     return err;
3296 }
3297
3298
3299 void Main::fileLoad(const LoadMode &lmode)
3300 {
3301     QString caption;
3302     switch (lmode)
3303     {
3304         case NewMap:
3305             caption=vymName+ " - " +tr("Load vym map");
3306             break;
3307         case ImportAdd:
3308             caption=vymName+ " - " +tr("Import: Add vym map to selection");
3309             break;
3310         case ImportReplace:
3311             caption=vymName+ " - " +tr("Import: Replace selection with vym map");
3312             break;
3313     }
3314
3315     QString filter;
3316     filter+="VYM map " + tr("or","File Dialog") +" Freemind map" + " (*.xml *.vym *.vyp *.mm);;";  
3317     filter+="VYM map (*.vym *.vyp);;";
3318     filter+="VYM Backups (*.vym~);;";
3319     filter+="Freemind map (*.mm);;";
3320     filter+="XML (*.xml);;";
3321     filter+="All (* *.*)";
3322     QStringList fns=QFileDialog::getOpenFileNames( 
3323             this,
3324             caption,
3325             lastMapDir.path(), 
3326             filter);
3327
3328     if (!fns.isEmpty() )
3329     {
3330         initProgressCounter (fns.count() );
3331         lastMapDir.setPath(fns.first().left(fns.first().lastIndexOf ("/")) );
3332         foreach (QString fn, fns)
3333             fileLoad(fn, lmode, getMapType (fn) );                 
3334     }
3335     removeProgressCounter();
3336
3337     fileSaveSession();
3338 }
3339
3340 void Main::fileLoad()
3341 {
3342     fileLoad (NewMap);
3343     tabWidget->setCurrentIndex (tabWidget->count()-1);
3344 }
3345
3346 void Main::fileSaveSession()
3347 {
3348     QStringList flist;
3349     for (int i=0;i<vymViews.count(); i++)
3350         flist.append (vymViews.at(i)->getModel()->getFilePath() );
3351     settings.setValue("/mainwindow/sessionFileList", flist);
3352 }
3353
3354 void Main::fileRestoreSession()
3355 {
3356     QStringList flist= settings.value("/mainwindow/sessionFileList").toStringList();
3357     QStringList::Iterator it=flist.begin();
3358
3359     initProgressCounter (flist.count());
3360     while (it !=flist.end() )
3361     {
3362         FileType type=getMapType (*it);
3363         fileLoad (*it, NewMap,type);
3364         *it++;
3365     }
3366     removeProgressCounter();
3367 }
3368
3369 void Main::fileLoadRecent()
3370 {
3371     QAction *action = qobject_cast<QAction *>(sender());
3372     if (action)
3373     {
3374         initProgressCounter ();
3375         QString fn=action->data().toString();
3376         FileType type=getMapType (fn);
3377         fileLoad (fn, NewMap,type);
3378         removeProgressCounter();
3379         tabWidget->setCurrentIndex (tabWidget->count()-1);
3380     }
3381 }
3382
3383 void Main::addRecentMap (const QString &fileName)
3384 {
3385
3386     QStringList files = settings.value("/mainwindow/recentFileList").toStringList();
3387     files.removeAll(fileName);
3388     files.prepend(fileName);
3389     while (files.size() > MaxRecentFiles)
3390         files.removeLast();
3391
3392     settings.setValue("/mainwindow/recentFileList", files);
3393
3394     setupRecentMapsMenu();
3395 }
3396
3397 void Main::fileSave(VymModel *m, const SaveMode &savemode)
3398 {
3399     if (!m) return;
3400
3401     if (m->isReadOnly() ) return;
3402
3403     if ( m->getFilePath().isEmpty() )
3404     {
3405         // We have  no filepath yet,
3406         // call fileSaveAs() now, this will call fileSave()
3407         // again.
3408         // First switch to editor
3409         fileSaveAs(savemode);
3410         return; // avoid saving twice...
3411     }
3412
3413     if (m->save (savemode)==File::Success)
3414     {
3415         statusBar()->showMessage(
3416                     tr("Saved  %1").arg(m->getFilePath()),
3417                     statusbarTime );
3418     } else
3419         statusBar()->showMessage(
3420                     tr("Couldn't save ").arg(m->getFilePath()),
3421                     statusbarTime );
3422 }
3423
3424 void Main::fileSave()
3425 {
3426     fileSave (currentModel(), CompleteMap);
3427 }
3428
3429 void Main::fileSave(VymModel *m)
3430 {
3431     fileSave (m,CompleteMap);
3432 }
3433
3434 void Main::fileSaveAs(const SaveMode& savemode)
3435 {
3436     if (currentMapEditor())
3437     {
3438         QString filter;
3439         if (savemode == CompleteMap)
3440             filter = "VYM map (*.vym)";
3441         else
3442             filter = "VYM part of map (*vyp)";
3443         filter += ";;All (* *.*)";
3444
3445         QString fn = QFileDialog::getSaveFileName (
3446                     this,
3447                     tr("Save map as"),
3448                     lastMapDir.path(),
3449                     filter,
3450                     NULL,
3451                     QFileDialog::DontConfirmOverwrite);
3452         if (!fn.isEmpty() )
3453         {
3454             // Check for existing file
3455             if (QFile (fn).exists())
3456             {
3457                 QMessageBox mb( vymName,
3458                                 tr("The file %1\nexists already. Do you want to").arg(fn),
3459                                 QMessageBox::Warning,
3460                                 QMessageBox::Yes | QMessageBox::Default,
3461                                 QMessageBox::Cancel | QMessageBox::Escape,
3462                                 QMessageBox::NoButton);
3463                 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3464                 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
3465                 switch( mb.exec() )
3466                 {
3467                 case QMessageBox::Yes:
3468                     // save
3469                     break;
3470                 case QMessageBox::Cancel:
3471                     // do nothing
3472                     return;
3473                     break;
3474                 }
3475                 lastMapDir.setPath(fn.left(fn.lastIndexOf ("/")) );
3476             } else
3477             {
3478                 // New file, add extension to filename, if missing
3479                 // This is always .vym or .vyp, depending on savemode
3480                 if (savemode == CompleteMap)
3481                 {
3482                     if (!fn.contains (".vym") && !fn.contains (".xml"))
3483                         fn += ".vym";
3484                 } else
3485                 {
3486                     if (!fn.contains (".vyp") && !fn.contains (".xml"))
3487                         fn += ".vyp";
3488                 }
3489             }
3490
3491             // Save now
3492             VymModel *m = currentModel();
3493             QString fn_org = m->getFilePath(); // Restore fn later, if savemode != CompleteMap
3494             if (savemode == CompleteMap )
3495             {
3496                 // Check for existing lockfile
3497                 QFile lockFile( fn + ".lock" );
3498                 if (lockFile.exists() )
3499                 {
3500                     QMessageBox::critical( 0, tr( "Critical Error" ), tr("Couldn't save %1,\nbecause of existing lockfile:\n\n%2").arg(fn).arg( lockFile.fileName()  ));
3501                     return;
3502                 }
3503
3504                 if ( !m->renameMap( fn ) )
3505                 {
3506                     QMessageBox::critical( 0, tr( "Critical Error" ), tr("Couldn't save %1").arg( fn ));
3507                     return;
3508                 }
3509             }
3510             fileSave(m, savemode);
3511
3512             // Set name of tab
3513             if (savemode == CompleteMap)
3514                 updateTabName( m );
3515             else
3516             {   // Renaming map to original name, because we only saved the selected part of it
3517                 m->setFilePath (fn_org);
3518             }
3519             return;
3520
3521         }
3522     }
3523 }
3524
3525 void Main::fileSaveAs()
3526 {
3527     fileSaveAs (CompleteMap);
3528 }
3529
3530 void Main::fileImportFirefoxBookmarks()
3531 {
3532     QFileDialog fd;
3533     fd.setDirectory (vymBaseDir.homePath()+"/.mozilla/firefox");
3534     fd.setFileMode (QFileDialog::ExistingFiles);
3535     QStringList filters;
3536     filters<<"Firefox "+tr("Bookmarks")+" (*.html)";
3537     fd.setNameFilters(filters);
3538     fd.setAcceptMode (QFileDialog::AcceptOpen);
3539     fd.setWindowTitle(tr("Import")+" "+"Firefox "+tr("Bookmarks"));
3540
3541     if ( fd.exec() == QDialog::Accepted )
3542     {
3543         ImportFirefoxBookmarks im;
3544         QStringList flist = fd.selectedFiles();
3545         QStringList::Iterator it = flist.begin();
3546         while( it != flist.end() ) 
3547         {
3548             im.setFile (*it);
3549             if (im.transform() && 
3550                 File::Aborted!=fileLoad (im.getTransformedFile(),NewMap,FreemindMap) && 
3551                 currentMapEditor() )
3552                 currentMapEditor()->getModel()->setFilePath ("");
3553             ++it;
3554         }
3555     }
3556 }
3557
3558 void Main::fileImportFreemind()
3559 {
3560     QStringList filters;
3561     filters <<"Freemind map (*.mm)"<<"All files (*)";
3562     QFileDialog fd;
3563     fd.setDirectory (lastMapDir);
3564     fd.setFileMode (QFileDialog::ExistingFiles);
3565     fd.setNameFilters (filters);
3566     fd.setWindowTitle(vymName+ " - " +tr("Load Freemind map"));
3567     fd.setAcceptMode (QFileDialog::AcceptOpen);
3568
3569     QString fn;
3570     if ( fd.exec() == QDialog::Accepted )
3571     {
3572         lastMapDir=fd.directory().path();
3573         QStringList flist = fd.selectedFiles();
3574         QStringList::Iterator it = flist.begin();
3575         while( it != flist.end() ) 
3576         {
3577             fn = *it;
3578             if ( fileLoad (fn,NewMap, FreemindMap)  )
3579             {   
3580                 currentMapEditor()->getModel()->setFilePath ("");
3581             }   
3582             ++it;
3583         }
3584     }
3585 }
3586
3587
3588 void Main::fileImportMM()
3589 {
3590     ImportMM im;
3591
3592     QFileDialog fd;
3593     fd.setDirectory (lastMapDir);
3594     fd.setFileMode (QFileDialog::ExistingFiles);
3595     QStringList filters;
3596     filters<<"Mind Manager (*.mmap)";
3597     fd.setNameFilters (filters);
3598     fd.setAcceptMode (QFileDialog::AcceptOpen);
3599     fd.setWindowTitle(tr("Import")+" "+"Mind Manager");
3600
3601     if ( fd.exec() == QDialog::Accepted )
3602     {
3603         lastMapDir=fd.directory();
3604         QStringList flist = fd.selectedFiles();
3605         QStringList::Iterator it = flist.begin();
3606         while( it != flist.end() ) 
3607         {
3608             im.setFile (*it);
3609             if (im.transform() && 
3610                 File::Success==fileLoad (im.getTransformedFile(),NewMap,VymMap) && 
3611                 currentMapEditor() )
3612                 currentMapEditor()->getModel()->setFilePath ("");
3613             ++it;
3614         }
3615     }
3616 }
3617
3618 void Main::fileImportDir()
3619 {
3620     VymModel *m=currentModel();
3621     if (m) m->importDir();
3622 }
3623
3624 void Main::fileExportXML()
3625 {
3626     VymModel *m=currentModel();
3627     if (m) m->exportXML();
3628 }
3629
3630 void Main::fileExportHTML() 
3631 {
3632     VymModel *m=currentModel();
3633     if (m) m->exportHTML();
3634 }
3635
3636 void Main::fileExportImage()    
3637 {
3638     VymModel *m=currentModel();
3639     if (m) m->exportImage();
3640 }
3641
3642 void Main::fileExportPDF()      
3643 {
3644     VymModel *m=currentModel();
3645     if (m) m->exportPDF();
3646 }
3647
3648 void Main::fileExportSVG()      
3649 {
3650     VymModel *m=currentModel();
3651     if (m) m->exportSVG();
3652 }
3653
3654 void Main::fileExportAO()
3655 {
3656     VymModel *m=currentModel();
3657     if (m) m->exportAO();
3658 }
3659
3660 void Main::fileExportASCII()
3661 {
3662     VymModel *m=currentModel();
3663     if (m) m->exportASCII();
3664 }
3665
3666 void Main::fileExportASCIITasks()
3667 {
3668     VymModel *m=currentModel();
3669     if (m) m->exportASCII(true);
3670 }
3671
3672 void Main::fileExportCSV()  //FIXME-3 not scriptable yet
3673 {
3674     VymModel *m=currentModel();
3675     if (m)
3676     {
3677         ExportCSV ex;
3678         ex.setModel (m);
3679         ex.addFilter ("CSV (*.csv)");
3680         ex.setDirPath(lastImageDir.absolutePath());
3681         ex.setWindowTitle(vymName+ " -" + tr("Export as CSV") + " " + tr("(still experimental)"));
3682         if (ex.execDialog() ) 
3683         {
3684             m->setExportMode(true);
3685             ex.doExport();
3686             m->setExportMode(false);
3687         }
3688     }
3689 }
3690
3691 void Main::fileExportLaTeX()
3692 {
3693     VymModel *m=currentModel();
3694     if (m) m->exportLaTeX();
3695 }
3696
3697 void Main::fileExportOrgMode()  
3698 {
3699     VymModel *m=currentModel();
3700     if (m) m->exportOrgMode();
3701 }
3702
3703 void Main::fileExportTaskjuggler()  //FIXME-3 not scriptable yet
3704 {
3705     ExportTaskjuggler ex;
3706     VymModel *m=currentModel();
3707     if (m)
3708     {
3709         ex.setModel (m);
3710         ex.setWindowTitle ( vymName + " - " + tr("Export to") + " Taskjuggler" + tr("(still experimental)"));
3711         ex.setDirPath (lastImageDir.absolutePath());
3712         ex.addFilter ("Taskjuggler (*.tjp)");
3713
3714         if (ex.execDialog() )
3715         {
3716             m->setExportMode(true);
3717             ex.doExport();
3718             m->setExportMode(false);
3719         }
3720     }
3721 }
3722
3723 void Main::fileExportImpress()  
3724 {
3725     ExportOOFileDialog fd;
3726     // TODO add preview in dialog
3727     fd.setWindowTitle(vymName+" - "+tr("Export to")+" LibreOffice");
3728     fd.setDirectory (QDir().current());
3729     fd.setAcceptMode (QFileDialog::AcceptSave);
3730     fd.setFileMode (QFileDialog::AnyFile);
3731     if (fd.foundConfig())
3732     {
3733         if ( fd.exec() == QDialog::Accepted )
3734         {
3735             if (!fd.selectedFiles().isEmpty())
3736             {
3737                 QString fn=fd.selectedFiles().first();
3738                 if (!fn.contains (".odp")) fn +=".odp";
3739
3740                 //lastImageDir=fn.left(fn.findRev ("/"));
3741                 VymModel *m=currentModel();
3742                 if (m) m->exportImpress (fn,fd.selectedConfig());
3743             }
3744         }
3745     } else
3746     {
3747         QMessageBox::warning(0,
3748                              tr("Warning"),
3749                              tr("Couldn't find configuration for export to LibreOffice\n"));
3750     }
3751 }
3752
3753 void Main::fileExportLast()
3754 {
3755     VymModel *m=currentModel();
3756     if (m) m->exportLast();
3757 }
3758
3759 bool Main::fileCloseMap(int i)
3760 {
3761     VymModel *m;
3762     VymView *vv;
3763     if ( i<0) i  = tabWidget->currentIndex();
3764
3765     vv = vymViews.at(i);
3766     m  = vv->getModel();
3767
3768     if (m)
3769     {
3770         if (m->hasChanged())
3771         {
3772             QMessageBox mb( vymName,
3773                             tr("The map %1 has been modified but not saved yet. Do you want to").arg(m->getFileName()),
3774                             QMessageBox::Warning,
3775                             QMessageBox::Yes | QMessageBox::Default,
3776                             QMessageBox::No,
3777                             QMessageBox::Cancel | QMessageBox::Escape );
3778             mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
3779             mb.setButtonText( QMessageBox::No, tr("Discard changes"));
3780             mb.setModal (true);
3781             mb.show();
3782             switch( mb.exec() )
3783             {
3784             case QMessageBox::Yes:
3785                 // save and close
3786                 fileSave(m, CompleteMap);
3787                 break;
3788             case QMessageBox::No:
3789                 // close  without saving
3790                 break;
3791             case QMessageBox::Cancel:
3792                 // do nothing
3793                 return true;
3794             }
3795         }
3796
3797         vymViews.removeAt (i);
3798         tabWidget->removeTab (i);
3799
3800         // Destroy stuff, order is important
3801         delete (m->getMapEditor());
3802         delete(vv);
3803         delete (m);
3804
3805         updateActions();
3806         return false;
3807     }
3808     return true; // Better don't exit vym if there is no currentModel()...
3809 }
3810
3811 void Main::filePrint()
3812 {
3813     if (currentMapEditor())
3814         currentMapEditor()->print();
3815 }
3816
3817 bool Main::fileExitVYM()    
3818 {
3819     fileSaveSession();
3820
3821     // Check if one or more editors have changed
3822     while (vymViews.count()>0)
3823     {
3824         tabWidget->setCurrentIndex(0);
3825         if (fileCloseMap()) return true;
3826     }
3827     qApp->quit();
3828     return false;
3829 }
3830
3831 void Main::editUndo()
3832 {
3833     VymModel *m=currentModel();
3834     if (m) m->undo();
3835 }
3836
3837 void Main::editRedo()      
3838 {
3839     VymModel *m=currentModel();
3840     if (m) m->redo();
3841 }
3842
3843 void Main::gotoHistoryStep (int i)     
3844 {
3845     VymModel *m=currentModel();
3846     if (m) m->gotoHistoryStep(i);
3847 }
3848
3849 void Main::editCopy()
3850 {
3851     VymModel *m=currentModel();
3852     if (m) m->copy();
3853 }
3854
3855 void Main::editPaste()
3856 {
3857     VymModel *m=currentModel();
3858     if (m) m->paste();
3859 }
3860
3861 void Main::editCut()
3862 {
3863     VymModel *m=currentModel();
3864     if (m) m->cut();
3865 }
3866
3867 bool Main::openURL(const QString &url)
3868 {
3869     if (url.isEmpty()) return false;
3870
3871     QString browser=settings.value("/system/readerURL" ).toString();
3872     QStringList args;
3873     args<<url;
3874     if (!QProcess::startDetached(browser,args,QDir::currentPath(),browserPID))
3875     {
3876         // try to set path to browser
3877         QMessageBox::warning(0, 
3878             tr("Warning"),
3879             tr("Couldn't find a viewer to open %1.\n").arg(url)+
3880             tr("Please use Settings->")+tr("Set application to open an URL"));
3881         settingsURL() ; 
3882         return false;
3883     }   
3884     return true;
3885 }
3886
3887 void Main::openTabs(QStringList urls)
3888 {
3889     if (urls.isEmpty()) return;
3890         
3891     QStringList args;
3892     QString browser=settings.value("/system/readerURL" ).toString();
3893 #if defined(VYM_DBUS)
3894     if ( browser.contains("konqueror") && 
3895             (browserPID==0 || !QDBusConnection::sessionBus().interface()->registeredServiceNames().value().contains (QString("org.kde.konqueror-%1").arg(*browserPID)))
3896        )         
3897     {
3898         // Start a new browser, if there is not one running already or
3899         // if a previously started konqueror is gone.
3900         if (debug) qDebug() <<"Main::openTabs no konqueror with PID "<<*browserPID<<" found";
3901         openURL(urls.takeFirst());
3902         if (debug) qDebug() << "Main::openTabs Started konqueror, new PID is "<<*browserPID;
3903     }
3904
3905     if (browser.contains("konqueror"))
3906     {
3907         foreach (QString u, urls) 
3908         {
3909             // Open new browser
3910             // Try to open new tab in existing konqueror started previously by vym
3911             args.clear();
3912
3913             args<< QString("org.kde.konqueror-%1").arg(*browserPID)<<
3914                 "/konqueror/MainWindow_1"<<
3915                 "newTab" << 
3916                 u <<
3917                 "false";
3918             if (!QProcess::startDetached ("qdbus",args))
3919             {
3920                 QMessageBox::warning(0, 
3921                     tr("Warning"),
3922                     tr("Couldn't start %1 to open a new tab in %2.").arg("qdbus").arg("konqueror"));
3923                 return;
3924             }
3925         }
3926         return; 
3927     } 
3928 #endif
3929     //
3930     // Other browser, e.g. xdg-open
3931     // Just open all urls and leave it to the system to cope with it
3932     foreach (QString u, urls) 
3933     {
3934         openURL(u);
3935
3936         // Now give the browser some time before opening the next tab
3937 #if defined(Q_OS_WIN32)
3938         // There's no sleep in VCEE, replace it with Qt's QThread::wait().
3939         this->thread()->wait(1000);
3940 #else
3941         sleep (1);      
3942 #endif
3943     }
3944 }
3945
3946
3947 void Main::editOpenURL()
3948 {
3949     // Open new browser
3950     VymModel *m=currentModel();
3951     if (m)
3952     {   
3953         QString url=m->getURL();
3954         if (url=="") return;
3955         openURL(url);
3956     }   
3957 }
3958 void Main::editOpenURLTab()
3959 {
3960     VymModel *m=currentModel();
3961     if (m)
3962     {   
3963         QStringList urls;
3964         urls.append(m->getURL());
3965         openTabs (urls);
3966     }   
3967 }
3968
3969 void Main::editOpenMultipleVisURLTabs(bool ignoreScrolled)
3970 {
3971     VymModel *m=currentModel();
3972     if (m)
3973     {   
3974         QStringList urls;
3975         urls=m->getURLs(ignoreScrolled);
3976         openTabs (urls);
3977     }   
3978 }
3979
3980 void Main::editOpenMultipleURLTabs()
3981 {
3982     editOpenMultipleVisURLTabs (false);
3983 }
3984
3985 void Main::editNote2URLs()
3986 {
3987     VymModel *m=currentModel();
3988     if (m) m->note2URLs();
3989 }
3990
3991 void Main::editURL()
3992 {
3993     VymModel *m=currentModel();
3994     if (m) 
3995     {
3996         QInputDialog *dia=new QInputDialog (this);
3997         dia->setLabelText (tr("Enter URL:"));
3998         dia->setWindowTitle (vymName);
3999         dia->setInputMode (QInputDialog::TextInput);
4000         TreeItem *selti=m->getSelectedItem();
4001         if (selti) dia->setTextValue (selti->getURL());
4002         dia->resize(width()*0.6,80);
4003         centerDialog(dia);
4004
4005         if ( dia->exec() ) m->setURL (dia->textValue() );
4006         delete dia;
4007     }
4008 }
4009
4010 void Main::editLocalURL()
4011 {
4012     VymModel *m=currentModel();
4013     if (m) 
4014     {
4015         TreeItem *selti=m->getSelectedItem();
4016         if (selti)
4017         {           
4018             QString filter;
4019             filter+="All files (*);;";
4020             filter+=tr("HTML","Filedialog") + " (*.html,*.htm);;";
4021             filter+=tr("Text","Filedialog") + " (*.txt);;";
4022             filter+=tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc);;";
4023             filter+=tr("Textdocument","Filedialog") +" (*.odw,*.sxw);;";
4024             filter+=tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
4025
4026             QString fn=QFileDialog::getOpenFileName( 
4027                 this,
4028                 vymName+" - " +tr("Set URL to a local file"), 
4029                 lastMapDir.path(), 
4030                 filter);
4031
4032             if (!fn.isEmpty() )
4033             {
4034                 lastMapDir.setPath(fn.left(fn.lastIndexOf ("/")) );
4035                 if (!fn.startsWith("file://") ) 
4036                     fn="file://" + fn;
4037                 m->setURL (fn);
4038             }
4039         }
4040     }
4041 }
4042
4043 void Main::editHeading2URL()
4044 {
4045     VymModel *m=currentModel();
4046     if (m) m->editHeading2URL();
4047 }
4048
4049 void Main::editBugzilla2URL()
4050 {
4051     VymModel *m=currentModel();
4052     if (m) m->editBugzilla2URL();
4053 }
4054
4055 void Main::getBugzillaData()
4056 {
4057     VymModel *m=currentModel();
4058     /*
4059     QProgressDialog progress ("Doing stuff","cancl",0,10,this);
4060     progress.setWindowModality(Qt::WindowModal);
4061     //progress.setCancelButton (NULL);
4062     progress.show();
4063     progress.setMinimumDuration (0);
4064     progress.setValue (1);
4065     progress.setValue (5);
4066     progress.update();
4067     */
4068     /*
4069     QProgressBar *pb=new QProgressBar;
4070     pb->setMinimum (0);
4071     pb->setMaximum (0);
4072     pb->show();
4073     pb->repaint();
4074     */
4075     if (m) m->getBugzillaData(false);
4076 }
4077
4078 void Main::getBugzillaDataSubtree()
4079 {
4080     VymModel *m=currentModel();
4081     if (m) m->getBugzillaData(true);
4082 }
4083
4084 void Main::editFATE2URL()
4085 {
4086     VymModel *m=currentModel();
4087     if (m) m->editFATE2URL();
4088 }
4089
4090 void Main::editHeading()
4091 {
4092     MapEditor *me=currentMapEditor();
4093     if (me) me->editHeading();
4094 }
4095
4096 void Main::editHeadingFinished(VymModel *m)
4097 {
4098     if (m)
4099     {
4100         if (!actionSettingsAutoSelectNewBranch->isChecked() &&
4101                 !prevSelection.isEmpty())
4102             m->select(prevSelection);
4103         prevSelection = "";
4104     }
4105 }
4106
4107 void Main::openVymLinks(const QStringList &vl, bool background)
4108 {
4109     QStringList vlmin;
4110     int index = -1;
4111     for (int j = 0; j < vl.size(); ++j)
4112     {
4113         // compare path with already loaded maps
4114         QString absPath = QFileInfo(vl.at(j)).absoluteFilePath();
4115         index = -1;
4116         for (int i = 0;i <= vymViews.count() -1; i++)
4117         {
4118             if ( absPath == vymViews.at(i)->getModel()->getFilePath() )
4119             {
4120                 index = i;
4121                 break;
4122             }
4123         }   
4124         if (index < 0) vlmin.append ( absPath );
4125     }
4126
4127     
4128     progressCounterTotal = vlmin.size();
4129     for (int j = 0; j < vlmin.size(); j++)
4130     {
4131         // Load map
4132         if (!QFile(vlmin.at(j)).exists() )
4133             QMessageBox::critical( 0, tr( "Critical Error" ),
4134                tr("Couldn't open map %1").arg(vlmin.at(j)));
4135         else
4136         {
4137             fileLoad (vlmin.at(j), NewMap,VymMap);
4138             if (!background) 
4139                 tabWidget->setCurrentIndex (tabWidget->count()-1);      
4140         }
4141     }       
4142     // Go to tab containing the map
4143     if (index >= 0)
4144         tabWidget->setCurrentIndex (index);     
4145     removeProgressCounter();
4146 }
4147
4148 void Main::editOpenVymLink(bool background)
4149 {
4150     VymModel *m = currentModel();
4151     if (m)
4152     {
4153         QStringList vl;
4154         vl.append(m->getVymLink()); 
4155         openVymLinks (vl, background);
4156     }
4157 }
4158
4159 void Main::editOpenVymLinkBackground()
4160 {
4161     editOpenVymLink (true);
4162 }
4163
4164 void Main::editOpenMultipleVymLinks()
4165 {
4166     QString currentVymLink;
4167     VymModel *m = currentModel();
4168     if (m)
4169     {
4170         QStringList vl = m->getVymLinks();
4171         openVymLinks (vl, true);
4172     }
4173 }
4174
4175 void Main::editVymLink()
4176 {
4177     VymModel *m = currentModel();
4178     if (m)
4179     {
4180         BranchItem *bi = m->getSelectedBranch();
4181         if (bi)
4182         {           
4183             QStringList filters;
4184             filters <<"VYM map (*.vym)";
4185             QFileDialog fd;
4186             fd.setWindowTitle (vymName+" - " +tr("Link to another map"));
4187             fd.setNameFilters (filters);
4188             fd.setWindowTitle(vymName+" - " +tr("Link to another map"));
4189             fd.setDirectory (lastMapDir);
4190             fd.setAcceptMode (QFileDialog::AcceptOpen);
4191             if (! bi->getVymLink().isEmpty() )
4192                 fd.selectFile( bi->getVymLink() );
4193             fd.show();
4194
4195             QString fn;
4196             if ( fd.exec() == QDialog::Accepted &&!fd.selectedFiles().isEmpty() )
4197             {
4198                 QString fn = fd.selectedFiles().first();
4199                 lastMapDir = QDir (fd.directory().path());
4200                 m->setVymLink (fn);
4201             }
4202         }
4203     }
4204 }
4205
4206 void Main::editDeleteVymLink()
4207 {
4208     VymModel *m=currentModel();
4209     if (m) m->deleteVymLink();  
4210 }
4211
4212 void Main::editToggleHideExport()
4213 {
4214     VymModel *m=currentModel();
4215     if (m) m->toggleHideExport();   
4216 }
4217
4218 void Main::editToggleTask()
4219 {
4220     VymModel *m=currentModel();
4221     if (m) m->toggleTask();   
4222 }
4223
4224 void Main::editCycleTaskStatus()
4225 {
4226     VymModel *m=currentModel();
4227     if (m) m->cycleTaskStatus();   
4228 }
4229
4230 void Main::editTaskSleepN()
4231 {
4232     VymModel *m=currentModel();
4233     if (m) 
4234     {
4235         int n=((QAction*)sender())->data().toInt();
4236         Task *task=m->getSelectedTask();
4237         if (task)
4238         {
4239             bool ok=true;
4240             QString s;
4241             if (n<0)
4242             {
4243                 n=task->getDaysSleep();
4244                 if (n<=0) n=0;
4245
4246                 LineEditDialog *dia=new LineEditDialog(this);
4247                 dia->setLabel(tr("Enter sleep time (number of days or date YYYY-MM-DD or DD.MM[.YYYY]","task sleep time dialog"));
4248                 dia->setText(QString("%1").arg(n));
4249                 centerDialog (dia);
4250                 if (dia->exec() == QDialog::Accepted)
4251                 {
4252                     ok=true;
4253                     s=dia->getText();
4254                 } else
4255                     ok=false;
4256
4257                 delete dia;
4258             } else
4259                 s=QString("%1").arg(n);
4260
4261             if (ok && !m->setTaskSleep(s) )
4262                 QMessageBox::warning(0, 
4263                     tr("Warning"),
4264                     tr("Couldn't set sleep time to %1.\n").arg(s));
4265         }
4266     }
4267 }
4268
4269 void Main::editAddTimestamp()
4270 {
4271     VymModel *m=currentModel();
4272     if (m) m->addTimestamp();   
4273 }
4274
4275 void Main::editMapProperties()    
4276 {
4277     VymModel *m = currentModel();
4278     if (!m) return;
4279
4280     ExtraInfoDialog dia;
4281     dia.setMapName  ( m->getFileName() );
4282     dia.setMapTitle ( m->getTitle() );
4283     dia.setAuthor   ( m->getAuthor() );
4284     dia.setComment  ( m->getComment() );
4285     dia.setReadOnly ( m->isReadOnly() );
4286
4287     // Calc some stats
4288     QString stats;
4289     stats += tr("%1 items on map\n","Info about map").arg (m->getScene()->items().size(),6);
4290
4291     uint b  = 0;
4292     uint f  = 0;
4293     uint n  = 0;
4294     uint xl = 0;
4295     BranchItem *cur  = NULL;
4296     BranchItem *prev = NULL;
4297     m->nextBranch(cur, prev);
4298     while (cur) 
4299     {
4300         if (!cur->getNote().isEmpty() ) n++;
4301         f += cur->imageCount();
4302         b++;
4303         xl += cur->xlinkCount();
4304         m->nextBranch(cur,prev);
4305     }
4306
4307     stats += QString ("%1 %2\n").arg (m->branchCount(),6).arg(tr("branches","Info about map") );
4308     stats += QString ("%1 %2\n").arg (n,6).arg(tr("notes","Info about map") );
4309     stats += QString ("%1 %2\n").arg (f,6).arg(tr("images","Info about map") );
4310     stats += QString ("%1 %2\n").arg (m->taskCount(),6 ).arg(tr("tasks","Info about map") );
4311     stats += QString ("%1 %2\n").arg (m->slideCount(),6 ).arg(tr("slides","Info about map") );
4312     stats += QString ("%1 %2\n").arg (xl/2,6).arg(tr("xLinks","Info about map") );
4313     dia.setStats (stats);
4314
4315     // Finally show dialog
4316     if (dia.exec() == QDialog::Accepted)
4317     {
4318         m->setAuthor (dia.getAuthor() );
4319         m->setComment (dia.getComment() );
4320         m->setTitle (dia.getMapTitle() );
4321     }
4322 }
4323
4324 void Main::editMoveUp()
4325 {
4326     MapEditor *me = currentMapEditor();
4327     VymModel  *m  = currentModel();
4328     if (me && m && me->getState() != MapEditor::EditingHeading) m->moveUp();
4329 }
4330
4331 void Main::editMoveDown()
4332 {
4333     MapEditor *me = currentMapEditor();
4334     VymModel  *m  = currentModel();
4335     if (me && m && me->getState() != MapEditor::EditingHeading) m->moveDown();
4336 }
4337
4338 void Main::editDetach()
4339 {
4340     VymModel *m=currentModel();
4341     if (m) m->detach();
4342 }
4343
4344 void Main::editSortChildren()
4345 {
4346     VymModel *m=currentModel();
4347     if (m) m->sortChildren(false);
4348 }
4349
4350 void Main::editSortBackChildren()
4351 {
4352     VymModel *m=currentModel();
4353     if (m) m->sortChildren(true);
4354 }
4355
4356 void Main::editToggleScroll()
4357 {
4358     VymModel *m=currentModel();
4359     if (m) m->toggleScroll();
4360 }
4361
4362 void Main::editExpandAll()
4363 {
4364     VymModel *m=currentModel();
4365     if (m) m->emitExpandAll();
4366 }
4367
4368 void Main::editExpandOneLevel()
4369 {
4370     VymModel *m=currentModel();
4371     if (m) m->emitExpandOneLevel();
4372 }
4373
4374 void Main::editCollapseOneLevel()
4375 {
4376     VymModel *m=currentModel();
4377     if (m) m->emitCollapseOneLevel();
4378 }
4379
4380 void Main::editCollapseUnselected()
4381 {
4382     VymModel *m=currentModel();
4383     if (m) m->emitCollapseUnselected();
4384 }
4385
4386 void Main::editUnscrollChildren()
4387 {
4388     VymModel *m=currentModel();
4389     if (m) m->unscrollChildren();
4390 }
4391
4392 void Main::editGrowSelectionSize()
4393 {
4394     VymModel *m=currentModel();
4395     if (m) m->growSelectionSize();
4396 }
4397
4398 void Main::editShrinkSelectionSize()
4399 {
4400     VymModel *m=currentModel();
4401     if (m) m->shrinkSelectionSize();
4402 }
4403
4404 void Main::editResetSelectionSize()
4405 {
4406     VymModel *m=currentModel();
4407     if (m) m->resetSelectionSize();
4408 }
4409
4410 void Main::editAddAttribute()
4411 {
4412     VymModel *m=currentModel();
4413     if (m) 
4414     {
4415
4416         m->addAttribute();
4417     }
4418 }
4419
4420 void Main::editAddMapCenter() 
4421 {
4422     VymModel *m=currentModel();
4423     if (m) 
4424     {
4425         m->select (m->addMapCenter ());
4426         MapEditor *me=currentMapEditor();
4427         if (me) 
4428         {
4429         m->setHeadingPlainText("");
4430             me->editHeading();
4431         }    
4432     }
4433 }
4434
4435 void Main::editNewBranch()
4436 {
4437     VymModel *m=currentModel();
4438     if (m)
4439     {
4440         BranchItem *bi=m->addNewBranch();
4441         if (!bi) return;
4442
4443         if (actionSettingsAutoEditNewBranch->isChecked() 
4444              && !actionSettingsAutoSelectNewBranch->isChecked() )
4445             prevSelection=m->getSelectString();
4446         else    
4447             prevSelection=QString();
4448
4449         if (actionSettingsAutoSelectNewBranch->isChecked()  
4450             || actionSettingsAutoEditNewBranch->isChecked()) 
4451         {
4452             m->select (bi);
4453             if (actionSettingsAutoEditNewBranch->isChecked())
4454                 currentMapEditor()->editHeading();
4455         }
4456     }   
4457 }
4458
4459 void Main::editNewBranchBefore()
4460 {
4461     VymModel *m=currentModel();
4462     if (m)
4463     {
4464         BranchItem *bi=m->addNewBranchBefore();
4465
4466         if (bi) 
4467             m->select (bi);
4468         else
4469             return;
4470
4471         if (actionSettingsAutoEditNewBranch->isChecked())
4472         {
4473             if (!actionSettingsAutoSelectNewBranch->isChecked())
4474                 prevSelection=m->getSelectString(bi); 
4475             currentMapEditor()->editHeading();
4476         }
4477     }   
4478 }
4479
4480 void Main::editNewBranchAbove() 
4481 {
4482     VymModel *m=currentModel();
4483     if (m)
4484     {
4485         BranchItem *selbi=m->getSelectedBranch();
4486         if (selbi)
4487         {
4488             BranchItem *bi=m->addNewBranch(selbi,-3);
4489
4490             if (bi) 
4491                 m->select (bi);
4492             else
4493                 return;
4494
4495             if (actionSettingsAutoEditNewBranch->isChecked())
4496             {
4497                 if (!actionSettingsAutoSelectNewBranch->isChecked())
4498                     prevSelection=m->getSelectString (bi);      
4499                 currentMapEditor()->editHeading();
4500             }
4501         }
4502     }   
4503 }
4504
4505 void Main::editNewBranchBelow()
4506 {
4507     VymModel *m=currentModel();
4508     if (m)
4509     {
4510         BranchItem *selbi=m->getSelectedBranch();
4511         if (selbi)
4512         {
4513             BranchItem *bi=m->addNewBranch(selbi,-1);
4514
4515             if (bi) 
4516                 m->select (bi);
4517             else
4518                 return;
4519
4520             if (actionSettingsAutoEditNewBranch->isChecked())
4521             {
4522                 if (!actionSettingsAutoSelectNewBranch->isChecked())
4523                     prevSelection=m->getSelectString(bi);
4524                 currentMapEditor()->editHeading();
4525             }
4526         }
4527     }   
4528 }
4529
4530 void Main::editImportAdd()
4531 {
4532     fileLoad (ImportAdd);
4533 }
4534
4535 void Main::editImportReplace()
4536 {
4537     fileLoad (ImportReplace);
4538 }
4539
4540 void Main::editSaveBranch() 
4541 {
4542     fileSaveAs (PartOfMap);
4543 }
4544
4545 void Main::editDeleteKeepChildren()
4546 {
4547     VymModel *m=currentModel();
4548      if (m) m->deleteKeepChildren();
4549 }
4550
4551 void Main::editDeleteChildren()
4552 {
4553     VymModel *m=currentModel();
4554     if (m) m->deleteChildren();
4555 }
4556
4557 void Main::editDeleteSelection()
4558 {
4559     VymModel *m=currentModel();
4560     if (m) m->deleteSelection();
4561 }
4562
4563 void Main::editLoadImage()
4564 {
4565     VymModel *m=currentModel();
4566     if (m) m->loadImage();
4567 }
4568
4569 void Main::editSaveImage()
4570 {
4571     VymModel *m=currentModel();
4572     if (m) m->saveImage();
4573 }
4574
4575 void Main::editEditXLink(QAction *a)
4576 {
4577     VymModel *m=currentModel();
4578     if (m)
4579     {
4580         BranchItem *selbi=m->getSelectedBranch();
4581         if (selbi)
4582         {
4583             Link *l=selbi->getXLinkItemNum(branchXLinksContextMenuEdit->actions().indexOf(a))->getLink();
4584             if (l && m->select (l->getBeginLinkItem() ) )
4585                 m->editXLink();
4586         }    
4587     }   
4588 }
4589
4590 void Main::popupFollowXLink()
4591 {
4592     branchXLinksContextMenuFollow->exec( QCursor::pos());
4593 }
4594
4595 void Main::editFollowXLink(QAction *a)
4596 {
4597     VymModel *m=currentModel();
4598
4599     if (m)
4600         m->followXLink(branchXLinksContextMenuFollow->actions().indexOf(a));
4601 }
4602
4603 void Main::editToggleTarget()  
4604 {
4605     VymModel *m=currentModel();
4606     if (m) m->toggleTarget();
4607 }
4608
4609 bool Main::initTargetsMenu( VymModel *model, QMenu *menu)
4610 {
4611     if (model)
4612     {
4613         ItemList targets = model->getTargets();
4614
4615         menu->clear();
4616
4617         QStringList targetNames;
4618         QList <uint> targetIDs;
4619
4620         // Build QStringList with all names of targets
4621         QMap<uint,QString>::const_iterator i;
4622         i = targets.constBegin();
4623         while (i != targets.constEnd()) 
4624         {
4625             targetNames.append( i.value() );
4626             targetIDs.append( i.key() );
4627             ++i;
4628         }
4629
4630         // Sort list of names
4631         targetNames.sort( Qt::CaseInsensitive );
4632
4633         // Build menu based on sorted names
4634         while ( !targetNames.isEmpty() )
4635         {
4636             // Find target by value
4637             i = targets.constBegin();
4638             while (i != targets.constEnd()) 
4639             {
4640                 if ( i.value() == targetNames.first() ) break;
4641                 ++i;
4642             }
4643
4644             menu->addAction( targetNames.first() )->setData( i.key() );
4645             targetNames.removeFirst();
4646             targets.remove( i.key() );
4647         }
4648         return true;
4649     }
4650     return false;
4651 }
4652
4653 void Main::editGoToTarget()  
4654 {
4655     VymModel *model = currentModel();
4656     if (initTargetsMenu( model, targetsContextMenu ) )
4657     {
4658         QAction *a = targetsContextMenu->exec (QCursor::pos());
4659         if (a) model->select (model->findID (a->data().toUInt() ) );
4660     }
4661 }
4662
4663 void Main::editMoveToTarget()  
4664 {
4665     VymModel *model = currentModel();
4666     if (initTargetsMenu( model, targetsContextMenu ) )
4667     {
4668         QAction *a = targetsContextMenu->exec (QCursor::pos());
4669         if (a) 
4670         {
4671             TreeItem *ti = model->findID ( a->data().toUInt() );
4672             BranchItem *selbi = model->getSelectedBranch();
4673             if (!selbi) return;
4674
4675             if (ti && ti->isBranchLikeType() && selbi)
4676             {
4677                 BranchItem *pi = selbi->parentBranch();
4678                 // If branch below exists, select that one
4679                 // Makes it easier to quickly resort using the MoveTo function
4680                 BranchItem *below = pi->getBranchNum( selbi->num() + 1 );
4681                 LinkableMapObj *lmo = selbi->getLMO();
4682                 QPointF orgPos;
4683                 if (lmo) orgPos = lmo->getAbsPos();
4684
4685                 if (model->relinkBranch ( selbi, (BranchItem*)ti, -1, true, orgPos) )
4686                 {
4687                     if (below) 
4688                         model->select (below);
4689                     else    
4690                         if (pi) model->select (pi);
4691                 }    
4692             }       
4693         }
4694     }
4695 }
4696
4697 void Main::editSelectPrevious()  
4698 {
4699     VymModel *m=currentModel();
4700     if (m) m->selectPrevious();
4701 }
4702
4703 void Main::editSelectNext()  
4704 {
4705     VymModel *m=currentModel();
4706     if (m) m->selectNext();
4707 }
4708
4709 void Main::editSelectNothing()  
4710 {
4711     VymModel *m=currentModel();
4712     if (m) m->unselectAll();
4713 }
4714
4715 void Main::editOpenFindResultWidget()  
4716 {
4717     if (!findResultWidget->parentWidget()->isVisible())
4718     {
4719 //      findResultWidget->parentWidget()->show();
4720         findResultWidget->popup();
4721     } else 
4722         findResultWidget->parentWidget()->hide();
4723 }
4724
4725 #include "findwidget.h" // FIXME-4 Integrated FRW and FW
4726 void Main::editFindNext(QString s)  
4727 {
4728     Qt::CaseSensitivity cs=Qt::CaseInsensitive;
4729     VymModel *m=currentModel();
4730     if (m) 
4731     {
4732         if (m->findAll (findResultWidget->getResultModel(),s,cs) )
4733             findResultWidget->setStatus (FindWidget::Success);
4734         else
4735             findResultWidget->setStatus (FindWidget::Failed);
4736     }
4737 }
4738
4739 void Main::editFindDuplicateURLs() //FIXME-4 feature: use FindResultWidget for display
4740 {
4741     VymModel *m=currentModel();
4742     if (m) m->findDuplicateURLs();
4743 }
4744
4745 void Main::updateQueries (VymModel* ) //FIXME-4 disabled for now to avoid selection in FRW
4746 {
4747     return;
4748 /*
4749     qDebug() << "MW::updateQueries m="<<m<<"   cM="<<currentModel();
4750     if (m && currentModel()==m)
4751     {
4752         QString s=findResultWidget->getFindText();
4753         if (!s.isEmpty() ) editFindNext (s);
4754     }   
4755 */
4756 }
4757
4758 void Main::formatPickColor()
4759 {
4760     VymModel *m=currentModel();
4761     if (m)
4762         setCurrentColor ( m->getCurrentHeadingColor() );
4763 }
4764
4765 QColor Main::getCurrentColor()
4766 {
4767     return currentColor;
4768 }
4769
4770 void Main::setCurrentColor(QColor c)
4771 {
4772     QPixmap pix( 16, 16 );
4773     pix.fill( c );
4774     actionFormatColor->setIcon( pix );
4775     currentColor=c;
4776 }
4777
4778 void Main::formatSelectColor()
4779 {
4780     QColor col = QColorDialog::getColor((currentColor ), this );
4781     if ( !col.isValid() ) return;
4782     setCurrentColor( col );
4783 }
4784
4785 void Main::formatColorBranch()
4786 {
4787     VymModel *m=currentModel();
4788     if (m) m->colorBranch(currentColor);
4789 }
4790
4791 void Main::formatColorSubtree()
4792 {
4793     VymModel *m=currentModel();
4794     if (m) m->colorSubtree (currentColor);
4795 }
4796
4797 void Main::formatLinkStyleLine()
4798 {
4799     VymModel *m=currentModel();
4800     if (m)
4801     {
4802         m->setMapLinkStyle("StyleLine");
4803         actionFormatLinkStyleLine->setChecked(true);
4804     }
4805 }
4806
4807 void Main::formatLinkStyleParabel()
4808 {
4809     VymModel *m=currentModel();
4810     if (m)
4811     {
4812         m->setMapLinkStyle("StyleParabel");
4813         actionFormatLinkStyleParabel->setChecked(true);
4814     }
4815 }
4816
4817 void Main::formatLinkStylePolyLine()
4818 {
4819     VymModel *m=currentModel();
4820     if (m)
4821     {
4822         m->setMapLinkStyle("StylePolyLine");
4823         actionFormatLinkStylePolyLine->setChecked(true);
4824     }
4825 }
4826
4827 void Main::formatLinkStylePolyParabel()
4828 {
4829     VymModel *m=currentModel();
4830     if (m)
4831     {
4832         m->setMapLinkStyle("StylePolyParabel");
4833         actionFormatLinkStylePolyParabel->setChecked(true);
4834     }
4835 }
4836
4837 void Main::formatSelectBackColor()
4838 {
4839     VymModel *m=currentModel();
4840     if (m) m->selectMapBackgroundColor();
4841 }
4842
4843 void Main::formatSelectBackImage()
4844 {
4845     VymModel *m=currentModel();
4846     if (m)
4847         m->selectMapBackgroundImage();
4848 }
4849
4850 void Main::formatSelectLinkColor()
4851 {
4852     VymModel *m=currentModel();
4853     if (m)
4854     {
4855         QColor col = QColorDialog::getColor( m->getMapDefLinkColor(), this );
4856         m->setMapDefLinkColor( col );
4857     }
4858 }
4859
4860 void Main::formatSelectSelectionColor()
4861 {
4862     VymModel *m=currentModel();
4863     if (m)
4864     {
4865         QColor col = QColorDialog::getColor( m->getMapDefLinkColor(), this );
4866         m->setSelectionColor (col);
4867     }
4868
4869 }
4870
4871 void Main::formatSelectFont()
4872 {
4873     VymModel *m=currentModel();
4874     if (m) 
4875     {
4876         bool ok;
4877         QFont font = QFontDialog::getFont( &ok, m->getMapDefaultFont(), this);
4878         if (ok) m->setMapDefaultFont (font);
4879     }
4880 }
4881
4882 void Main::formatToggleLinkColorHint()
4883 {
4884     VymModel *m=currentModel();
4885     if (m) m->toggleMapLinkColorHint();
4886 }
4887
4888 void Main::formatHideLinkUnselected()   //FIXME-4 get rid of this with imagepropertydialog
4889 {
4890     VymModel *m=currentModel();
4891     if (m)
4892         m->setHideLinkUnselected(actionFormatHideLinkUnselected->isChecked());
4893 }
4894
4895 void Main::viewZoomReset()
4896 {
4897     MapEditor *me=currentMapEditor();
4898     if (me) me->setViewCenterTarget();
4899 }
4900
4901 void Main::viewZoomIn()
4902 {
4903     MapEditor *me=currentMapEditor();
4904     if (me) me->setZoomFactorTarget (me->getZoomFactorTarget()*1.15);
4905 }
4906
4907 void Main::viewZoomOut()
4908 {
4909     MapEditor *me=currentMapEditor();
4910     if (me) me->setZoomFactorTarget (me->getZoomFactorTarget()*0.85);
4911 }
4912
4913 void Main::viewRotateCounterClockwise()
4914 {
4915     MapEditor *me=currentMapEditor();
4916     if (me) me->setAngleTarget (me->getAngleTarget()-10);
4917 }
4918
4919 void Main::viewRotateClockwise()
4920 {
4921     MapEditor *me=currentMapEditor();
4922     if (me) me->setAngleTarget (me->getAngleTarget()+10);
4923 }
4924
4925 void Main::viewCenter()
4926 {
4927     VymModel *m=currentModel();
4928     if (m) m->emitShowSelection();
4929 }
4930
4931 void Main::networkStartServer()
4932 {
4933     VymModel *m=currentModel();
4934     if (m) m->newServer();
4935 }
4936
4937 void Main::networkConnect()
4938 {
4939     VymModel *m=currentModel();
4940     if (m) m->connectToServer();
4941 }
4942
4943 void Main::downloadFinished()   // only used for drop events in mapeditor and VM::downloadImage 
4944 {
4945     QString s;
4946     DownloadAgent *agent = static_cast<DownloadAgent*>(sender());
4947     agent->isSuccess() ? s="Success" : s="Error  "; 
4948
4949     /*
4950     qDebug()<<"Main::downloadFinished ";
4951     qDebug()<<"  result" <<  s;
4952     qDebug()<<"     msg" << agent->getResultMessage();
4953     */
4954
4955     QString script = agent->getFinishedScript();
4956     VymModel *model=getModel (agent->getFinishedScriptModelID());
4957     if (!script.isEmpty() && model)
4958     {
4959         script.replace("$TMPFILE",agent->getDestination());
4960         model->execute(script);
4961     }
4962 }
4963
4964 bool Main::settingsPDF()
4965 {
4966     // Default browser is set in constructor
4967     bool ok;
4968     QString text = QInputDialog::getText(
4969         this,
4970         "VYM", tr("Set application to open PDF files")+":", QLineEdit::Normal,
4971         settings.value("/system/readerPDF").toString(), &ok);
4972     if (ok)
4973         settings.setValue ("/system/readerPDF",text);
4974     return ok;
4975 }
4976
4977
4978 bool Main::settingsURL()
4979 {
4980     // Default browser is set in constructor
4981     bool ok;
4982     QString text = QInputDialog::getText(
4983         this,
4984         "VYM", tr("Set application to open an URL")+":", QLineEdit::Normal,
4985         settings.value("/system/readerURL").toString()
4986         , &ok);
4987     if (ok)
4988         settings.setValue ("/system/readerURL",text);
4989     return ok;
4990 }
4991
4992 void Main::settingsZipTool()
4993 {
4994     // Default zip tool is 7z on windows, zip/unzip elsewhere
4995     bool ok = false;
4996
4997 #if defined(Q_OS_WIN32)
4998     QString filter;
4999     filter = "Windows executable (*.exe);;";
5000
5001     QString fn = QFileDialog::getOpenFileName( 
5002         this,
5003         vymName + " - " + tr("Set application to zip/unzip files") + ":", 
5004         zipToolPath,
5005         filter);
5006
5007     if (!fn.isEmpty() ) ok = true;
5008
5009 #else
5010
5011     QString fn = QInputDialog::getText(
5012                 this,
5013                 vymName, tr("Set application to zip/unzip files")+":", QLineEdit::Normal,
5014                 zipToolPath, &ok);
5015 #endif
5016
5017     if (ok)
5018     {
5019         zipToolPath = fn;
5020         settings.setValue ("/system/zipToolPath", zipToolPath);
5021     }
5022 }
5023
5024 void Main::settingsMacroDir()
5025 {
5026     QDir defdir(vymBaseDir.path() + "/macros");
5027     if (!defdir.exists())
5028         defdir=vymBaseDir;
5029     QDir dir=QFileDialog::getExistingDirectory (
5030         this,
5031         tr ("Directory with vym macros:"), 
5032         settings.value ("/macros/macroDir",defdir.path()).toString()
5033     );
5034     if (dir.exists())
5035         settings.setValue ("/macros/macroDir",dir.absolutePath());
5036 }
5037
5038 void Main::settingsUndoLevels()     
5039 {
5040     bool ok;
5041     int i = QInputDialog::getInt(
5042         this, 
5043         "QInputDialog::getInt()",
5044         tr("Number of undo/redo levels:"), settings.value("/history/stepsTotal",1000).toInt(), 0, 100000, 1, &ok);
5045     if (ok)
5046     {
5047         settings.setValue ("/history/stepsTotal",i);
5048         QMessageBox::information( this, tr( "VYM -Information:" ),
5049            tr("Settings have been changed. The next map opened will have \"%1\" undo/redo levels").arg(i)); 
5050    }    
5051 }
5052
5053 bool Main::useAutosave()
5054 {
5055     return actionSettingsToggleAutosave->isChecked();
5056 }
5057
5058 void Main::setAutosave(bool b)
5059 {
5060     actionSettingsToggleAutosave->setChecked(b);
5061 }
5062
5063 void Main::settingsAutosaveTime()
5064 {
5065     bool ok;
5066     int i = QInputDialog::getInt(
5067         this, 
5068         vymName,
5069         tr("Number of seconds before autosave:"), settings.value("/system/autosave/ms").toInt() / 1000, 10, 60000, 1, &ok);
5070     if (ok)
5071         settings.setValue ("/system/autosave/ms",i * 1000);
5072 }
5073
5074 void Main::settingsDefaultMapAuthor()       
5075 {
5076     bool ok;
5077     QString s = QInputDialog::getText(
5078                 this,
5079                 vymName, tr("Set author for new maps (used in lockfile)") + ":", QLineEdit::Normal,
5080                 settings.value("/user/name", tr("unknown user","default name for map author in settings")).toString(), 
5081                 &ok);
5082     if (ok) settings.setValue("/user/name", s);
5083 }
5084
5085 void Main::settingsShowParentsLevelFindResults()            
5086 {
5087     bool ok;
5088     int i = QInputDialog::getInt(
5089         this, 
5090         vymName,
5091         tr("Number of parents shown in find results:"), findResultWidget->getResultModel()->getShowParentsLevel(), 0, 10, 0, &ok);
5092     if (ok) findResultWidget->getResultModel()->setShowParentsLevel(i);
5093 }
5094
5095 void Main::settingsShowParentsLevelTasks()          
5096 {
5097     bool ok;
5098     int i = QInputDialog::getInt(
5099         this, 
5100         vymName,
5101         tr("Number of parents shown for a task:"), taskModel->getShowParentsLevel(), 0, 10, 0, &ok);
5102     if (ok) taskModel->setShowParentsLevel(i);
5103 }
5104
5105 void Main::settingsToggleAutoLayout()
5106 {
5107     settings.setValue ("/mainwindow/autoLayout/use",actionSettingsToggleAutoLayout->isChecked() );
5108 }
5109
5110 void Main::settingsToggleWriteBackupFile()
5111 {
5112     settings.setValue ("/system/writeBackupFile",actionSettingsWriteBackupFile->isChecked() );
5113 }
5114
5115 void Main::settingsToggleAnimation()
5116 {
5117     settings.setValue ("/animation/use",actionSettingsUseAnimation->isChecked() );
5118 }
5119
5120 void Main::settingsToggleDownloads()
5121 {
5122     downloadsEnabled(true);
5123 }
5124
5125 void Main::windowToggleNoteEditor()
5126 {
5127     if (noteEditor->parentWidget()->isVisible() )
5128         noteEditor->parentWidget()->hide();
5129     else
5130     {
5131         noteEditor->parentWidget()->show();
5132         noteEditor->setFocus();
5133     }
5134 }
5135
5136 void Main::windowToggleTreeEditor()
5137 {
5138     if ( tabWidget->currentWidget())
5139         vymViews.at(tabWidget->currentIndex())->toggleTreeEditor();
5140 }
5141
5142 void Main::windowToggleTaskEditor()
5143 {
5144     if (taskEditor->parentWidget()->isVisible() )
5145     {
5146         taskEditor->parentWidget()->hide();
5147         actionViewToggleTaskEditor->setChecked (false);
5148     } else
5149     {
5150         taskEditor->parentWidget()->show();
5151         actionViewToggleTaskEditor->setChecked (true);
5152     }
5153 }
5154
5155 void Main::windowToggleSlideEditor()
5156 {
5157     if ( tabWidget->currentWidget())
5158         vymViews.at(tabWidget->currentIndex())->toggleSlideEditor();
5159 }
5160
5161 void Main::windowToggleScriptEditor()
5162 {
5163     if (scriptEditor->parentWidget()->isVisible() )
5164     {
5165         scriptEditor->parentWidget()->hide();
5166         actionViewToggleScriptEditor->setChecked (false);
5167     } else
5168     {
5169         scriptEditor->parentWidget()->show();
5170         actionViewToggleScriptEditor->setChecked (true);
5171     }
5172 }
5173
5174 void Main::windowToggleHistory()
5175 {
5176     if (historyWindow->isVisible())
5177         historyWindow->parentWidget()->hide();
5178     else    
5179         historyWindow->parentWidget()->show();
5180 }
5181
5182 void Main::windowToggleProperty()
5183 {
5184     if (branchPropertyEditor->parentWidget()->isVisible())
5185         branchPropertyEditor->parentWidget()->hide();
5186     else    
5187         branchPropertyEditor->parentWidget()->show();
5188     branchPropertyEditor->setModel (currentModel() );
5189 }
5190
5191 void Main::windowShowHeadingEditor()
5192 {
5193     headingEditorDW->show();
5194 }
5195
5196 void Main::windowToggleHeadingEditor()
5197 {
5198     if (headingEditor->parentWidget()->isVisible() )
5199         headingEditor->parentWidget()->hide();
5200     else
5201     {
5202         headingEditor->parentWidget()->show();
5203         headingEditor->setFocus();
5204     }
5205 }
5206
5207 void Main::windowToggleAntiAlias()
5208 {
5209     bool b=actionViewToggleAntiAlias->isChecked();
5210     MapEditor *me;
5211     for (int i=0;i<vymViews.count();i++)
5212     {
5213         me=vymViews.at(i)->getMapEditor();
5214         if (me) me->setAntiAlias(b);
5215     }   
5216
5217 }
5218
5219 bool Main::isAliased()
5220 {
5221     return actionViewToggleAntiAlias->isChecked();
5222 }
5223
5224 bool Main::hasSmoothPixmapTransform()
5225 {
5226     return actionViewToggleSmoothPixmapTransform->isChecked();
5227 }
5228
5229 void Main::windowToggleSmoothPixmap()
5230 {
5231     bool b=actionViewToggleSmoothPixmapTransform->isChecked();
5232     MapEditor *me;
5233     for (int i=0;i<vymViews.count();i++)
5234     {
5235         
5236         me=vymViews.at(i)->getMapEditor();
5237         if (me) me->setSmoothPixmap(b);
5238     }   
5239 }
5240
5241 void Main::updateHistory(SimpleSettings &undoSet)
5242 {
5243     historyWindow->update (undoSet);
5244 }
5245
5246 void Main::updateHeading()
5247 {
5248     VymModel *m=currentModel();
5249     if (m) m->setHeading (headingEditor->getVymText() );
5250 }
5251
5252 void Main::updateNoteFlag() 
5253 {
5254     // this slot is connected to noteEditor::textHasChanged()
5255     VymModel *m=currentModel();
5256     if (m) m->updateNoteFlag();
5257 }
5258
5259 void Main::updateNoteEditor(QModelIndex index ) //FIXME-4 maybe change to TreeItem as parameter?
5260 {
5261     if (index.isValid() )
5262     {
5263         TreeItem *ti=((VymModel*) QObject::sender())->getItem(index);
5264         /*
5265     qDebug()<< "Main::updateNoteEditor model="<<sender()
5266         << "  item="<<ti->getHeading()<<" ("<<ti<<")";
5267     qDebug()<< "RT="<<ti->getNote().isRichText();
5268     */
5269         if (ti)
5270             noteEditor->setNote (ti->getNote() );
5271         updateDockWidgetTitles( ti->getModel());
5272     }
5273 }
5274
5275 void Main::selectInNoteEditor(QString s,int i)
5276 {
5277     // TreeItem is already selected at this time, therefor
5278     // the note is already in the editor
5279     noteEditor->findText (s,0,i);
5280 }
5281
5282 void Main::setFocusMapEditor()
5283 {
5284     VymView *vv=currentView();
5285     if (vv) vv->setFocusMapEditor();
5286 }
5287
5288 void Main::changeSelection (VymModel *model, const QItemSelection &newsel, const QItemSelection &)
5289 {
5290     branchPropertyEditor->setModel (model ); 
5291
5292     if (model && model == currentModel() )
5293     {
5294         TreeItem *ti;
5295         if (!newsel.indexes().isEmpty() )
5296         {
5297             ti = model->getItem(newsel.indexes().first());
5298
5299             // Update note editor
5300             if (!ti->hasEmptyNote() )
5301                 noteEditor->setNote(ti->getNote() );
5302             else
5303                 noteEditor->setNote(VymNote() );
5304             // Show URL and link in statusbar
5305             QString status;
5306             QString s = ti->getURL();
5307             if (!s.isEmpty() ) status += "URL: " + s + "  ";
5308             s = ti->getVymLink();
5309             if (!s.isEmpty() ) status += "Link: " + s;
5310             if (!status.isEmpty() ) statusMessage (status);
5311
5312             headingEditor->setVymText (ti->getHeading() );
5313
5314             // Select in TaskEditor, if necessary
5315             Task *t = NULL;
5316             if (ti->isBranchLikeType() )
5317                 t = ((BranchItem*)ti)->getTask();
5318
5319             if (t)
5320                 taskEditor->select (t);
5321             else
5322                 taskEditor->clearSelection();
5323         } else
5324             noteEditor->setInactive();
5325
5326         updateActions();
5327     }
5328 }
5329
5330 void Main::updateDockWidgetTitles( VymModel *model)
5331 {
5332     QString s;
5333     if (model && !model->isRepositionBlocked() ) 
5334     {
5335         BranchItem *bi = model->getSelectedBranch();
5336         if (bi) s = bi->getHeadingPlain();
5337
5338         noteEditor->setEditorTitle(s);
5339         noteEditorDW->setWindowTitle (noteEditor->getEditorTitle() );
5340     }
5341 }
5342
5343 void Main::updateActions()
5344 {
5345     // updateActions is also called when satellites are closed  
5346     actionViewToggleNoteEditor->setChecked (noteEditor->parentWidget()->isVisible());
5347     actionViewToggleTaskEditor->setChecked (taskEditor->parentWidget()->isVisible());
5348     actionViewToggleHistoryWindow->setChecked (historyWindow->parentWidget()->isVisible());
5349     actionViewTogglePropertyEditor->setChecked (branchPropertyEditor->parentWidget()->isVisible());
5350     actionViewToggleScriptEditor->setChecked (scriptEditor->parentWidget()->isVisible());
5351
5352     VymView *vv=currentView();
5353     if (vv)
5354     {
5355         actionViewToggleTreeEditor->setChecked ( vv->treeEditorIsVisible() );
5356         actionViewToggleSlideEditor->setChecked( vv->slideEditorIsVisible() );
5357     } else      
5358     {
5359         actionViewToggleTreeEditor->setChecked  ( false );
5360         actionViewToggleSlideEditor->setChecked ( false );
5361     }
5362
5363     VymModel  *m =currentModel();
5364     if ( m ) 
5365     {
5366         // readonly mode
5367         if (m->isReadOnly() )
5368         {
5369             // Disable toolbars
5370             standardFlagsMaster->setEnabled (false);
5371
5372             // Disable map related actions
5373             foreach (QAction *a, restrictedMapActions)
5374                 a->setEnabled( false );
5375
5376             // FIXME-2 updateactions: refactor actionListFiles: probably not needed, wrong actions there atm
5377         } else
5378         {   // not readonly     // FIXME-2 updateactions: maybe only required in testing, as mode should not change
5379             
5380             // Enable toolbars
5381             standardFlagsMaster->setEnabled (true);
5382
5383             // Enable map related actions
5384             foreach (QAction *a, restrictedMapActions)
5385                 a->setEnabled( true );
5386
5387         }
5388         // Enable all files actions first   
5389         for (int i=0; i<actionListFiles.size(); ++i)    
5390             actionListFiles.at(i)->setEnabled(true);
5391
5392         foreach (QAction *a, unrestrictedMapActions)
5393             a->setEnabled( true  );
5394         
5395         // Disable other actions for now
5396         for (int i=0; i<actionListBranches.size(); ++i) 
5397             actionListBranches.at(i)->setEnabled(false);
5398
5399         for (int i=0; i<actionListItems.size(); ++i) 
5400             actionListItems.at(i)->setEnabled(false);
5401
5402         // Link style in context menu
5403         switch (m->getMapLinkStyle())
5404         {
5405             case LinkableMapObj::Line: 
5406                 actionFormatLinkStyleLine->setChecked(true);
5407                 break;
5408             case LinkableMapObj::Parabel:
5409                 actionFormatLinkStyleParabel->setChecked(true);
5410                 break;
5411             case LinkableMapObj::PolyLine:  
5412                 actionFormatLinkStylePolyLine->setChecked(true);
5413                 break;
5414             case LinkableMapObj::PolyParabel:   
5415                 actionFormatLinkStylePolyParabel->setChecked(true);
5416                 break;
5417             default:
5418                 break;
5419         }       
5420
5421         // Update colors
5422         QPixmap pix( 16, 16 );
5423         pix.fill( m->getMapBackgroundColor() );
5424         actionFormatBackColor->setIcon( pix );
5425         pix.fill( m->getSelectionColor() );
5426         actionFormatSelectionColor->setIcon( pix );
5427         pix.fill( m->getMapDefLinkColor() );
5428         actionFormatLinkColor->setIcon( pix );
5429
5430         // Selection history
5431         if (!m->canSelectPrevious() )
5432             actionSelectPrevious->setEnabled(false);
5433
5434         if (!m->canSelectNext() )
5435             actionSelectNext->setEnabled(false);
5436             
5437         if (!m->getSelectedItem() )
5438             actionSelectNothing->setEnabled (false);
5439
5440         // Save
5441         if (! m->hasChanged() )
5442             actionFileSave->setEnabled( false);
5443
5444         // Undo/Redo
5445         if (! m->isUndoAvailable())
5446             actionUndo->setEnabled( false);
5447
5448         if (! m->isRedoAvailable())
5449             actionRedo->setEnabled( false);
5450
5451         // History window
5452         historyWindow->setWindowTitle (vymName + " - " +tr("History for %1","Window Caption").arg(m->getFileName()));
5453
5454         // Expanding/collapsing
5455         actionExpandAll->setEnabled (true);
5456         actionExpandOneLevel->setEnabled (true);
5457         actionCollapseOneLevel->setEnabled (true);
5458         actionCollapseUnselected->setEnabled (true);
5459
5460         if (m->getMapLinkColorHint()==LinkableMapObj::HeadingColor) 
5461             actionFormatLinkColorHint->setChecked(true);
5462         else    
5463             actionFormatLinkColorHint->setChecked(false);
5464
5465         // Export last
5466         QString s, t, u, v;
5467         if (m && m->exportLastAvailable(s,t,u, v) )
5468             actionFileExportLast->setEnabled (true);
5469         else
5470         {
5471             actionFileExportLast->setEnabled (false);
5472             t=u="";
5473             s=" - ";
5474         }       
5475         actionFileExportLast->setText( tr( "Export in last used format (%1) to: %2","status tip" ).arg(s).arg(u));
5476
5477         TreeItem *selti=m->getSelectedItem();
5478         BranchItem *selbi=m->getSelectedBranch();
5479
5480         if (selti)
5481         {   // Tree Item selected
5482             actionToggleTarget->setChecked (selti->isTarget() );
5483             actionDelete->setEnabled (true);
5484             actionDeleteChildren->setEnabled (true);
5485
5486             if (selbi || selti->getType()==TreeItem::Image)
5487             {
5488                 actionFormatHideLinkUnselected->setChecked (((MapItem*)selti)->getHideLinkUnselected());
5489                 actionFormatHideLinkUnselected->setEnabled (true);
5490             }
5491
5492             if (selbi)  
5493             {   // Branch Item selected
5494                 for (int i=0; i<actionListBranches.size(); ++i) 
5495                     actionListBranches.at(i)->setEnabled(true);
5496
5497                 actionHeading2URL->setEnabled (true);  
5498
5499                 // Note
5500                 actionGetURLsFromNote->setEnabled (!selbi->getNote().isEmpty());
5501
5502                 // Take care of xlinks  
5503                 // FIXME-4 similar code in mapeditor mousePressEvent
5504                 int b=selbi->xlinkCount();
5505                 branchXLinksContextMenuEdit->setEnabled(b);
5506                 branchXLinksContextMenuFollow->setEnabled(b);
5507                 branchXLinksContextMenuEdit->clear();
5508                 branchXLinksContextMenuFollow->clear();
5509                 if (b)
5510                 {
5511                     BranchItem *bi;
5512                     QString s;
5513                     for (int i=0; i<selbi->xlinkCount();++i)
5514                     {
5515                         bi=selbi->getXLinkItemNum(i)->getPartnerBranch();
5516                         if (bi)
5517                         {
5518                 s=bi->getHeadingPlain();
5519                             if (s.length()>xLinkMenuWidth)
5520                                 s=s.left(xLinkMenuWidth)+"...";
5521                             branchXLinksContextMenuEdit->addAction (s);
5522                             branchXLinksContextMenuFollow->addAction (s);
5523                         }   
5524                     }
5525                 }
5526                 //Standard Flags
5527                 standardFlagsMaster->updateToolBar (selbi->activeStandardFlagNames() );
5528
5529                 // System Flags
5530                 actionToggleScroll->setEnabled (true);
5531                 if ( selbi->isScrolled() )
5532                     actionToggleScroll->setChecked(true);
5533                 else    
5534                     actionToggleScroll->setChecked(false);
5535
5536                 actionGetBugzillaDataSubtree->setEnabled (bugzillaClientAvailable);
5537                 if ( selti->getURL().isEmpty() )
5538                 {
5539                     actionOpenURL->setEnabled (false);
5540                     actionOpenURLTab->setEnabled (false);
5541                     actionGetBugzillaData->setEnabled (false);
5542                 }   
5543                 else    
5544                 {
5545                     actionOpenURL->setEnabled (true);
5546                     actionOpenURLTab->setEnabled (true);
5547                     actionGetBugzillaData->setEnabled (
5548                         selti->getURL().contains("bugzilla") && bugzillaClientAvailable);
5549                 }
5550                 if ( selti->getVymLink().isEmpty() )
5551                 {
5552                     actionOpenVymLink->setEnabled (false);
5553                     actionOpenVymLinkBackground->setEnabled (false);
5554                     actionDeleteVymLink->setEnabled (false);
5555                 } else  
5556                 {
5557                     actionOpenVymLink->setEnabled (true);
5558                     actionOpenVymLinkBackground->setEnabled (true);
5559                     actionDeleteVymLink->setEnabled (true);
5560                 }   
5561
5562                 if (!selbi->canMoveUp()) 
5563                     actionMoveUp->setEnabled (false);
5564
5565                 if (!selbi->canMoveDown()) 
5566                     actionMoveDown->setEnabled (false);
5567
5568                 if (selbi->branchCount() <2 )
5569                 {
5570                     actionSortChildren->setEnabled (false);
5571                     actionSortBackChildren->setEnabled (false);
5572                 }
5573
5574                 actionToggleHideExport->setEnabled (true);  
5575                 actionToggleHideExport->setChecked (selbi->hideInExport() );    
5576
5577                 actionToggleTask->setEnabled (true);  
5578                 if (!selbi->getTask() )
5579                     actionToggleTask->setChecked (false);
5580                 else
5581                     actionToggleTask->setChecked (true);
5582
5583                 if (!clipboardEmpty)
5584                     actionPaste->setEnabled (true); 
5585                 else    
5586                     actionPaste->setEnabled (false);    
5587
5588                 actionToggleTarget->setEnabled (true);
5589             }   // end of BranchItem
5590
5591             if ( selti->getType()==TreeItem::Image)
5592             {
5593                 for (int i=0; i<actionListBranches.size(); ++i) 
5594                     actionListBranches.at(i)->setEnabled(false);
5595
5596                 standardFlagsMaster->setEnabled (false);
5597
5598                 actionOpenURL->setEnabled (false);
5599                 actionOpenVymLink->setEnabled (false);
5600                 actionOpenVymLinkBackground->setEnabled (false);
5601                 actionDeleteVymLink->setEnabled (false);    
5602                 actionToggleHideExport->setEnabled (true);  
5603                 actionToggleHideExport->setChecked (selti->hideInExport() );    
5604
5605                 actionToggleTarget->setEnabled (true);
5606
5607                 actionPaste->setEnabled (false); 
5608                 actionDelete->setEnabled (true);
5609
5610                 actionGrowSelectionSize->setEnabled (true);
5611                 actionShrinkSelectionSize->setEnabled (true);
5612                 actionResetSelectionSize->setEnabled (true);
5613             }   // Image
5614         } // TreeItem 
5615         
5616         // Check (at least for some) multiple selection //FIXME-4
5617         QList <TreeItem*> selItems=m->getSelectedItems();
5618         if (selItems.count()>0 )
5619         {
5620             actionDelete->setEnabled (true);
5621             actionToggleHideExport->setEnabled (true);  
5622             actionToggleHideExport->setChecked (false); 
5623         }
5624
5625         QList <BranchItem*> selbis=m->getSelectedBranches();
5626         if (selbis.count()>0 )
5627             actionFormatColorBranch->setEnabled (true);
5628
5629     } else
5630     {
5631         // No map available 
5632         for (int i=0; i<actionListFiles.size(); ++i)    
5633             actionListFiles.at(i)->setEnabled(false);
5634
5635         foreach (QAction *a, unrestrictedMapActions)
5636             a->setEnabled( false );
5637
5638         // Disable toolbars
5639         standardFlagsMaster->setEnabled (false);
5640     }
5641 }
5642
5643 Main::ModMode Main::getModMode()
5644 {
5645     if (actionModModeColor->isChecked()) return ModModeColor;
5646     if (actionModModeCopy->isChecked()) return ModModeCopy;
5647     if (actionModModeXLink->isChecked()) return ModModeXLink;
5648     return ModModeNone;
5649 }
5650
5651 bool Main::autoEditNewBranch()
5652 {
5653     return actionSettingsAutoEditNewBranch->isChecked();
5654 }
5655
5656 bool Main::autoSelectNewBranch()
5657 {
5658     return actionSettingsAutoSelectNewBranch->isChecked();
5659 }
5660
5661 void Main::setScriptFile (const QString &fn)
5662 {
5663     scriptEditor->setScriptFile (fn);
5664 }
5665
5666 QVariant Main::execute (const QString &script)
5667 {
5668     VymModel *m=currentModel();
5669     if (m) return m->execute (script);
5670     return QVariant();
5671 }
5672
5673 void Main::executeEverywhere (const QString &script)
5674 {
5675     foreach (VymView *vv,vymViews)
5676     {
5677         VymModel *m=vv->getModel();
5678         if (m) m->execute (script);
5679     }
5680 }
5681
5682 void Main::gotoWindow (const int &n)
5683 {
5684     if (n < tabWidget->count() && n>=0 )
5685         tabWidget->setCurrentIndex (n);
5686 }
5687
5688 void Main::windowNextEditor()
5689 {
5690     if (tabWidget->currentIndex() < tabWidget->count())
5691         tabWidget->setCurrentIndex (tabWidget->currentIndex() +1);
5692 }
5693
5694 void Main::windowPreviousEditor()
5695 {
5696     if (tabWidget->currentIndex() >0)
5697         tabWidget->setCurrentIndex (tabWidget->currentIndex() -1);
5698 }
5699
5700 void Main::nextSlide()
5701 {
5702     VymView *cv=currentView();
5703     if (cv) cv->nextSlide();
5704 }
5705
5706
5707 void Main::previousSlide()
5708 {
5709     VymView *cv=currentView();
5710     if (cv) cv->previousSlide();
5711 }
5712
5713 void Main::standardFlagChanged()
5714 {
5715     MapEditor *me = currentMapEditor();
5716     VymModel  *m  = currentModel();
5717     if (me && m && me->getState() != MapEditor::EditingHeading) 
5718     {
5719         if ( actionSettingsUseFlagGroups->isChecked() )
5720             m->toggleStandardFlag(sender()->objectName(),standardFlagsMaster);
5721         else
5722             m->toggleStandardFlag(sender()->objectName());
5723         updateActions();
5724     }
5725 }
5726
5727 void Main::testFunction1()
5728 {
5729     /*
5730     VymModel *m = currentModel();
5731     if (m)
5732     {
5733         m->getMapEditor()->minimizeView();
5734     }
5735     */
5736
5737     /*
5738     QString zp = "c:\\Program Files\\7-Zip\\7z.exe";
5739     QString zipName = "c:\\Users\\uwdr9542\\x\\ü1.vym";
5740     QString zipDir  = "c:\\Users\\uwdr9542\\x\\y\\";
5741     */
5742     QString zp = "c:/Program Files/7-Zip/7z.exe";
5743     QString zipName = "c:/Users/uwdr9542/x/ü1.vym";
5744     QString zipDir  = "c:/Users/uwdr9542/x/y/";
5745
5746     zp = QDir::toNativeSeparators(zp);
5747     zipName = QDir::toNativeSeparators(zipName);
5748     zipDir  = QDir::toNativeSeparators(zipDir);
5749     QStringList args;
5750     args << "a" << zipName << "-tzip" << "-scsUTF-8" << "-sccUTF-8" << "*" ;
5751
5752     VymProcess *zipProc=new VymProcess ();
5753     zipProc->setWorkingDirectory (zipDir);
5754
5755     zipProc->start(zipToolPath, args);
5756     qDebug() << "7z:" << zp;
5757     qDebug() << "7z started in dir: " << zipProc->workingDirectory();
5758     qDebug() << "args:" << args;
5759     qDebug() << zipProc->getStdout()<<flush;
5760 }
5761
5762 void Main::testFunction2()
5763 {
5764 }
5765
5766 void Main::toggleWinter()
5767 {
5768     if (!currentMapEditor()) return;
5769     currentMapEditor()->toggleWinter();
5770 }
5771
5772 void Main::toggleHideExport()
5773 {
5774     VymModel *m=currentModel();
5775     if (!m) return;
5776     if (actionToggleHideMode->isChecked() )
5777         m->setHideTmpMode (TreeItem::HideExport);
5778     else
5779         m->setHideTmpMode (TreeItem::HideNone);
5780 }
5781
5782 void Main::testCommand()
5783 {
5784     if (!currentMapEditor()) return;
5785     scriptEditor->show();
5786 }
5787
5788 void Main::helpDoc()
5789 {
5790     QString locale = QLocale::system().name();
5791     QString docname;
5792     if (locale.left(2)=="es")
5793         docname="vym_es.pdf";
5794     else    
5795         docname="vym.pdf";
5796
5797     QStringList searchList;
5798     QDir docdir;
5799     #if defined(Q_OS_MACX)
5800         searchList << vymBaseDir.path() + "/doc";
5801     #elif defined(Q_OS_WIN32)
5802         searchList << vymInstallDir.path() + "doc/" + docname;
5803     #else
5804         #if defined(VYM_DOCDIR)
5805             searchList << VYM_DOCDIR;
5806         #endif
5807         // default path in SUSE LINUX
5808         searchList << "/usr/share/doc/packages/vym";
5809     #endif
5810
5811     searchList << "doc";    // relative path for easy testing in tarball
5812     searchList << "/usr/share/doc/vym"; // Debian
5813     searchList << "/usr/share/doc/packages";// Knoppix
5814
5815     bool found=false;
5816     QFile docfile;
5817     for (int i=0; i<searchList.count(); ++i)
5818     {
5819         docfile.setFileName(searchList.at(i)+"/"+docname);
5820         if (docfile.exists())
5821         {
5822             found=true;
5823             break;
5824         }   
5825     }
5826
5827     if (!found)
5828     {
5829         QMessageBox::critical(0, 
5830             tr("Critcal error"),
5831         tr("Couldn't find the documentation %1 in:\n%2").arg(docname).arg(searchList.join("\n")));
5832         return;
5833     }   
5834
5835     QStringList args;
5836     VymProcess *pdfProc = new VymProcess();
5837     args << QDir::toNativeSeparators(docfile.fileName());
5838
5839     if (!pdfProc->startDetached( settings.value("/system/readerPDF").toString(),args) )
5840     {
5841         // error handling
5842         QMessageBox::warning(0, 
5843             tr("Warning"),
5844             tr("Couldn't find a viewer to open %1.\n").arg(docfile.fileName())+
5845             tr("Please use Settings->")+tr("Set application to open PDF files"));
5846         settingsPDF();  
5847         return;
5848     }
5849 }
5850
5851 void Main::helpDemo()
5852 {
5853     QStringList filters;
5854     filters <<"VYM example map (*.vym)";
5855     QFileDialog fd;
5856     fd.setDirectory (vymBaseDir.path() + "/demos");
5857     fd.setFileMode (QFileDialog::ExistingFiles);
5858     fd.setNameFilters (filters);
5859     fd.setWindowTitle (vymName+ " - " +tr("Load vym example map"));
5860     fd.setAcceptMode (QFileDialog::AcceptOpen);
5861
5862     QString fn;
5863     if ( fd.exec() == QDialog::Accepted )
5864     {
5865         lastMapDir=fd.directory().path();
5866         QStringList flist = fd.selectedFiles();
5867         QStringList::Iterator it = flist.begin();
5868         initProgressCounter( flist.count());
5869         while( it != flist.end() )
5870         {
5871             fn = *it;
5872             fileLoad(*it, NewMap,VymMap);
5873             ++it;
5874         }
5875         removeProgressCounter();
5876     }
5877 }
5878
5879 void Main::helpShortcuts()
5880 {
5881     ShowTextDialog dia;
5882     dia.useFixedFont (true);
5883     dia.setText( switchboard.getASCII() );
5884     dia.exec();
5885 }
5886
5887 void Main::debugInfo()  
5888 {
5889     QString s;
5890     s = QString ("Platform: %1\n").arg(vymPlatform);
5891     s += QString ("localeName: %1\nPath: %2\n")
5892         .arg(localeName)
5893         .arg(vymBaseDir.path() + "/lang");
5894     s += QString("vymBaseDir: %1\n").arg(vymBaseDir.path());
5895     s += QString("currentPath: %1\n").arg(QDir::currentPath());
5896     s += QString("appDirPath: %1\n").arg(QCoreApplication::applicationDirPath());
5897     QMessageBox mb;
5898     mb.setText(s);
5899     mb.exec();
5900 }
5901
5902 void Main::helpAbout()
5903 {
5904     AboutDialog ad;
5905     ad.setMinimumSize(500,500);
5906     ad.resize (QSize (500,500));
5907     ad.exec();
5908 }
5909
5910 void Main::helpAboutQT()
5911 {
5912     QMessageBox::aboutQt( this, "Qt Application Example" );
5913 }
5914
5915 void Main::callMacro ()
5916 {
5917     QAction *action = qobject_cast<QAction *>(sender());
5918     int i=-1;
5919     if (action)
5920     {
5921         i=action->data().toInt();
5922         QString s=macros.getMacro (i+1);
5923         if (!s.isEmpty())
5924         {
5925             VymModel *m=currentModel();
5926             if (m) m->execute(s);
5927         }
5928     }   
5929 }
5930
5931 void Main::downloadReleaseNotesFinished()
5932 {
5933     DownloadAgent *agent = static_cast<DownloadAgent*>(sender());
5934     QString s;
5935     
5936     if (agent->isSuccess() )
5937     {
5938         QString page;
5939         if (agent->isSuccess() )
5940         {
5941             if ( loadStringFromDisk(agent->getDestination(), page) )
5942             {
5943                 ShowTextDialog dia(this);
5944                 dia.setText(page);
5945                 dia.exec();
5946
5947                 // Don't load the release notes automatically again
5948                 settings.setValue("/downloads/releaseNotes/shownVersion", __VYM_VERSION);
5949             } 
5950         }
5951     } else
5952     {
5953         if (debug)
5954         {
5955             qDebug()<<"Main::downloadReleaseNotesFinished ";
5956             qDebug()<<"  result: failed";
5957             qDebug()<<"     msg: " << agent->getResultMessage();
5958         }
5959     }
5960 }
5961
5962 void Main::checkReleaseNotes()
5963 {
5964     bool userTriggered;
5965     if (qobject_cast<QAction *>(sender()) )
5966         userTriggered = true;
5967     else
5968         userTriggered = false;
5969
5970     if (downloadsEnabled())
5971     {
5972         if ( userTriggered ||
5973              versionLowerThanVym( settings.value("/downloads/releaseNotes/shownVersion", "0.0.1").toString() ) )
5974         {
5975             QUrl releaseNotesUrl(
5976                 //QString("http://localhost/release-notes.php?vymVersion=%1") /
5977                 QString("http://www.insilmaril.de/vym/release-notes.php?vymVersion=%1")
5978                 .arg(vymVersion)
5979             );
5980             DownloadAgent *agent = new DownloadAgent(releaseNotesUrl);
5981             connect (agent, SIGNAL( downloadFinished()), this, SLOT(downloadReleaseNotesFinished()));
5982             QTimer::singleShot(0, agent, SLOT(execute()));
5983         }
5984     } else
5985     {
5986         // No downloads enabled
5987         if (userTriggered)
5988         {
5989             // Notification: vym could not download release notes
5990             QMessageBox::warning(0,  tr("Warning"), tr("Please allow vym to download release notes!"));
5991             if (downloadsEnabled(userTriggered)) checkUpdates();
5992         }
5993     }
5994 }
5995
5996 bool Main::downloadsEnabled (bool userTriggered)
5997 {
5998     bool result;
5999     if (!userTriggered && settings.value("/downloads/enabled", false).toBool())
6000     {
6001         result = true;
6002     } else
6003     {
6004         QDate lastAsked = settings.value("/downloads/permissionLastAsked", QDate(1970,1,1) ).toDate();
6005         if (userTriggered ||
6006             !settings.contains("/downloads/permissionLastAsked") ||
6007             lastAsked.daysTo( QDate::currentDate()) > 7
6008            )
6009         {
6010             QString infotext;
6011             infotext = tr("<html>"
6012                           "<h3>Do you allow vym to check online for updates or release notes?</h3>"
6013                           "If you allow, vym will "
6014                           "<ul>"
6015                             "<li>check once for release notes</li>"
6016                             "<li>check regulary for updates and notify you in case you should update, e.g. if there are "
6017                               "important bug fixes available</li>"
6018                             "<li>receive a cookie with a random ID and send vym version and platform name and the ID  "
6019                               "(e.g. \"Windows\" or \"Linux\") back to me, Uwe Drechsel."
6020                               "<p>As vym developer I am motivated to see "
6021                               "many people using vym. Of course I am curious to see, on which system vym is used. Maintaining each "
6022                               "of the systems requires a lot of my (spare) time.</p> "
6023                               "<p>No other data than above will be sent, especially no private data will be collected or sent."
6024                               "(Check the source code, if you don't believe.)"
6025                               "</p>"
6026                             "</li>"
6027                           "</ul>"
6028                           "If you do not allow, "
6029                           "<ul>"
6030                             "<li>nothing will be downloaded and especially I will <b>not be motivated</b> "
6031                             "to spend some more thousands of hours on developing a free software tool."
6032                           "</ul>"
6033                           "Please allow vym to check for updates :-)"
6034                           );
6035             QMessageBox mb( vymName, infotext,
6036                 QMessageBox::Information,
6037                 QMessageBox::Yes | QMessageBox::Default,
6038                 QMessageBox::Cancel | QMessageBox::Escape,
6039                 QMessageBox::NoButton);
6040             mb.setButtonText( QMessageBox::Yes, tr("Allow") );
6041             mb.setButtonText( QMessageBox::Cancel, tr("Do not allow"));
6042             switch( mb.exec() )
6043             {
6044                 case QMessageBox::Yes:
6045                     result = true;
6046                     QMessageBox::information(0, vymName,
6047                         tr("Thank you for enabling downloads!"));
6048                 break;
6049                 default :
6050                     result = false;
6051                 break;
6052             }
6053         } else
6054             result = false;
6055         actionSettingsToggleDownloads->setChecked( result );
6056         settings.setValue("/downloads/enabled", result);
6057         settings.setValue("/downloads/permissionLastAsked", QDate::currentDate().toString(Qt::ISODate));
6058     }
6059     return result;
6060 }
6061
6062 void Main::downloadUpdatesFinished(bool userTriggered)
6063 {
6064     DownloadAgent *agent = static_cast<DownloadAgent*>(sender());
6065     QString s;
6066
6067     if (agent->isSuccess() )
6068     {
6069         ShowTextDialog dia;
6070         dia.setWindowTitle( vymName + " - " + tr("Update information") );
6071         QString page;
6072         if (loadStringFromDisk(agent->getDestination(), page) )
6073         {
6074             if (page.contains("vymisuptodate"))
6075             {
6076                 statusMessage( tr("vym is up to date.","MainWindow"));
6077                 if (userTriggered)
6078                 {
6079                     // Notification: vym is up to date!
6080                     dia.setHtml( page );
6081                     dia.exec();
6082                 }
6083             } else if (page.contains("vymneedsupdate"))
6084             {
6085                 // Notification: updates available
6086                 dia.setHtml( page );
6087                 dia.exec();
6088             } else 
6089             {
6090                 // Notification: Unknown version found
6091                 dia.setHtml( page );
6092                 dia.exec();
6093             } 
6094
6095             // Prepare to check again later
6096             settings.setValue("/downloads/updates/lastChecked", QDate::currentDate().toString(Qt::ISODate));
6097         } else
6098             statusMessage( "Couldn't load update page from " + agent->getDestination());
6099
6100     } else
6101     {
6102         statusMessage( "Check for updates failed.");
6103         if (debug)
6104         {
6105             qDebug()<<"Main::downloadUpdatesFinished ";
6106             qDebug()<<"  result: failed";
6107             qDebug()<<"     msg: " << agent->getResultMessage();
6108         }
6109     }
6110 }
6111 void Main::downloadUpdatesFinishedInt()
6112 {
6113     downloadUpdatesFinished(true);
6114 }
6115
6116 void Main::downloadUpdates(bool userTriggered)
6117 {
6118     QUrl updatesUrl(
6119         QString("http://www.insilmaril.de/vym/updates.php?vymVersion=%1")
6120         .arg(vymVersion)
6121     );
6122     DownloadAgent *agent = new DownloadAgent(updatesUrl);
6123     if (userTriggered)
6124         connect (agent, SIGNAL( downloadFinished()), this, SLOT(downloadUpdatesFinishedInt()));
6125     else
6126         connect (agent, SIGNAL( downloadFinished()), this, SLOT(downloadUpdatesFinished()));
6127     statusMessage( tr("Checking for updates...","MainWindow"));
6128     QTimer::singleShot(0, agent, SLOT(execute()));
6129 }
6130
6131 void Main::checkUpdates()
6132 {
6133     bool userTriggered;
6134     if (qobject_cast<QAction *>(sender()) )
6135         userTriggered = true;
6136     else
6137         userTriggered = false;
6138
6139     if (downloadsEnabled())
6140     {
6141         // Too much time passed since last update check?
6142         QDate lastChecked = settings.value("/downloads/updates/lastChecked", QDate(1970,1,1) ).toDate();
6143         if ( !lastChecked.isValid()) lastChecked = QDate(1970,1,1);
6144         if ( lastChecked.daysTo( QDate::currentDate()) > settings.value("/downloads/updates/checkInterval",3).toInt() ||
6145              userTriggered == true)
6146         {
6147             downloadUpdates( userTriggered );
6148         }
6149     } else
6150     {
6151         // No downloads enabled
6152         if (userTriggered)
6153         {
6154             // Notification: vym could not check for updates
6155             QMessageBox::warning(0,  tr("Warning"), tr("Please allow vym to check for updates!"));
6156             if (downloadsEnabled(userTriggered)) checkUpdates();
6157         }
6158     }
6159 }