2
This file is part of Kig, a KDE program for Interactive Geometry...
3
Copyright (C) 2002 Dominique Devriese <devriese@kde.org>
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
23
#include <qbytearray.h>
25
#include <kuniqueapplication.h>
26
#include <kaboutdata.h>
27
#include <kcmdlineargs.h>
29
#include <klibloader.h>
32
#include "aboutdata.h"
35
: public KUniqueApplication
38
KigApplication( bool gui = true );
40
void handleArgs( KCmdLineArgs* args );
43
KigApplication::KigApplication( bool gui )
44
: KUniqueApplication( gui, gui )
48
int KigApplication::newInstance()
50
static bool first = true;
51
if (isSessionRestored() && first)
58
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
64
void KigApplication::handleArgs( KCmdLineArgs* args )
66
if ( args->count() == 0 )
68
Kig *widget = new Kig;
73
for (int i = 0; i < args->count(); i++ )
75
Kig *widget = new Kig;
77
widget->load( args->url( i ) );
82
static int convertToNative( const KUrl& file, const QByteArray& outfile )
84
KComponentData maindata( KCmdLineArgs::aboutData() );
85
KLibrary* library = KLibLoader::self()->library( "kigpart", QLibrary::ExportExternalSymbolsHint );
86
int ( *converterfunction )( const KUrl&, const QByteArray& );
87
converterfunction = ( int ( * )( const KUrl&, const QByteArray& ) ) library->resolveFunction( "convertToNative" );
88
if ( !converterfunction )
90
kError() << "Error: broken Kig installation: different library and application version !" << endl;
93
return (*converterfunction)( file, outfile );
96
int main(int argc, char **argv)
98
KAboutData about = kigAboutData( "kig", I18N_NOOP("Kig") );
100
KCmdLineArgs::init(argc, argv, &about);
102
KCmdLineOptions options;
104
options.add("convert-to-native", ki18n( "Do not show a GUI. Convert the specified file to the native Kig format. Output goes to stdout unless --outfile is specified." ));
106
options.add("outfile <file>", ki18n( "File to output the created native file to. '-' means output to stdout. Default is stdout as well." ));
107
options.add("+[URL]", ki18n( "Document to open" ));
108
KCmdLineArgs::addCmdLineOptions( options );
109
KigApplication::addCmdLineOptions();
111
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
112
if ( args->isSet( "convert-to-native" ) )
114
QString outfile = args->getOption( "outfile" );
115
if ( outfile.isEmpty() )
118
if ( args->count() == 0 )
120
kError() << "Error: --convert-to-native specified without a file to convert." << endl;
123
if ( args->count() > 1 )
125
kError() << "Error: --convert-to-native specified with more than one file to convert." << endl;
128
return convertToNative( args->url( 0 ), outfile.toLocal8Bit() );
132
if ( args->isSet( "outfile" ) )
134
kError() << "Error: --outfile specified without convert-to-native." << endl;
139
// see if we are starting with session management
140
if (app.isSessionRestored()) RESTORE(Kig)