Subversion Repositories Scribus

Rev

Rev 512 | Rev 517 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
506 fschmid 1
#include "fileloader.h"
2
#include <qfile.h>
3
#include <qfileinfo.h>
4
#include "scribus.h"
5
#include "scribusXml.h"
6
#if (_MSC_VER >= 1200)
7
        #include "win-config.h"
8
#else
9
        #include "config.h"
10
#endif
11
#ifdef HAVE_LIBZ
12
        #include <zlib.h>
13
#endif
14
extern bool loadText(QString nam, QString *Buffer);
15
 
16
/*!
17
 \fn FileLoader::FileLoader(QString fileName)
18
 \author Franz Schmid
19
 \date
20
 \brief Constructor, sets the variable "FileName" to the input parameter fileName
21
 \param QString fileName
22
 \retval None
23
 */
516 fschmid 24
FileLoader::FileLoader(QString fileName, ScribusApp* app)
506 fschmid 25
{
26
        FileName = fileName;
27
        FileType = -1;
516 fschmid 28
        havePS = app->DLLexists(6);
29
        haveSVG = app->DLLexists(10);
506 fschmid 30
}
31
 
32
/*!
33
 \fn int FileLoader::TestFile()
34
 \author Franz Schmid
35
 \date
36
 \brief Tests if the file "FileName" exists and determines the type of the file.
37
 \param None
38
 \retval int -1 if the file doesn't exist or any other error has occured, 0 for the old Format, 1 for the new Format, 2 for EPS and PS files, 3 for SVG files and 4 for PDF files
39
 */
40
int FileLoader::TestFile()
41
{
42
        QFileInfo fi = QFileInfo(FileName);
43
        int ret = -1;
44
        if (!fi.exists())
45
                ret = -1;
46
        QString ext = fi.extension(true).lower();
47
        if ((ext == "sla.gz") || (ext == "sla") || (ext == "scd.gz") || (ext == "scd"))
48
                ret = CheckScribus();
516 fschmid 49
        if (((ext == "ps") || (ext == "eps")) && (havePS))
506 fschmid 50
                ret = 2;
516 fschmid 51
        if (((ext == "svg") || (ext == "svgz")) && (haveSVG))
506 fschmid 52
                ret = 3;
53
/*      if (ext == "pdf")
54
                ret = 4; */
55
        FileType = ret;
56
        return ret;
57
}
58
 
59
/*!
60
 \fn int FileLoader::CheckScribus()
61
 \author Franz Schmid
62
 \date
63
 \brief Checks which Scribus fileformat the File in FileName has.
64
 \param None
65
 \retval 0 for old Scribus files, 1 for Scribus files created by Scribus 1.3 and above
66
 */
67
int FileLoader::CheckScribus()
68
{
69
        int ret = -1;
70
        QString fText = ReadDatei(FileName);
71
        if (fText == "")
72
                return ret;
73
        if ((fText.startsWith("<SCRIBUS")) && (fText.contains("<PAGE ", TRUE) != 0))
74
                return 0;
75
        if ((fText.startsWith("<SCRIBUSUTF8NEW")) && (fText.contains("<PAGE ", TRUE) != 0))
76
                return 1;
77
        return ret;
78
}
79
 
80
/*!
81
 \fn QString FileLoader::ReadDatei(QString fileName)
82
 \author Franz Schmid
83
 \date
84
 \brief Auxiliary function loads the file "fileName" into a QString and does conversion from UTF8 if required
85
 \param QString fileName
86
 \retval QString Contents of the file, converted from UTF8
87
 */
88
QString FileLoader::ReadDatei(QString fileName)
89
{
90
/**
91
  * added to support gz docs
92
  * 2.7.2002 C.Toepp
93
  * <c.toepp@gmx.de>
94
  */
95
        QString f = "";
96
#ifdef HAVE_LIBZ
97
        if(fileName.right(2) == "gz")
98
        {
99
                gzFile gzDoc;
100
                char buff[4097];
101
                int i;
102
                gzDoc = gzopen(fileName.latin1(),"rb");
103
                if(gzDoc == NULL)
104
                        return "";
105
                while((i = gzread(gzDoc,&buff,4096)) > 0)
106
                {
107
                        buff[i] = '\0';
108
                        f.append(buff);
109
                }
110
                gzclose(gzDoc);
111
        }
112
        else
113
                loadText(fileName, &f);
114
#else
115
        loadText(fileName, &f);
116
#endif
117
        QString ff = "";
118
        if (f.startsWith("<SCRIBUSUTF8"))
119
                ff = QString::fromUtf8(f);
120
        else if (f.startsWith("<SCRIBUS"))
121
                ff = f;
122
        return ff;
123
/** end changes */
124
}
125
 
126
/*!
127
 \fn bool FileLoader::LoadFile(ScribusApp* app)
128
 \author Franz Schmid
129
 \date
130
 \brief Loads the file "FileName" as a Scribus document
131
 \param ScribusApp* app, pointer to the main application class
132
 \retval bool true when loading is succsessful, false otherwise
133
 */
134
bool FileLoader::LoadFile(ScribusApp* app)
135
{
136
        bool ret = false;
137
        switch (FileType)
138
        {
139
                case 0:
140
                        {
141
                                ScriXmlDoc *ss = new ScriXmlDoc();
142
                                QObject::connect(ss, SIGNAL(NewPage(int)), app, SLOT(slotNewPage(int)));
143
                                ret = ss->ReadDoc(FileName, app->Prefs.AvailFonts, app->doc, app->view, app->FProg);
144
                                QObject::disconnect(ss, SIGNAL(NewPage(int)), app, SLOT(slotNewPage(int)));
145
                                delete ss;
146
                        }
147
                        break;
148
                case 2:
149
                        app->DLLinput = FileName;
512 fschmid 150
                        app->CallDLL( 6 );
506 fschmid 151
                        ret = true;
152
                        break;
153
                case 3:
154
                        app->DLLinput = FileName;
512 fschmid 155
                        app->CallDLL( 10 );
506 fschmid 156
                        ret = true;
157
                        break;
158
                default:
159
                        ret = false;
160
                        break;
161
        }
162
        return ret;
163
}