• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kate
 

kate

  • kate
  • app
katemain.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
3  Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "kateapp.h"
21 
22 #include <kstandarddirs.h>
23 #include <tdelocale.h>
24 #include <tdecmdlineargs.h>
25 #include <tdeaboutdata.h>
26 #include <tdeglobal.h>
27 #include <tdeconfig.h>
28 #include <kinstance.h>
29 #include <tdestartupinfo.h>
30 #include <dcopclient.h>
31 #include <dcopref.h>
32 #include <kdebug.h>
33 
34 #include <tqtextcodec.h>
35 
36 #include <stdlib.h>
37 
38 static TDECmdLineOptions options[] =
39 {
40  { "s", 0 , 0 },
41  { "start <name>", I18N_NOOP("Start Kate with a given session"), 0 },
42  { "u", 0, 0 },
43  { "use", I18N_NOOP("Use a already running kate instance (if possible)"), 0 },
44  { "f", 0, 0 },
45  { "force-sdi", I18N_NOOP("Force single document mode if the MDI setting is enabled."), 0 },
46  { "p", 0, 0 },
47  { "pid <pid>", I18N_NOOP("Only try to reuse kate instance with this pid"), 0 },
48  { "e", 0, 0 },
49  { "encoding <name>", I18N_NOOP("Set encoding for the file to open"), 0 },
50  { "l", 0, 0 },
51  { "line <line>", I18N_NOOP("Navigate to this line"), 0 },
52  { "c", 0, 0 },
53  { "column <column>", I18N_NOOP("Navigate to this column"), 0 },
54  { "i", 0, 0 },
55  { "stdin", I18N_NOOP("Read the contents of stdin"), 0 },
56  { "+[URL]", I18N_NOOP("Document to open"), 0 },
57  TDECmdLineLastOption
58 };
59 
60 extern "C" TDE_EXPORT int kdemain( int argc, char **argv )
61 {
62  TDEConfig * config = NULL;
63  bool alwaysUseInstance;
64  // here we go, construct the Kate version
65  TQString kateVersion = KateApp::kateVersion();
66 
67  TDEAboutData aboutData ("kate", I18N_NOOP("Kate"), kateVersion.latin1(),
68  I18N_NOOP( "Kate - Advanced Text Editor" ), TDEAboutData::License_LGPL_V2,
69  I18N_NOOP( "(c) 2000-2005 The Kate Authors" ), 0);
70 
71  aboutData.addAuthor ("Christoph Cullmann", I18N_NOOP("Maintainer"), "cullmann@kde.org", "http://www.babylon2k.de");
72  aboutData.addAuthor ("Anders Lund", I18N_NOOP("Core Developer"), "anders@alweb.dk", "http://www.alweb.dk");
73  aboutData.addAuthor ("Joseph Wenninger", I18N_NOOP("Core Developer"), "jowenn@kde.org","http://stud3.tuwien.ac.at/~e9925371");
74  aboutData.addAuthor ("Hamish Rodda",I18N_NOOP("Core Developer"), "rodda@kde.org");
75  aboutData.addAuthor ("Waldo Bastian", I18N_NOOP( "The cool buffersystem" ), "bastian@kde.org" );
76  aboutData.addAuthor ("Charles Samuels", I18N_NOOP("The Editing Commands"), "charles@kde.org");
77  aboutData.addAuthor ("Matt Newell", I18N_NOOP("Testing, ..."), "newellm@proaxis.com");
78  aboutData.addAuthor ("Michael Bartl", I18N_NOOP("Former Core Developer"), "michael.bartl1@chello.at");
79  aboutData.addAuthor ("Michael McCallum", I18N_NOOP("Core Developer"), "gholam@xtra.co.nz");
80  aboutData.addAuthor ("Jochen Wilhemly", I18N_NOOP( "KWrite Author" ), "digisnap@cs.tu-berlin.de" );
81  aboutData.addAuthor ("Michael Koch",I18N_NOOP("KWrite port to KParts"), "koch@kde.org");
82  aboutData.addAuthor ("Christian Gebauer", 0, "gebauer@kde.org" );
83  aboutData.addAuthor ("Simon Hausmann", 0, "hausmann@kde.org" );
84  aboutData.addAuthor ("Glen Parker",I18N_NOOP("KWrite Undo History, Kspell integration"), "glenebob@nwlink.com");
85  aboutData.addAuthor ("Scott Manson",I18N_NOOP("KWrite XML Syntax highlighting support"), "sdmanson@alltel.net");
86  aboutData.addAuthor ("John Firebaugh",I18N_NOOP("Patches and more"), "jfirebaugh@kde.org");
87  aboutData.addAuthor ("Dominik Haumann", I18N_NOOP("Developer & Highlight wizard"), "dhdev@gmx.de");
88 
89  aboutData.addCredit ("Matteo Merli",I18N_NOOP("Highlighting for RPM Spec-Files, Perl, Diff and more"), "merlim@libero.it");
90  aboutData.addCredit ("Rocky Scaletta",I18N_NOOP("Highlighting for VHDL"), "rocky@purdue.edu");
91  aboutData.addCredit ("Yury Lebedev",I18N_NOOP("Highlighting for SQL"),"");
92  aboutData.addCredit ("Chris Ross",I18N_NOOP("Highlighting for Ferite"),"");
93  aboutData.addCredit ("Nick Roux",I18N_NOOP("Highlighting for ILERPG"),"");
94  aboutData.addCredit ("Carsten Niehaus", I18N_NOOP("Highlighting for LaTeX"),"");
95  aboutData.addCredit ("Per Wigren", I18N_NOOP("Highlighting for Makefiles, Python"),"");
96  aboutData.addCredit ("Jan Fritz", I18N_NOOP("Highlighting for Python"),"");
97  aboutData.addCredit ("Daniel Naber","","");
98  aboutData.addCredit ("Roland Pabel",I18N_NOOP("Highlighting for Scheme"),"");
99  aboutData.addCredit ("Cristi Dumitrescu",I18N_NOOP("PHP Keyword/Datatype list"),"");
100  aboutData.addCredit ("Carsten Pfeiffer", I18N_NOOP("Very nice help"), "");
101  aboutData.addCredit (I18N_NOOP("All people who have contributed and I have forgotten to mention"),"","");
102 
103  aboutData.setTranslator(I18N_NOOP2("NAME OF TRANSLATORS","Your names"), I18N_NOOP2("EMAIL OF TRANSLATORS","Your emails"));
104 
105  TDEInstance instance( &aboutData );
106 
107  // command line args init and co
108  TDECmdLineArgs::init (argc, argv, &aboutData);
109  TDECmdLineArgs::addCmdLineOptions (options);
110  TDECmdLineArgs::addTempFileOption();
111  KateApp::addCmdLineOptions ();
112 
113  // get our command line args ;)
114  TDECmdLineArgs* args = TDECmdLineArgs::parsedArgs();
115 
116  config = TDEGlobal::config();
117  config->setGroup("General");
118  alwaysUseInstance = config->readBoolEntry("UseInstance");
119 
120 // now, first try to contact running kate instance if needed
121  if ( ((args->isSet("use") || alwaysUseInstance) &&
122  !(args->isSet("force-sdi"))) || (::getenv("KATE_PID")!=0) )
123  {
124  DCOPClient client;
125  client.attach ();
126 
127  // get all attached clients ;)
128  QCStringList allClients = client.registeredApplications();
129 
130  // search for a kate app client, use the first found
131  TQCString kateApp;
132 
133  if ( args->isSet("start") )
134  {
135  for (unsigned int i=0; i < allClients.count(); i++)
136  {
137  if (allClients[i] == "kate" || allClients[i].left(5) == "kate-")
138  {
139  DCOPRef ref( allClients[i], "KateApplication" );
140  TQString s = ref.call( "session" );
141  if ( TQString(args->getOption("start")) == s )
142  {
143  kateApp = allClients[i];
144  break;
145  }
146  }
147  }
148  }
149  else if ( (args->isSet("pid")) || (::getenv("KATE_PID") !=0 ) )
150  {
151  TQCString tryApp;
152  if ( args->isSet("pid") )
153  tryApp = args->getOption("pid");
154  else
155  tryApp = ::getenv("KATE_PID");
156 
157  if ( client.isApplicationRegistered( tryApp.prepend("kate-") ) )
158  kateApp = tryApp;
159  }
160  else
161  {
162  for (unsigned int i=0; i < allClients.count(); ++i)
163  {
164  if (allClients[i] == "kate" || allClients[i].left(5) == "kate-")
165  {
166  kateApp = allClients[i];
167  break;
168  }
169  }
170  }
171 
172  // found a matching kate client ;)
173  if (!kateApp.isEmpty())
174  {
175  kdDebug () << "kate app: " << kateApp << endl;
176  // make tdeinit happy
177  client.registerAs( "kate" );
178 
179  DCOPRef kRef (kateApp, "KateApplication");
180 
181  if (args->isSet ("start"))
182  kRef.call( "activateSession", TQString (args->getOption("start")) );
183 
184  TQString enc = args->isSet("encoding") ? args->getOption("encoding") : TQCString("");
185 
186  bool tempfileSet = TDECmdLineArgs::isTempFileSet();
187 
188  for (int z=0; z<args->count(); z++)
189  kRef.call( "openURL", args->url(z), enc, tempfileSet );
190 
191  if( args->isSet( "stdin" ) )
192  {
193  TQTextIStream input(stdin);
194 
195  // set chosen codec
196  TQTextCodec *codec = args->isSet("encoding") ? TQTextCodec::codecForName(args->getOption("encoding")) : 0;
197 
198  if (codec)
199  input.setCodec (codec);
200 
201  TQString line;
202  TQString text;
203 
204  do
205  {
206  line = input.readLine();
207  text.append( line + "\n" );
208  } while( !line.isNull() );
209 
210  kRef.call( "openInput", text );
211  }
212 
213  int line = 0;
214  int column = 0;
215  bool nav = false;
216 
217  if (args->isSet ("line"))
218  {
219  line = args->getOption ("line").toInt();
220  nav = true;
221  }
222 
223  if (args->isSet ("column"))
224  {
225  column = args->getOption ("column").toInt();
226  nav = true;
227  }
228 
229  if (nav)
230  kRef.call( "setCursor", line, column );
231 
232  // since the user tried to open a document, let us assume [s]he
233  // wants to see that document.
234  // ### what to do about the infamous focus stealing prevention?
235  uint mwn = kRef.call("activeMainWindowNumber");
236  TQCString smwn;
237  DCOPRef wRef( kateApp, TQCString( "__KateMainWindow#") + smwn.setNum(mwn) );
238  if ( wRef.call("minimized") )
239  {
240  if ( wRef.call( "maximized" ) )
241  wRef.call( "maximize" );
242  else
243  wRef.call("restore");
244  }
245  wRef.call( "setActiveWindowFocused" );
246 
247  // stop startup notification
248  TDEStartupInfo::appStarted( );
249 
250  return 0;
251  }
252  }
253 
254  // construct the real kate app object ;)
255  KateApp app (args);
256 
257  // app execution should already end :)
258  if (app.shouldExit())
259  {
260  return 0;
261  }
262 
263  // execute ourself ;)
264  return app.exec();
265 }
KateApp
Kate Application This class represents the core kate application object.
Definition: kateapp.h:43
KateApp::kateVersion
static TQString kateVersion(bool fullVersion=true)
Returns the current Kate version (X.Y) or (X.Y.Z)
Definition: kateapp.cpp:128

kate

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

kate

Skip menu "kate"
  • kate
  • libkonq
  • twin
  •   lib
Generated for kate by doxygen 1.9.1
This website is maintained by Timothy Pearson.