mainwindow.cpp
author insilmaril
Wed, 10 Feb 2010 13:48:42 +0000
changeset 822 c2ce9944148c
parent 821 4a84d7e444d8
child 823 0bba81dde1bc
permissions -rw-r--r--
More fixes and sorting lexically backwards
     1 #include "mainwindow.h"
     2 
     3 #include <QtGui>
     4 
     5 #include <iostream>
     6 #include <typeinfo>
     7 
     8 #include "aboutdialog.h"
     9 #include "branchpropwindow.h"
    10 #include "branchitem.h"
    11 #include "exportoofiledialog.h"
    12 #include "exports.h"
    13 #include "file.h"
    14 #include "flagrow.h"
    15 #include "historywindow.h"
    16 #include "imports.h"
    17 #include "mapeditor.h"
    18 #include "misc.h"
    19 #include "options.h"
    20 #include "process.h"
    21 #include "settings.h"
    22 #include "shortcuts.h"
    23 #include "texteditor.h"
    24 #include "warningdialog.h"
    25 #include "xlinkitem.h"
    26 
    27 //#include <modeltest.h>	// FIXME-3
    28 
    29 #if defined(Q_OS_WIN32)
    30 // Define only this structure as opposed to
    31 // including full 'windows.h'. FindWindow
    32 // clashes with the one in Win32 API.
    33 typedef struct _PROCESS_INFORMATION
    34 {
    35 	long hProcess;
    36 	long hThread;
    37 	long dwProcessId;
    38 	long dwThreadId;
    39 } PROCESS_INFORMATION, *LPPROCESS_INFORMATION;
    40 #endif
    41 
    42 extern TextEditor *textEditor;
    43 extern Main *mainWindow;
    44 extern QString tmpVymDir;
    45 extern QString clipboardDir;
    46 extern QString clipboardFile;
    47 extern bool clipboardEmpty;
    48 extern int statusbarTime;
    49 extern FlagRow *standardFlagsMaster;	
    50 extern FlagRow *systemFlagsMaster;
    51 extern QString vymName;
    52 extern QString vymVersion;
    53 extern QString vymBuildDate;
    54 extern bool debug;
    55 
    56 QMenu* branchContextMenu;
    57 QMenu* branchAddContextMenu;
    58 QMenu* branchRemoveContextMenu;
    59 QMenu* branchLinksContextMenu;
    60 QMenu* branchXLinksContextMenuEdit;
    61 QMenu* floatimageContextMenu;
    62 QMenu* canvasContextMenu;
    63 QMenu* fileLastMapsMenu;
    64 QMenu* fileImportMenu;
    65 QMenu* fileExportMenu;
    66 
    67 
    68 extern Settings settings;
    69 extern Options options;
    70 extern ImageIO imageIO;
    71 
    72 extern QDir vymBaseDir;
    73 extern QDir lastImageDir;
    74 extern QDir lastFileDir;
    75 #if defined(Q_OS_WIN32)
    76 extern QDir vymInstallDir;
    77 #endif
    78 extern QString iconPath;
    79 extern QString flagsPath;
    80 
    81 
    82 Main::Main(QWidget* parent, const char* name, Qt::WFlags f) :
    83 QMainWindow(parent,name,f)
    84 {
    85 	mainWindow=this;
    86 
    87 	setCaption ("VYM - View Your Mind");
    88 
    89 	// Load window settings
    90 	#if defined(Q_OS_WIN32)
    91 	if (settings.value("/mainwindow/geometry/maximized", false).toBool())
    92 	{
    93 		setWindowState(Qt::WindowMaximized);
    94 	}
    95 	else
    96 	#endif
    97 	{
    98 		resize (settings.value("/mainwindow/geometry/size", QSize (800,600)).toSize());
    99 		move   (settings.value("/mainwindow/geometry/pos",  QPoint(300,100)).toPoint());
   100 	}
   101 
   102 	// Sometimes we may need to remember old selections
   103 	prevSelection="";
   104 
   105 	// Default color
   106 	currentColor=Qt::black;
   107 
   108 	// Create unique temporary directory
   109 	bool ok;
   110 	tmpVymDir=makeTmpDir (ok,"vym");
   111 	if (!ok)
   112 	{
   113 		qWarning ("Mainwindow: Could not create temporary directory, failed to start vym");
   114 		exit (1);
   115 	}
   116 	if (debug) qDebug (QString("vym tmpDir=%1").arg(tmpVymDir) );
   117 
   118 	// Create direcctory for clipboard
   119 	clipboardDir=tmpVymDir+"/clipboard";
   120 	clipboardFile="map.xml";
   121 	QDir d(clipboardDir);
   122 	d.mkdir (clipboardDir,true);
   123 	makeSubDirs (clipboardDir);
   124 	clipboardEmpty=true;
   125 
   126 	browserPID=new qint64;
   127 	*browserPID=0;
   128 
   129 	// Satellite windows //////////////////////////////////////////
   130 	// history window
   131 	historyWindow=new HistoryWindow();
   132 	connect (historyWindow, SIGNAL (windowClosed() ), this, SLOT (updateActions()));
   133 
   134 	// properties window
   135 	branchPropertyWindow = new BranchPropertyWindow();
   136 	connect (branchPropertyWindow, SIGNAL (windowClosed() ), this, SLOT (updateActions()));
   137 
   138 	// Connect TextEditor, so that we can update flags if text changes
   139 	connect (textEditor, SIGNAL (textHasChanged() ), this, SLOT (updateNoteFlag()));
   140 	connect (textEditor, SIGNAL (windowClosed() ), this, SLOT (updateActions()));
   141 
   142 	// Initialize script editor
   143 	scriptEditor = new SimpleScriptEditor();
   144 	scriptEditor->move (50,50);
   145 
   146 	connect( scriptEditor, SIGNAL( runScript ( QString ) ), 
   147 		this, SLOT( runScript( QString ) ) );
   148 
   149 	// Initialize some settings, which are platform dependant
   150 	QString p,s;
   151 
   152 		// application to open URLs
   153 		p="/mainwindow/readerURL";
   154 		#if defined(Q_OS_LINUX)
   155 			s=settings.value (p,"xdg-open").toString();
   156 		#else
   157 			#if defined(Q_OS_MACX)
   158 				s=settings.value (p,"/usr/bin/open").toString();
   159 
   160 			#else
   161 				#if defined(Q_OS_WIN32)
   162 					// Assume that system has been set up so that
   163 					// Explorer automagically opens up the URL
   164 					// in the user's preferred browser.
   165 					s=settings.value (p,"explorer").toString();
   166 				#else
   167 					s=settings.value (p,"mozilla").toString();
   168 				#endif
   169 			#endif
   170 		#endif
   171 		settings.setValue( p,s);
   172 
   173 		// application to open PDFs
   174 		p="/mainwindow/readerPDF";
   175 		#if defined(Q_OS_LINUX)
   176 			s=settings.value (p,"xdg-open").toString();
   177 		#else
   178 			#if defined(Q_OS_MACX)
   179 				s=settings.value (p,"/usr/bin/open").toString();
   180 			#elif defined(Q_OS_WIN32)
   181 				s=settings.value (p,"acrord32").toString();
   182 			#else
   183 				s=settings.value (p,"acroread").toString();
   184 			#endif
   185 		#endif
   186 		settings.setValue( p,s);
   187 
   188 	// width of xLinksMenu
   189 	xLinkMenuWidth=60;
   190 
   191 	// Create tab widget which holds the maps
   192 	tabWidget= new QTabWidget (this);
   193 	connect( tabWidget, SIGNAL( currentChanged( QWidget * ) ), 
   194 		this, SLOT( editorChanged( QWidget * ) ) );
   195 
   196 	setCentralWidget(tabWidget);	
   197 
   198 	setupFileActions();
   199 	setupEditActions();
   200 	setupFormatActions();
   201 	setupViewActions();
   202 	setupModeActions();
   203 	setupFlagActions();
   204 	setupNetworkActions();
   205 	setupSettingsActions();
   206 	setupContextMenus();
   207 	setupMacros();
   208 	if (settings.value( "/mainwindow/showTestMenu",false).toBool()) setupTestActions();
   209 	setupHelpActions();
   210 
   211 	// Status bar and progress bar there
   212 	statusBar();
   213 	progressMax=0;
   214 	progressCounter=0;
   215 	progressCounterTotal=0;
   216 
   217 	progressDialog.setLabelText (tr("Loading maps","Mainwindow"));
   218 	progressDialog.setAutoReset(false);
   219 	progressDialog.setAutoClose(false);
   220 	//progressDialog.setWindowModality (Qt::WindowModal);	// That forces mainwindo to update and slows down
   221 	//progressDialog.setCancelButton (NULL);
   222 
   223 	restoreState (settings.value("/mainwindow/state",0).toByteArray());
   224 
   225 	updateGeometry();
   226 }
   227 
   228 Main::~Main()
   229 {
   230 	// Save Settings
   231 	#if defined(Q_OS_WIN32)
   232 	settings.setValue ("/mainwindow/geometry/maximized", isMaximized());
   233 	#endif
   234 	settings.setValue ("/mainwindow/geometry/size", size());
   235 	settings.setValue ("/mainwindow/geometry/pos", pos());
   236 	settings.setValue ("/mainwindow/state",saveState(0));
   237 
   238 	settings.setValue ("/mainwindow/view/AntiAlias",actionViewToggleAntiAlias->isOn());
   239 	settings.setValue ("/mainwindow/view/SmoothPixmapTransform",actionViewToggleSmoothPixmapTransform->isOn());
   240 	settings.setValue( "/version/version", vymVersion );
   241 	settings.setValue( "/version/builddate", vymBuildDate );
   242 
   243 	settings.setValue( "/mainwindow/autosave/use",actionSettingsAutosaveToggle->isOn() );
   244 	settings.setValue( "/mapeditor/editmode/autoSelectNewBranch",actionSettingsAutoSelectNewBranch->isOn() );
   245 	settings.setValue( "/mainwindow/writeBackupFile",actionSettingsWriteBackupFile->isOn() );
   246 	settings.setValue( "/mapeditor/editmode/autoSelectText",actionSettingsAutoSelectText->isOn() );
   247 	settings.setValue( "/mapeditor/editmode/autoEditNewBranch",actionSettingsAutoEditNewBranch->isOn() );
   248 	settings.setValue( "/mapeditor/editmode/useDelKey",actionSettingsUseDelKey->isOn() );
   249 	settings.setValue( "/mapeditor/editmode/useFlagGroups",actionSettingsUseFlagGroups->isOn() );
   250 	settings.setValue( "/export/useHideExport",actionSettingsUseHideExport->isOn() );
   251 
   252 	//TODO save scriptEditor settings
   253 
   254 	// call the destructors
   255 	delete textEditor;
   256 	delete historyWindow;
   257 	delete branchPropertyWindow;
   258 
   259 	// Remove temporary directory
   260 	removeDir (QDir(tmpVymDir));
   261 }
   262 
   263 void Main::loadCmdLine()
   264 {
   265 	/* TODO draw some kind of splashscreen while loading...
   266 	if (qApp->argc()>1)
   267 	{
   268 	}
   269 	*/
   270 
   271 	QStringList flist=options.getFileList();
   272 	QStringList::Iterator it=flist.begin();
   273 
   274 	progressCounter=flist.count();
   275 	progressCounterTotal=flist.count();
   276 	while (it !=flist.end() )
   277 	{
   278 		fileLoad (*it, NewMap);
   279 		*it++;
   280 	}	
   281 }
   282 
   283 
   284 void Main::statusMessage(const QString &s)
   285 {
   286 	// Surpress messages while progressdialog during 
   287 	// load is active
   288 	if (progressMax==0)
   289 		statusBar()->message( s);
   290 }
   291 
   292 void Main::setProgressMaximum (int max)	
   293 {
   294 	if (progressCounterTotal!=0)
   295 	
   296 		progressDialog.setRange (0,progressCounterTotal*1000);
   297 	else
   298 		progressDialog.setRange (0,max+10);
   299 
   300 	progressDialog.setValue (0);
   301 	progressMax=max*1000;
   302 	//cout << "Main  max="<<max<<"  v="<<progressDialog.value()<<endl;
   303 	progressDialog.show();
   304 }
   305 
   306 void Main::addProgressValue (float v)
   307 {
   308 	//cout << "addVal v="<<v*1000<<"/"<<progressMax<<"  cur="<<progressDialog.value()<<"  counter="<<v+progressCounter<<"/"<<progressCounterTotal<<endl;
   309 	if (progressCounterTotal!=0)
   310 		progressDialog.setValue ( (v+progressCounterTotal-progressCounter)*1000 );
   311 	else	
   312 		progressDialog.setValue (v+progressDialog.value());
   313 }
   314 
   315 void Main::removeProgressCounter()
   316 {
   317 	progressMax=0;
   318 	progressCounter--;
   319 	if (progressCounter<=0)
   320 	{ 
   321 		// Hide dialog again
   322 		progressCounterTotal=0;
   323 		progressDialog.reset();
   324 		progressDialog.hide();
   325 	}	
   326 }
   327 
   328 void Main::closeEvent (QCloseEvent* )
   329 {
   330 	fileExitVYM();
   331 }
   332 
   333 // File Actions
   334 void Main::setupFileActions()
   335 {
   336 	QMenu *fileMenu = menuBar()->addMenu ( tr ("&Map") );
   337 	QToolBar *tb = addToolBar( tr ("&Map") );
   338 	tb->setObjectName ("mapTB");
   339 
   340 	QAction *a;
   341 	a = new QAction(QPixmap( iconPath+"filenew.png"), tr( "&New map","File menu" ),this);
   342 	a->setStatusTip ( tr( "New map","Status tip File menu" ) );
   343 	a->setShortcut ( Qt::CTRL + Qt::Key_N );		//New map
   344 	a->addTo( tb );
   345 	fileMenu->addAction (a);
   346 	connect( a, SIGNAL( triggered() ), this, SLOT( fileNew() ) );
   347 
   348 	a = new QAction(QPixmap( iconPath+"filenewcopy.png"), tr( "&Copy to new map","File menu" ),this);
   349 	a->setStatusTip ( tr( "Copy selection to mapcenter of a new map","Status tip File menu" ) );
   350 	a->setShortcut ( Qt::CTRL +Qt::SHIFT + Qt::Key_N );		//New map
   351 	fileMenu->addAction (a);
   352 	connect( a, SIGNAL( triggered() ), this, SLOT( fileNewCopy() ) );
   353 	actionFileNewCopy=a;
   354 
   355 	a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Open..." ,"File menu"),this);
   356 	a->setStatusTip (tr( "Open","Status tip File menu" ) );
   357 	a->setShortcut ( Qt::CTRL + Qt::Key_O );		//Open map
   358 	a->addTo( tb );
   359 	fileMenu->addAction (a);
   360 	connect( a, SIGNAL( triggered() ), this, SLOT( fileLoad() ) );
   361 
   362 	fileLastMapsMenu = fileMenu->addMenu (tr("Open Recent","File menu"));
   363 	fileMenu->addSeparator();
   364 
   365 	a = new QAction( QPixmap( iconPath+"filesave.png"), tr( "&Save...","File menu" ), this);
   366 	a->setStatusTip ( tr( "Save","Status tip file menu" ));
   367 	a->setShortcut (Qt::CTRL + Qt::Key_S );			//Save map
   368 	a->addTo( tb );
   369 	fileMenu->addAction (a);
   370 	connect( a, SIGNAL( triggered() ), this, SLOT( fileSave() ) );
   371 	actionFileSave=a;
   372 
   373 	a = new QAction( QPixmap(iconPath+"filesaveas.png"), tr( "Save &As...","File menu" ), this);
   374 	a->setStatusTip (tr( "Save &As","Status tip file menu" ) );
   375 	fileMenu->addAction (a);
   376 	connect( a, SIGNAL( triggered() ), this, SLOT( fileSaveAs() ) );
   377 
   378 	fileMenu->addSeparator();
   379 
   380 	fileImportMenu = fileMenu->addMenu (tr("Import","File menu"));
   381 
   382 	a = new QAction(tr("KDE 3 Bookmarks"), this);
   383 	a->setStatusTip ( tr( "Import %1","Status tip file menu" ).arg(tr("KDE 3 bookmarks")));
   384 	a->addTo (fileImportMenu);
   385 	connect( a, SIGNAL( triggered() ), this, SLOT( fileImportKDE3Bookmarks() ) );
   386 
   387 	a = new QAction(tr("KDE 4 Bookmarks"), this);
   388 	a->setStatusTip ( tr( "Import %1","Status tip file menu" ).arg(tr("KDE 4 bookmarks")));
   389 	a->addTo (fileImportMenu);
   390 	connect( a, SIGNAL( triggered() ), this, SLOT( fileImportKDE4Bookmarks() ) );
   391 
   392 	if (settings.value( "/mainwindow/showTestMenu",false).toBool()) 
   393 	{
   394 		a = new QAction( QPixmap(), tr("Firefox Bookmarks","File menu"),this);
   395 		a->setStatusTip (tr( "Import %1","Status tip file menu").arg(tr("Firefox Bookmarks" ) ));
   396 		a->addTo (fileImportMenu);
   397 		connect( a, SIGNAL( triggered() ), this, SLOT( fileImportFirefoxBookmarks() ) );
   398 	}	
   399 
   400 	a = new QAction("Freemind...",this);
   401 	a->setStatusTip ( tr( "Import %1","status tip file menu").arg(" Freemind")  );
   402 	fileImportMenu->addAction (a);
   403 	connect( a, SIGNAL( triggered() ), this, SLOT( fileImportFreemind() ) );
   404 
   405 	a = new QAction("Mind Manager...",this);
   406 	a->setStatusTip ( tr( "Import %1","status tip file menu").arg(" Mind Manager")  );
   407 	fileImportMenu->addAction (a);
   408 	connect( a, SIGNAL( triggered() ), this, SLOT( fileImportMM() ) );
   409 
   410 	a = new QAction( tr( "Import Dir%1","File menu").arg("..."), this);
   411 	a->setStatusTip (tr( "Import directory structure (experimental)","status tip file menu" ) );
   412 	fileImportMenu->addAction (a);
   413 	connect( a, SIGNAL( triggered() ), this, SLOT( fileImportDir() ) );
   414 
   415 	fileExportMenu = fileMenu->addMenu (tr("Export","File menu"));
   416 
   417 	a = new QAction( tr("Image%1","File export menu").arg("..."), this);
   418 	a->setStatusTip( tr( "Export map as image","status tip file menu" ));
   419 	connect( a, SIGNAL( triggered() ), this, SLOT( fileExportImage() ) );
   420 	fileExportMenu->addAction (a);
   421 
   422 	a = new QAction( "Open Office...", this);
   423 	a->setStatusTip( tr( "Export in Open Document Format used e.g. in Open Office ","status tip file menu" ));
   424 	connect( a, SIGNAL( triggered() ), this, SLOT( fileExportOOPresentation() ) );
   425 	fileExportMenu->addAction (a);
   426 
   427 	a = new QAction(  "Webpage (HTML)...",this );
   428 	a->setShortcut (Qt::ALT + Qt::Key_X);			//Export HTML
   429 	a->setStatusTip ( tr( "Export as %1","status tip file menu").arg(tr(" webpage (XHTML)","status tip file menu")));
   430 	connect( a, SIGNAL( triggered() ), this, SLOT( fileExportHTML() ) );
   431 	fileExportMenu->addAction (a);
   432 
   433 	a = new QAction(  "Webpage (XHTML)...",this );	//Export XHTML
   434 
   435 	//a->setShortcut (Qt::ALT + Qt::SHIFT + Qt::Key_X);	a->setStatusTip ( tr( "Export as %1","status tip file menu").arg(tr(" webpage (XHTML)","status tip file menu")));
   436 	connect( a, SIGNAL( triggered() ), this, SLOT( fileExportXHTML() ) );
   437 	fileExportMenu->addAction (a);
   438 
   439 	a = new QAction( "Text (A&O report)...", this);
   440 	a->setStatusTip ( tr( "Export as %1").arg("A&O report "+tr("(still experimental)" )));
   441 	connect( a, SIGNAL( triggered() ), this, SLOT( fileExportAO() ) );
   442 	fileExportMenu->addAction (a);
   443 
   444 	a = new QAction( "Text (ASCII)...", this);
   445 	a->setStatusTip ( tr( "Export as %1").arg("ASCII "+tr("(still experimental)" )));
   446 	connect( a, SIGNAL( triggered() ), this, SLOT( fileExportASCII() ) );
   447 	fileExportMenu->addAction (a);
   448 
   449 	a = new QAction( "Spreadsheet (CSV)...", this);
   450 	a->setStatusTip ( tr( "Export as %1").arg("CSV "+tr("(still experimental)" )));
   451 	connect( a, SIGNAL( triggered() ), this, SLOT( fileExportCSV() ) );
   452 	fileExportMenu->addAction (a);
   453 
   454 	a = new QAction( tr("KDE 3 Bookmarks","File menu"), this);
   455 	a->setStatusTip( tr( "Export as %1").arg(tr("KDE 3 Bookmarks" )));
   456 	connect( a, SIGNAL( triggered() ), this, SLOT( fileExportKDE3Bookmarks() ) );
   457 	fileExportMenu->addAction (a);
   458 
   459 	a = new QAction( tr("KDE 4 Bookmarks","File menu"), this);
   460 	a->setStatusTip( tr( "Export as %1").arg(tr("KDE 4 Bookmarks" )));
   461 	connect( a, SIGNAL( triggered() ), this, SLOT( fileExportKDE4Bookmarks() ) );
   462 	fileExportMenu->addAction (a);
   463 
   464 	a = new QAction( "Taskjuggler...", this );
   465 	a->setStatusTip( tr( "Export as %1").arg("Taskjuggler "+tr("(still experimental)" )));
   466 	connect( a, SIGNAL( triggered() ), this, SLOT( fileExportTaskjuggler() ) );
   467 	fileExportMenu->addAction (a);
   468 
   469 	a = new QAction( "LaTeX...", this);
   470 	a->setStatusTip( tr( "Export as %1").arg("LaTeX "+tr("(still experimental)" )));
   471 	connect( a, SIGNAL( triggered() ), this, SLOT( fileExportLaTeX() ) );
   472 	fileExportMenu->addAction (a);
   473 
   474 	a = new QAction( "XML..." , this );
   475 	a->setStatusTip (tr( "Export as %1").arg("XML"));
   476 	connect( a, SIGNAL( triggered() ), this, SLOT( fileExportXML() ) );
   477 	fileExportMenu->addAction (a);
   478 
   479 	fileMenu->addSeparator();
   480 
   481 	a = new QAction(QPixmap( iconPath+"fileprint.png"), tr( "&Print")+QString("..."), this);
   482 	a->setStatusTip ( tr( "Print" ,"File menu") );
   483 	a->setShortcut (Qt::CTRL + Qt::Key_P );			//Print map
   484 	a->addTo( tb );
   485 	fileMenu->addAction (a);
   486 	connect( a, SIGNAL( triggered() ), this, SLOT( filePrint() ) );
   487 	actionFilePrint=a;
   488 
   489 	a = new QAction( QPixmap(iconPath+"fileclose.png"), tr( "&Close Map","File menu" ), this);
   490 	a->setStatusTip (tr( "Close Map" ) );
   491 	a->setShortcut (Qt::CTRL + Qt::Key_W );			//Close map
   492 	fileMenu->addAction (a);
   493 	connect( a, SIGNAL( triggered() ), this, SLOT( fileCloseMap() ) );
   494 
   495 	a = new QAction(QPixmap(iconPath+"exit.png"), tr( "E&xit","File menu")+" "+vymName, this);
   496 	a->setStatusTip ( tr( "Exit")+" "+vymName );
   497 	a->setShortcut (Qt::CTRL + Qt::Key_Q );			//Quit vym
   498 	fileMenu->addAction (a);
   499 	connect( a, SIGNAL( triggered() ), this, SLOT( fileExitVYM() ) );
   500 }
   501 
   502 
   503 //Edit Actions
   504 void Main::setupEditActions()
   505 {
   506 	QToolBar *tb = addToolBar( tr ("&Actions toolbar","Toolbar name") );
   507 	tb->setLabel( "Edit Actions" );
   508 	tb->setObjectName ("actionsTB");
   509 	QMenu *editMenu = menuBar()->addMenu( tr("&Edit","Edit menu") );
   510 
   511 	QAction *a;
   512 	QAction *alt;
   513 	a = new QAction( QPixmap( iconPath+"undo.png"), tr( "&Undo","Edit menu" ),this);
   514 	connect( a, SIGNAL( triggered() ), this, SLOT( editUndo() ) );
   515 	a->setStatusTip (tr( "Undo" ) );
   516 	a->setShortcut ( Qt::CTRL + Qt::Key_Z );		//Undo last action
   517 	a->setEnabled (false);
   518 	tb->addAction (a);
   519 	editMenu->addAction (a);
   520 	actionUndo=a;
   521 
   522 	a = new QAction( QPixmap( iconPath+"redo.png"), tr( "&Redo","Edit menu" ), this); 
   523 	a->setStatusTip (tr( "Redo" ));
   524 	a->setShortcut (Qt::CTRL + Qt::Key_Y );			//Redo last action
   525 	tb->addAction (a);
   526 	editMenu->addAction (a);
   527 	connect( a, SIGNAL( triggered() ), this, SLOT( editRedo() ) );
   528 	actionRedo=a;
   529 
   530 	editMenu->addSeparator();
   531 	a = new QAction(QPixmap( iconPath+"editcopy.png"), tr( "&Copy","Edit menu" ), this);
   532 	a->setStatusTip ( tr( "Copy" ) );
   533 	a->setShortcut (Qt::CTRL + Qt::Key_C );			//Copy
   534 	a->setEnabled (false);
   535 	tb->addAction (a);
   536 	editMenu->addAction (a);
   537 	connect( a, SIGNAL( triggered() ), this, SLOT( editCopy() ) );
   538 	actionCopy=a;
   539 
   540 	a = new QAction(QPixmap( iconPath+"editcut.png" ), tr( "Cu&t","Edit menu" ), this);
   541 	a->setStatusTip ( tr( "Cut" ) );
   542 	a->setShortcut (Qt::CTRL + Qt::Key_X );			//Cut
   543 	a->setEnabled (false);
   544 	tb->addAction (a);
   545 	editMenu->addAction (a);
   546 	actionCut=a;
   547 	connect( a, SIGNAL( triggered() ), this, SLOT( editCut() ) );
   548 
   549 	a = new QAction(QPixmap( iconPath+"editpaste.png"), tr( "&Paste","Edit menu" ),this);
   550 	connect( a, SIGNAL( triggered() ), this, SLOT( editPaste() ) );
   551 	a->setStatusTip ( tr( "Paste" ) );
   552 	a->setShortcut ( Qt::CTRL + Qt::Key_V );		//Paste
   553 	a->setEnabled (false);
   554 	tb->addAction (a);
   555 	editMenu->addAction (a);
   556 	actionPaste=a;
   557 
   558 	// Shortcut to delete selection
   559 	a = new QAction( tr( "Delete Selection","Edit menu" ),this);
   560 	a->setStatusTip (tr( "Delete Selection" ));
   561 	a->setShortcut ( Qt::Key_Delete);				//Delete selection
   562 	a->setShortcutContext (Qt::WindowShortcut);
   563 	addAction (a);
   564 	connect( a, SIGNAL( triggered() ), this, SLOT( editDeleteSelection() ) );
   565 	actionDelete=a;
   566 
   567 	// Shortcut to add attribute
   568 	a= new QAction(tr( "Add attribute" ), this);
   569 	a->setShortcut ( Qt::Key_Q);	
   570 	a->setShortcutContext (Qt::WindowShortcut);
   571 	addAction (a);
   572 	connect( a, SIGNAL( triggered() ), this, SLOT( editAddAttribute() ) );
   573 	actionAddAttribute= a;
   574 
   575 
   576 	// Shortcut to add mapcenter
   577 	a= new QAction(QPixmap(iconPath+"newmapcenter.png"),tr( "Add mapcenter","Canvas context menu" ), this);
   578 	a->setShortcut ( Qt::Key_M);	
   579 	a->setShortcutContext (Qt::WindowShortcut);
   580 	connect( a, SIGNAL( triggered() ), this, SLOT( editAddMapCenter() ) );
   581 	//actionListBranches.append(a);
   582 	tb->addAction (a);
   583 	actionAddMapCenter = a;
   584 
   585 
   586 	// Shortcut to add branch
   587 	alt = new QAction(QPixmap(iconPath+"newbranch.png"), tr( "Add branch as child","Edit menu" ), this);
   588 	alt->setStatusTip ( tr( "Add a branch as child of selection" ));
   589 	alt->setShortcut (Qt::Key_A);					//Add branch
   590 	alt->setShortcutContext (Qt::WindowShortcut);
   591 	addAction (alt);
   592 	connect( alt, SIGNAL( triggered() ), this, SLOT( editNewBranch() ) );
   593 	a = new QAction(QPixmap(iconPath+"newbranch.png"), tr( "Add branch as child","Edit menu" ), this);
   594 	a->setStatusTip ( tr( "Add a branch as child of selection" ));
   595 	a->setShortcut (Qt::Key_Insert);				//Add branch
   596 	connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranch() ) );
   597 	actionListBranches.append(a);
   598 	#if defined (Q_OS_MACX)
   599 		// In OSX show different shortcut in menues, the keys work indepently always			
   600 		actionAddBranch=alt;
   601 	#else	
   602 		actionAddBranch=a;
   603 	#endif	
   604 	editMenu->addAction (actionAddBranch);
   605 	tb->addAction (actionAddBranch);
   606 
   607 
   608 	// Add branch by inserting it at selection
   609 	a = new QAction(tr( "Add branch (insert)","Edit menu" ), this);
   610 	a->setStatusTip ( tr( "Add a branch by inserting and making selection its child" ));
   611 	a->setShortcut (Qt::ALT + Qt::Key_Insert );		//Insert branch
   612 	a->setShortcutContext (Qt::WindowShortcut);
   613 	addAction (a);
   614 	connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBefore() ) );
   615 	a->setEnabled (false);
   616 	actionListBranches.append(a);
   617 	actionAddBranchBefore=a;
   618 	a = new QAction(tr( "Add branch (insert)","Edit menu" ),this);
   619 	a->setStatusTip ( tr( "Add a branch by inserting and making selection its child" ));
   620 	a->setShortcut ( Qt::ALT + Qt::Key_A );			//Insert branch
   621 	a->setShortcutContext (Qt::WindowShortcut);
   622 	addAction (a);
   623 	connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBefore() ) );
   624 	actionListBranches.append(a);
   625 
   626 	// Add branch above
   627 	a = new QAction(tr( "Add branch above","Edit menu" ), this);
   628 	a->setStatusTip ( tr( "Add a branch above selection" ));
   629 	a->setShortcut (Qt::SHIFT+Qt::Key_Insert );		//Add branch above
   630 	a->setShortcutContext (Qt::WindowShortcut);
   631 	addAction (a);
   632 	connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchAbove() ) );
   633 	a->setEnabled (false);
   634 	actionListBranches.append(a);
   635 	actionAddBranchAbove=a;
   636 	a = new QAction(tr( "Add branch above","Edit menu" ), this);
   637 	a->setStatusTip ( tr( "Add a branch above selection" ));
   638 	a->setShortcut (Qt::SHIFT+Qt::Key_A );			//Add branch above
   639 	a->setShortcutContext (Qt::WindowShortcut);
   640 	addAction (a);
   641 	connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchAbove() ) );
   642 	actionListBranches.append(a);
   643 
   644 	// Add branch below 
   645 	a = new QAction(tr( "Add branch below","Edit menu" ), this);
   646 	a->setStatusTip ( tr( "Add a branch below selection" ));
   647 	a->setShortcut (Qt::CTRL +Qt::Key_Insert );		//Add branch below
   648 	a->setShortcutContext (Qt::WindowShortcut);
   649 	addAction (a);
   650 	connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBelow() ) );
   651 	a->setEnabled (false);
   652 	actionListBranches.append(a);
   653 	actionAddBranchBelow=a;
   654 	a = new QAction(tr( "Add branch below","Edit menu" ), this);
   655 	a->setStatusTip ( tr( "Add a branch below selection" ));
   656 	a->setShortcut (Qt::CTRL +Qt::Key_A );			// Add branch below
   657 	a->setShortcutContext (Qt::WindowShortcut);
   658 	addAction (a);
   659 	connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBelow() ) );
   660 	actionListBranches.append(a);
   661 
   662 	a = new QAction(QPixmap(iconPath+"up.png" ), tr( "Move up","Edit menu" ), this);
   663 	a->setStatusTip ( tr( "Move branch up" ) );
   664 	a->setShortcut (Qt::Key_PageUp );				// Move branch up
   665 	a->setEnabled (false);
   666 	tb->addAction (a);
   667 	editMenu->addAction (a);
   668 	connect( a, SIGNAL( triggered() ), this, SLOT( editMoveUp() ) );
   669 	actionMoveUp=a;
   670 
   671 	a = new QAction( QPixmap( iconPath+"down.png"), tr( "Move down","Edit menu" ),this);
   672 	connect( a, SIGNAL( triggered() ), this, SLOT( editMoveDown() ) );
   673 	a->setStatusTip (tr( "Move branch down" ) );
   674 	a->setShortcut ( Qt::Key_PageDown );			// Move branch down
   675 	a->setEnabled (false);
   676 	tb->addAction (a);
   677 	editMenu->addAction (a);
   678 	actionMoveDown=a;
   679 
   680 	a = new QAction(QPixmap(), tr( "&Detach","Context menu" ),this);
   681 	a->setStatusTip ( tr( "Detach branch and use as mapcenter","Context menu" ) );
   682 	a->setShortcut ( Qt::Key_D );					// Detach branch
   683 	editMenu->addAction (a);
   684 	connect( a, SIGNAL( triggered() ), this, SLOT( editDetach() ) );
   685 	actionDetach=a;
   686 
   687 	a = new QAction( QPixmap(iconPath+"editsort.png" ), tr( "Sort children","Edit menu" ), this );
   688 	connect( a, SIGNAL( activated() ), this, SLOT( editSortChildren() ) );
   689 	a->setEnabled (true);
   690 	a->addTo( tb );
   691 	editMenu->addAction (a);
   692 	actionSortChildren=a;
   693 
   694 	a = new QAction( QPixmap(iconPath+"editsortback.png" ), tr( "Sort children backwards","Edit menu" ), this );
   695 	connect( a, SIGNAL( activated() ), this, SLOT( editSortBackChildren() ) );
   696 	a->setEnabled (true);
   697 	a->addTo( tb );
   698 	editMenu->addAction (a);
   699 	actionSortBackChildren=a;
   700 
   701 	alt = new QAction( QPixmap(flagsPath+"flag-scrolled-right.png"), tr( "Scroll branch","Edit menu" ), this);
   702 	alt->setShortcut ( Qt::Key_S );					// Scroll branch
   703 	alt->setStatusTip (tr( "Scroll branch" )); 
   704 	connect( alt, SIGNAL( triggered() ), this, SLOT( editToggleScroll() ) );
   705 	#if defined(Q_OS_MACX)
   706 		actionToggleScroll=alt;
   707 	#else	
   708 		actionToggleScroll=a;
   709 	#endif	
   710 	actionToggleScroll->setEnabled (false);
   711 	actionToggleScroll->setToggleAction(true);
   712 	tb->addAction (actionToggleScroll);
   713 	editMenu->addAction ( actionToggleScroll);
   714 	editMenu->addAction (actionToggleScroll);
   715 	addAction (a);
   716 	addAction (alt);
   717 	actionListBranches.append(actionToggleScroll);
   718 
   719 	a = new QAction( QPixmap(), tr( "Expand all branches","Edit menu" ), this);
   720 	a->setShortcut ( Qt::SHIFT + Qt::Key_X );		// Expand all branches 
   721 	a->setStatusTip (tr( "Expand all branches" )); 
   722 	connect( a, SIGNAL( triggered() ), this, SLOT( editExpandAll() ) );
   723 	actionExpandAll=a;
   724 	actionExpandAll->setEnabled (false);
   725 	actionExpandAll->setToggleAction(false);
   726 	//tb->addAction (actionExpandAll);
   727 	editMenu->addAction ( actionExpandAll);
   728 	addAction (a);
   729 	actionListBranches.append(actionExpandAll);
   730 
   731 	a = new QAction( QPixmap(), tr( "Expand one level","Edit menu" ), this);
   732 	a->setShortcut ( Qt::Key_Greater );		// Expand one level in tree editor
   733 	a->setStatusTip (tr( "Expand one level in tree editor" )); 
   734 	connect( a, SIGNAL( triggered() ), this, SLOT( editExpandOneLevel() ) );
   735 	a->setEnabled (false);
   736 	a->setToggleAction(false);
   737 	actionExpandOneLevel=a;
   738 	//tb->addAction (a);
   739 	editMenu->addAction ( a);
   740 	addAction (a);
   741 	actionListBranches.append(a);
   742 
   743 	a = new QAction( QPixmap(), tr( "Collapse one level","Edit menu" ), this);
   744 	a->setShortcut ( Qt::Key_Less);			// Collapse one level in tree editor
   745 	a->setStatusTip (tr( "Collapse one level in tree editor" )); 
   746 	connect( a, SIGNAL( triggered() ), this, SLOT( editCollapseOneLevel() ) );
   747 	a->setEnabled (false);
   748 	a->setToggleAction(false);
   749 	actionCollapseOneLevel=a;
   750 	//tb->addAction (a);
   751 	editMenu->addAction ( a);
   752 	addAction (a);
   753 	actionListBranches.append(a);
   754 
   755 	a = new QAction( tr( "Unscroll children","Edit menu" ), this);
   756 	a->setStatusTip (tr( "Unscroll all scrolled branches in selected subtree" ));
   757 	editMenu->addAction (a);
   758 	connect( a, SIGNAL( triggered() ), this, SLOT( editUnscrollChildren() ) );
   759 
   760 	editMenu->addSeparator();
   761 
   762 	a = new QAction( QPixmap(iconPath+"find.png"), tr( "Find...","Edit menu"), this);
   763 	a->setStatusTip (tr( "Find" ) );
   764 	a->setShortcut (Qt::CTRL + Qt::Key_F );				//Find
   765 	editMenu->addAction (a);
   766 	connect( a, SIGNAL( triggered() ), this, SLOT( editOpenFindWidget() ) );
   767 
   768 	a = new QAction( tr( "Find duplicate URLs","Edit menu"), this);
   769 	//a->setStatusTip (tr( "Find" ) );
   770 	a->setShortcut (Qt::SHIFT + Qt::Key_F);				//Find duplicate URLs
   771 	if (settings.value( "/mainwindow/showTestMenu",false).toBool() ) 
   772 		editMenu->addAction (a);
   773 	connect( a, SIGNAL( triggered() ), this, SLOT( editFindDuplicateURLs() ) );
   774 
   775 	editMenu->addSeparator();
   776 
   777 	a = new QAction( QPixmap(flagsPath+"flag-url.png"), tr( "Open URL","Edit menu" ), this);
   778 	a->setShortcut (Qt::SHIFT + Qt::Key_U );
   779 	a->setShortcut (tr( "Open URL" ));
   780 	tb->addAction (a);
   781 	addAction(a);
   782 	connect( a, SIGNAL( triggered() ), this, SLOT( editOpenURL() ) );
   783 	actionOpenURL=a;
   784 
   785 	a = new QAction( tr( "Open URL in new tab","Edit menu" ), this);
   786 	a->setStatusTip (tr( "Open URL in new tab" ));
   787 	//a->setShortcut (Qt::CTRL+Qt::Key_U );
   788 	addAction(a);
   789 	connect( a, SIGNAL( triggered() ), this, SLOT( editOpenURLTab() ) );
   790 	actionOpenURLTab=a;
   791 
   792 	a = new QAction( tr( "Open all URLs in subtree (including scrolled branches)","Edit menu" ), this);
   793 	a->setStatusTip (tr( "Open all URLs in subtree (including scrolled branches)" ));
   794 	a->setShortcut ( Qt::CTRL + Qt::Key_U );
   795 	addAction(a);
   796 	actionListBranches.append(a);
   797 	connect( a, SIGNAL( triggered() ), this, SLOT( editOpenMultipleVisURLTabs() ) );
   798 	actionOpenMultipleVisURLTabs=a;
   799 
   800 	a = new QAction( tr( "Open all URLs in subtree","Edit menu" ), this);
   801 	a->setStatusTip (tr( "Open all URLs in subtree" ));
   802 	addAction(a);
   803 	actionListBranches.append(a);
   804 	connect( a, SIGNAL( triggered() ), this, SLOT( editOpenMultipleURLTabs() ) );
   805 	actionOpenMultipleURLTabs=a;
   806 
   807 	a = new QAction(QPixmap(), tr( "Edit URL...","Edit menu"), this);
   808 	a->setStatusTip ( tr( "Edit URL" ) );
   809 	a->setShortcut ( Qt::Key_U );
   810 	a->setShortcutContext (Qt::WindowShortcut);
   811 	actionListBranches.append(a);
   812 	addAction(a);
   813 	connect( a, SIGNAL( triggered() ), this, SLOT( editURL() ) );
   814 	actionURL=a;
   815 
   816 	a = new QAction(QPixmap(), tr( "Edit local URL...","Edit menu"), this);
   817 	a->setStatusTip ( tr( "Edit local URL" ) );
   818 	//a->setShortcut (Qt::SHIFT +  Qt::Key_U );
   819 	a->setShortcutContext (Qt::WindowShortcut);
   820 	actionListBranches.append(a);
   821 	addAction(a);
   822 	connect( a, SIGNAL( triggered() ), this, SLOT( editLocalURL() ) );
   823 	actionLocalURL=a;
   824 
   825 	a = new QAction( tr( "Use heading for URL","Edit menu" ), this);
   826 	a->setStatusTip ( tr( "Use heading of selected branch as URL" ));
   827 	a->setEnabled (false);
   828 	actionListBranches.append(a);
   829 	connect( a, SIGNAL( triggered() ), this, SLOT( editHeading2URL() ) );
   830 	actionHeading2URL=a;
   831 
   832 	a = new QAction(tr( "Create URL to Novell Bugzilla","Edit menu" ), this);
   833 	a->setStatusTip ( tr( "Create URL to Novell Bugzilla" ));
   834 	a->setEnabled (false);
   835 	actionListBranches.append(a);
   836 	a->setShortcut ( Qt::Key_B );
   837 	a->setShortcutContext (Qt::WindowShortcut);
   838 	addAction(a);
   839 	connect( a, SIGNAL( triggered() ), this, SLOT( editBugzilla2URL() ) );
   840 	actionBugzilla2URL=a;
   841 
   842 	a = new QAction(tr( "Get data from Novell Bugzilla","Edit menu" ), this);
   843 	a->setStatusTip ( tr( "Get data from Novell Bugzilla" ));
   844 	a->setEnabled (false);
   845 	actionListBranches.append(a);
   846 	a->setShortcut ( Qt::Key_B + Qt::SHIFT);
   847 	a->setShortcutContext (Qt::WindowShortcut);
   848 	addAction(a);
   849 	connect( a, SIGNAL( triggered() ), this, SLOT( getBugzillaData() ) );
   850 	actionGetBugzillaData=a;
   851 
   852 	a = new QAction(tr( "Create URL to Novell FATE","Edit menu" ), this);
   853 	a->setStatusTip ( tr( "Create URL to Novell FATE" ));
   854 	a->setEnabled (false);
   855 	actionListBranches.append(a);
   856 	connect( a, SIGNAL( triggered() ), this, SLOT( editFATE2URL() ) );
   857 	actionFATE2URL=a;
   858 
   859 	a = new QAction(QPixmap(flagsPath+"flag-vymlink.png"), tr( "Open linked map","Edit menu" ), this);
   860 	a->setStatusTip ( tr( "Jump to another vym map, if needed load it first" ));
   861 	tb->addAction (a);
   862 	a->setEnabled (false);
   863 	connect( a, SIGNAL( triggered() ), this, SLOT( editOpenVymLink() ) );
   864 	actionOpenVymLink=a;
   865 
   866 	a = new QAction(QPixmap(), tr( "Open all vym links in subtree","Edit menu" ), this);
   867 	a->setStatusTip ( tr( "Open all vym links in subtree" ));
   868 	a->setEnabled (false);
   869 	actionListBranches.append(a);
   870 	connect( a, SIGNAL( triggered() ), this, SLOT( editOpenMultipleVymLinks() ) );
   871 	actionOpenMultipleVymLinks=a;
   872 
   873 
   874 	a = new QAction(tr( "Edit vym link...","Edit menu" ), this);
   875 	a->setEnabled (false);
   876 	a->setStatusTip ( tr( "Edit link to another vym map" ));
   877 	connect( a, SIGNAL( triggered() ), this, SLOT( editVymLink() ) );
   878 	actionListBranches.append(a);
   879 	actionVymLink=a;
   880 
   881 	a = new QAction(tr( "Delete vym link","Edit menu" ),this);
   882 	a->setStatusTip ( tr( "Delete link to another vym map" ));
   883 	a->setEnabled (false);
   884 	connect( a, SIGNAL( triggered() ), this, SLOT( editDeleteVymLink() ) );
   885 	actionDeleteVymLink=a;
   886 
   887 	a = new QAction(QPixmap(flagsPath+"flag-hideexport.png"), tr( "Hide in exports","Edit menu" ), this);
   888 	a->setStatusTip ( tr( "Hide object in exports" ) );
   889 	a->setShortcut (Qt::Key_H );
   890 	a->setToggleAction(true);
   891 	tb->addAction (a);
   892 	a->setEnabled (false);
   893 	connect( a, SIGNAL( triggered() ), this, SLOT( editToggleHideExport() ) );
   894 	actionToggleHideExport=a;
   895 
   896 	a = new QAction(tr( "Add timestamp","Edit menu" ), this);
   897 	a->setStatusTip ( tr( "Add timestamp" ));
   898 	a->setEnabled (false);
   899 	actionListBranches.append(a);
   900 	a->setShortcut ( Qt::Key_T );	// Add timestamp
   901 	a->setShortcutContext (Qt::WindowShortcut);
   902 	addAction(a);
   903 	connect( a, SIGNAL( triggered() ), this, SLOT( editAddTimestamp() ) );
   904 	actionAddTimestamp=a;
   905 
   906 	a = new QAction(tr( "Edit Map Info...","Edit menu" ),this);
   907 	a->setStatusTip ( tr( "Edit Map Info" ));
   908 	a->setEnabled (true);
   909 	connect( a, SIGNAL( triggered() ), this, SLOT( editMapInfo() ) );
   910 	actionMapInfo=a;
   911 
   912 	// Import at selection (adding to selection)
   913 	a = new QAction( tr( "Add map (insert)","Edit menu" ),this);
   914 	a->setStatusTip (tr( "Add map at selection" ));
   915 	connect( a, SIGNAL( triggered() ), this, SLOT( editImportAdd() ) );
   916 	a->setEnabled (false);
   917 	actionListBranches.append(a);
   918 	actionImportAdd=a;
   919 
   920 	// Import at selection (replacing selection)
   921 	a = new QAction( tr( "Add map (replace)","Edit menu" ), this);
   922 	a->setStatusTip (tr( "Replace selection with map" ));
   923 	connect( a, SIGNAL( triggered() ), this, SLOT( editImportReplace() ) );
   924 	a->setEnabled (false);
   925 	actionListBranches.append(a);
   926 	actionImportReplace=a;
   927 
   928 	// Save selection 
   929 	a = new QAction( tr( "Save selection","Edit menu" ), this);
   930 	a->setStatusTip (tr( "Save selection" ));
   931 	connect( a, SIGNAL( triggered() ), this, SLOT( editSaveBranch() ) );
   932 	a->setEnabled (false);
   933 	actionListBranches.append(a);
   934 	actionSaveBranch=a;
   935 
   936 	// Only remove branch, not its children
   937 	a = new QAction(tr( "Remove only branch ","Edit menu" ), this);
   938 	a->setStatusTip ( tr( "Remove only branch and keep its children" ));
   939 	a->setShortcut (Qt::ALT + Qt::Key_Delete );
   940 	connect( a, SIGNAL( triggered() ), this, SLOT( editDeleteKeepChildren() ) );
   941 	a->setEnabled (false);
   942 	addAction (a);
   943 	actionListBranches.append(a);
   944 	actionDeleteKeepChildren=a;
   945 
   946 	// Only remove children of a branch
   947 	a = new QAction( tr( "Remove children","Edit menu" ), this);
   948 	a->setStatusTip (tr( "Remove children of branch" ));
   949 	a->setShortcut (Qt::SHIFT + Qt::Key_Delete );
   950 	connect( a, SIGNAL( triggered() ), this, SLOT( editDeleteChildren() ) );
   951 	a->setEnabled (false);
   952 	actionListBranches.append(a);
   953 	actionDeleteChildren=a;
   954 
   955 	a = new QAction( tr( "Add Image...","Edit menu" ), this);
   956 	a->setStatusTip (tr( "Add Image" ));
   957 	connect( a, SIGNAL( triggered() ), this, SLOT( editLoadImage() ) );
   958 	actionLoadImage=a;
   959 
   960 	a = new QAction( tr( "Property window","Dialog to edit properties of selection" )+QString ("..."), this);
   961 	a->setStatusTip (tr( "Set properties for selection" ));
   962 	a->setShortcut ( Qt::CTRL + Qt::Key_I );		//Property window
   963 	a->setShortcutContext (Qt::WindowShortcut);
   964 	a->setToggleAction (true);
   965 	addAction (a);
   966 	connect( a, SIGNAL( triggered() ), this, SLOT( windowToggleProperty() ) );
   967 	actionViewTogglePropertyWindow=a;
   968 }
   969 
   970 // Format Actions
   971 void Main::setupFormatActions()
   972 {
   973 	QMenu *formatMenu = menuBar()->addMenu (tr ("F&ormat","Format menu"));
   974 
   975 	QToolBar *tb = addToolBar( tr("Format Actions","Format Toolbar name"));
   976 	tb->setObjectName ("formatTB");
   977 	QAction *a;
   978 	QPixmap pix( 16,16);
   979 	pix.fill (Qt::black);
   980 	a= new QAction(pix, tr( "Set &Color" )+QString("..."), this);
   981 	a->setStatusTip ( tr( "Set Color" ));
   982 	connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectColor() ) );
   983 	a->addTo( tb );
   984 	formatMenu->addAction (a);
   985 	actionFormatColor=a;
   986 	a= new QAction( QPixmap(iconPath+"formatcolorpicker.png"), tr( "Pic&k color","Edit menu" ), this);
   987 	a->setStatusTip (tr( "Pick color\nHint: You can pick a color from another branch and color using CTRL+Left Button" ) );
   988 	a->setShortcut (Qt::CTRL + Qt::Key_K );
   989 	connect( a, SIGNAL( triggered() ), this, SLOT( formatPickColor() ) );
   990 	a->setEnabled (false);
   991 	a->addTo( tb );
   992 	formatMenu->addAction (a);
   993 	actionListBranches.append(a);
   994 	actionFormatPickColor=a;
   995 
   996 	a= new QAction(QPixmap(iconPath+"formatcolorbranch.png"), tr( "Color &branch","Edit menu" ), this);
   997 	a->setStatusTip ( tr( "Color branch" ) );
   998 	a->setShortcut (Qt::CTRL + Qt::Key_B);
   999 	connect( a, SIGNAL( triggered() ), this, SLOT( formatColorBranch() ) );
  1000 	a->setEnabled (false);
  1001 	a->addTo( tb );
  1002 	formatMenu->addAction (a);
  1003 	actionListBranches.append(a);
  1004 	actionFormatColorSubtree=a;
  1005 
  1006 	a= new QAction(QPixmap(iconPath+"formatcolorsubtree.png"), tr( "Color sub&tree","Edit menu" ), this);
  1007 	a->setStatusTip ( tr( "Color Subtree" ));
  1008 	//FIXME-2 switch back to that a->setShortcut (Qt::CTRL + Qt::Key_T);	// Color subtree
  1009 	connect( a, SIGNAL( triggered() ), this, SLOT( formatColorSubtree() ) );
  1010 	a->setEnabled (false);
  1011 	formatMenu->addAction (a);
  1012 	a->addTo( tb );
  1013 	actionListBranches.append(a);
  1014 	actionFormatColorSubtree=a;
  1015 
  1016 	formatMenu->addSeparator();
  1017 	actionGroupFormatLinkStyles=new QActionGroup ( this);
  1018 	actionGroupFormatLinkStyles->setExclusive (true);
  1019 	a= new QAction( tr( "Linkstyle Line" ), actionGroupFormatLinkStyles);
  1020 	a->setStatusTip (tr( "Line" ));
  1021 	a->setToggleAction(true);
  1022 	connect( a, SIGNAL( triggered() ), this, SLOT( formatLinkStyleLine() ) );
  1023 	formatMenu->addAction (a);
  1024 	actionFormatLinkStyleLine=a;
  1025 	a= new QAction( tr( "Linkstyle Curve" ), actionGroupFormatLinkStyles);
  1026 	a->setStatusTip (tr( "Line" ));
  1027 	a->setToggleAction(true);
  1028 	connect( a, SIGNAL( triggered() ), this, SLOT( formatLinkStyleParabel() ) );
  1029 	formatMenu->addAction (a);
  1030 	actionFormatLinkStyleParabel=a;
  1031 	a= new QAction( tr( "Linkstyle Thick Line" ), actionGroupFormatLinkStyles );
  1032 	a->setStatusTip (tr( "PolyLine" ));
  1033 	a->setToggleAction(true);
  1034 	connect( a, SIGNAL( triggered() ), this, SLOT( formatLinkStylePolyLine() ) );
  1035 	formatMenu->addAction (a);
  1036 	actionFormatLinkStylePolyLine=a;
  1037 	a= new QAction( tr( "Linkstyle Thick Curve" ), actionGroupFormatLinkStyles);
  1038 	a->setStatusTip (tr( "PolyParabel" ) );
  1039 	a->setToggleAction(true);
  1040 	a->setChecked (true);
  1041 	connect( a, SIGNAL( triggered() ), this, SLOT( formatLinkStylePolyParabel() ) );
  1042 	formatMenu->addAction (a);
  1043 	actionFormatLinkStylePolyParabel=a;
  1044 
  1045 	a = new QAction( tr( "Hide link if object is not selected","Branch attribute" ), this);
  1046 	a->setStatusTip (tr( "Hide link" ));
  1047 	a->setToggleAction(true);
  1048 	connect( a, SIGNAL( triggered() ), this, SLOT( formatHideLinkUnselected() ) );
  1049 	actionFormatHideLinkUnselected=a;
  1050 
  1051 	formatMenu->addSeparator();
  1052 	a= new QAction( tr( "&Use color of heading for link","Branch attribute" ),  this);
  1053 	a->setStatusTip (tr( "Use same color for links and headings" ));
  1054 	a->setToggleAction(true);
  1055 	connect( a, SIGNAL( triggered() ), this, SLOT( formatToggleLinkColorHint() ) );
  1056 	formatMenu->addAction (a);
  1057 	actionFormatLinkColorHint=a;
  1058 
  1059 	pix.fill (Qt::white);
  1060 	a= new QAction( pix, tr( "Set &Link Color"+QString("...") ), this  );
  1061 	a->setStatusTip (tr( "Set Link Color" ));
  1062 	formatMenu->addAction (a);
  1063 	connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectLinkColor() ) );
  1064 	actionFormatLinkColor=a;
  1065 
  1066 	a= new QAction( pix, tr( "Set &Selection Color"+QString("...") ), this  );
  1067 	a->setStatusTip (tr( "Set Selection Color" ));
  1068 	formatMenu->addAction (a);
  1069 	connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectSelectionColor() ) );
  1070 	actionFormatSelectionColor=a;
  1071 
  1072 	a= new QAction( pix, tr( "Set &Background Color" )+QString("..."), this );
  1073 	a->setStatusTip (tr( "Set Background Color" ));
  1074 	formatMenu->addAction (a);
  1075 	connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectBackColor() ) );
  1076 	actionFormatBackColor=a;
  1077 
  1078 	a= new QAction( pix, tr( "Set &Background image" )+QString("..."), this );
  1079 	a->setStatusTip (tr( "Set Background image" ));
  1080 	formatMenu->addAction (a);
  1081 	connect( a, SIGNAL( triggered() ), this, SLOT( formatSelectBackImage() ) );
  1082 	actionFormatBackImage=a;
  1083 }
  1084 
  1085 // View Actions
  1086 void Main::setupViewActions()
  1087 {
  1088 	QToolBar *tb = addToolBar( tr("View Actions","View Toolbar name") );
  1089 	tb->setLabel( "View Actions" );
  1090 	tb->setObjectName ("viewTB");
  1091 	QMenu *viewMenu = menuBar()->addMenu ( tr( "&View" ));
  1092 
  1093 	Switchboard switchboard;	//FIXME-2 testing...
  1094 
  1095 	QAction *a;
  1096 	a = new QAction(QPixmap(iconPath+"viewmag-reset.png"), tr( "reset Zoom","View action" ), this);
  1097 	a->setStatusTip ( tr( "Zoom reset" ) );
  1098 	a->setShortcut (Qt::CTRL + Qt::Key_0);	// Reset zoom
  1099 	switchboard.addConnection(a,"CTRL+0");
  1100 	a->addTo( tb );
  1101 	viewMenu->addAction (a);
  1102 	connect( a, SIGNAL( triggered() ), this, SLOT(viewZoomReset() ) );
  1103 
  1104 	a = new QAction( QPixmap(iconPath+"viewmag+.png"), tr( "Zoom in","View action" ), this);
  1105 	a->setStatusTip (tr( "Zoom in" ));
  1106 	switchboard.addConnection(a,"CTRL++");
  1107 	a->addTo( tb );
  1108 	viewMenu->addAction (a);
  1109 	connect( a, SIGNAL( triggered() ), this, SLOT(viewZoomIn() ) );
  1110 
  1111 	a = new QAction( QPixmap(iconPath+"viewmag-.png"), tr( "Zoom out","View action" ), this);
  1112 	a->setStatusTip (tr( "Zoom out" ));
  1113 	switchboard.addConnection(a,"CTRL+-");
  1114 	a->addTo( tb );
  1115 	viewMenu->addAction (a);
  1116 	connect( a, SIGNAL( triggered() ), this, SLOT( viewZoomOut() ) );
  1117 
  1118 	a = new QAction( QPixmap(iconPath+"viewshowsel.png"), tr( "Show selection","View action" ), this);
  1119 	a->setStatusTip (tr( "Show selection" ));
  1120 	switchboard.addConnection(a,".");
  1121 	a->addTo( tb );
  1122 	viewMenu->addAction (a);
  1123 	connect( a, SIGNAL( triggered() ), this, SLOT( viewCenter() ) );
  1124 
  1125 	viewMenu->addSeparator();	
  1126 
  1127 	a = new QAction(QPixmap(flagsPath+"flag-note.png"), tr( "Show Note Editor","View action" ),this);
  1128 	a->setStatusTip ( tr( "Show Note Editor" ));
  1129 	a->setShortcut ( Qt::CTRL + Qt::Key_E );	// Toggle Note Editor
  1130 	a->setToggleAction(true);
  1131 	a->addTo( tb );
  1132 	viewMenu->addAction (a);
  1133 	connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleNoteEditor() ) );
  1134 	actionViewToggleNoteEditor=a;
  1135 
  1136 	a = new QAction(QPixmap(iconPath+"history.png"),  tr( "History Window","View action" ),this );
  1137 	a->setStatusTip ( tr( "Show History Window" ));
  1138 	a->setShortcut ( Qt::CTRL + Qt::Key_H  );	// Toggle history window
  1139 	a->setToggleAction(true);
  1140 	a->addTo( tb );
  1141 	viewMenu->addAction (a);
  1142 	connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleHistory() ) );
  1143 	actionViewToggleHistoryWindow=a;
  1144 
  1145 	viewMenu->addAction (actionViewTogglePropertyWindow);
  1146 
  1147 	viewMenu->addSeparator();	
  1148 
  1149 	a = new QAction(tr( "Antialiasing","View action" ),this );
  1150 	a->setStatusTip ( tr( "Antialiasing" ));
  1151 	a->setToggleAction(true);
  1152 	a->setChecked (settings.value("/mainwindow/view/AntiAlias",true).toBool());
  1153 	viewMenu->addAction (a);
  1154 	connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleAntiAlias() ) );
  1155 	actionViewToggleAntiAlias=a;
  1156 
  1157 	a = new QAction(tr( "Smooth pixmap transformations","View action" ),this );
  1158 	a->setStatusTip (a->text());
  1159 	a->setToggleAction(true);
  1160 	a->setChecked (settings.value("/mainwindow/view/SmoothPixmapTransformation",true).toBool());
  1161 	viewMenu->addAction (a);
  1162 	connect( a, SIGNAL( triggered() ), this, SLOT(windowToggleSmoothPixmap() ) );
  1163 	actionViewToggleSmoothPixmapTransform=a;
  1164 
  1165 	a = new QAction(tr( "Next Map","View action" ), this);
  1166 	a->setStatusTip (a->text());
  1167 	a->setShortcut (Qt::ALT + Qt::Key_N );
  1168 	viewMenu->addAction (a);
  1169 	connect( a, SIGNAL( triggered() ), this, SLOT(windowNextEditor() ) );
  1170 
  1171 	a = new QAction (tr( "Previous Map","View action" ), this );
  1172 	a->setStatusTip (a->text());
  1173 	a->setShortcut (Qt::ALT + Qt::Key_P );
  1174 	viewMenu->addAction (a);
  1175 	connect( a, SIGNAL( triggered() ), this, SLOT(windowPreviousEditor() ) );
  1176 
  1177 	if (debug) switchboard.print();
  1178 }
  1179 
  1180 // Mode Actions
  1181 void Main::setupModeActions()
  1182 {
  1183 	//QPopupMenu *menu = new QPopupMenu( this );
  1184 	//menuBar()->insertItem( tr( "&Mode (using modifiers)" ), menu );
  1185 
  1186 	QToolBar *tb = addToolBar( tr ("Modes when using modifiers","Modifier Toolbar name") );
  1187 	tb->setObjectName ("modesTB");
  1188 	QAction *a;
  1189 	actionGroupModModes=new QActionGroup ( this);
  1190 	actionGroupModModes->setExclusive (true);
  1191 	a= new QAction( QPixmap(iconPath+"modecolor.png"), tr( "Use modifier to color branches","Mode modifier" ), actionGroupModModes);
  1192 	a->setShortcut (Qt::Key_J);
  1193 	a->setStatusTip ( tr( "Use modifier to color branches" ));
  1194 	a->setToggleAction(true);
  1195 	a->addTo (tb);
  1196 	a->setChecked(true);
  1197 	actionModModeColor=a;
  1198 
  1199 	a= new QAction( QPixmap(iconPath+"modecopy.png"), tr( "Use modifier to copy","Mode modifier" ), actionGroupModModes );
  1200 	a->setShortcut( Qt::Key_K); 
  1201 	a->setStatusTip( tr( "Use modifier to copy" ));
  1202 	a->setToggleAction(true);
  1203 	a->addTo (tb);
  1204 	actionModModeCopy=a;
  1205 
  1206 	a= new QAction(QPixmap(iconPath+"modelink.png"), tr( "Use modifier to draw xLinks","Mode modifier" ), actionGroupModModes );
  1207 	a->setShortcut (Qt::Key_L);
  1208 	a->setStatusTip( tr( "Use modifier to draw xLinks" ));
  1209 	a->setToggleAction(true);
  1210 	a->addTo (tb);
  1211 	actionModModeXLink=a;
  1212 }
  1213 
  1214 // Flag Actions
  1215 void Main::setupFlagActions()
  1216 {
  1217 	// Create System Flags
  1218 	QToolBar *tb=NULL;
  1219 
  1220 	Flag *flag=new Flag;;
  1221 	flag->setVisible(true);
  1222 
  1223 	flag->load(QPixmap(flagsPath+"flag-note.png"));
  1224 	setupFlag (flag,tb,"system-note",tr("Note","SystemFlag"));
  1225 
  1226 	flag->load(QPixmap(flagsPath+"flag-url.png"));
  1227 	setupFlag (flag,tb,"system-url",tr("URL to Document ","SystemFlag"));
  1228 
  1229 	flag->load(QPixmap(flagsPath+"flag-vymlink.png"));
  1230 	setupFlag (flag,tb,"system-vymLink",tr("Link to another vym map","SystemFlag"));
  1231 
  1232 	flag->load(QPixmap(flagsPath+"flag-scrolled-right.png"));
  1233 	setupFlag (flag,tb,"system-scrolledright",tr("subtree is scrolled","SystemFlag"));
  1234 
  1235 	flag->load(QPixmap(flagsPath+"flag-tmpUnscrolled-right.png"));
  1236 	setupFlag (flag,tb,"system-tmpUnscrolledRight",tr("subtree is temporary scrolled","SystemFlag"));
  1237 
  1238 	flag->load(QPixmap(flagsPath+"flag-hideexport.png"));
  1239 	setupFlag (flag,tb,"system-hideInExport",tr("Hide object in exported maps","SystemFlag"));
  1240 
  1241 	// Create Standard Flags
  1242 	tb=addToolBar (tr ("Standard Flags","Standard Flag Toolbar"));
  1243 	tb->setObjectName ("standardFlagTB");
  1244 	standardFlagsMaster->setToolBar (tb);
  1245 
  1246 	flag->load(flagsPath+"flag-exclamationmark.png");
  1247 	flag->setGroup("standard-mark");
  1248 	setupFlag (flag,tb,"exclamationmark",tr("Take care!","Standardflag"));
  1249 
  1250 	flag->load(flagsPath+"flag-questionmark.png");
  1251 	flag->setGroup("standard-mark");
  1252 	setupFlag (flag,tb,"questionmark",tr("Really?","Standardflag"));
  1253 
  1254 	flag->load(flagsPath+"flag-hook-green.png");
  1255 	flag->setGroup("standard-status");
  1256 	setupFlag (flag,tb,"hook-green",tr("Status - ok,done","Standardflag"));
  1257 
  1258 	flag->load(flagsPath+"flag-wip.png");
  1259 	flag->setGroup("standard-status");
  1260 	setupFlag (flag,tb,"wip",tr("Status - work in progress","Standardflag"));
  1261 
  1262 	flag->load(flagsPath+"flag-cross-red.png");
  1263 	flag->setGroup("standard-status");
  1264 	setupFlag (flag,tb,"cross-red",tr("Status - missing, not started","Standardflag"));
  1265 	flag->unsetGroup();
  1266 
  1267 	flag->load(flagsPath+"flag-stopsign.png");
  1268 	setupFlag (flag,tb,"stopsign",tr("This won't work!","Standardflag"));
  1269 
  1270 	flag->load(flagsPath+"flag-smiley-good.png");
  1271 	flag->setGroup("standard-smiley");
  1272 	setupFlag (flag,tb,"smiley-good",tr("Good","Standardflag"));
  1273 
  1274 	flag->load(flagsPath+"flag-smiley-sad.png");
  1275 	flag->setGroup("standard-smiley");
  1276 	setupFlag (flag,tb,"smiley-sad",tr("Bad","Standardflag"));
  1277 
  1278 	flag->load(flagsPath+"flag-smiley-omg.png");
  1279 	flag->setGroup("standard-smiley");
  1280 	setupFlag (flag,tb,"smiley-omb",tr("Oh no!","Standardflag"));
  1281 	// Original omg.png (in KDE emoticons)
  1282 	flag->unsetGroup();
  1283 
  1284 	flag->load(flagsPath+"flag-kalarm.png");
  1285 	setupFlag (flag,tb,"clock",tr("Time critical","Standardflag"));
  1286 
  1287 	flag->load(flagsPath+"flag-phone.png");
  1288 	setupFlag (flag,tb,"phone",tr("Call...","Standardflag"));
  1289 
  1290 	flag->load(flagsPath+"flag-lamp.png");
  1291 	setupFlag (flag,tb,"lamp",tr("Idea!","Standardflag"));
  1292 
  1293 	flag->load(flagsPath+"flag-arrow-up.png");
  1294 	flag->setGroup("standard-arrow");
  1295 	setupFlag (flag,tb,"arrow-up",tr("Important","Standardflag"));
  1296 
  1297 	flag->load(flagsPath+"flag-arrow-down.png");
  1298 	flag->setGroup("standard-arrow");
  1299 	setupFlag (flag,tb,"arrow-down",tr("Unimportant","Standardflag"));
  1300 
  1301 	flag->load(flagsPath+"flag-arrow-2up.png");
  1302 	flag->setGroup("standard-arrow");
  1303 	setupFlag (flag,tb,"2arrow-up",tr("Very important!","Standardflag"));
  1304 
  1305 	flag->load(flagsPath+"flag-arrow-2down.png");
  1306 	flag->setGroup("standard-arrow");
  1307 	setupFlag (flag,tb,"2arrow-down",tr("Very unimportant!","Standardflag"));
  1308 	flag->unsetGroup();
  1309 
  1310 	flag->load(flagsPath+"flag-thumb-up.png");
  1311 	flag->setGroup("standard-thumb");
  1312 	setupFlag (flag,tb,"thumb-up",tr("I like this","Standardflag"));
  1313 
  1314 	flag->load(flagsPath+"flag-thumb-down.png");
  1315 	flag->setGroup("standard-thumb");
  1316 	setupFlag (flag,tb,"thumb-down",tr("I do not like this","Standardflag"));
  1317 	flag->unsetGroup();
  1318 
  1319 	flag->load(flagsPath+"flag-rose.png");
  1320 	setupFlag (flag,tb,"rose",tr("Rose","Standardflag"));
  1321 
  1322 	flag->load(flagsPath+"flag-heart.png");
  1323 	setupFlag (flag,tb,"heart",tr("I just love...","Standardflag"));
  1324 
  1325 	flag->load(flagsPath+"flag-present.png");
  1326 	setupFlag (flag,tb,"present",tr("Surprise!","Standardflag"));
  1327 
  1328 	flag->load(flagsPath+"flag-flash.png");
  1329 	setupFlag (flag,tb,"flash",tr("Dangerous","Standardflag"));
  1330 
  1331 	// Original: xsldbg_output.png
  1332 	flag->load(flagsPath+"flag-info.png");
  1333 	setupFlag (flag,tb,"info",tr("Info","Standardflag"));
  1334 
  1335 	// Original khelpcenter.png
  1336 	flag->load(flagsPath+"flag-lifebelt.png");
  1337 	setupFlag (flag,tb,"lifebelt",tr("This will help","Standardflag"));
  1338 
  1339 	// Freemind flags
  1340 	flag->setVisible(false);
  1341 	flag->load(flagsPath+"freemind/warning.png");
  1342 	setupFlag (flag,tb,  "freemind-warning",tr("Important","Freemind-Flag"));
  1343 
  1344 	for (int i=1; i<8; i++)
  1345 	{
  1346 		flag->load(flagsPath+QString("freemind/priority-%1.png").arg(i));
  1347 		setupFlag (flag,tb, QString("freemind-priority-%1").arg(i),tr("Priority","Freemind-Flag"));
  1348 	}
  1349 
  1350 	flag->load(flagsPath+"freemind/back.png");
  1351 	setupFlag (flag,tb,"freemind-back",tr("Back","Freemind-Flag"));
  1352 
  1353 	flag->load(flagsPath+"freemind/forward.png");
  1354 	setupFlag (flag,tb,"freemind-forward",tr("forward","Freemind-Flag"));
  1355 
  1356 	flag->load(flagsPath+"freemind/attach.png");
  1357 	setupFlag (flag,tb,"freemind-attach",tr("Look here","Freemind-Flag"));
  1358 
  1359 	flag->load(flagsPath+"freemind/clanbomber.png");
  1360 	setupFlag (flag,tb,"freemind-clanbomber",tr("Dangerous","Freemind-Flag"));
  1361 
  1362 	flag->load(flagsPath+"freemind/desktopnew.png");
  1363 	setupFlag (flag,tb,"freemind-desktopnew",tr("Don't flagrget","Freemind-Flag"));
  1364 
  1365 	flag->load(flagsPath+"freemind/flag.png");
  1366 	setupFlag (flag,tb,"freemind-flag",tr("Flag","Freemind-Flag"));
  1367 
  1368 
  1369 	flag->load(flagsPath+"freemind/gohome.png");
  1370 	setupFlag (flag,tb,"freemind-gohome",tr("Home","Freemind-Flag"));
  1371 
  1372 
  1373 	flag->load(flagsPath+"freemind/kaddressbook.png");
  1374 	setupFlag (flag,tb,"freemind-kaddressbook",tr("Telephone","Freemind-Flag"));
  1375 
  1376 	flag->load(flagsPath+"freemind/knotify.png");
  1377 	setupFlag (flag,tb,"freemind-knotify",tr("Music","Freemind-Flag"));
  1378 
  1379 	flag->load(flagsPath+"freemind/korn.png");
  1380 	setupFlag (flag,tb,"freemind-korn",tr("Mailbox","Freemind-Flag"));
  1381 
  1382 	flag->load(flagsPath+"freemind/mail.png");
  1383 	setupFlag (flag,tb,"freemind-mail",tr("Maix","Freemind-Flag"));
  1384 
  1385 	flag->load(flagsPath+"freemind/password.png");
  1386 	setupFlag (flag,tb,"freemind-password",tr("Password","Freemind-Flag"));
  1387 
  1388 	flag->load(flagsPath+"freemind/pencil.png");
  1389 	setupFlag (flag,tb,"freemind-pencil",tr("To be improved","Freemind-Flag"));
  1390 
  1391 	flag->load(flagsPath+"freemind/stop.png");
  1392 	setupFlag (flag,tb,"freemind-stop",tr("Stop","Freemind-Flag"));
  1393 
  1394 	flag->load(flagsPath+"freemind/wizard.png");
  1395 	setupFlag (flag,tb,"freemind-wizard",tr("Magic","Freemind-Flag"));
  1396 
  1397 	flag->load(flagsPath+"freemind/xmag.png");
  1398 	setupFlag (flag,tb,"freemind-xmag",tr("To be discussed","Freemind-Flag"));
  1399 
  1400 	flag->load(flagsPath+"freemind/bell.png");
  1401 	setupFlag (flag,tb,"freemind-bell",tr("Reminder","Freemind-Flag"));
  1402 
  1403 	flag->load(flagsPath+"freemind/bookmark.png");
  1404 	setupFlag (flag,tb,"freemind-bookmark",tr("Excellent","Freemind-Flag"));
  1405 
  1406 	flag->load(flagsPath+"freemind/penguin.png");
  1407 	setupFlag (flag,tb,"freemind-penguin",tr("Linux","Freemind-Flag"));
  1408 
  1409 	flag->load(flagsPath+"freemind/licq.png");
  1410 	setupFlag (flag,tb,"freemind-licq",tr("Sweet","Freemind-Flag"));
  1411 }
  1412 
  1413 void Main::setupFlag (Flag *flag, QToolBar *tb, const QString &name, const QString &tooltip)
  1414 {
  1415 	flag->setName(name);
  1416 	flag->setToolTip (tooltip);
  1417 	QAction *a;
  1418 	if (tb)
  1419 	{
  1420 		a=new QAction (flag->getPixmap(),name,this);
  1421 		// StandardFlag
  1422 		tb->addAction (a);
  1423 		flag->setAction (a);
  1424 		a->setVisible (flag->isVisible());
  1425 		a->setCheckable(true);
  1426 		a->setObjectName(name);
  1427 		a->setToolTip(tooltip);
  1428 		connect (a, SIGNAL( triggered() ), this, SLOT( standardFlagChanged() ) );
  1429 		standardFlagsMaster->addFlag (flag);	
  1430 	} else
  1431 	{
  1432 		// SystemFlag
  1433 		systemFlagsMaster->addFlag (flag);	
  1434 	}
  1435 }
  1436 
  1437 // Network Actions
  1438 void Main::setupNetworkActions()
  1439 {
  1440 	if (!settings.value( "/mainwindow/showTestMenu",false).toBool() ) 
  1441 		return;
  1442 	QMenu *netMenu = menuBar()->addMenu(  "Network" );
  1443 
  1444 	QAction *a;
  1445 
  1446 	a = new QAction(  "Start TCPserver for MapEditor",this);
  1447 	//a->setStatusTip ( "Set application to open pdf files"));
  1448 	//a->setShortcut ( Qt::ALT + Qt::Key_T );		//New TCP server
  1449 	connect( a, SIGNAL( triggered() ), this, SLOT( networkStartServer() ) );
  1450 	netMenu->addAction (a);
  1451 
  1452 	a = new QAction(  "Connect MapEditor to server",this);
  1453 	//a->setStatusTip ( "Set application to open pdf files"));
  1454 	a->setShortcut ( Qt::ALT + Qt::Key_C );		// Connect to server
  1455 	connect( a, SIGNAL( triggered() ), this, SLOT( networkConnect() ) );
  1456 	netMenu->addAction (a);
  1457 }
  1458 
  1459 // Settings Actions
  1460 void Main::setupSettingsActions()
  1461 {
  1462 	QMenu *settingsMenu = menuBar()->addMenu( tr( "&Settings" ));
  1463 
  1464 	QAction *a;
  1465 
  1466 	a = new QAction( tr( "Set application to open pdf files","Settings action"), this);
  1467 	a->setStatusTip ( tr( "Set application to open pdf files"));
  1468 	connect( a, SIGNAL( triggered() ), this, SLOT( settingsPDF() ) );
  1469 	settingsMenu->addAction (a);
  1470 
  1471 	a = new QAction( tr( "Set application to open external links","Settings action"), this);
  1472 	a->setStatusTip( tr( "Set application to open external links"));
  1473 	connect( a, SIGNAL( triggered() ), this, SLOT( settingsURL() ) );
  1474 	settingsMenu->addAction (a);
  1475 
  1476 	a = new QAction( tr( "Set path for macros","Settings action")+"...", this);
  1477 	a->setStatusTip( tr( "Set path for macros"));
  1478 	connect( a, SIGNAL( triggered() ), this, SLOT( settingsMacroDir() ) );
  1479 	settingsMenu->addAction (a);
  1480 
  1481 	a = new QAction( tr( "Set number of undo levels","Settings action")+"...", this);
  1482 	a->setStatusTip( tr( "Set number of undo levels"));
  1483 	connect( a, SIGNAL( triggered() ), this, SLOT( settingsUndoLevels() ) );
  1484 	settingsMenu->addAction (a);
  1485 
  1486 	settingsMenu->addSeparator();
  1487 
  1488 	a = new QAction( tr( "Autosave","Settings action"), this);
  1489 	a->setStatusTip( tr( "Autosave"));
  1490 	a->setToggleAction(true);
  1491 	a->setChecked ( settings.value ("/mainwindow/autosave/use",false).toBool());
  1492 	connect( a, SIGNAL( triggered() ), this, SLOT( settingsAutosaveToggle() ) );
  1493 	settingsMenu->addAction (a);
  1494 	actionSettingsAutosaveToggle=a;
  1495 
  1496 	a = new QAction( tr( "Autosave time","Settings action")+"...", this);
  1497 	a->setStatusTip( tr( "Autosave time"));
  1498 	connect( a, SIGNAL( triggered() ), this, SLOT( settingsAutosaveTime() ) );
  1499 	settingsMenu->addAction (a);
  1500 	actionSettingsAutosaveTime=a;
  1501 
  1502 	a = new QAction( tr( "Write backup file on save","Settings action"), this);
  1503 	a->setStatusTip( tr( "Write backup file on save"));
  1504 	a->setToggleAction(true);
  1505 	a->setChecked ( settings.value ("/mainwindow/writeBackupFile",false).toBool());
  1506 	connect( a, SIGNAL( triggered() ), this, SLOT( settingsWriteBackupFileToggle() ) );
  1507 	settingsMenu->addAction (a);
  1508 	actionSettingsWriteBackupFile=a;
  1509 
  1510 	settingsMenu->addSeparator();
  1511 
  1512 	a = new QAction( tr( "Edit branch after adding it","Settings action" ), this );
  1513 	a->setStatusTip( tr( "Edit branch after adding it" ));
  1514 	a->setToggleAction(true);
  1515 	a->setChecked ( settings.value ("/mapeditor/editmode/autoEditNewBranch",true).toBool());
  1516 	settingsMenu->addAction (a);
  1517 	actionSettingsAutoEditNewBranch=a;
  1518 
  1519 	a= new QAction( tr( "Select branch after adding it","Settings action" ), this );
  1520 	a->setStatusTip( tr( "Select branch after adding it" ));
  1521 	a->setToggleAction(true);
  1522 	a->setChecked ( settings.value ("/mapeditor/editmode/autoSelectNewBranch",false).toBool() );
  1523 	settingsMenu->addAction (a);
  1524 	actionSettingsAutoSelectNewBranch=a;
  1525 
  1526 	a= new QAction(tr( "Select existing heading","Settings action" ), this);
  1527 	a->setStatusTip( tr( "Select heading before editing" ));
  1528 	a->setToggleAction(true);
  1529 	a->setChecked ( settings.value ("/mapeditor/editmode/autoSelectText",true).toBool() );
  1530 	settingsMenu->addAction (a);
  1531 	actionSettingsAutoSelectText=a;
  1532 
  1533 	a= new QAction( tr( "Delete key","Settings action" ), this);
  1534 	a->setStatusTip( tr( "Delete key for deleting branches" ));
  1535 	a->setToggleAction(true);
  1536 	a->setChecked ( settings.value ("/mapeditor/editmode/useDelKey",true).toBool() );
  1537 	settingsMenu->addAction (a);
  1538 	connect( a, SIGNAL( triggered() ), this, SLOT( settingsToggleDelKey() ) );
  1539 	actionSettingsUseDelKey=a;
  1540 
  1541 	a= new QAction( tr( "Exclusive flags","Settings action" ), this);
  1542 	a->setStatusTip( tr( "Use exclusive flags in flag toolbars" ));
  1543 	a->setToggleAction(true);
  1544 	a->setChecked ( settings.value ("/mapeditor/editmode/useFlagGroups",true).toBool() );
  1545 	settingsMenu->addAction (a);
  1546 	actionSettingsUseFlagGroups=a;
  1547 
  1548 	a= new QAction( tr( "Use hide flags","Settings action" ), this);
  1549 	a->setStatusTip( tr( "Use hide flag during exports " ));
  1550 	a->setToggleAction(true);
  1551 	a->setChecked ( settings.value ("/export/useHideExport",true).toBool() );
  1552 	settingsMenu->addAction (a);
  1553 	actionSettingsUseHideExport=a;
  1554 
  1555 	a = new QAction( tr( "Animation","Settings action"), this);
  1556 	a->setStatusTip( tr( "Animation"));
  1557 	a->setToggleAction(true);
  1558 	a->setChecked (settings.value("/animation/use",true).toBool() );
  1559 	connect( a, SIGNAL( triggered() ), this, SLOT( settingsToggleAnimation() ) );
  1560 	settingsMenu->addAction (a);
  1561 	actionSettingsUseAnimation=a;
  1562 }
  1563 
  1564 // Test Actions
  1565 void Main::setupTestActions()
  1566 {
  1567 	QMenu *testMenu = menuBar()->addMenu( tr( "&Test" ));
  1568 
  1569 	QAction *a;
  1570 	a = new QAction( "Test function 1" , this);
  1571 	a->setStatusTip( "Call test function 1" );
  1572 	a->setShortcut (Qt::CTRL + Qt::Key_T);	// Test function 1  //FIXME-2 originally: color subtree
  1573 	testMenu->addAction (a);
  1574 	connect( a, SIGNAL( triggered() ), this, SLOT( testFunction1() ) );
  1575 
  1576 	a = new QAction( "Test function 2" , this);
  1577 	a->setStatusTip( "Call test function 2" );
  1578 	a->setShortcut (Qt::SHIFT + Qt::Key_T);		// Test function 2
  1579 	testMenu->addAction (a);
  1580 	connect( a, SIGNAL( triggered() ), this, SLOT( testFunction2() ) );
  1581 
  1582 	a = new QAction( "Command" , this);
  1583 	a->setStatusTip( "Enter command to call in editor" );
  1584 	connect( a, SIGNAL( triggered() ), this, SLOT( testCommand() ) );
  1585 	testMenu->addAction (a);
  1586 }
  1587 
  1588 // Help Actions
  1589 void Main::setupHelpActions()
  1590 {
  1591 	QMenu *helpMenu = menuBar()->addMenu ( tr( "&Help","Help menubar entry" ));
  1592 
  1593 	QAction *a;
  1594 	a = new QAction(  tr( "Open VYM Documentation (pdf) ","Help action" ), this );
  1595 	a->setStatusTip( tr( "Open VYM Documentation (pdf)" ));
  1596 	connect( a, SIGNAL( triggered() ), this, SLOT( helpDoc() ) );
  1597 	helpMenu->addAction (a);
  1598 
  1599 	a = new QAction(  tr( "Open VYM example maps ","Help action" ), this );
  1600 	a->setStatusTip( tr( "Open VYM example maps " ));
  1601 	connect( a, SIGNAL( triggered() ), this, SLOT( helpDemo() ) );
  1602 	helpMenu->addAction (a);
  1603 
  1604 	a = new QAction( tr( "About VYM","Help action" ), this);
  1605 	a->setStatusTip( tr( "About VYM")+vymName);
  1606 	connect( a, SIGNAL( triggered() ), this, SLOT( helpAbout() ) );
  1607 	helpMenu->addAction (a);
  1608 
  1609 	a = new QAction( tr( "About QT","Help action" ), this);
  1610 	a->setStatusTip( tr( "Information about QT toolkit" ));
  1611 	connect( a, SIGNAL( triggered() ), this, SLOT( helpAboutQT() ) );
  1612 	helpMenu->addAction (a);
  1613 }
  1614 
  1615 // Context Menus
  1616 void Main::setupContextMenus()
  1617 {
  1618 	QAction*a;
  1619 
  1620 	// Context Menu for branch or mapcenter
  1621 	branchContextMenu =new QMenu (this);
  1622 	branchContextMenu->addAction (actionViewTogglePropertyWindow);
  1623 	branchContextMenu->addSeparator();	
  1624 
  1625 		// Submenu "Add"
  1626 		branchAddContextMenu =branchContextMenu->addMenu (tr("Add"));
  1627 		branchAddContextMenu->addAction (actionPaste );
  1628 		branchAddContextMenu->addAction ( actionAddMapCenter );
  1629 		branchAddContextMenu->addAction ( actionAddBranch );
  1630 		branchAddContextMenu->addAction ( actionAddBranchBefore );
  1631 		branchAddContextMenu->addAction ( actionAddBranchAbove);
  1632 		branchAddContextMenu->addAction ( actionAddBranchBelow );
  1633 		branchAddContextMenu->addSeparator();	
  1634 		branchAddContextMenu->addAction ( actionImportAdd );
  1635 		branchAddContextMenu->addAction ( actionImportReplace );
  1636 
  1637 		// Submenu "Remove"
  1638 		branchRemoveContextMenu =branchContextMenu->addMenu (tr ("Remove","Context menu name"));
  1639 		branchRemoveContextMenu->addAction (actionCut);
  1640 		branchRemoveContextMenu->addAction ( actionDelete );
  1641 		branchRemoveContextMenu->addAction ( actionDeleteKeepChildren );
  1642 		branchRemoveContextMenu->addAction ( actionDeleteChildren );
  1643 		
  1644 
  1645 	actionSaveBranch->addTo( branchContextMenu );
  1646 	actionFileNewCopy->addTo (branchContextMenu );
  1647 	actionDetach->addTo (branchContextMenu );
  1648 
  1649 	branchContextMenu->addSeparator();	
  1650 	branchContextMenu->addAction ( actionLoadImage);
  1651 	if (settings.value( "/mainwindow/showTestMenu",false).toBool() )
  1652 		branchContextMenu->addAction ( actionAddAttribute);
  1653 
  1654 	// Submenu for Links (URLs, vymLinks)
  1655 	branchLinksContextMenu =new QMenu (this);
  1656 
  1657 		branchContextMenu->addSeparator();	
  1658 		branchLinksContextMenu=branchContextMenu->addMenu(tr("References (URLs, vymLinks, ...)","Context menu name"));	
  1659 		branchLinksContextMenu->addAction ( actionOpenURL );
  1660 		branchLinksContextMenu->addAction ( actionOpenURLTab );
  1661 		branchLinksContextMenu->addAction ( actionOpenMultipleVisURLTabs );
  1662 		branchLinksContextMenu->addAction ( actionOpenMultipleURLTabs );
  1663 		branchLinksContextMenu->addAction ( actionURL );
  1664 		branchLinksContextMenu->addAction ( actionLocalURL );
  1665 		branchLinksContextMenu->addAction ( actionHeading2URL );
  1666 		branchLinksContextMenu->addAction ( actionBugzilla2URL );
  1667 		if (settings.value( "/mainwindow/showTestMenu",false).toBool() )
  1668 		{
  1669 			branchLinksContextMenu->addAction ( actionGetBugzillaData );
  1670 			branchLinksContextMenu->addAction ( actionFATE2URL );
  1671 		}	
  1672 		branchLinksContextMenu->addSeparator();	
  1673 		branchLinksContextMenu->addAction ( actionOpenVymLink );
  1674 		branchLinksContextMenu->addAction ( actionOpenMultipleVymLinks );
  1675 		branchLinksContextMenu->addAction ( actionVymLink );
  1676 		branchLinksContextMenu->addAction ( actionDeleteVymLink );
  1677 		
  1678 
  1679 	// Context Menu for XLinks in a branch menu
  1680 	// This will be populated "on demand" in MapEditor::updateActions
  1681 	branchContextMenu->addSeparator();	
  1682 	branchXLinksContextMenuEdit =branchContextMenu->addMenu (tr ("Edit XLink","Context menu name"));
  1683 	connect( branchXLinksContextMenuEdit, SIGNAL( triggered(QAction *) ), this, SLOT( editEditXLink(QAction * ) ) );
  1684 
  1685 
  1686 	// Context menu for floatimage
  1687 	floatimageContextMenu =new QMenu (this);
  1688 	a= new QAction (tr ("Save image","Context action"),this);
  1689 	connect (a, SIGNAL (triggered()), this, SLOT (editSaveImage()));
  1690 	floatimageContextMenu->addAction (a);
  1691 
  1692 	floatimageContextMenu->addSeparator();	
  1693 	actionCopy->addTo( floatimageContextMenu );
  1694 	actionCut->addTo( floatimageContextMenu );
  1695 
  1696 	floatimageContextMenu->addSeparator();	
  1697 	floatimageContextMenu->addAction ( actionFormatHideLinkUnselected );
  1698 
  1699 
  1700 	// Context menu for canvas
  1701 	canvasContextMenu =new QMenu (this);
  1702 	actionAddMapCenter->addTo( canvasContextMenu );
  1703 	actionMapInfo->addTo( canvasContextMenu );
  1704 	canvasContextMenu->insertSeparator();	
  1705 	actionGroupFormatLinkStyles->addTo( canvasContextMenu );
  1706 	canvasContextMenu->insertSeparator();	
  1707 	actionFormatLinkColorHint->addTo( canvasContextMenu );
  1708 	actionFormatLinkColor->addTo( canvasContextMenu );
  1709 	actionFormatSelectionColor->addTo( canvasContextMenu );
  1710 	actionFormatBackColor->addTo( canvasContextMenu );
  1711 	// actionFormatBackImage->addTo( canvasContextMenu );  //FIXME-4 makes vym too slow: postponed for later version 
  1712 
  1713 	// Menu for last opened files
  1714 	// Create actions
  1715 	for (int i = 0; i < MaxRecentFiles; ++i) 
  1716 	{
  1717 		recentFileActions[i] = new QAction(this);
  1718 		recentFileActions[i]->setVisible(false);
  1719 		fileLastMapsMenu->addAction(recentFileActions[i]);
  1720 		connect(recentFileActions[i], SIGNAL(triggered()),
  1721 				this, SLOT(fileLoadRecent()));
  1722 	}
  1723 	setupRecentMapsMenu();
  1724 }
  1725 
  1726 void Main::setupRecentMapsMenu()
  1727 {
  1728 	QStringList files = settings.value("/mainwindow/recentFileList").toStringList();
  1729 
  1730 	int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles);
  1731 
  1732 	for (int i = 0; i < numRecentFiles; ++i) {
  1733 		QString text = tr("&%1 %2").arg(i + 1).arg(files[i]);
  1734 		recentFileActions[i]->setText(text);
  1735 		recentFileActions[i]->setData(files[i]);
  1736 		recentFileActions[i]->setVisible(true);
  1737 	}
  1738 	for (int j = numRecentFiles; j < MaxRecentFiles; ++j)
  1739 		recentFileActions[j]->setVisible(false);
  1740 }
  1741 
  1742 void Main::setupMacros()
  1743 {
  1744 	for (int i = 0; i <= 11; i++) 
  1745 	{
  1746 		macroActions[i] = new QAction(this);
  1747 		macroActions[i]->setData(i);
  1748 		addAction (macroActions[i]);
  1749 		connect(macroActions[i], SIGNAL(triggered()),
  1750 				this, SLOT(callMacro()));
  1751 	}			
  1752 	macroActions[0]->setShortcut ( Qt::Key_F1 );
  1753 	macroActions[1]->setShortcut ( Qt::Key_F2 );
  1754 	macroActions[2]->setShortcut ( Qt::Key_F3 );
  1755 	macroActions[3]->setShortcut ( Qt::Key_F4 );
  1756 	macroActions[4]->setShortcut ( Qt::Key_F5 );
  1757 	macroActions[5]->setShortcut ( Qt::Key_F6 );
  1758 	macroActions[6]->setShortcut ( Qt::Key_F7 );
  1759 	macroActions[7]->setShortcut ( Qt::Key_F8 );
  1760 	macroActions[8]->setShortcut ( Qt::Key_F9 );
  1761 	macroActions[9]->setShortcut ( Qt::Key_F10 );
  1762 	macroActions[10]->setShortcut ( Qt::Key_F11 );
  1763 	macroActions[11]->setShortcut ( Qt::Key_F12 );
  1764 }
  1765 
  1766 void Main::hideEvent (QHideEvent * )
  1767 {
  1768 	if (!textEditor->isMinimized() ) textEditor->hide();
  1769 }
  1770 
  1771 void Main::showEvent (QShowEvent * )
  1772 {
  1773 	if (actionViewToggleNoteEditor->isOn()) textEditor->showNormal();
  1774 }
  1775 
  1776 
  1777 MapEditor* Main::currentMapEditor() const
  1778 {
  1779 	if ( tabWidget->currentPage())
  1780 		return vymViews.at(tabWidget->currentIndex())->getMapEditor();
  1781 	return NULL;	
  1782 }
  1783 
  1784 VymModel* Main::currentModel() const
  1785 {
  1786 	if ( tabWidget->currentPage())
  1787 		return vymViews.at(tabWidget->currentIndex())->getModel();
  1788 	return NULL;	
  1789 }
  1790 
  1791 
  1792 void Main::editorChanged(QWidget *)
  1793 {
  1794 	// Unselect all possibly selected objects
  1795 	// (Important to update note editor)
  1796 	VymModel *m;
  1797 	for (int i=0;i<=tabWidget->count() -1;i++)
  1798 	{
  1799 		m= vymViews.at(i)->getModel();
  1800 		if (m) m->unselect();
  1801 	}
  1802 	m=currentModel();
  1803 	if (m) m->reselect();
  1804 
  1805 	// Update actions to in menus and toolbars according to editor
  1806 	updateActions();
  1807 }
  1808 
  1809 void Main::fileNew()
  1810 {
  1811 	VymModel *vm=new VymModel;
  1812 
  1813 	/////////////////////////////////////
  1814 //	new ModelTest(vm, this);	//FIXME-3
  1815 	/////////////////////////////////////
  1816 
  1817 	VymView *vv=new VymView (vm);
  1818 	vymViews.append (vv);
  1819 	tabWidget->addTab (vv,tr("unnamed","MainWindow: name for new and empty file"));
  1820 	tabWidget->setCurrentIndex (vymViews.count() );
  1821 	vv->initFocus();
  1822 
  1823 	// Create MapCenter for empty map
  1824 	vm->addMapCenter();
  1825 	vm->makeDefault();
  1826 
  1827 	// For the very first map we do not have flagrows yet...
  1828 	vm->select("mc:");
  1829 }
  1830 
  1831 void Main::fileNewCopy()
  1832 {
  1833 	QString fn="unnamed";
  1834 	VymModel *srcModel=currentModel();
  1835 	if (srcModel)
  1836 	{
  1837 		srcModel->copy();
  1838 		fileNew();
  1839 		VymModel *dstModel=vymViews.last()->getModel();
  1840 		dstModel->select("mc:");
  1841 		dstModel->load (clipboardDir+"/"+clipboardFile,ImportReplace, VymMap);
  1842 	}
  1843 }
  1844 
  1845 ErrorCode Main::fileLoad(QString fn, const LoadMode &lmode, const FileType &ftype)
  1846 {
  1847 	ErrorCode err=success;
  1848 
  1849 	// fn is usually the archive, mapfile the file after uncompressing
  1850 	QString mapfile;
  1851 
  1852 	// Make fn absolute (needed for unzip)
  1853 	fn=QDir (fn).absPath();
  1854 
  1855 	VymModel *vm;
  1856 
  1857 	if (lmode==NewMap)
  1858 	{
  1859 		// Check, if map is already loaded
  1860 		int i=0;
  1861 		while (i<=tabWidget->count() -1)
  1862 		{
  1863 			if (vymViews.at(i)->getModel()->getFilePath() == fn)
  1864 			{
  1865 				// Already there, ask for confirmation
  1866 				QMessageBox mb( vymName,
  1867 					tr("The map %1\nis already opened."
  1868 					"Opening the same map in multiple editors may lead \n"
  1869 					"to confusion when finishing working with vym."
  1870 					"Do you want to").arg(fn),
  1871 					QMessageBox::Warning,
  1872 					QMessageBox::Yes | QMessageBox::Default,
  1873 					QMessageBox::Cancel | QMessageBox::Escape,
  1874 					QMessageBox::NoButton);
  1875 				mb.setButtonText( QMessageBox::Yes, tr("Open anyway") );
  1876 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  1877 				switch( mb.exec() ) 
  1878 				{
  1879 					case QMessageBox::Yes:
  1880 						// end loop and load anyway
  1881 						i=tabWidget->count();
  1882 						break;
  1883 					case QMessageBox::Cancel:
  1884 						// do nothing
  1885 						return aborted;
  1886 						break;
  1887 				}
  1888 			}
  1889 			i++;
  1890 		}
  1891 	}
  1892 
  1893 	int tabIndex=tabWidget->currentPageIndex();
  1894 
  1895 	// Try to load map
  1896     if ( !fn.isEmpty() )
  1897 	{
  1898 		vm = currentModel();
  1899 		// Check first, if mapeditor exists
  1900 		// If it is not default AND we want a new map, 
  1901 		// create a new mapeditor in a new tab
  1902 		if ( lmode==NewMap && (!vm || !vm->isDefault() )  )
  1903 		{
  1904 			vm=new VymModel;
  1905 			VymView *vv=new VymView (vm);
  1906 			vymViews.append (vv);
  1907 			tabWidget->addTab (vv,fn);
  1908 			tabIndex=tabWidget->count()-1;
  1909 			tabWidget->setCurrentPage (tabIndex);
  1910 			vv->initFocus();
  1911 		}
  1912 		
  1913 		// Check, if file exists (important for creating new files
  1914 		// from command line
  1915 		if (!QFile(fn).exists() )
  1916 		{
  1917 			QMessageBox mb( vymName,
  1918 				tr("This map does not exist:\n  %1\nDo you want to create a new one?").arg(fn),
  1919 				QMessageBox::Question,
  1920 				QMessageBox::Yes ,
  1921 				QMessageBox::Cancel | QMessageBox::Default,
  1922 				QMessageBox::NoButton );
  1923 
  1924 			mb.setButtonText( QMessageBox::Yes, tr("Create"));
  1925 			mb.setButtonText( QMessageBox::No, tr("Cancel"));
  1926 			switch( mb.exec() ) 
  1927 			{
  1928 				case QMessageBox::Yes:
  1929 					// Create new map
  1930 					currentMapEditor()->getModel()->setFilePath(fn);
  1931 					tabWidget->setTabText (tabIndex,
  1932 						currentMapEditor()->getModel()->getFileName() );
  1933 					statusBar()->message( "Created " + fn , statusbarTime );
  1934 					return success;
  1935 						
  1936 				case QMessageBox::Cancel:
  1937 					// don't create new map
  1938 					statusBar()->message( "Loading " + fn + " failed!", statusbarTime );
  1939 					fileCloseMap();
  1940 					return aborted;
  1941 			}
  1942 		}	
  1943 
  1944 
  1945 		//tabWidget->currentPage() won't be NULL here, because of above...
  1946 		tabWidget->setCurrentIndex (tabIndex);
  1947 		//FIXME-3 no me anymore... me->viewport()->setFocus();
  1948 
  1949 		if (err!=aborted)
  1950 		{
  1951 			// Save existing filename in case  we import
  1952 			QString fn_org=vm->getFilePath();
  1953 
  1954 			// Finally load map into mapEditor
  1955 			vm->setFilePath (fn);
  1956 			err=vm->load(fn,lmode,ftype);
  1957 
  1958 			// Restore old (maybe empty) filepath, if this is an import
  1959 			if (lmode!=NewMap)
  1960 				vm->setFilePath (fn_org);
  1961 		}	
  1962 
  1963 		// Finally check for errors and go home
  1964 		if (err==aborted) 
  1965 		{
  1966 			if (lmode==NewMap) fileCloseMap();
  1967 			statusBar()->message( "Could not load " + fn, statusbarTime );
  1968 		} else 
  1969 		{
  1970 			if (lmode==NewMap)
  1971 			{
  1972 				vm->setFilePath (fn);
  1973 				tabWidget->setTabText (tabIndex, vm->getFileName());
  1974 				if (!isInTmpDir (fn))
  1975 				{
  1976 					// Only append to lastMaps if not loaded from a tmpDir
  1977 					// e.g. imported bookmarks are in a tmpDir
  1978 					addRecentMap(vm->getFilePath() );
  1979 				}
  1980 				actionFilePrint->setEnabled (true);
  1981 			}	
  1982 			statusBar()->message( "Loaded " + fn, statusbarTime );
  1983 		}	
  1984 	}
  1985 	return err;
  1986 }
  1987 
  1988 
  1989 void Main::fileLoad(const LoadMode &lmode)
  1990 {
  1991 	QStringList filters;
  1992 	filters <<"VYM map (*.vym *.vyp)"<<"XML (*.xml)";
  1993 	QFileDialog *fd=new QFileDialog( this);
  1994 	fd->setDir (lastFileDir);
  1995 	fd->setFileMode (QFileDialog::ExistingFiles);
  1996 	fd->setFilters (filters);
  1997 	switch (lmode)
  1998 	{
  1999 		case NewMap:
  2000 			fd->setCaption(vymName+ " - " +tr("Load vym map"));
  2001 			break;
  2002 		case ImportAdd:
  2003 			fd->setCaption(vymName+ " - " +tr("Import: Add vym map to selection"));
  2004 			break;
  2005 		case ImportReplace:
  2006 			fd->setCaption(vymName+ " - " +tr("Import: Replace selection with vym map"));
  2007 			break;
  2008 	}
  2009 	fd->show();
  2010 
  2011 	QString fn;
  2012 	if ( fd->exec() == QDialog::Accepted )
  2013 	{
  2014 		lastFileDir=fd->directory().path();
  2015 	    QStringList flist = fd->selectedFiles();
  2016 		QStringList::Iterator it = flist.begin();
  2017 		
  2018 		progressCounter=flist.count();
  2019 		progressCounterTotal=flist.count();
  2020 		while( it != flist.end() ) 
  2021 		{
  2022 			fn = *it;
  2023 			fileLoad(*it, lmode);				   
  2024 			++it;
  2025 		}
  2026 	}
  2027 	delete (fd);
  2028 }
  2029 
  2030 void Main::fileLoad()
  2031 {
  2032 	fileLoad (NewMap);
  2033 }
  2034 
  2035 void Main::fileLoadRecent()
  2036 {
  2037     QAction *action = qobject_cast<QAction *>(sender());
  2038     if (action)
  2039         fileLoad (action->data().toString(), NewMap);
  2040 }
  2041 
  2042 void Main::addRecentMap (const QString &fileName)
  2043 {
  2044 
  2045     QStringList files = settings.value("/mainwindow/recentFileList").toStringList();
  2046     files.removeAll(fileName);
  2047     files.prepend(fileName);
  2048     while (files.size() > MaxRecentFiles)
  2049         files.removeLast();
  2050 
  2051     settings.setValue("/mainwindow/recentFileList", files);
  2052 
  2053 	setupRecentMapsMenu();
  2054 }
  2055 
  2056 void Main::fileSave(VymModel *m, const SaveMode &savemode)
  2057 {
  2058 	if (!m) return;
  2059 
  2060 	if ( m->getFilePath().isEmpty() ) 
  2061 	{
  2062 		// We have  no filepath yet,
  2063 		// call fileSaveAs() now, this will call fileSave() 
  2064 		// again.
  2065 		// First switch to editor
  2066 		//FIXME-3 needed???  tabWidget->setCurrentWidget (m->getMapEditor());
  2067 		fileSaveAs(savemode);
  2068 	}
  2069 
  2070 	if (m->save (savemode)==success)
  2071 	{
  2072 		statusBar()->message( 
  2073 			tr("Saved  %1").arg(m->getFilePath()), 
  2074 			statusbarTime );
  2075 		addRecentMap (m->getFilePath() );
  2076 	} else		
  2077 		statusBar()->message( 
  2078 			tr("Couldn't save ").arg(m->getFilePath()), 
  2079 			statusbarTime );
  2080 }
  2081 
  2082 void Main::fileSave()
  2083 {
  2084 	fileSave (currentModel(), CompleteMap);
  2085 }
  2086 
  2087 void Main::fileSave(VymModel *m)
  2088 {
  2089 	fileSave (m,CompleteMap);
  2090 }
  2091 
  2092 void Main::fileSaveAs(const SaveMode& savemode)
  2093 {
  2094 	QString fn;
  2095 
  2096 	if (currentMapEditor())
  2097 	{
  2098 		if (savemode==CompleteMap)
  2099 			fn = Q3FileDialog::getSaveFileName( QString::null, "VYM map (*.vym)", this );
  2100 		else		
  2101 			fn = Q3FileDialog::getSaveFileName( QString::null, "VYM part of map (*.vyp)", this );
  2102 		if ( !fn.isEmpty() ) 
  2103 		{
  2104 			// Check for existing file
  2105 			if (QFile (fn).exists())
  2106 			{
  2107 				QMessageBox mb( vymName,
  2108 					tr("The file %1\nexists already. Do you want to").arg(fn),
  2109 					QMessageBox::Warning,
  2110 					QMessageBox::Yes | QMessageBox::Default,
  2111 					QMessageBox::Cancel | QMessageBox::Escape,
  2112 					QMessageBox::NoButton);
  2113 				mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
  2114 				mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
  2115 				switch( mb.exec() ) 
  2116 				{
  2117 					case QMessageBox::Yes:
  2118 						// save 
  2119 						break;
  2120 					case QMessageBox::Cancel:
  2121 						// do nothing
  2122 						return;
  2123 						break;
  2124 				}
  2125 			} else
  2126 			{
  2127 				// New file, add extension to filename, if missing
  2128 				// This is always .vym or .vyp, depending on savemode
  2129 				if (savemode==CompleteMap)
  2130 				{
  2131 					if (!fn.contains (".vym") && !fn.contains (".xml"))
  2132 						fn +=".vym";
  2133 				} else		
  2134 				{
  2135 					if (!fn.contains (".vyp") && !fn.contains (".xml"))
  2136 						fn +=".vyp";
  2137 				}
  2138 			}
  2139 	
  2140 
  2141 
  2142 
  2143 			// Save now
  2144 			VymModel *m=currentModel();
  2145 			m->setFilePath(fn);
  2146 			fileSave(m, savemode);
  2147 
  2148 			// Set name of tab, assuming current tab is the one we just saved
  2149 			if (savemode==CompleteMap)
  2150 				tabWidget->setTabText (tabWidget->currentIndex(), m->getFileName() );
  2151 			return;
  2152 		} 
  2153 	}
  2154 }
  2155 
  2156 void Main::fileSaveAs()
  2157 {
  2158 	fileSaveAs (CompleteMap);
  2159 }
  2160 
  2161 void Main::fileImportKDE3Bookmarks()
  2162 {
  2163 	ImportKDE3Bookmarks im;
  2164 	im.transform();
  2165 	if (aborted!=fileLoad (im.getTransformedFile(),NewMap) && currentMapEditor() )
  2166 		currentMapEditor()->getModel()->setFilePath ("");
  2167 }
  2168 
  2169 void Main::fileImportKDE4Bookmarks()
  2170 {
  2171 	ImportKDE4Bookmarks im;
  2172 	im.transform();
  2173 	if (aborted!=fileLoad (im.getTransformedFile(),NewMap) && currentMapEditor() )
  2174 		currentMapEditor()->getModel()->setFilePath ("");
  2175 }
  2176 
  2177 void Main::fileImportFirefoxBookmarks()
  2178 {
  2179 	Q3FileDialog *fd=new Q3FileDialog( this);
  2180 	fd->setDir (vymBaseDir.homeDirPath()+"/.mozilla/firefox");
  2181 	fd->setMode (Q3FileDialog::ExistingFiles);
  2182 	fd->addFilter ("Firefox "+tr("Bookmarks")+" (*.html)");
  2183 	fd->setCaption(tr("Import")+" "+"Firefox "+tr("Bookmarks"));
  2184 	fd->show();
  2185 
  2186 	if ( fd->exec() == QDialog::Accepted )
  2187 	{
  2188 		ImportFirefoxBookmarks im;
  2189 	    QStringList flist = fd->selectedFiles();
  2190 		QStringList::Iterator it = flist.begin();
  2191 		while( it != flist.end() ) 
  2192 		{
  2193 			im.setFile (*it);
  2194 			if (im.transform() && 
  2195 				aborted!=fileLoad (im.getTransformedFile(),NewMap,FreemindMap) && 
  2196 				currentMapEditor() )
  2197 				currentMapEditor()->getModel()->setFilePath ("");
  2198 			++it;
  2199 		}
  2200 	}
  2201 	delete (fd);
  2202 }
  2203 
  2204 void Main::fileImportFreemind()
  2205 {
  2206 	QStringList filters;
  2207 	filters <<"Freemind map (*.mm)"<<"All files (*)";
  2208 	QFileDialog *fd=new QFileDialog( this);
  2209 	fd->setDir (lastFileDir);
  2210 	fd->setFileMode (QFileDialog::ExistingFiles);
  2211 	fd->setFilters (filters);
  2212 	fd->setCaption(vymName+ " - " +tr("Load Freemind map"));
  2213 	fd->show();
  2214 
  2215 	QString fn;
  2216 	if ( fd->exec() == QDialog::Accepted )
  2217 	{
  2218 		lastFileDir=fd->directory().path();
  2219 	    QStringList flist = fd->selectedFiles();
  2220 		QStringList::Iterator it = flist.begin();
  2221 		while( it != flist.end() ) 
  2222 		{
  2223 			fn = *it;
  2224 			if ( fileLoad (fn,NewMap, FreemindMap)  )
  2225 			{	
  2226 				currentMapEditor()->getModel()->setFilePath ("");
  2227 			}	
  2228 			++it;
  2229 		}
  2230 	}
  2231 	delete (fd);
  2232 }
  2233 
  2234 
  2235 void Main::fileImportMM()
  2236 {
  2237 	ImportMM im;
  2238 
  2239 	Q3FileDialog *fd=new Q3FileDialog( this);
  2240 	fd->setDir (lastFileDir);
  2241 	fd->setMode (Q3FileDialog::ExistingFiles);
  2242 	fd->addFilter ("Mind Manager (*.mmap)");
  2243 	fd->setCaption(tr("Import")+" "+"Mind Manager");
  2244 	fd->show();
  2245 
  2246 	if ( fd->exec() == QDialog::Accepted )
  2247 	{
  2248 		lastFileDir=fd->dirPath();
  2249 	    QStringList flist = fd->selectedFiles();
  2250 		QStringList::Iterator it = flist.begin();
  2251 		while( it != flist.end() ) 
  2252 		{
  2253 			im.setFile (*it);
  2254 			if (im.transform() && 
  2255 				success==fileLoad (im.getTransformedFile(),NewMap) && 
  2256 				currentMapEditor() )
  2257 				currentMapEditor()->getModel()->setFilePath ("");
  2258 			++it;
  2259 		}
  2260 	}
  2261 	delete (fd);
  2262 }
  2263 
  2264 void Main::fileImportDir()
  2265 {
  2266 	VymModel *m=currentModel();
  2267 	if (m) m->importDir();
  2268 }
  2269 
  2270 void Main::fileExportXML()	
  2271 {
  2272 	VymModel *m=currentModel();
  2273 	if (m) m->exportXML();
  2274 }
  2275 
  2276 void Main::fileExportHTML()	
  2277 {
  2278 	VymModel *m=currentModel();
  2279 	if (m) m->exportHTML();
  2280 }
  2281 
  2282 
  2283 void Main::fileExportXHTML()	
  2284 {
  2285 	VymModel *m=currentModel();
  2286 	if (m) m->exportXHTML();
  2287 }
  2288 
  2289 void Main::fileExportImage()	
  2290 {
  2291 	VymModel *m=currentModel();
  2292 	if (m) m->exportImage();
  2293 }
  2294 
  2295 void Main::fileExportAO()
  2296 {
  2297 	VymModel *m=currentModel();
  2298 	if (m) m->exportAO();
  2299 }
  2300 
  2301 void Main::fileExportASCII()
  2302 {
  2303 	VymModel *m=currentModel();
  2304 	if (m) m->exportASCII();
  2305 }
  2306 
  2307 void Main::fileExportCSV()	//FIXME-3 not scriptable yet
  2308 {
  2309 	VymModel *m=currentModel();
  2310 	if (m)
  2311 	{
  2312 		ExportCSV ex;
  2313 		ex.setModel (m);
  2314 		ex.addFilter ("CSV (*.csv)");
  2315 		ex.setDir(lastImageDir);
  2316 		ex.setCaption(vymName+ " -" +tr("Export as CSV")+" "+tr("(still experimental)"));
  2317 		if (ex.execDialog() ) 
  2318 		{
  2319 			m->setExportMode(true);
  2320 			ex.doExport();
  2321 			m->setExportMode(false);
  2322 		}
  2323 	}
  2324 }
  2325 
  2326 void Main::fileExportLaTeX()	//FIXME-3 not scriptable yet
  2327 {
  2328 	VymModel *m=currentModel();
  2329 	if (m)
  2330 	{
  2331 		ExportLaTeX ex;
  2332 		ex.setModel (m);
  2333 		ex.addFilter ("Tex (*.tex)");
  2334 		ex.setDir(lastImageDir);
  2335 		ex.setCaption(vymName+ " -" +tr("Export as LaTeX")+" "+tr("(still experimental)"));
  2336 		if (ex.execDialog() ) 
  2337 		{
  2338 			m->setExportMode(true);
  2339 			ex.doExport();
  2340 			m->setExportMode(false);
  2341 		}
  2342 	}
  2343 }
  2344 
  2345 void Main::fileExportKDE3Bookmarks()	//FIXME-3 not scriptable yet
  2346 {
  2347 	ExportKDE3Bookmarks ex;
  2348 	VymModel *m=currentModel();
  2349 	if (m)
  2350 	{
  2351 		ex.setModel (m);
  2352 		ex.doExport();
  2353 	}	
  2354 }
  2355 
  2356 void Main::fileExportKDE4Bookmarks()	//FIXME-3 not scriptable yet
  2357 {
  2358 	ExportKDE4Bookmarks ex;
  2359 	VymModel *m=currentModel();
  2360 	if (m)
  2361 	{
  2362 		ex.setModel (m);
  2363 		ex.doExport();
  2364 	}	
  2365 }
  2366 
  2367 void Main::fileExportTaskjuggler()	//FIXME-3 not scriptable yet
  2368 {
  2369 	ExportTaskjuggler ex;
  2370 	VymModel *m=currentModel();
  2371 	if (m)
  2372 	{
  2373 		ex.setModel (m);
  2374 		ex.setCaption ( vymName+" - "+tr("Export to")+" Taskjuggler"+tr("(still experimental)"));
  2375 		ex.setDir(lastImageDir);
  2376 		ex.addFilter ("Taskjuggler (*.tjp)");
  2377 		if (ex.execDialog() ) 
  2378 		{
  2379 			m->setExportMode(true);
  2380 			ex.doExport();
  2381 			m->setExportMode(false);
  2382 		}
  2383 	}	
  2384 }
  2385 
  2386 void Main::fileExportOOPresentation()	//FIXME-3 not scriptable yet
  2387 {
  2388 	ExportOOFileDialog *fd=new ExportOOFileDialog( this,vymName+" - "+tr("Export to")+" Open Office");
  2389 	// TODO add preview in dialog
  2390 	//ImagePreview *p =new ImagePreview (fd);
  2391 	//fd->setContentsPreviewEnabled( TRUE );
  2392 	//fd->setContentsPreview( p, p );
  2393 	//fd->setPreviewMode( QFileDialog::Contents );
  2394 	fd->setCaption(vymName+" - " +tr("Export to")+" Open Office");
  2395 	fd->setDir (QDir().current());
  2396 	if (fd->foundConfig())
  2397 	{
  2398 		fd->show();
  2399 
  2400 		if ( fd->exec() == QDialog::Accepted )
  2401 		{
  2402 			QString fn=fd->selectedFile();
  2403 			if (!fn.contains (".odp"))
  2404 				fn +=".odp";
  2405 
  2406 			//lastImageDir=fn.left(fn.findRev ("/"));
  2407 			VymModel *m=currentModel();
  2408 			if (m) m->exportOOPresentation(fn,fd->selectedConfig());	
  2409 		}
  2410 	} else
  2411 	{
  2412 		QMessageBox::warning(0, 
  2413 		tr("Warning"),
  2414 		tr("Couldn't find configuration for export to Open Office\n"));
  2415 	}
  2416 }
  2417 
  2418 void Main::fileCloseMap()	
  2419 {
  2420 	VymModel *m=currentModel();
  2421 	if (m)
  2422 	{
  2423 		if (m->hasChanged())
  2424 		{
  2425 			QMessageBox mb( vymName,
  2426 				tr("The map %1 has been modified but not saved yet. Do you want to").arg(m->getFileName()),
  2427 				QMessageBox::Warning,
  2428 				QMessageBox::Yes | QMessageBox::Default,
  2429 				QMessageBox::No,
  2430 				QMessageBox::Cancel | QMessageBox::Escape );
  2431 			mb.setButtonText( QMessageBox::Yes, tr("Save modified map before closing it") );
  2432 			mb.setButtonText( QMessageBox::No, tr("Discard changes"));
  2433 			switch( mb.exec() ) 
  2434 			{
  2435 				case QMessageBox::Yes:
  2436 					// save and close
  2437 					fileSave(m, CompleteMap);
  2438 					break;
  2439 				case QMessageBox::No:
  2440 				// close  without saving
  2441 					break;
  2442 				case QMessageBox::Cancel:
  2443 					// do nothing
  2444 				return;
  2445 			}
  2446 		} 
  2447 		// And here comes the segfault, because removeTab triggers 
  2448 		// FIXME-3 currentChanged->Main::editorChanged -> updateActions and VM is not NULL yet...
  2449 		vymViews.removeAt (tabWidget->currentIndex() );
  2450 		tabWidget->removeTab (tabWidget->currentIndex() );
  2451 
  2452 		// Remove mapEditor/model FIXME-3   Huh? seems to work now...
  2453 		// Better would be delete (me), but then we could have a Qt error:
  2454 		// "QObject: Do not delete object, 'MapEditor', during its event handler!"
  2455 		// So we only remove data now and call deconstructor when vym closes later
  2456 		// this needs to be moved to vymview...   me->clear();
  2457 		// some model->clear is needed to free up memory ...
  2458 
  2459 		delete (m->getMapEditor());
  2460 		delete (m);
  2461 
  2462 		updateActions();
  2463 	}
  2464 }
  2465 
  2466 void Main::filePrint()
  2467 {
  2468 	if (currentMapEditor())
  2469 		currentMapEditor()->print();
  2470 }
  2471 
  2472 void Main::fileExitVYM()
  2473 {
  2474 	// Check if one or more editors have changed
  2475 	int i;
  2476 	for (i=0;i<=vymViews.count() -1;i++)
  2477 	{
  2478 		// If something changed, ask what to do
  2479 		if (vymViews.at(i)->getModel()->hasChanged())
  2480 		{
  2481 			tabWidget->setCurrentPage(i);
  2482 			QMessageBox mb( vymName,
  2483 				tr("This map is not saved yet. Do you want to"),
  2484 				QMessageBox::Warning,
  2485 				QMessageBox::Yes | QMessageBox::Default,
  2486 				QMessageBox::No,
  2487 				QMessageBox::Cancel | QMessageBox::Escape );
  2488 			mb.setButtonText( QMessageBox::Yes, tr("Save map") );
  2489 			mb.setButtonText( QMessageBox::No, tr("Discard changes") );
  2490 			mb.setModal (true);
  2491 			mb.show();
  2492 			mb.setActiveWindow();
  2493 			switch( mb.exec() ) {
  2494 				case QMessageBox::Yes:
  2495 					// save (the changed editors) and exit
  2496 					fileSave(currentModel(), CompleteMap);
  2497 					break;
  2498 				case QMessageBox::No:
  2499 					// exit without saving
  2500 					break;
  2501 				case QMessageBox::Cancel:
  2502 					// don't save and don't exit
  2503 				return;
  2504 			}
  2505 		}
  2506 	} // loop over all MEs	
  2507     qApp->quit();
  2508 }
  2509 
  2510 void Main::editUndo()
  2511 {
  2512 	VymModel *m=currentModel();
  2513 	if (m) m->undo();
  2514 }
  2515 
  2516 void Main::editRedo()	   
  2517 {
  2518 	VymModel *m=currentModel();
  2519 	if (m) m->redo();
  2520 }
  2521 
  2522 void Main::gotoHistoryStep (int i)	   
  2523 {
  2524 	VymModel *m=currentModel();
  2525 	if (m) m->gotoHistoryStep(i);
  2526 }
  2527 
  2528 void Main::editCopy()
  2529 {
  2530 	VymModel *m=currentModel();
  2531 	if (m) m->copy();
  2532 }
  2533 
  2534 void Main::editPaste()
  2535 {
  2536 	VymModel *m=currentModel();
  2537 	if (m) m->paste();
  2538 }
  2539 
  2540 void Main::editCut()
  2541 {
  2542 	VymModel *m=currentModel();
  2543 	if (m) m->cut();
  2544 }
  2545 
  2546 void Main::editOpenFindWidget()
  2547 {
  2548 	VymModel *m=currentModel();
  2549 	if (m) m->emitShowFindWidget();
  2550 }
  2551 
  2552 void Main::editFindDuplicateURLs()
  2553 {
  2554 	VymModel *m=currentModel();
  2555 	if (m) m->findDuplicateURLs();
  2556 }
  2557 
  2558 void Main::openTabs(QStringList urls)
  2559 {
  2560 	if (!urls.isEmpty())
  2561 	{	
  2562 		bool success=true;
  2563 		QStringList args;
  2564 		QString browser=settings.value("/mainwindow/readerURL" ).toString();
  2565 		//qDebug ()<<"Services: "<<QDBusConnection::sessionBus().interface()->registeredServiceNames().value();
  2566 		if (*browserPID==0 ||
  2567 			(browser.contains("konqueror") &&
  2568 			 !QDBusConnection::sessionBus().interface()->registeredServiceNames().value().contains (QString("org.kde.konqueror-%1").arg(*browserPID)))
  2569 		   )	 
  2570 		{
  2571 			// Start a new browser, if there is not one running already or
  2572 			// if a previously started konqueror is gone.
  2573 			if (debug) cout <<"Main::openTabs no konqueror-"<<*browserPID<<" found\n";
  2574 			QString u=urls.takeFirst();
  2575 			args<<u;
  2576 			QString workDir=QDir::currentDirPath();
  2577 			if (!QProcess::startDetached(browser,args,workDir,browserPID))
  2578 			{
  2579 				// try to set path to browser
  2580 				QMessageBox::warning(0, 
  2581 					tr("Warning"),
  2582 					tr("Couldn't find a viewer to open %1.\n").arg(u)+
  2583 					tr("Please use Settings->")+tr("Set application to open an URL"));
  2584 				return;
  2585 			}
  2586 			if (debug) cout << "Main::openTabs  Started konqueror-"<<*browserPID<<endl;
  2587 #if defined(Q_OS_WIN32)
  2588             // There's no sleep in VCEE, replace it with Qt's QThread::wait().
  2589             this->thread()->wait(3000);
  2590 #else
  2591 			sleep (3);	//FIXME-3 needed?
  2592 #endif
  2593 		}
  2594 
  2595 		if (browser.contains("konqueror"))
  2596 		{
  2597 			for (int i=0; i<urls.size(); i++)
  2598 			{
  2599 				// Open new browser
  2600 				// Try to open new tab in existing konqueror started previously by vym
  2601 				args.clear();
  2602 
  2603 /*	On KDE3 use DCOP
  2604 				args<< QString("konqueror-%1").arg(procBrowser->pid())<<
  2605 					"konqueror-mainwindow#1"<<
  2606 					"newTab" <<
  2607 					urls.at(i);
  2608 */					
  2609 				args<< QString("org.kde.konqueror-%1").arg(*browserPID)<<
  2610 					"/konqueror/MainWindow_1"<<
  2611 					"newTab" <<
  2612 					urls.at(i)<<
  2613 					"false";
  2614 				if (debug) cout << "MainWindow::openURLs  args="<<args.join(" ").toStdString()<<endl;
  2615 				if (!QProcess::startDetached ("qdbus",args))
  2616 					success=false;
  2617 			}
  2618 			if (!success)
  2619 				QMessageBox::warning(0, 
  2620 					tr("Warning"),
  2621 					tr("Couldn't start %1 to open a new tab in %2.").arg("dcop").arg("konqueror"));
  2622 			return;		
  2623 		} else if (browser.contains ("firefox") || browser.contains ("mozilla") )
  2624 		{
  2625 			for (int i=0; i<urls.size(); i++)
  2626 			{
  2627 				// Try to open new tab in firefox
  2628 				args<< "-remote"<< QString("openurl(%1,new-tab)").arg(urls.at(i));
  2629 				if (!QProcess::startDetached (browser,args))
  2630 					success=false;
  2631 			}			
  2632 			if (!success)
  2633 				QMessageBox::warning(0, 
  2634 					tr("Warning"),
  2635 					tr("Couldn't start %1 to open a new tab").arg(browser));
  2636 			return;		
  2637 		}			
  2638 		QMessageBox::warning(0, 
  2639 			tr("Warning"),
  2640 			tr("Sorry, currently only Konqueror and Mozilla support tabbed browsing."));
  2641 	}	
  2642 }
  2643 
  2644 void Main::editOpenURL()
  2645 {
  2646 	// Open new browser
  2647 	VymModel *m=currentModel();
  2648 	if (m)
  2649 	{	
  2650 	    QString url=m->getURL();
  2651 		QStringList args;
  2652 		if (url=="") return;
  2653 		QString browser=settings.value("/mainwindow/readerURL" ).toString();
  2654 		args<<url;
  2655 		QString workDir=QDir::currentDirPath();
  2656 		if (!procBrowser->startDetached(browser,args))
  2657 		{
  2658 			// try to set path to browser
  2659 			QMessageBox::warning(0, 
  2660 				tr("Warning"),
  2661 				tr("Couldn't find a viewer to open %1.\n").arg(url)+
  2662 				tr("Please use Settings->")+tr("Set application to open an URL"));
  2663 			settingsURL() ; 
  2664 		}	
  2665 	}	
  2666 }
  2667 void Main::editOpenURLTab()
  2668 {
  2669 	VymModel *m=currentModel();
  2670 	if (m)
  2671 	{	
  2672 	    QStringList urls;
  2673 		urls.append(m->getURL());
  2674 		openTabs (urls);
  2675 	}	
  2676 }
  2677 
  2678 void Main::editOpenMultipleVisURLTabs(bool ignoreScrolled)
  2679 {
  2680 	VymModel *m=currentModel();
  2681 	if (m)
  2682 	{	
  2683 	    QStringList urls;
  2684 		urls=m->getURLs(ignoreScrolled);
  2685 		openTabs (urls);
  2686 	}	
  2687 }
  2688 
  2689 void Main::editOpenMultipleURLTabs()
  2690 {
  2691 	editOpenMultipleVisURLTabs (false);
  2692 }
  2693 
  2694 
  2695 void Main::editURL()
  2696 {
  2697 	VymModel *m=currentModel();
  2698 	if (m) m->editURL();
  2699 }
  2700 
  2701 void Main::editLocalURL()
  2702 {
  2703 	VymModel *m=currentModel();
  2704 	if (m) m->editLocalURL();
  2705 }
  2706 
  2707 void Main::editHeading2URL()
  2708 {
  2709 	VymModel *m=currentModel();
  2710 	if (m) m->editHeading2URL();
  2711 }
  2712 
  2713 void Main::editBugzilla2URL()
  2714 {
  2715 	VymModel *m=currentModel();
  2716 	if (m) m->editBugzilla2URL();
  2717 }
  2718 
  2719 void Main::getBugzillaData()
  2720 {
  2721 	VymModel *m=currentModel();
  2722 	/*
  2723 	QProgressDialog progress ("Doing stuff","cancl",0,10,this);
  2724 	progress.setWindowModality(Qt::WindowModal);
  2725 	//progress.setCancelButton (NULL);
  2726 	progress.show();
  2727 	progress.setMinimumDuration (0);
  2728 	progress.setValue (1);
  2729 	progress.setValue (5);
  2730 	progress.update();
  2731 	*/
  2732 	/*
  2733 	QProgressBar *pb=new QProgressBar;
  2734 	pb->setMinimum (0);
  2735 	pb->setMaximum (0);
  2736 	pb->show();
  2737 	pb->repaint();
  2738 	*/
  2739 	if (m) m->getBugzillaData();
  2740 }
  2741 
  2742 void Main::editFATE2URL()
  2743 {
  2744 	VymModel *m=currentModel();
  2745 	if (m) m->editFATE2URL();
  2746 }
  2747 
  2748 void Main::editHeadingFinished(VymModel *m)
  2749 {
  2750 	if (m)
  2751 	{
  2752 		if (!actionSettingsAutoSelectNewBranch->isOn() && 
  2753 			!prevSelection.isEmpty()) 
  2754 			m->select(prevSelection);
  2755 		prevSelection="";
  2756 	}
  2757 }
  2758 
  2759 void Main::openVymLinks(const QStringList &vl)
  2760 {
  2761 	for (int j=0; j<vl.size(); j++)
  2762 	{
  2763 		// compare path with already loaded maps
  2764 		int index=-1;
  2765 		int i;
  2766 		for (i=0;i<=vymViews.count() -1;i++)
  2767 		{
  2768 			if (vl.at(j)==vymViews.at(i)->getModel()->getFilePath() )
  2769 			{
  2770 				index=i;
  2771 				break;
  2772 			}
  2773 		}	
  2774 		if (index<0)
  2775 		// Load map
  2776 		{
  2777 			if (!QFile(vl.at(j)).exists() )
  2778 				QMessageBox::critical( 0, tr( "Critical Error" ),
  2779 				   tr("Couldn't open map %1").arg(vl.at(j)));
  2780 			else
  2781 			{
  2782 				fileLoad (vl.at(j), NewMap);
  2783 				tabWidget->setCurrentIndex (tabWidget->count()-1);	
  2784 			}
  2785 		} else
  2786 			// Go to tab containing the map
  2787 			tabWidget->setCurrentIndex (index);	
  2788 	}
  2789 }
  2790 
  2791 void Main::editOpenVymLink()
  2792 {
  2793 	VymModel *m=currentModel();
  2794 	if (m)
  2795 	{
  2796 		QStringList vl;
  2797 		vl.append(m->getVymLink());	
  2798 		openVymLinks (vl);
  2799 	}
  2800 }
  2801 
  2802 void Main::editOpenMultipleVymLinks()
  2803 {
  2804 	QString currentVymLink;
  2805 	VymModel *m=currentModel();
  2806 	if (m)
  2807 	{
  2808 		QStringList vl=m->getVymLinks();
  2809 		openVymLinks (vl);
  2810 	}
  2811 }
  2812 
  2813 void Main::editVymLink()
  2814 {
  2815 	VymModel *m=currentModel();
  2816 	if (m)
  2817 		m->editVymLink();	
  2818 }
  2819 
  2820 void Main::editDeleteVymLink()
  2821 {
  2822 	VymModel *m=currentModel();
  2823 	if (m) m->deleteVymLink();	
  2824 }
  2825 
  2826 void Main::editToggleHideExport()
  2827 {
  2828 	VymModel *m=currentModel();
  2829 	if (m) m->toggleHideExport();	
  2830 }
  2831 
  2832 void Main::editAddTimestamp()
  2833 {
  2834 	VymModel *m=currentModel();
  2835 	if (m) m->addTimestamp();	
  2836 }
  2837 
  2838 void Main::editMapInfo()
  2839 {
  2840 	VymModel *m=currentModel();
  2841 	if (!m) return;
  2842 
  2843 	ExtraInfoDialog dia;
  2844 	dia.setMapName (m->getFileName() );
  2845 	dia.setAuthor (m->getAuthor() );
  2846 	dia.setComment(m->getComment() );
  2847 
  2848 	// Calc some stats
  2849 	QString stats;
  2850     stats+=tr("%1 items on map\n","Info about map").arg (m->getScene()->items().size(),6);
  2851 
  2852 	uint b=0;
  2853 	uint f=0;
  2854 	uint n=0;
  2855 	uint xl=0;
  2856 	BranchItem *cur=NULL;
  2857 	BranchItem *prev=NULL;
  2858 	m->nextBranch(cur,prev);
  2859 	while (cur) 
  2860 	{
  2861 		if (!cur->getNote().isEmpty() ) n++;
  2862 		f+= cur->imageCount();
  2863 		b++;
  2864 		xl+=cur->xlinkCount();
  2865 		m->nextBranch(cur,prev);
  2866 	}
  2867 
  2868     stats+=QString ("%1 xLinks \n").arg (xl,6);
  2869     stats+=QString ("%1 notes\n").arg (n,6);
  2870     stats+=QString ("%1 images\n").arg (f,6);
  2871     stats+=QString ("%1 branches\n").arg (m->branchCount(),6);
  2872 	dia.setStats (stats);
  2873 
  2874 	// Finally show dialog
  2875 	if (dia.exec() == QDialog::Accepted)
  2876 	{
  2877 		m->setAuthor (dia.getAuthor() );
  2878 		m->setComment (dia.getComment() );
  2879 	}
  2880 }
  2881 
  2882 void Main::editMoveUp()
  2883 {
  2884 	VymModel *m=currentModel();
  2885 	if (m) m->moveUp();
  2886 }
  2887 
  2888 void Main::editMoveDown()
  2889 {
  2890 	VymModel *m=currentModel();
  2891 	if (m) m->moveDown();
  2892 }
  2893 
  2894 void Main::editDetach()
  2895 {
  2896 	VymModel *m=currentModel();
  2897 	if (m) m->detach();
  2898 }
  2899 
  2900 void Main::editSortChildren()
  2901 {
  2902 	VymModel *m=currentModel();
  2903 	if (m) m->sortChildren(false);
  2904 }
  2905 
  2906 void Main::editSortBackChildren()
  2907 {
  2908 	VymModel *m=currentModel();
  2909 	if (m) m->sortChildren(true);
  2910 }
  2911 
  2912 void Main::editToggleScroll()
  2913 {
  2914 	VymModel *m=currentModel();
  2915 	if (m) m->toggleScroll();
  2916 }
  2917 
  2918 void Main::editExpandAll()
  2919 {
  2920 	VymModel *m=currentModel();
  2921 	if (m) m->emitExpandAll();
  2922 }
  2923 
  2924 void Main::editExpandOneLevel()
  2925 {
  2926 	VymModel *m=currentModel();
  2927 	if (m) m->emitExpandOneLevel();
  2928 }
  2929 
  2930 void Main::editCollapseOneLevel()
  2931 {
  2932 	VymModel *m=currentModel();
  2933 	if (m) m->emitCollapseOneLevel();
  2934 }
  2935 
  2936 void Main::editUnscrollChildren()
  2937 {
  2938 	VymModel *m=currentModel();
  2939 	if (m) m->unscrollChildren();
  2940 }
  2941 
  2942 void Main::editAddAttribute()
  2943 {
  2944 	VymModel *m=currentModel();
  2945 	if (m) 
  2946 	{
  2947 
  2948 		m->addAttribute();
  2949 	}
  2950 }
  2951 
  2952 void Main::editAddMapCenter()
  2953 {
  2954 	VymModel *m=currentModel();
  2955 	if (m) m->addMapCenter ();
  2956 }
  2957 
  2958 void Main::editNewBranch()
  2959 {
  2960 	VymModel *m=currentModel();
  2961 	if (m)
  2962 	{
  2963 		BranchItem *bi=m->addNewBranch();
  2964 		if (!bi) return;
  2965 
  2966 		if (actionSettingsAutoEditNewBranch->isOn() 
  2967 		     && !actionSettingsAutoSelectNewBranch->isOn() )
  2968 			prevSelection=m->getSelectString();
  2969 		else	
  2970 			prevSelection=QString();
  2971 
  2972 		if (actionSettingsAutoSelectNewBranch->isOn()  
  2973 			|| actionSettingsAutoEditNewBranch->isOn()) 
  2974 		{
  2975 			m->select (bi);
  2976 			if (actionSettingsAutoEditNewBranch->isOn())
  2977 				currentMapEditor()->editHeading();
  2978 		}
  2979 	}	
  2980 }
  2981 
  2982 void Main::editNewBranchBefore()
  2983 {
  2984 	VymModel *m=currentModel();
  2985 	if (m)
  2986 	{
  2987 		BranchItem *bi=m->addNewBranchBefore();
  2988 
  2989 		if (bi) 
  2990 			m->select (bi);
  2991 		else
  2992 			return;
  2993 
  2994 		if (actionSettingsAutoEditNewBranch->isOn())
  2995 		{
  2996 			if (!actionSettingsAutoSelectNewBranch->isOn())
  2997 				prevSelection=m->getSelectString(bi); 
  2998 			currentMapEditor()->editHeading();
  2999 		}
  3000 	}	
  3001 }
  3002 
  3003 void Main::editNewBranchAbove()	
  3004 {
  3005 	VymModel *m=currentModel();
  3006 	if ( m)
  3007 	{
  3008 		BranchItem *bi=m->addNewBranch (-1);
  3009 
  3010 
  3011 		if (bi) 
  3012 			m->select (bi);
  3013 		else
  3014 			return;
  3015 
  3016 		if (actionSettingsAutoEditNewBranch->isOn())
  3017 		{
  3018 			if (!actionSettingsAutoSelectNewBranch->isOn())
  3019 				prevSelection=m->getSelectString (bi);	
  3020 			currentMapEditor()->editHeading();
  3021 		}
  3022 	}	
  3023 }
  3024 
  3025 void Main::editNewBranchBelow()
  3026 {
  3027 	VymModel *m=currentModel();
  3028 	if (m)
  3029 	{
  3030 		BranchItem *bi=m->addNewBranch (1);
  3031 
  3032 		if (bi) 
  3033 			m->select (bi);
  3034 		else
  3035 			return;
  3036 
  3037 		if (actionSettingsAutoEditNewBranch->isOn())
  3038 		{
  3039 			if (!actionSettingsAutoSelectNewBranch->isOn())
  3040 				prevSelection=m->getSelectString(bi);
  3041 			currentMapEditor()->editHeading();
  3042 		}
  3043 	}	
  3044 }
  3045 
  3046 void Main::editImportAdd()
  3047 {
  3048 	fileLoad (ImportAdd);
  3049 }
  3050 
  3051 void Main::editImportReplace()
  3052 {
  3053 	fileLoad (ImportReplace);
  3054 }
  3055 
  3056 void Main::editSaveBranch()
  3057 {
  3058 	fileSaveAs (PartOfMap);
  3059 }
  3060 
  3061 void Main::editDeleteKeepChildren()
  3062 {
  3063 	VymModel *m=currentModel();
  3064 	 if (m) m->deleteKeepChildren();
  3065 }
  3066 
  3067 void Main::editDeleteChildren()
  3068 {
  3069 	VymModel *m=currentModel();
  3070 	if (m) m->deleteChildren();
  3071 }
  3072 
  3073 void Main::editDeleteSelection()
  3074 {
  3075 	VymModel *m=currentModel();
  3076 	if (m && actionSettingsUseDelKey->isOn())
  3077 		m->deleteSelection();
  3078 }
  3079 
  3080 void Main::editLoadImage()
  3081 {
  3082 	VymModel *m=currentModel();
  3083 	if (m) m->loadFloatImage();
  3084 }
  3085 
  3086 void Main::editSaveImage()
  3087 {
  3088 	VymModel *m=currentModel();
  3089 	if (m) m->saveFloatImage();
  3090 }
  3091 
  3092 void Main::editEditXLink(QAction *a)
  3093 {
  3094 	VymModel *m=currentModel();
  3095 	if (m)
  3096 		m->editXLink(branchXLinksContextMenuEdit->actions().indexOf(a));
  3097 }
  3098 
  3099 void Main::formatSelectColor()
  3100 {
  3101 	QColor col = QColorDialog::getColor((currentColor ), this );
  3102 	if ( !col.isValid() ) return;
  3103 	colorChanged( col );
  3104 }
  3105 
  3106 void Main::formatPickColor()
  3107 {
  3108 	VymModel *m=currentModel();
  3109 	if (m)
  3110 		colorChanged( m->getCurrentHeadingColor() );
  3111 }
  3112 
  3113 void Main::colorChanged(QColor c)
  3114 {
  3115     QPixmap pix( 16, 16 );
  3116     pix.fill( c );
  3117     actionFormatColor->setIconSet( pix );
  3118 	currentColor=c;
  3119 }
  3120 
  3121 void Main::formatColorBranch()
  3122 {
  3123 	VymModel *m=currentModel();
  3124 	if (m) m->colorBranch(currentColor);
  3125 }
  3126 
  3127 void Main::formatColorSubtree()
  3128 {
  3129 	VymModel *m=currentModel();
  3130 	if (m) m->colorSubtree (currentColor);
  3131 }
  3132 
  3133 void Main::formatLinkStyleLine()
  3134 {
  3135 	VymModel *m=currentModel();
  3136 	if (m)
  3137     {
  3138 		m->setMapLinkStyle("StyleLine");
  3139         actionFormatLinkStyleLine->setChecked(true);
  3140     }
  3141 }
  3142 
  3143 void Main::formatLinkStyleParabel()
  3144 {
  3145 	VymModel *m=currentModel();
  3146 	if (m)
  3147     {
  3148 		m->setMapLinkStyle("StyleParabel");
  3149         actionFormatLinkStyleParabel->setChecked(true);
  3150     }
  3151 }
  3152 
  3153 void Main::formatLinkStylePolyLine()
  3154 {
  3155 	VymModel *m=currentModel();
  3156 	if (m)
  3157     {
  3158 		m->setMapLinkStyle("StylePolyLine");
  3159         actionFormatLinkStylePolyLine->setChecked(true);
  3160     }
  3161 }
  3162 
  3163 void Main::formatLinkStylePolyParabel()
  3164 {
  3165 	VymModel *m=currentModel();
  3166 	if (m)
  3167     {
  3168 		m->setMapLinkStyle("StylePolyParabel");
  3169         actionFormatLinkStylePolyParabel->setChecked(true);
  3170     }
  3171 }
  3172 
  3173 void Main::formatSelectBackColor()
  3174 {
  3175 	VymModel *m=currentModel();
  3176 	if (m) m->selectMapBackgroundColor();
  3177 }
  3178 
  3179 void Main::formatSelectBackImage()
  3180 {
  3181 	VymModel *m=currentModel();
  3182 	if (m)
  3183 		m->selectMapBackgroundImage();
  3184 }
  3185 
  3186 void Main::formatSelectLinkColor()
  3187 {
  3188 	VymModel *m=currentModel();
  3189 	if (m)
  3190 	{
  3191 		QColor col = QColorDialog::getColor( m->getMapDefLinkColor(), this );
  3192 		m->setMapDefLinkColor( col );
  3193 	}
  3194 }
  3195 
  3196 void Main::formatSelectSelectionColor()
  3197 {
  3198 	VymModel *m=currentModel();
  3199 	if (m)
  3200 	{
  3201 		QColor col = QColorDialog::getColor( m->getMapDefLinkColor(), this );
  3202 		m->setSelectionColor (col);
  3203 	}
  3204 
  3205 }
  3206 
  3207 void Main::formatToggleLinkColorHint()
  3208 {
  3209 	VymModel *m=currentModel();
  3210 	if (m) m->toggleMapLinkColorHint();
  3211 }
  3212 
  3213 
  3214 void Main::formatHideLinkUnselected()	//FIXME-3 get rid of this with imagepropertydialog
  3215 {
  3216 	VymModel *m=currentModel();
  3217 	if (m)
  3218 		m->setHideLinkUnselected(actionFormatHideLinkUnselected->isOn());
  3219 }
  3220 
  3221 void Main::viewZoomReset()
  3222 {
  3223 	MapEditor *me=currentMapEditor();
  3224 	if (me) me->setZoomFactorTarget (1);
  3225 }
  3226 
  3227 void Main::viewZoomIn()
  3228 {
  3229 	MapEditor *me=currentMapEditor();
  3230 	if (me) me->setZoomFactorTarget (me->getZoomFactorTarget()*1.25);
  3231 }
  3232 
  3233 void Main::viewZoomOut()
  3234 {
  3235 	MapEditor *me=currentMapEditor();
  3236 	if (me) me->setZoomFactorTarget (me->getZoomFactorTarget()*0.75);
  3237 }
  3238 
  3239 void Main::viewCenter()
  3240 {
  3241 	VymModel *m=currentModel();
  3242 	if (m) m->emitShowSelection();
  3243 }
  3244 
  3245 void Main::networkStartServer()
  3246 {
  3247 	VymModel *m=currentModel();
  3248 	if (m) m->newServer();
  3249 }
  3250 
  3251 void Main::networkConnect()
  3252 {
  3253 	VymModel *m=currentModel();
  3254 	if (m) m->connectToServer();
  3255 }
  3256 
  3257 bool Main::settingsPDF()
  3258 {
  3259 	// Default browser is set in constructor
  3260 	bool ok;
  3261 	QString text = QInputDialog::getText(
  3262 		"VYM", tr("Set application to open PDF files")+":", QLineEdit::Normal,
  3263 		settings.value("/mainwindow/readerPDF").toString(), &ok, this );
  3264 	if (ok)
  3265 		settings.setValue ("/mainwindow/readerPDF",text);
  3266 	return ok;
  3267 }
  3268 
  3269 
  3270 bool Main::settingsURL()
  3271 {
  3272 	// Default browser is set in constructor
  3273 	bool ok;
  3274 	QString text = QInputDialog::getText(
  3275 		"VYM", tr("Set application to open an URL")+":", QLineEdit::Normal,
  3276 		settings.value("/mainwindow/readerURL").toString()
  3277 		, &ok, this );
  3278 	if (ok)
  3279 		settings.setValue ("/mainwindow/readerURL",text);
  3280 	return ok;
  3281 }
  3282 
  3283 void Main::settingsMacroDir()
  3284 {
  3285 	QDir defdir(vymBaseDir.path() + "/macros");
  3286 	if (!defdir.exists())
  3287 		defdir=vymBaseDir;
  3288 	QDir dir=QFileDialog::getExistingDirectory (
  3289 		this,
  3290 		tr ("Directory with vym macros:"), 
  3291 		settings.value ("/macros/macroDir",defdir.path()).toString()
  3292 	);
  3293 	if (dir.exists())
  3294 		settings.setValue ("/macros/macroDir",dir.absolutePath());
  3295 }
  3296 
  3297 void Main::settingsUndoLevels()
  3298 {
  3299 	bool ok;
  3300 	int i = QInputDialog::getInteger(
  3301 		this, 
  3302 		tr("QInputDialog::getInteger()"),
  3303 	    tr("Number of undo/redo levels:"), settings.value("/mapeditor/stepsTotal").toInt(), 0, 1000, 1, &ok);
  3304 	if (ok)
  3305 	{
  3306 		settings.setValue ("/mapeditor/stepsTotal",i);
  3307 		QMessageBox::information( this, tr( "VYM -Information:" ),
  3308 		   tr("Settings have been changed. The next map opened will have \"%1\" undo/redo levels").arg(i)); 
  3309    }	
  3310 }
  3311 
  3312 void Main::settingsAutosaveToggle()
  3313 {
  3314 	settings.setValue ("/mainwindow/autosave/use",actionSettingsAutosaveToggle->isOn() );
  3315 }
  3316 
  3317 void Main::settingsAutosaveTime()
  3318 {
  3319 	bool ok;
  3320 	int i = QInputDialog::getInteger(
  3321 		this, 
  3322 		tr("QInputDialog::getInteger()"),
  3323 	    tr("Number of seconds before autosave:"), settings.value("/mainwindow/autosave/ms").toInt() / 1000, 10, 10000, 1, &ok);
  3324 	if (ok)
  3325 		settings.setValue ("/mainwindow/autosave/ms",i * 1000);
  3326 }
  3327 
  3328 void Main::settingsWriteBackupFileToggle()
  3329 {
  3330 	settings.setValue ("/mainwindow/writeBackupFile",actionSettingsWriteBackupFile->isOn() );
  3331 }
  3332 
  3333 void Main::settingsToggleAnimation()
  3334 {
  3335 	settings.setValue ("/animation/use",actionSettingsUseAnimation->isOn() );
  3336 }
  3337 
  3338 void Main::settingsToggleDelKey()
  3339 {
  3340 	if (actionSettingsUseDelKey->isOn())
  3341 	{
  3342 		actionDelete->setAccel (QKeySequence (Qt::Key_Delete));
  3343 	} else
  3344 	{
  3345 		actionDelete->setAccel (QKeySequence (""));
  3346 	}
  3347 }
  3348 
  3349 void Main::windowToggleNoteEditor()
  3350 {
  3351 	if (textEditor->isVisible() )
  3352 		windowHideNoteEditor();
  3353 	else
  3354 		windowShowNoteEditor();
  3355 }
  3356 
  3357 void Main::windowToggleHistory()
  3358 {
  3359 	if (historyWindow->isVisible())
  3360 		historyWindow->hide();
  3361 	else	
  3362 		historyWindow->show();
  3363 
  3364 }
  3365 
  3366 void Main::windowToggleProperty()
  3367 {
  3368 	if (branchPropertyWindow->isVisible())
  3369 		branchPropertyWindow->hide();
  3370 	else	
  3371 		branchPropertyWindow->show();
  3372 	branchPropertyWindow->setModel (currentModel() );
  3373 }
  3374 
  3375 void Main::windowToggleAntiAlias()
  3376 {
  3377 	bool b=actionViewToggleAntiAlias->isOn();
  3378 	MapEditor *me;
  3379 	for (int i=0;i<vymViews.count();i++)
  3380 	{
  3381 		me=vymViews.at(i)->getMapEditor();
  3382 		if (me) me->setAntiAlias(b);
  3383 	}	
  3384 
  3385 }
  3386 
  3387 bool Main::isAliased()
  3388 {
  3389 	return actionViewToggleAntiAlias->isOn();
  3390 }
  3391 
  3392 bool Main::hasSmoothPixmapTransform()
  3393 {
  3394 	return actionViewToggleSmoothPixmapTransform->isOn();
  3395 }
  3396 
  3397 void Main::windowToggleSmoothPixmap()
  3398 {
  3399 	bool b=actionViewToggleSmoothPixmapTransform->isOn();
  3400 	MapEditor *me;
  3401 	for (int i=0;i<vymViews.count();i++)
  3402 	{
  3403 		
  3404 		me=vymViews.at(i)->getMapEditor();
  3405 		if (me) me->setSmoothPixmap(b);
  3406 	}	
  3407 }
  3408 
  3409 void Main::updateHistory(SimpleSettings &undoSet)
  3410 {
  3411 	historyWindow->update (undoSet);
  3412 }
  3413 
  3414 void Main::updateNoteFlag()	
  3415 {
  3416 	// this slot is connected to TextEditor::textHasChanged()
  3417 	VymModel *m=currentModel();
  3418 	if (m) m->updateNoteFlag();
  3419 }
  3420 
  3421 void Main::updateNoteEditor(QModelIndex index )
  3422 {
  3423 	TreeItem *ti=((VymModel*) QObject::sender())->getItem(index);
  3424 	/*
  3425 	cout << "Main::updateNoteEditor model="<<sender();
  3426 	cout << "  item="<<ti->getHeadingStd()<<" ("<<ti<<")"<<endl;
  3427 	*/
  3428 	textEditor->setNote (ti->getNoteObj() );
  3429 }
  3430 
  3431 void Main::changeSelection (VymModel *model, const QItemSelection &newsel, const QItemSelection &oldsel)
  3432 {
  3433 	branchPropertyWindow->setModel (model ); //FIXME-3 this used to be called from BranchObj::select(). Maybe use signal now...
  3434 
  3435 	if (model && model==currentModel() )
  3436 	{
  3437 		// NoteEditor
  3438 		TreeItem *ti;
  3439 		if (!oldsel.indexes().isEmpty() )
  3440 		{
  3441 			ti=model->getItem(oldsel.indexes().first());
  3442 
  3443 			// Don't update note if both treeItem and textEditor are empty
  3444 			//if (! (ti->hasEmptyNote() && textEditor->isEmpty() ))
  3445 			//	ti->setNoteObj (textEditor->getNoteObj(),false );
  3446 		} 
  3447 		if (!newsel.indexes().isEmpty() )
  3448 		{
  3449 			ti=model->getItem(newsel.indexes().first());
  3450 			if (!ti->hasEmptyNote() )
  3451 				textEditor->setNote(ti->getNoteObj() );
  3452 			else
  3453 				textEditor->setNote(NoteObj() );	//FIXME-4 maybe add a clear() to TE
  3454 			
  3455 			// Show URL and link in statusbar	
  3456 			QString status;
  3457 			QString s=ti->getURL();
  3458 			if (!s.isEmpty() ) status+="URL: "+s+"  ";
  3459 			s=ti->getVymLink();
  3460 			if (!s.isEmpty() ) status+="Link: "+s;
  3461 			if (!status.isEmpty() ) statusMessage (status);
  3462 
  3463 		} else
  3464 			textEditor->setInactive();
  3465 
  3466 		updateActions();
  3467 	}
  3468 }
  3469 
  3470 void Main::updateActions()
  3471 {
  3472 	// updateActions is also called when satellites are closed	//FIXME-2 doesn't update immediatly, e.g. historyWindow is still visible, when "close" is pressed
  3473 	actionViewToggleNoteEditor->setChecked (textEditor->isVisible());
  3474 	actionViewToggleHistoryWindow->setChecked (historyWindow->isVisible());
  3475 	actionViewTogglePropertyWindow->setChecked (branchPropertyWindow->isVisible());
  3476 
  3477 	VymModel  *m =currentModel();
  3478 	if (m) 
  3479 	{
  3480 		// Printing
  3481 		actionFilePrint->setEnabled (true);
  3482 
  3483 		// Link style in context menu
  3484 		switch (m->getMapLinkStyle())
  3485 		{
  3486 			case LinkableMapObj::Line: 
  3487 				actionFormatLinkStyleLine->setChecked(true);
  3488 				break;
  3489 			case LinkableMapObj::Parabel:
  3490 				actionFormatLinkStyleParabel->setChecked(true);
  3491 				break;
  3492 			case LinkableMapObj::PolyLine:	
  3493 				actionFormatLinkStylePolyLine->setChecked(true);
  3494 				break;
  3495 			case LinkableMapObj::PolyParabel:	
  3496 				actionFormatLinkStylePolyParabel->setChecked(true);
  3497 				break;
  3498 			default:
  3499 				break;
  3500 		}		
  3501 
  3502 		// Update colors
  3503 		QPixmap pix( 16, 16 );
  3504 		pix.fill( m->getMapBackgroundColor() );
  3505 		actionFormatBackColor->setIconSet( pix );
  3506 		pix.fill( m->getSelectionColor() );
  3507 		actionFormatSelectionColor->setIconSet( pix );
  3508 		pix.fill( m->getMapDefLinkColor() );
  3509 		actionFormatLinkColor->setIconSet( pix );
  3510 
  3511 		// History window
  3512 		historyWindow->setCaption (vymName + " - " +tr("History for %1","Window Caption").arg(m->getFileName()));
  3513 
  3514 
  3515 		// Expanding/collapsing
  3516 		actionExpandAll->setEnabled (true);
  3517 		actionExpandOneLevel->setEnabled (true);
  3518 		actionCollapseOneLevel->setEnabled (true);
  3519 	} else
  3520 	{
  3521 		// Printing
  3522 		actionFilePrint->setEnabled (false);
  3523 
  3524 		// Expanding/collapsing
  3525 		actionExpandAll->setEnabled (false);
  3526 		actionExpandOneLevel->setEnabled (false);
  3527 		actionCollapseOneLevel->setEnabled (false);
  3528 	}
  3529 
  3530 	if (m && m->getMapLinkColorHint()==LinkableMapObj::HeadingColor) 
  3531 		actionFormatLinkColorHint->setChecked(true);
  3532 	else	
  3533 		actionFormatLinkColorHint->setChecked(false);
  3534 
  3535 
  3536 	if (m && m->hasChanged() )
  3537 		actionFileSave->setEnabled( true);
  3538 	else	
  3539 		actionFileSave->setEnabled( false);
  3540 	if (m && m->isUndoAvailable())
  3541 		actionUndo->setEnabled( true);
  3542 	else	
  3543 		actionUndo->setEnabled( false);
  3544 
  3545 	if (m && m->isRedoAvailable())
  3546 		actionRedo->setEnabled( true);
  3547 	else	
  3548 		actionRedo->setEnabled( false);
  3549 
  3550 	if (m)
  3551 	{
  3552 		TreeItem *selti=m->getSelectedItem();
  3553 		BranchItem *selbi=m->getSelectedBranch();
  3554 		if (selti)
  3555 		{
  3556 			if (selbi || selti->getType()==TreeItem::Image)
  3557 			{
  3558 				actionFormatHideLinkUnselected->setChecked (((MapItem*)selti)->getHideLinkUnselected());
  3559 				actionFormatHideLinkUnselected->setEnabled (true);
  3560 			}
  3561 
  3562 			if (selbi)	
  3563 			{
  3564 				// Take care of xlinks  
  3565 				branchXLinksContextMenuEdit->clear();
  3566 				if (selbi->xlinkCount()>0)
  3567 				{
  3568 					BranchItem *bi;
  3569 					QString s;
  3570 					for (int i=0; i<selbi->xlinkCount();++i)
  3571 					{
  3572 						bi=selbi->getXLinkNum(i)->getPartnerBranch();
  3573 						if (bi)
  3574 						{
  3575 							s=bi->getHeading();
  3576 							if (s.length()>xLinkMenuWidth)
  3577 								s=s.left(xLinkMenuWidth)+"...";
  3578 							branchXLinksContextMenuEdit->addAction (s);
  3579 						}	
  3580 					}
  3581 				}
  3582 				//Standard Flags
  3583 				standardFlagsMaster->updateToolBar (selbi->activeStandardFlagNames() );
  3584 
  3585 				// System Flags
  3586 				actionToggleScroll->setEnabled (true);
  3587 				if ( selbi->isScrolled() )
  3588 					actionToggleScroll->setChecked(true);
  3589 				else	
  3590 					actionToggleScroll->setChecked(false);
  3591 
  3592 				if ( selti->getURL().isEmpty() )
  3593 				{
  3594 					actionOpenURL->setEnabled (false);
  3595 					actionOpenURLTab->setEnabled (false);
  3596 				}	
  3597 				else	
  3598 				{
  3599 					actionOpenURL->setEnabled (true);
  3600 					actionOpenURLTab->setEnabled (true);
  3601 				}
  3602 				if ( selti->getVymLink().isEmpty() )
  3603 				{
  3604 					actionOpenVymLink->setEnabled (false);
  3605 					actionDeleteVymLink->setEnabled (false);
  3606 				} else	
  3607 				{
  3608 					actionOpenVymLink->setEnabled (true);
  3609 					actionDeleteVymLink->setEnabled (true);
  3610 				}	
  3611 
  3612 				if (selbi->canMoveUp()) 
  3613 					actionMoveUp->setEnabled (true);
  3614 				else	
  3615 					actionMoveUp->setEnabled (false);
  3616 				if (selbi->canMoveDown()) 
  3617 					actionMoveDown->setEnabled (true);
  3618 				else	
  3619 					actionMoveDown->setEnabled (false);
  3620 
  3621 				actionSortChildren->setEnabled (true);
  3622 				actionSortBackChildren->setEnabled (true);
  3623 
  3624 				actionToggleHideExport->setEnabled (true);	
  3625 				actionToggleHideExport->setChecked (selbi->hideInExport() );	
  3626 
  3627 				actionCopy->setEnabled (true);	
  3628 				actionCut->setEnabled (true);	
  3629 				if (!clipboardEmpty)
  3630 					actionPaste->setEnabled (true);	
  3631 				else	
  3632 					actionPaste->setEnabled (false);	
  3633 				for (int i=0; i<actionListBranches.size(); ++i)	
  3634 					actionListBranches.at(i)->setEnabled(true);
  3635 				actionDelete->setEnabled (true);
  3636 			}	// Branch
  3637 			if ( selti->getType()==TreeItem::Image)
  3638 			{
  3639 				actionOpenURL->setEnabled (false);
  3640 				actionOpenVymLink->setEnabled (false);
  3641 				actionDeleteVymLink->setEnabled (false);	
  3642 				actionToggleHideExport->setEnabled (true);	
  3643 				actionToggleHideExport->setChecked (selti->hideInExport() );	
  3644 
  3645 
  3646 				actionCopy->setEnabled (true);
  3647 				actionCut->setEnabled (true);	
  3648 				actionPaste->setEnabled (false);	//FIXME-4 why not allowing copy of images?
  3649 				for (int i=0; i<actionListBranches.size(); ++i)	
  3650 					actionListBranches.at(i)->setEnabled(false);
  3651 				actionDelete->setEnabled (true);
  3652 				actionMoveUp->setEnabled (false);
  3653 				actionMoveDown->setEnabled (false);
  3654 			}	// Image
  3655 
  3656 		} else
  3657 		{	// !selti
  3658 			actionCopy->setEnabled (false);	
  3659 			actionCut->setEnabled (false);	
  3660 			actionPaste->setEnabled (false);	
  3661 			for (int i=0; i<actionListBranches.size(); ++i)	
  3662 				actionListBranches.at(i)->setEnabled(false);
  3663 
  3664 			actionToggleScroll->setEnabled (false);
  3665 			actionOpenURL->setEnabled (false);
  3666 			actionOpenVymLink->setEnabled (false);
  3667 			actionDeleteVymLink->setEnabled (false);	
  3668 			actionHeading2URL->setEnabled (false);	
  3669 			actionDelete->setEnabled (false);
  3670 			actionMoveUp->setEnabled (false);
  3671 			actionMoveDown->setEnabled (false);
  3672 			actionFormatHideLinkUnselected->setEnabled (false);
  3673 			actionSortChildren->setEnabled (false);
  3674 			actionSortBackChildren->setEnabled (false);
  3675 			actionToggleHideExport->setEnabled (false);	
  3676 		}	
  3677 	} // m
  3678 }
  3679 
  3680 Main::ModMode Main::getModMode()
  3681 {
  3682 	if (actionModModeColor->isOn()) return ModModeColor;
  3683 	if (actionModModeCopy->isOn()) return ModModeCopy;
  3684 	if (actionModModeXLink->isOn()) return ModModeXLink;
  3685 	return ModModeNone;
  3686 }
  3687 
  3688 bool Main::autoEditNewBranch()
  3689 {
  3690 	return actionSettingsAutoEditNewBranch->isOn();
  3691 }
  3692 
  3693 bool Main::autoSelectNewBranch()
  3694 {
  3695 	return actionSettingsAutoSelectNewBranch->isOn();
  3696 }
  3697 
  3698 void Main::windowShowNoteEditor()
  3699 {
  3700 	textEditor->setShowWithMain(true);
  3701 	textEditor->show();
  3702 	actionViewToggleNoteEditor->setChecked (true);
  3703 }
  3704 
  3705 void Main::windowHideNoteEditor()
  3706 {
  3707 	textEditor->setShowWithMain(false);
  3708 	textEditor->hide();
  3709 	actionViewToggleNoteEditor->setChecked (false);
  3710 }
  3711 
  3712 void Main::setScript (const QString &script)
  3713 {
  3714 	scriptEditor->setScript (script);
  3715 }
  3716 
  3717 void Main::runScript (const QString &script)
  3718 {
  3719 	VymModel *m=currentModel();
  3720 	if (m) m->runScript (script);
  3721 }
  3722 
  3723 void Main::runScriptEverywhere (const QString &script)
  3724 {
  3725 	MapEditor *me;
  3726 	for (int i=0;i<=tabWidget->count() -1;i++)
  3727 	{
  3728 		me=(MapEditor*)tabWidget->page(i);
  3729 		if (me) me->getModel()->runScript (script);
  3730 	}	
  3731 }
  3732 
  3733 void Main::windowNextEditor()
  3734 {
  3735 	if (tabWidget->currentIndex() < tabWidget->count())
  3736 		tabWidget->setCurrentIndex (tabWidget->currentIndex() +1);
  3737 }
  3738 
  3739 void Main::windowPreviousEditor()
  3740 {
  3741 	if (tabWidget->currentIndex() >0)
  3742 		tabWidget->setCurrentIndex (tabWidget->currentIndex() -1);
  3743 }
  3744 
  3745 void Main::standardFlagChanged()
  3746 {
  3747 	if (currentModel())
  3748 	{
  3749 		if ( actionSettingsUseFlagGroups->isOn() )
  3750 			currentModel()->toggleStandardFlag(sender()->name(),standardFlagsMaster);
  3751 		else	
  3752 			currentModel()->toggleStandardFlag(sender()->name());
  3753 		updateActions();	
  3754 	}
  3755 }
  3756 
  3757 void Main::testFunction1()
  3758 {
  3759 
  3760 	Process p;
  3761 	QString script="test/sleep.sh";
  3762 	p.start (script);
  3763 	if (!p.waitForStarted())
  3764 	{
  3765 		cout <<"VM::getBugzillaData couldn't start "<<script.toStdString()<<endl;
  3766 		return;
  3767 	}	
  3768 	if (!p.waitForFinished())
  3769 	{
  3770 		cout <<"VM::getBugzillaData couldn't finish "<<script.toStdString()<<endl;
  3771 		return;
  3772 	}
  3773 	//QByteArray result=p.readAll();
  3774 	QString result=p.getStdout();
  3775 	while (result.endsWith("\n")) result.chop(1); 
  3776 	//cout << QString(result).toStdString()<<endl;
  3777 	QString err=p.getErrout();
  3778 	if (!err.isEmpty())
  3779 	{
  3780 		cout << "VM::getBugzillaData Error:\n";
  3781 		cout <<err.toStdString()<<endl;
  3782 	}
  3783 	else if (!result.isEmpty())
  3784 	{
  3785 		cout << "ok\n";
  3786 	}	
  3787 /*
  3788 	int max=100000;
  3789 	QProgressDialog p ("testprogress","cancel",0,max,this);
  3790 	p.setWindowModality (Qt::WindowModal);
  3791 	p.setAutoReset (false);
  3792 	p.setAutoClose (false);
  3793 	p.show();
  3794 	for (int i=0;i<max;i++)
  3795 	{
  3796 		p.setValue(i);
  3797 		if (p.wasCanceled()) break;
  3798 	}
  3799 
  3800 	cout << "Doing it again...\n";
  3801 	p.reset();
  3802 	p.hide();
  3803 	max=max+10;
  3804 	p.setRange(0,max);
  3805 	p.setValue (0);
  3806 	p.show();
  3807 	for (int i=0;i<max;i++)
  3808 	{
  3809 		p.setValue (i);
  3810 		if (p.wasCanceled()) break;
  3811 	}
  3812 	p.setValue (max);
  3813 	cout << "Done.\n";
  3814 	return;
  3815 */
  3816 /*
  3817 	if (!currentMapEditor()) return;
  3818 	currentMapEditor()->testFunction1();
  3819 */
  3820 /*
  3821 
  3822 	VymModel *m=currentModel();
  3823 	if (!m) return;
  3824 
  3825 	bool ok;
  3826 	QString text = QInputDialog::getText(
  3827 			"VYM", "Enter Filter:", QLineEdit::Normal,	// FIXME-3 no translation yet
  3828 			m->getSortFilter(), &ok, NULL);
  3829 	if ( ok) 
  3830 		// user entered something and pressed OK
  3831 		m->setSortFilter (text);
  3832 */
  3833 }
  3834 
  3835 void Main::testFunction2()
  3836 {
  3837 	if (!currentMapEditor()) return;
  3838 	currentMapEditor()->testFunction2();
  3839 }
  3840 
  3841 void Main::testCommand()
  3842 {
  3843 	if (!currentMapEditor()) return;
  3844 	scriptEditor->show();
  3845 	/*
  3846 	bool ok;
  3847 	QString com = QInputDialog::getText(
  3848 			vymName, "Enter Command:", QLineEdit::Normal,"command", &ok, this );
  3849 	if (ok) currentMapEditor()->parseAtom(com);
  3850 	*/
  3851 }
  3852 
  3853 void Main::helpDoc()
  3854 {
  3855 	QString locale = QLocale::system().name();
  3856 	QString docname;
  3857 	if (locale.left(2)=="es")
  3858 		docname="vym_es.pdf";
  3859 	else	
  3860 		docname="vym.pdf";
  3861 
  3862 	QStringList searchList;
  3863 	QDir docdir;
  3864 	#if defined(Q_OS_MACX)
  3865 		searchList << "./vym.app/Contents/Resources/doc";
  3866     #elif defined(Q_OS_WIN32)
  3867         searchList << vymInstallDir.path() + "/share/doc/packages/vym";
  3868 	#else
  3869 		#if defined(VYM_DOCDIR)
  3870 			searchList << VYM_DOCDIR;
  3871 		#endif
  3872 		// default path in SUSE LINUX
  3873 		searchList << "/usr/share/doc/packages/vym";
  3874 	#endif
  3875 
  3876 	searchList << "doc";	// relative path for easy testing in tarball
  3877 	searchList << "doc/tex";	// Easy testing working on vym.tex
  3878 	searchList << "/usr/share/doc/vym";	// Debian
  3879 	searchList << "/usr/share/doc/packages";// Knoppix
  3880 
  3881 	bool found=false;
  3882 	QFile docfile;
  3883 	for (int i=0; i<searchList.count(); ++i)
  3884 	{
  3885 		docfile.setFileName(searchList.at(i)+"/"+docname);
  3886 		if (docfile.exists())
  3887 		{
  3888 			found=true;
  3889 			break;
  3890 		}	
  3891 	}
  3892 
  3893 	if (!found)
  3894 	{
  3895 		QMessageBox::critical(0, 
  3896 			tr("Critcal error"),
  3897 			tr("Couldn't find the documentation %1 in:\n%2").arg(searchList.join("\n")));
  3898 		return;
  3899 	}	
  3900 
  3901 	QStringList args;
  3902 	Process *pdfProc = new Process();
  3903     args << QDir::toNativeSeparators(docfile.fileName());
  3904 
  3905 	if (!pdfProc->startDetached( settings.value("/mainwindow/readerPDF").toString(),args) )
  3906 	{
  3907 		// error handling
  3908 		QMessageBox::warning(0, 
  3909 			tr("Warning"),
  3910 			tr("Couldn't find a viewer to open %1.\n").arg(docfile.fileName())+
  3911 			tr("Please use Settings->")+tr("Set application to open PDF files"));
  3912 		settingsPDF();	
  3913 		return;
  3914 	}
  3915 }
  3916 
  3917 
  3918 void Main::helpDemo()
  3919 {
  3920 	QStringList filters;
  3921 	filters <<"VYM example map (*.vym)";
  3922 	QFileDialog *fd=new QFileDialog( this);
  3923 	#if defined(Q_OS_MACX)
  3924 		fd->setDir (QDir("./vym.app/Contents/Resources/demos"));
  3925 	#else
  3926 		// default path in SUSE LINUX
  3927 		fd->setDir (QDir(vymBaseDir.path()+"/demos"));
  3928 	#endif
  3929 
  3930 	fd->setFileMode (QFileDialog::ExistingFiles);
  3931 	fd->setFilters (filters);
  3932 	fd->setCaption(vymName+ " - " +tr("Load vym example map"));
  3933 	fd->show();
  3934 
  3935 	QString fn;
  3936 	if ( fd->exec() == QDialog::Accepted )
  3937 	{
  3938 		lastFileDir=fd->directory().path();
  3939 	    QStringList flist = fd->selectedFiles();
  3940 		QStringList::Iterator it = flist.begin();
  3941 		while( it != flist.end() ) 
  3942 		{
  3943 			fn = *it;
  3944 			fileLoad(*it, NewMap);				   
  3945 			++it;
  3946 		}
  3947 	}
  3948 	delete (fd);
  3949 }
  3950 
  3951 
  3952 void Main::helpAbout()
  3953 {
  3954 	AboutDialog ad;
  3955 	ad.setName ("aboutwindow");
  3956 	ad.setMinimumSize(500,500);
  3957 	ad.resize (QSize (500,500));
  3958 	ad.exec();
  3959 }
  3960 
  3961 void Main::helpAboutQT()
  3962 {
  3963 	QMessageBox::aboutQt( this, "Qt Application Example" );
  3964 }
  3965 
  3966 void Main::callMacro ()
  3967 {
  3968     QAction *action = qobject_cast<QAction *>(sender());
  3969 	int i=-1;
  3970     if (action)
  3971 	{
  3972         i=action->data().toInt();
  3973 		QString mDir (settings.value ("macros/macroDir").toString() );
  3974 
  3975 		QString fn=mDir + QString("/macro-%1.vys").arg(i+1);
  3976 		QFile f (fn);
  3977 		if ( !f.open( QIODevice::ReadOnly ) )
  3978 		{
  3979 			QMessageBox::warning(0, 
  3980 				tr("Warning"),
  3981 				tr("Couldn't find a macro at  %1.\n").arg(fn)+
  3982 				tr("Please use Settings->")+tr("Set directory for vym macros"));
  3983 			return;
  3984 		}	
  3985 
  3986 		QTextStream ts( &f );
  3987 		QString macro= ts.read();
  3988 
  3989 		if (! macro.isEmpty())
  3990 		{
  3991 			VymModel *m=currentModel();
  3992 			if (m) m->runScript(macro);
  3993 		}	
  3994 	}	
  3995 }
  3996