# HG changeset patch
# User insilmaril
# Date 1140538703 0
# Node ID e211e2fc9d54aff99ac01bf66669ffca94e09331
# Parent  519970fe6c84174a3e89d727944f38682a29104f
rudimentary mmap import

diff -r 519970fe6c84 -r e211e2fc9d54 file.cpp
--- a/file.cpp	Tue Feb 21 16:18:23 2006 +0000
+++ b/file.cpp	Tue Feb 21 16:18:23 2006 +0000
@@ -183,6 +183,7 @@
 	zipProc->clearArguments();
 	zipProc->setWorkingDirectory (zipDir);
 	zipProc->addArgument ("unzip");
+	zipProc->addArgument ("-o");	// overwrite existing files!
 	zipProc->addArgument (zipName );
 	zipProc->addArgument ("-d");
 	zipProc->addArgument (zipDir.path());
@@ -219,7 +220,6 @@
 			} 
 		}
 	}
-	if (err==aborted) qWarning("file.cpp: unzip aborted"); 
 	return err;	
 }
 
diff -r 519970fe6c84 -r e211e2fc9d54 icons/vym-48x48.xpm
--- a/icons/vym-48x48.xpm	Tue Feb 21 16:18:23 2006 +0000
+++ b/icons/vym-48x48.xpm	Tue Feb 21 16:18:23 2006 +0000
@@ -1,24 +1,54 @@
 /* XPM */
-static char * vym_xpm[] = {
-"16 16 5 1",
+static char * vym_48x48_xpm[] = {
+"48 48 3 1",
 " 	c None",
-".	c #0026FF",
-"+	c #001EFF",
-"@	c #FF0000",
-"#	c #1C22E3",
-"                ",
-"       ...+ @@  ",
-"  @@@@@@#@@@    ",
-"     ...@+..@@  ",
-"     ..@@#..    ",
-"  @@ ..@.@@@@@  ",
-"    @@@@....    ",
-"  @@++......    ",
-"      ......    ",
-"      .....     ",
-"      .....     ",
-"       ....     ",
-"       ....     ",
-"                ",
-"                ",
-"                "};
+".	c #FF0000",
+"+	c #0026FF",
+"                                                ",
+"                                                ",
+"                                   .........    ",
+"                                ....            ",
+"                    ++++++++++  .               ",
+"  ....             ++++++++++++..               ",
+"     ... ..............++++++++............     ",
+"       ...       +++++..+++++...++              ",
+"     ...        +++++++..+++..++++              ",
+"  ....          ++++++++.++..++++++             ",
+"                ++++++++.++.+++++++             ",
+"                ++++++++...++++++++             ",
+"                +++++++..+++++++++++            ",
+"                +++++++....+++++++++            ",
+"                 +++++..++..++++++++  ......    ",
+"                 +++++.++++...+++++....         ",
+"                ++++++.++++++.......            ",
+"               ++++++..+++++++++.......         ",
+"    ........   ++++++.++++++++++++++  .....     ",
+"           ......+++..++++++++++++++            ",
+"             ........+++++++++++++++            ",
+"         .....++..++++++++++++++++++            ",
+"     .....   ++..+++++++++++++++++++            ",
+"             +..++++++++++++++++++++            ",
+"           ....++++++++++++++++++++             ",
+"       .....      +++++++++++++++++             ",
+"    ....          +++++++++++++++++             ",
+"                  ++++++++++++++++              ",
+"                  ++++++++++++++++              ",
+"                 ++++++++++++++++               ",
+"                 ++++++++++++++++               ",
+"                 +++++++++++++++                ",
+"                  ++++++++++++++                ",
+"                     +++++++++++                ",
+"                      ++++++++++                ",
+"                      ++++++++++                ",
+"                      ++++++++++                ",
+"                      ++++++++++                ",
+"                       +++++++++                ",
+"                        +++++++                 ",
+"                                                ",
+"                                                ",
+"                                                ",
+"                                                ",
+"                                                ",
+"                                                ",
+"                                                ",
+"                                                "};
diff -r 519970fe6c84 -r e211e2fc9d54 imports.cpp
--- a/imports.cpp	Tue Feb 21 16:18:23 2006 +0000
+++ b/imports.cpp	Tue Feb 21 16:18:23 2006 +0000
@@ -1,13 +1,14 @@
 #include <qmessagebox.h>
 
+#include "file.h"
 #include "imports.h"
-#include "file.h"
 #include "linkablemapobj.h"
 #include "misc.h"
 #include "mainwindow.h"
 #include "xsltproc.h"
 
 extern Main *mainWindow;
