exports.cpp
author insilmaril
Thu, 22 Sep 2005 12:14:23 +0000
changeset 164 d442a66e9121
parent 163 30b22f7bd009
child 171 a98a07994eed
permissions -rw-r--r--
new way to handle tmpdir, minor changes
     1 #include "exports.h"
     2 
     3 #include <qregexp.h>
     4 
     5 #include "linkablemapobj.h"
     6 #include "texteditor.h"
     7 
     8 
     9 Export::Export()
    10 {
    11 	indentPerDepth="  ";
    12 }
    13 
    14 void Export::setPath (const QString &p)
    15 {
    16 	filepath=p;
    17 }
    18 
    19 void Export::setMapCenter(MapCenterObj *mc)
    20 {
    21 	mapCenter=mc;
    22 }
    23 
    24 QString Export::getSectionString(BranchObj *bostart)
    25 {
    26 	QString r;
    27 	BranchObj *bo=bostart;
    28 	int depth=bo->getDepth();
    29 	while (depth>0)
    30 	{
    31 		r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
    32 		bo=(BranchObj*)(bo->getParObj());
    33 		depth=bo->getDepth();
    34 	}	
    35 	if (r.isEmpty())
    36 		return r;
    37 	else	
    38 		return r + " ";
    39 }
    40 
    41 void Export::exportMap()
    42 {
    43 	QFile file (filepath);
    44 	if ( !file.open( IO_WriteOnly ) )
    45 	{
    46 		// FIXME experimental, testing
    47 		cout << "Export::exportMap  couldn't open "<<filepath<<endl;
    48 		return;
    49 	}
    50 	QTextStream ts( &file );	// use LANG decoding here...
    51 
    52 	// Main loop over all branches
    53 	QString s;
    54 	QString actIndent("");
    55 	int i;
    56 	uint j;
    57 	BranchObj *bo;
    58 	bo=mapCenter->first();
    59 	while (bo) 
    60 	{
    61 		// Make indentstring
    62 		for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
    63 
    64 		// Write heading
    65 		//	write (actIndent + getSectionString(bo) + bo->getHeading()+ "\n");
    66 		if (bo->getDepth()==0)
    67 		{
    68 			ts << (bo->getHeading()+ "\n");
    69 			for (j=0;j<bo->getHeading().length();j++) ts<<"=";
    70 			ts << "\n";
    71 		} else 	if (bo->getDepth()==1)
    72 			ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
    73 		else	if (bo->getDepth()==2)
    74 			ts << (actIndent + " o " + bo->getHeading()+ "\n");
    75 		else	
    76 			ts << (actIndent + " - " + bo->getHeading()+ "\n");
    77 		
    78 		// If necessary, write note
    79 		if (!bo->getNote().isEmpty())
    80 		{
    81 			s =textConvertToASCII(bo->getNote());
    82 			s=s.replace ("\n","\n"+actIndent);
    83 			ts << (s+"\n\n");
    84 		}
    85 		
    86 		bo=bo->next();
    87 		actIndent="";
    88 	}
    89 	file.close();
    90 }
    91 
    92 // Exports a map to a LaTex file.  This file needs to be included or inported into a LaTex document
    93 // it will not add a preamble, or anything that makes a full LaTex document.
    94 void Export::exportLaTeX() 
    95 {
    96   QFile file (filepath);
    97   if ( !file.open( IO_WriteOnly ) ) {
    98     // FIXME
    99     cout << "Export::exportMap  couldn't open "<<filepath<<endl;
   100     return;
   101   }
   102   QTextStream ts( &file );	// use LANG decoding here...
   103   ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
   104   
   105   // Main loop over all branches
   106   QString s;
   107   // QString actIndent("");
   108   // int i;
   109   BranchObj *bo;
   110   bo=mapCenter->first();
   111   while (bo) {
   112     if (bo->getDepth()==0);
   113     else if (bo->getDepth()==1) {
   114       ts << ("\\chapter{" + bo->getHeading()+ "}\n");
   115     }
   116     else if (bo->getDepth()==2) {
   117       ts << ("\\section{" + bo->getHeading()+ "}\n");
   118     }
   119     else if (bo->getDepth()==3) {
   120       ts << ("\\subsection{" + bo->getHeading()+ "}\n");
   121     }
   122     else if (bo->getDepth()==4) {
   123       ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
   124     }
   125     else {
   126       ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
   127     }
   128     
   129     // If necessary, write note
   130     if (!bo->getNote().isEmpty()) {
   131       ts << (textConvertToASCII(bo->getNote()));
   132       ts << ("\n");
   133     }
   134     
   135     bo=bo->next();
   136    }
   137   file.close();
   138 }
   139 
   140 #include "settings.h"
   141 
   142 void Export::exportOOPresentation()
   143 {
   144 	QString templateDir="oo-test/suse-template/";
   145 	QString templateContent="content.xml";
   146 	QString tmpDir="/tmp/vym-ootest/";
   147 	QString header="";
   148 
   149 
   150 	// Create tmpdir
   151 		// TODO
   152 
   153 	// Copy template to tmpdir
   154 		// TODO
   155 
   156 
   157 	// Read content-template
   158 		// TODO
   159 	QString content;
   160 	if (!loadStringFromDisk (templateDir+templateContent,content))
   161 	{
   162 		qWarning ("Export::exportOOPresentation() Couldn't load from "+templateDir+templateContent);
   163 		return;
   164 	}
   165 
   166 
   167 	// Walk through map
   168 	QString s;
   169 	QString actIndent("");
   170 	uint j;
   171 	int i;
   172 	BranchObj *bo;
   173 	bo=mapCenter->first();
   174 	while (bo) 
   175 	{
   176 		// Make indentstring
   177 		for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
   178 
   179 		// Write heading
   180 		//	write (actIndent + getSectionString(bo) + bo->getHeading()+ "\n");
   181 		if (bo->getDepth()==0)
   182 		{
   183 			s+= (bo->getHeading()+ "\n");
   184 			for (j=0;j<bo->getHeading().length();j++) s+="=";
   185 			s+= "\n";
   186 		} else 	if (bo->getDepth()==1)
   187 			s+= ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
   188 		else	if (bo->getDepth()==2)
   189 			s+= (actIndent + " o " + bo->getHeading()+ "\n");
   190 		else	
   191 			s+ (actIndent + " - " + bo->getHeading()+ "\n");
   192 		
   193 		/*
   194 		// If necessary, write note
   195 		if (!bo->getNote().isEmpty())
   196 		{
   197 			s =textConvertToASCII(bo->getNote());
   198 			s=s.replace ("\n","\n"+actIndent);
   199 			ts << (s+"\n\n");
   200 		}
   201 		*/
   202 		bo=bo->next();
   203 		actIndent="";
   204 	}
   205 
   206 	
   207 	// Insert new content
   208 		// TODO
   209 	cout <<"\n\ns="<<s<<endl;
   210 	content.replace ("<!--INSERT PAGES HERE-->",s);
   211 	cout << "ExportOO: content=\n"<<content<<endl;
   212 
   213 	// zip tmpdir to destination
   214 		// TODO
   215 
   216 }
   217