Back to index

scribus-ng  1.3.4.dfsg+svn20071115
sxwim.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008  *   Copyright (C) 2004 by Riku Leino                                      *
00009  *   tsoots@gmail.com                                                      *
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  *   This program is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00019  *   GNU General Public License for more details.                          *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU General Public License     *
00022  *   along with this program; if not, write to the                         *
00023  *   Free Software Foundation, Inc.,                                       *
00024  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00025  ***************************************************************************/
00026 
00027 #include "sxwim.h"
00028 #include <qstringlist.h>
00029 
00030 #ifdef HAVE_XML
00031 
00032 #include "prefsmanager.h"
00033 #include <prefsfile.h>
00034 #include <prefscontext.h>
00035 #include <prefstable.h>
00036 #include "fileunzip.h"
00037 #include "stylereader.h"
00038 #include "contentreader.h"
00039 #include "sxwdia.h"
00040 
00041 QString FileFormatName()
00042 {
00043     return QObject::tr("OpenOffice.org Writer Documents");
00044 }
00045 
00046 QStringList FileExtensions()
00047 {
00048        return QStringList("sxw");
00049 }
00050 
00051 void GetText(QString filename, QString encoding, bool textOnly, gtWriter *writer)
00052 {
00053        SxwIm* sim = new SxwIm(filename, encoding, writer, textOnly);
00054        delete sim;
00055 }
00056 
00057 /********** Class SxwIm ************************************************************/
00058 
00059 SxwIm::SxwIm(QString fileName, QString enc, gtWriter* w, bool textOnly)
00060 {
00061        PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("SxwIm");
00062        bool update = prefs->getBool("update", true);
00063        bool prefix = prefs->getBool("prefix", true);
00064        bool ask = prefs->getBool("askAgain", true);
00065        bool pack = prefs->getBool("pack", true);
00066        encoding = enc;
00067        if (!textOnly)
00068        {
00069               if (ask)
00070               {
00071                      SxwDialog* sxwdia = new SxwDialog(update, prefix, pack);
00072                      if (sxwdia->exec()) {
00073                             update = sxwdia->shouldUpdate();
00074                             prefix = sxwdia->usePrefix();
00075                             pack = sxwdia->packStyles();
00076                             prefs->set("update", update);
00077                             prefs->set("prefix", sxwdia->usePrefix());
00078                             prefs->set("askAgain", sxwdia->askAgain());
00079                             prefs->set("pack", sxwdia->packStyles());
00080                             delete sxwdia;
00081                      } else {
00082                             delete sxwdia;
00083                             return;
00084                      }
00085               }
00086        }
00087        filename = fileName;
00088        writer = w;
00089        writer->setUpdateParagraphStyles(update);
00090        FileUnzip* fun = new FileUnzip(fileName);
00091        stylePath   = fun->getFile(STYLE);
00092        contentPath = fun->getFile(CONTENT);
00093        delete fun;
00094        if ((stylePath != NULL) && (contentPath != NULL))
00095        {
00096               QString docname = filename.right(filename.length() - filename.findRev("/") - 1);
00097               docname = docname.left(docname.findRev("."));
00098               StyleReader *sreader = new StyleReader(docname, writer, textOnly, prefix, pack);
00099               sreader->parse(stylePath);
00100               ContentReader *creader = new ContentReader(docname, sreader, writer, textOnly);
00101               creader->parse(contentPath);
00102               delete sreader;
00103               delete creader;
00104               QFile f1(stylePath);
00105               f1.remove();
00106               QFile f2(contentPath);
00107               f2.remove();
00108        }
00109        else if ((stylePath == NULL) && (contentPath != NULL))
00110        {
00111               QFile f2(contentPath);
00112               f2.remove();
00113        }
00114        else if ((stylePath != NULL) && (contentPath == NULL))
00115        {
00116               QFile f1(stylePath);
00117               f1.remove();
00118        }
00119 }
00120 
00121 SxwIm::~SxwIm()
00122 {
00123 
00124 }
00125 
00126 #endif