• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kig

  • sources
  • kde-4.14
  • kdeedu
  • kig
  • kig
main.cpp
Go to the documentation of this file.
1 
21 #include "kig.h"
22 
23 #include <qbytearray.h>
24 
25 #include <kuniqueapplication.h>
26 #include <kaboutdata.h>
27 #include <kcmdlineargs.h>
28 #include <klocale.h>
29 #include <klibloader.h>
30 #include <kdebug.h>
31 
32 #include "aboutdata.h"
33 
34 class KigApplication
35  : public KUniqueApplication
36 {
37 public:
38  KigApplication( bool gui = true );
39  int newInstance();
40  void handleArgs( KCmdLineArgs* args );
41 };
42 
43 KigApplication::KigApplication( bool gui )
44  : KUniqueApplication( gui, gui )
45 {
46 }
47 
48 int KigApplication::newInstance()
49 {
50  static bool first = true;
51  if (isSessionRestored() && first)
52  {
53  first = false;
54  return 0;
55  }
56  first = false;
57 
58  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
59  handleArgs(args);
60  args->clear();
61  return 0;
62 }
63 
64 void KigApplication::handleArgs( KCmdLineArgs* args )
65 {
66  if ( args->count() == 0 )
67  {
68  Kig *widget = new Kig;
69  widget->show();
70  }
71  else
72  {
73  for (int i = 0; i < args->count(); i++ )
74  {
75  Kig *widget = new Kig;
76  widget->show();
77  widget->load( args->url( i ) );
78  }
79  }
80 }
81 
82 static int convertToNative( const KUrl& file, const QByteArray& outfile )
83 {
84  KComponentData maindata( KCmdLineArgs::aboutData() );
85  KPluginLoader libraryLoader( "kigpart" );
86  QLibrary library( libraryLoader.fileName() );
87  int ( *converterfunction )( const KUrl&, const QByteArray& );
88  converterfunction = ( int ( * )( const KUrl&, const QByteArray& ) ) library.resolve( "convertToNative" );
89  if ( !converterfunction )
90  {
91  kError() << "Error: broken Kig installation: different library and application version !" << endl;
92  return -1;
93  }
94  return (*converterfunction)( file, outfile );
95 }
96 
97 int main(int argc, char **argv)
98 {
99  KAboutData about = kigAboutData( "kig", I18N_NOOP("Kig") );
100 
101  KCmdLineArgs::init(argc, argv, &about);
102 
103  KCmdLineOptions options;
104  options.add("c");
105  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("o");
107  options.add("outfile <file>", ki18n( "File to output the created native file to. '-' means output to stdout. Default is stdout as well." ));
108  options.add("+[URL]", ki18n( "Document to open" ));
109  KCmdLineArgs::addCmdLineOptions( options );
110  KigApplication::addCmdLineOptions();
111 
112  KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
113  if ( args->isSet( "convert-to-native" ) )
114  {
115  QString outfile = args->getOption( "outfile" );
116  if ( outfile.isEmpty() )
117  outfile = "-";
118 
119  if ( args->count() == 0 )
120  {
121  kError() << "Error: --convert-to-native specified without a file to convert." << endl;
122  return -1;
123  }
124  if ( args->count() > 1 )
125  {
126  kError() << "Error: --convert-to-native specified with more than one file to convert." << endl;
127  return -1;
128  }
129  return convertToNative( args->url( 0 ), outfile.toLocal8Bit() );
130  }
131  else
132  {
133  if ( args->isSet( "outfile" ) )
134  {
135  kError() << "Error: --outfile specified without convert-to-native." << endl;
136  return -1;
137  }
138  KigApplication app;
139 
140  // see if we are starting with session management
141  if (app.isSessionRestored()) RESTORE(Kig)
142  return app.exec();
143  }
144 }
Kig::load
void load(const KUrl &file)
Open file in this window.
Definition: kig.cpp:135
QByteArray
main
int main(int argc, char **argv)
Definition: main.cpp:97
QString::isEmpty
bool isEmpty() const
aboutdata.h
QString
QString::toLocal8Bit
QByteArray toLocal8Bit() const
convertToNative
static int convertToNative(const KUrl &file, const QByteArray &outfile)
Definition: main.cpp:82
kigAboutData
KAboutData kigAboutData(const char *name, const char *iname)
Definition: aboutdata.h:26
kig.h
QLibrary::resolve
void * resolve(const char *symbol)
Kig
This is the application "Shell".
Definition: kig.h:30
QLibrary
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:12:05 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

Skip menu "kig"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal