From 8362bf63dea22bbf6736609b0f49c152f975eb63 Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 20 Jan 2010 01:29:50 +0000 Subject: Added old abandoned KDE3 version of koffice git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- tools/converter/Makefile.am | 11 +++ tools/converter/koconverter.cpp | 162 ++++++++++++++++++++++++++++++++++++++++ tools/converter/koconverter.h | 34 +++++++++ 3 files changed, 207 insertions(+) create mode 100644 tools/converter/Makefile.am create mode 100644 tools/converter/koconverter.cpp create mode 100644 tools/converter/koconverter.h (limited to 'tools/converter') diff --git a/tools/converter/Makefile.am b/tools/converter/Makefile.am new file mode 100644 index 00000000..ea0c5662 --- /dev/null +++ b/tools/converter/Makefile.am @@ -0,0 +1,11 @@ +INCLUDES = $(KOFFICE_INCLUDES) $(all_includes) + +bin_PROGRAMS = koconverter +koconverter_SOURCES = koconverter.cpp +koconverter_LDFLAGS = $(all_libraries) $(KDE_RPATH) +koconverter_LDADD = $(top_builddir)/lib/kofficecore/libkofficecore.la + +METASOURCES = AUTO + +messages: + $(XGETTEXT) *.cpp -o $(podir)/koconverter.pot diff --git a/tools/converter/koconverter.cpp b/tools/converter/koconverter.cpp new file mode 100644 index 00000000..df44daa8 --- /dev/null +++ b/tools/converter/koconverter.cpp @@ -0,0 +1,162 @@ +/* This file is part of the KDE project + Copyright (C) 2001-2006 David Faure + Copyright (C) 2004 Nicolas GOUTTE + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "koconverter.h" + + +static const KCmdLineOptions options[]= +{ + {"+in", I18N_NOOP("Input file"),0}, + {"+out", I18N_NOOP("Output file"),0}, + {"backup", I18N_NOOP("Make a backup of the destination file"),0}, + {"batch", I18N_NOOP("Batch mode: do not show dialogs"),0}, + {"interactive", I18N_NOOP("Interactive mode: show dialogs (default)"),0}, + {"mimetype ", I18N_NOOP("Mimetype of the output file"),0}, + KCmdLineLastOption +}; + +bool convert( const KURL & uIn, const QString & /*inputFormat*/, const KURL & uOut, const QString & outputFormat, const bool batch ) +{ + KoFilterManager* manager = new KoFilterManager( uIn.path() ); + + ProgressObject progressObj; + QObject::connect(manager, SIGNAL(sigProgress(int)), &progressObj, SLOT(slotProgress(int))); + + manager->setBatchMode( batch ); + + QCString mime( outputFormat.latin1() ); + KoFilter::ConversionStatus status = manager->exp0rt( uOut.path(), mime ); + progressObj.slotProgress(-1); + + delete manager; + return status == KoFilter::OK; +} + +void ProgressObject::slotProgress(int /* progress */ ) +{ + // Well, we could have a nifty "=====> " progress bar, but with all the + // debug output, it would be badly messed up :) + // kdDebug() << "ProgressObject::slotProgress " << progress << endl; +} + +int main( int argc, char **argv ) +{ + KAboutData aboutData( "koconverter", I18N_NOOP("KOConverter"), "1.4", + I18N_NOOP("KOffice Document Converter"), + KAboutData::License_GPL, + I18N_NOOP("(c) 2001-2004 KOffice developers") ); + aboutData.addAuthor("David Faure",0, "faure@kde.org"); + aboutData.addAuthor("Nicolas Goutte",0, "goutte@kde.org"); + KCmdLineArgs::init( argc, argv, &aboutData); + KCmdLineArgs::addCmdLineOptions( options ); + + KApplication app; + + // Install the libkoffice* translations + KGlobal::locale()->insertCatalogue("koffice"); + + KImageIO::registerFormats(); + + // Get the command line arguments which we have to parse + KCmdLineArgs *args= KCmdLineArgs::parsedArgs(); + if ( args->count() == 2 ) + { + KURL uIn = args->url( 0 ); + KURL uOut = args->url( 1 ); + + // Are we in batch mode or in interactive mode. + bool batch = args->isSet("batch"); + if ( args->isSet("interactive") ) + batch = false; + + if ( args->isSet("backup") ) + { + // Code form koDocument.cc + KIO::UDSEntry entry; + if ( KIO::NetAccess::stat( uOut, entry, 0L ) ) // this file exists => backup + { + kdDebug() << "Making backup..." << endl;; + KURL backup( uOut ); + backup.setPath( uOut.path() + '~' ); + KIO::NetAccess::file_copy( uOut, backup, -1, true /*overwrite*/, false /*resume*/, 0L ); + } + } + + + KMimeType::Ptr inputMimetype = KMimeType::findByURL( uIn ); + if ( inputMimetype->name() == KMimeType::defaultMimeType() ) + { + kdError() << i18n("Mimetype for input file %1 not found!").arg(uIn.prettyURL()) << endl; + return 1; + } + KMimeType::Ptr outputMimetype; + if ( args->isSet("mimetype") ) + { + QString mime = QString::fromLatin1( args->getOption("mimetype") ); + outputMimetype = KMimeType::mimeType( mime ); + if ( outputMimetype->name() == KMimeType::defaultMimeType() ) + { + kdError() << i18n("Mimetype not found %1").arg(mime) << endl; + return 1; + } + } + else + { + outputMimetype = KMimeType::findByURL( uOut, 0, false, true /* file doesn't exist */ ); + if ( outputMimetype->name() == KMimeType::defaultMimeType() ) + { + kdError() << i18n("Mimetype not found, try using the -mimetype option") << endl; + return 1; + } + } + + QApplication::setOverrideCursor( Qt::waitCursor ); + bool ok = convert( uIn, inputMimetype->name(), uOut, outputMimetype->name(), batch ); + QApplication::restoreOverrideCursor(); + if ( ok ) + { + return 0; + } + else + { + kdError() << i18n("*** The conversion failed! ***") << endl; + return 2; + } + } + + KCmdLineArgs::usage(i18n("Two arguments required")); + return 3; +} + +#include "koconverter.moc" diff --git a/tools/converter/koconverter.h b/tools/converter/koconverter.h new file mode 100644 index 00000000..ce21ac74 --- /dev/null +++ b/tools/converter/koconverter.h @@ -0,0 +1,34 @@ +/* This file is part of the KDE project + Copyright (C) 2001 David Faure + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef koconverter_h +#define koconverter_h + +#include + +class ProgressObject : public QObject +{ + Q_OBJECT +public: + ProgressObject() : QObject( 0, 0 ) { } +public slots: + void slotProgress(int); +}; + +#endif -- cgit v1.2.1