]> git.sven.stormbind.net Git - sven/vym.git/blob - imports.cpp
Import Upstream version 2.6.11
[sven/vym.git] / imports.cpp
1 #include "file.h"
2 #include "imports.h"
3 #include "linkablemapobj.h"
4 #include "misc.h"
5 #include "mainwindow.h"
6 #include "xsltproc.h"
7
8 #include <QMessageBox>
9
10 extern Main *mainWindow;
11 extern QDir vymBaseDir;
12
13 ImportBase::ImportBase()
14 {
15     bool ok;
16     tmpDir.setPath (makeTmpDir(ok,"vym-import"));
17     if (!tmpDir.exists() || !ok)
18         QMessageBox::critical( 0, QObject::tr( "Error" ),
19                        QObject::tr("Couldn't access temporary directory\n"));
20 }
21
22
23 ImportBase::~ImportBase()
24 {
25     // Remove tmpdir
26     removeDir (tmpDir);
27 }
28
29 void ImportBase::setDir(const QString &p)
30 {
31     inputDir=p;
32 }
33
34 void ImportBase::setFile (const QString &p)
35 {
36     inputFile=p;
37 }
38
39 bool ImportBase::transform()
40 {
41     return true;
42 }
43
44 QString ImportBase::getTransformedFile()
45 {
46     return transformedFile;
47 }
48
49 /////////////////////////////////////////////////
50 bool ImportFirefoxBookmarks::transform()
51 {
52     transformedFile=tmpDir.path()+"/bookmarks.xml";
53
54     QStringList lines;
55     QFile file( inputFile );
56     if ( file.open( QIODevice::ReadOnly ) ) 
57     {
58         QTextStream stream( &file );
59         while ( !stream.atEnd() ) 
60             lines += stream.readLine(); // line of text excluding '\n'
61         file.close();
62     }
63     // TODO Generate vym from broken bookmarks above...
64
65     return true;
66 }
67
68 /////////////////////////////////////////////////
69 bool ImportMM::transform()
70 {
71     // try to unzip 
72     if (File::Success==unzipDir (tmpDir, inputFile))
73     {
74         
75         // Set short name, too. Search from behind:
76         transformedFile=inputFile;
77         int i=transformedFile.lastIndexOf ("/");
78         if (i>=0) transformedFile=transformedFile.remove (0,i+1);
79         transformedFile.replace(".mmap",".xml");
80         transformedFile=tmpDir.path()+"/"+transformedFile;
81
82         XSLTProc p;
83         p.setInputFile (tmpDir.path()+"/Document.xml");
84         p.setOutputFile (transformedFile);
85         p.setXSLFile (vymBaseDir.path()+"/styles/mmap2vym.xsl");
86         p.process();
87
88         return true;
89     } else
90         return false;
91     
92 }