+extern QDir vymBaseDir;
 
 ImportBase::ImportBase()
 {
@@ -19,7 +20,7 @@
 ImportBase::~ImportBase()
 {
 	// Remove tmpdir
-	removeDir (tmpDir);
+	//removeDir (tmpDir);
 }
 
 void ImportBase::setDir(const QString &p)
@@ -37,20 +38,57 @@
 	mapCenter=mc;
 }
 
+bool ImportBase::transform()
+{
+	return true;
+}
+
+QString ImportBase::getTransformedFile()
+{
+	return transformedFile;
+}
+
 /////////////////////////////////////////////////
-void ImportKDEBookmarks::transform()
+bool ImportKDEBookmarks::transform()
 {
 	transformedFile=tmpDir.path()+"/bookmarks.xml";
 
 	XSLTProc p;
 	p.setInputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
 	p.setOutputFile (transformedFile);
-	p.setXSLFile ("styles/kdebookmarks2vym.xsl");
+	p.setXSLFile (vymBaseDir.path()+"/styles/kdebookmarks2vym.xsl");
 	p.process();
+
+	return true;
 }
 
-QString ImportKDEBookmarks::getTransformedFile()
+
+/////////////////////////////////////////////////
+bool ImportMM::transform()
 {
-	return transformedFile;
+	// try to unzip 
+	if (success==unzipDir (tmpDir, inputFile))
+	{
+		cout << "Unzipped "<<inputFile<<" to "<<tmpDir.path()<<endl;
+		
+		// Set short name, too. Search from behind:
+		transformedFile=inputFile;
+		int i=transformedFile.findRev("/");
+		if (i>=0) transformedFile=transformedFile.remove (0,i+1);
+		transformedFile.replace(".mmap",".xml");
+		transformedFile=tmpDir.path()+"/"+transformedFile;
+		cout << "  transformedFile="<<transformedFile<<endl;
+
+		XSLTProc p;
+		p.setInputFile (tmpDir.path()+"/Document.xml");
+		p.setOutputFile (transformedFile);
+		p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl");
+		p.process();
+
+		cout << "  xslt done"<<endl;
+
+		return true;
+	} else
+		return false;
+	
 }
-
diff -r 519970fe6c84 -r e211e2fc9d54 imports.h
--- a/imports.h	Tue Feb 21 16:18:23 2006 +0000
+++ b/imports.h	Tue Feb 21 16:18:23 2006 +0000
@@ -15,15 +15,18 @@
 {
 public:
 	ImportBase();
-	~ImportBase();
-	void setDir(const QString &);
-	void setFile(const QString &);
-	void setMapCenter (MapCenterObj*);
+	virtual ~ImportBase();
+	virtual void setDir(const QString &);
+	virtual void setFile(const QString &);
+	virtual void setMapCenter (MapCenterObj*);
+	virtual bool transform();
+	virtual QString getTransformedFile();
 protected:
 	QDir tmpDir;
 	QString inputDir;
 	QString inputFile;
 	MapCenterObj *mapCenter;
+	QString transformedFile;
 	
 };
 
@@ -31,12 +34,17 @@
 class ImportKDEBookmarks:public ImportBase
 {
 public:
-	void transform();
-	QString getTransformedFile();
-private:
-	QString transformedFile;
+	bool transform();
 };	
 
 
+///////////////////////////////////////////////////////////////////////
+class ImportMM:public ImportBase
+{
+public:
+	bool transform();
+};	
+
+
 
 #endif
diff -r 519970fe6c84 -r e211e2fc9d54 main.cpp
--- a/main.cpp	Tue Feb 21 16:18:23 2006 +0000
+++ b/main.cpp	Tue Feb 21 16:18:23 2006 +0000
@@ -24,6 +24,7 @@
 Main *mainWindow;				// used in BranchObj::select()								
 QString tmpVymDir;				// All temp files go there, created in mainwindow
 QString clipboardDir;			// Clipboard used in all mapEditors
+QDir vymBaseDir;				// Containing all styles, scripts, images, ...
 bool clipboardEmpty;			
 FlagRowObj *systemFlagsDefault;	// used to copy from in LinkableMapObj
 FlagRowObj *standardFlagsDefault;
@@ -131,17 +132,17 @@
     factory->setPixmap("vym_128x128", QPixmap(vym_128x128_xpm));
     qInitNetworkProtocols();
 
