Back to index

scribus-ng  1.3.4.dfsg+svn20071115
odtim.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 "odtim.h"
00028 #include <qstringlist.h>
00029 
00030 #ifdef HAVE_XML
00031 
00032 #include <scribusstructs.h>
00033 #include "prefsmanager.h"
00034 #include <prefsfile.h>
00035 #include <prefscontext.h>
00036 #include <prefstable.h>
00037 #include "fileunzip.h"
00038 #include "stylereader.h"
00039 #include "contentreader.h"
00040 #include "odtdia.h"
00041 
00042 QString FileFormatName()
00043 {
00044     return QObject::tr("OpenDocument Text Documents");
00045 }
00046 
00047 QStringList FileExtensions()
00048 {
00049        return QStringList("odt");
00050 }
00051 
00052 void GetText(QString filename, QString encoding, bool textOnly, gtWriter *writer)
00053 {
00054        OdtIm* sim = new OdtIm(filename, encoding, writer, textOnly);
00055        delete sim;
00056 }
00057 
00058 /********** Class OdtIm ************************************************************/
00059 
00060 OdtIm::OdtIm(QString fileName, QString enc, gtWriter* w, bool textOnly)
00061 {
00062        PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("OdtIm");
00063        bool update = prefs->getBool("update", true);
00064        bool prefix = prefs->getBool("prefix", true);
00065        bool ask = prefs->getBool("askAgain", true);
00066        bool pack = prefs->getBool("pack", true);
00067        encoding = enc;
00068        if (!textOnly)
00069        {
00070               if (ask)
00071               {
00072                      OdtDialog* sxwdia = new OdtDialog(update, prefix, pack);
00073                      if (sxwdia->exec()) {
00074                             update = sxwdia->shouldUpdate();
00075                             prefix = sxwdia->usePrefix();
00076                             pack = sxwdia->packStyles();
00077                             prefs->set("update", update);
00078                             prefs->set("prefix", sxwdia->usePrefix());
00079                             prefs->set("askAgain", sxwdia->askAgain());
00080                             prefs->set("pack", sxwdia->packStyles());
00081                             delete sxwdia;
00082                      } else {
00083                             delete sxwdia;
00084                             return;
00085                      }
00086               }
00087        }
00088        filename = fileName;
00089        writer = w;
00090        writer->setUpdateParagraphStyles(update);
00091        FileUnzip* fun = new FileUnzip(fileName);
00092        stylePath   = fun->getFile(STYLE);
00093        contentPath = fun->getFile(CONTENT);
00094        delete fun;
00095        if ((stylePath != NULL) && (contentPath != NULL))
00096        {
00097               QString docname = filename.right(filename.length() - filename.findRev("/") - 1);
00098               docname = docname.left(docname.findRev("."));
00099               StyleReader *sreader = new StyleReader(docname, writer, textOnly, prefix, pack);
00100               sreader->parse(stylePath);
00101               ContentReader *creader = new ContentReader(docname, sreader, writer, textOnly);
00102               creader->parse(contentPath);
00103               delete sreader;
00104               delete creader;
00105               QFile f1(stylePath);
00106               f1.remove();
00107               QFile f2(contentPath);
00108               f2.remove();
00109        }
00110        else if ((stylePath == NULL) && (contentPath != NULL))
00111        {
00112               QFile f2(contentPath);
00113               f2.remove();
00114        }
00115        else if ((stylePath != NULL) && (contentPath == NULL))
00116        {
00117               QFile f1(stylePath);
00118               f1.remove();
00119        }
00120 }
00121 
00122 OdtIm::~OdtIm()
00123 {
00124 
00125 }
00126 
00127 #endif