-	// Use /usr/share/vym or /usr/local/share/vym or .
-	QDir shareDir;
-	shareDir.setPath ("/usr/share/vym");
-	if (!shareDir.exists())
-        shareDir.setPath ("/usr/local/share/vym");
-	if (!shareDir.exists())
-        shareDir.setPath(".");
+	// Use /usr/share/vym or /usr/local/share/vym or . ?
+	QDir vymBaseDir;
+	vymBaseDir.setPath ("/usr/share/vym");
+	if (!vymBaseDir.exists())
+        vymBaseDir.setPath ("/usr/local/share/vym");
+	if (!vymBaseDir.exists())
+        vymBaseDir.setPath(vymBaseDir.currentDirPath() );
 
 	// Initialize translations
 	QTranslator translator (0);
-	translator.load( QString("vym_")+QTextCodec::locale(), shareDir.path() + "/lang");
+	translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
     app.installTranslator( &translator );
 
 	// Initializing the row of system flags
diff -r 519970fe6c84 -r e211e2fc9d54 mainwindow.cpp
--- a/mainwindow.cpp	Tue Feb 21 16:18:23 2006 +0000
+++ b/mainwindow.cpp	Tue Feb 21 16:18:23 2006 +0000
@@ -390,6 +390,10 @@
 	connect( a, SIGNAL( activated() ), this, SLOT( fileImportKDEBookmarks() ) );
 	a->addTo (importMenu);
 
+	a = new QAction( tr( "Import")+" "+tr("Mind Manager" ), QPixmap(), tr("Mind Manager"), 0, this, "importMM" );
+	connect( a, SIGNAL( activated() ), this, SLOT( fileImportMM() ) );
+	a->addTo (importMenu);
+
     a = new QAction( tr( "Import directory structure (experimental)" ), QPixmap(), tr( "Import Dir"+QString("...") ), 0, this, "export" );
     connect( a, SIGNAL( activated() ), this, SLOT( fileImportDir() ) );
     a->addTo( importMenu);
@@ -1123,7 +1127,9 @@
 
 	branchContextMenu->insertSeparator();	
 	actionFormatIncludeImagesVer->addTo( branchContextMenu );
-	// FIXME not implemented yet actionFormatIncludeImagesHor->addTo( branchContextMenu );
+    if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) 
+		// FIXME not implemented yet 
+		actionFormatIncludeImagesHor->addTo( branchContextMenu );
 	actionFormatHideLinkUnselected->addTo( branchContextMenu );
 
 	// Context Menu for links in a branch menu
@@ -1778,12 +1784,6 @@
 	fileSaveAs (CompleteMap);
 }
 
-void Main::fileImportDir()
-{
-	if (currentMapEditor())
-		currentMapEditor()->importDir();	
-}
-
 void Main::fileImportKDEBookmarks()
 {
 	ImportKDEBookmarks im;
@@ -1792,6 +1792,44 @@
 		currentMapEditor()->setFilePath ("");
 }
 
+void Main::fileImportMM()
+{
+	ImportMM im;
+
+	QFileDialog *fd=new QFileDialog( this);
+	if (!lastFileDir.isEmpty()) 
+		fd->setDir (lastFileDir);
+	fd->setMode (QFileDialog::ExistingFiles);
+	fd->addFilter ("Mind Manager (*.mmap)");
+	fd->setCaption(tr("Import")+" "+"Mind Manager");
+	fd->show();
+
+	if ( fd->exec() == QDialog::Accepted )
+	{
+		lastFileDir=fd->dirPath();
+	    QStringList flist = fd->selectedFiles();
+		QStringList::Iterator it = flist.begin();
+		while( it != flist.end() ) 
+		{
+			im.setFile (*it);
+			if (im.transform() && 
+				success==fileLoad (im.getTransformedFile(),NewMap) && 
+				currentMapEditor() )
+				currentMapEditor()->setFilePath ("");
+
+			++it;
+		}
+	}
+	delete (fd);
+
+}
+
+void Main::fileImportDir()
+{
+	if (currentMapEditor())
+		currentMapEditor()->importDir();	
+}
+
 void Main::fileExportXML()
 {
 	if (currentMapEditor())
diff -r 519970fe6c84 -r e211e2fc9d54 mainwindow.h
--- a/mainwindow.h	Tue Feb 21 16:18:23 2006 +0000
+++ b/mainwindow.h	Tue Feb 21 16:18:23 2006 +0000
@@ -65,8 +65,9 @@
     void fileSave();
     void fileSaveAs(const SaveMode &);
     void fileSaveAs();
+    void fileImportKDEBookmarks();
+    void fileImportMM();
     void fileImportDir();
-    void fileImportKDEBookmarks();
     void fileExportXML();
     void fileExportHTML();
     void fileExportXHTML();