• 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 <klocale.h>
24 #include <kcmdlineargs.h>
25 #include <kaboutdata.h>
26 #include <kglobal.h>
27 #include <kconfig.h>
28 #include <kinstance.h>
29 #include <kstartupinfo.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 KCmdLineOptions 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  { "p", 0, 0 },
45  { "pid <pid>", I18N_NOOP("Only try to reuse kate instance with this pid"), 0 },
46  { "e", 0, 0 },
47  { "encoding <name>", I18N_NOOP("Set encoding for the file to open"), 0 },
48  { "l", 0, 0 },
49  { "line <line>", I18N_NOOP("Navigate to this line"), 0 },
50  { "c", 0, 0 },
51  { "column <column>", I18N_NOOP("Navigate to this column"), 0 },
52  { "i", 0, 0 },
53  { "stdin", I18N_NOOP("Read the contents of stdin"), 0 },
54  { "+[URL]", I18N_NOOP("Document to open"), 0 },
55  KCmdLineLastOption
56 };
57 
58 extern "C" KDE_EXPORT int kdemain( int argc, char **argv )
59 {
60  // here we go, construct the Kate version
61  TQString kateVersion = KateApp::kateVersion();
62 
63  KAboutData aboutData ("kate", I18N_NOOP("Kate"), kateVersion.latin1(),
64  I18N_NOOP( "Kate - Advanced Text Editor" ), KAboutData::License_LGPL_V2,
65  I18N_NOOP( "(c) 2000-2005 The Kate Authors" ), 0, "http://kate.kde.org");
66 
67  aboutData.addAuthor ("Christoph Cullmann", I18N_NOOP("Maintainer"), "cullmann@kde.org", "http://www.babylon2k.de");
68  aboutData.addAuthor ("Anders Lund", I18N_NOOP("Core Developer"), "anders@alweb.dk", "http://www.alweb.dk");
69  aboutData.addAuthor ("Joseph Wenninger", I18N_NOOP("Core Developer"), "jowenn@kde.org","http://stud3.tuwien.ac.at/~e9925371");
70  aboutData.addAuthor ("Hamish Rodda",I18N_NOOP("Core Developer"), "rodda@kde.org");
71  aboutData.addAuthor ("Waldo Bastian", I18N_NOOP( "The cool buffersystem" ), "bastian@kde.org" );
72  aboutData.addAuthor ("Charles Samuels", I18N_NOOP("The Editing Commands"), "charles@kde.org");
73  aboutData.addAuthor ("Matt Newell", I18N_NOOP("Testing, ..."), "newellm@proaxis.com");
74  aboutData.addAuthor ("Michael Bartl", I18N_NOOP("Former Core Developer"), "michael.bartl1@chello.at");
75  aboutData.addAuthor ("Michael McCallum", I18N_NOOP("Core Developer"), "gholam@xtra.co.nz");
76  aboutData.addAuthor ("Jochen Wilhemly", I18N_NOOP( "KWrite Author" ), "digisnap@cs.tu-berlin.de" );
77  aboutData.addAuthor ("Michael Koch",I18N_NOOP("KWrite port to KParts"), "koch@kde.org");
78  aboutData.addAuthor ("Christian Gebauer", 0, "gebauer@kde.org" );
79  aboutData.addAuthor ("Simon Hausmann", 0, "hausmann@kde.org" );
80  aboutData.addAuthor ("Glen Parker",I18N_NOOP("KWrite Undo History, Kspell integration"), "glenebob@nwlink.com");
81  aboutData.addAuthor ("Scott Manson",I18N_NOOP("KWrite XML Syntax highlighting support"), "sdmanson@alltel.net");
82  aboutData.addAuthor ("John Firebaugh",I18N_NOOP("Patches and more"), "jfirebaugh@kde.org");
83  aboutData.addAuthor ("Dominik Haumann", I18N_NOOP("Developer & Highlight wizard"), "dhdev@gmx.de");
84 
85  aboutData.addCredit ("Matteo Merli",I18N_NOOP("Highlighting for RPM Spec-Files, Perl, Diff and more"), "merlim@libero.it");
86  aboutData.addCredit ("Rocky Scaletta",I18N_NOOP("Highlighting for VHDL"), "rocky@purdue.edu");
87  aboutData.addCredit ("Yury Lebedev",I18N_NOOP("Highlighting for SQL"),"");
88  aboutData.addCredit ("Chris Ross",I18N_NOOP("Highlighting for Ferite"),"");
89  aboutData.addCredit ("Nick Roux",I18N_NOOP("Highlighting for ILERPG"),"");
90  aboutData.addCredit ("Carsten Niehaus", I18N_NOOP("Highlighting for LaTeX"),"");
91  aboutData.addCredit ("Per Wigren", I18N_NOOP("Highlighting for Makefiles, Python"),"");
92  aboutData.addCredit ("Jan Fritz", I18N_NOOP("Highlighting for Python"),"");
93  aboutData.addCredit ("Daniel Naber","","");
94  aboutData.addCredit ("Roland Pabel",I18N_NOOP("Highlighting for Scheme"),"");
95  aboutData.addCredit ("Cristi Dumitrescu",I18N_NOOP("PHP Keyword/Datatype list"),"");
96  aboutData.addCredit ("Carsten Pfeiffer", I18N_NOOP("Very nice help"), "");
97  aboutData.addCredit (I18N_NOOP("All people who have contributed and I have forgotten to mention"),"","");
98 
99  aboutData.setTranslator(I18N_NOOP2("NAME OF TRANSLATORS","Your names"), I18N_NOOP2("EMAIL OF TRANSLATORS","Your emails"));
100 
101  // command line args init and co
102  KCmdLineArgs::init (argc, argv, &aboutData);
103  KCmdLineArgs::addCmdLineOptions (options);
104  KCmdLineArgs::addTempFileOption();
105  KateApp::addCmdLineOptions ();
106 
107  // get our command line args ;)
108  KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
109 
110  // now, first try to contact running kate instance if needed
111  if ( args->isSet("use") || (::getenv("KATE_PID")!=0) )
112  {
113  DCOPClient client;
114  client.attach ();
115 
116  // get all attached clients ;)
117  QCStringList allClients = client.registeredApplications();
118 
119  // search for a kate app client, use the first found
120  TQCString kateApp;
121 
122  if ( args->isSet("start") )
123  {
124  for (unsigned int i=0; i < allClients.count(); i++)
125  {
126  if (allClients[i] == "kate" || allClients[i].left(5) == "kate-")
127  {
128  DCOPRef ref( allClients[i], "KateApplication" );
129  TQString s = ref.call( "session" );
130  if ( TQString(args->getOption("start")) == s )
131  {
132  kateApp = allClients[i];
133  break;
134  }
135  }
136  }
137  }
138  else if ( (args->isSet("pid")) || (::getenv("KATE_PID") !=0 ) )
139  {
140  TQCString tryApp;
141  if ( args->isSet("pid") )
142  tryApp = args->getOption("pid");
143  else
144  tryApp = ::getenv("KATE_PID");
145 
146  if ( client.isApplicationRegistered( tryApp.prepend("kate-") ) )
147  kateApp = tryApp;
148  }
149  else
150  {
151  for (unsigned int i=0; i < allClients.count(); ++i)
152  {
153  if (allClients[i] == "kate" || allClients[i].left(5) == "kate-")
154  {
155  kateApp = allClients[i];
156  break;
157  }
158  }
159  }
160 
161  // found a matching kate client ;)
162  if (!kateApp.isEmpty())
163  {
164  kdDebug () << "kate app: " << kateApp << endl;
165  // make kdeinit happy
166  client.registerAs( "kate" );
167 
168  DCOPRef kRef (kateApp, "KateApplication");
169 
170  if (args->isSet ("start"))
171  kRef.call( "activateSession", TQString (args->getOption("start")) );
172 
173  TQString enc = args->isSet("encoding") ? args->getOption("encoding") : TQCString("");
174 
175  bool tempfileSet = KCmdLineArgs::isTempFileSet();
176 
177  for (int z=0; z<args->count(); z++)
178  kRef.call( "openURL", args->url(z), enc, tempfileSet );
179 
180  if( args->isSet( "stdin" ) )
181  {
182  TQTextIStream input(stdin);
183 
184  // set chosen codec
185  TQTextCodec *codec = args->isSet("encoding") ? TQTextCodec::codecForName(args->getOption("encoding")) : 0;
186 
187  if (codec)
188  input.setCodec (codec);
189 
190  TQString line;
191  TQString text;
192 
193  do
194  {
195  line = input.readLine();
196  text.append( line + "\n" );
197  } while( !line.isNull() );
198 
199  kRef.call( "openInput", text );
200  }
201 
202  int line = 0;
203  int column = 0;
204  bool nav = false;
205 
206  if (args->isSet ("line"))
207  {
208  line = args->getOption ("line").toInt();
209  nav = true;
210  }
211 
212  if (args->isSet ("column"))
213  {
214  column = args->getOption ("column").toInt();
215  nav = true;
216  }
217 
218  if (nav)
219  kRef.call( "setCursor", line, column );
220 
221  // since the user tried to open a document, let us assume [s]he
222  // wants to see that document.
223  // ### what to do about the infamous focus stealing prevention?
224  uint mwn = kRef.call("activeMainWindowNumber");
225  TQCString smwn;
226  DCOPRef wRef( kateApp, TQCString( "__KateMainWindow#") + smwn.setNum(mwn) );
227  if ( wRef.call("minimized") )
228  {
229  if ( wRef.call( "maximized" ) )
230  wRef.call( "maximize" );
231  else
232  wRef.call("restore");
233  }
234  // The --use parameter forces Kate to use a single session window to host
235  // all opened files. Generally, that parameter works. Yet when a file is
236  // opened into Kate externally, such as from Konqueror, Kate will pop
237  // forward (raise) but not grab the focus (show). The following snippet
238  // resolves that problem. For whatever reason the hide call is needed
239  // before the raise and show otherwise the snippet fails. Some extra glue
240  // might be needed. With Kate open:
241  // "Right-click" on the title bar
242  // Select Advanced
243  // Select Special Application Settings (Not Special Window Settings)
244  // Select the Workarounds tab
245  // Enable the Focus stealing prevention check box
246  // Select the Force option
247  // Select the None option
248 
249  wRef.call( "hide" );
250  wRef.call( "raise" );
251  wRef.call( "show" );
252 
253  // stop startup notification
254  KStartupInfo::appStarted( );
255 
256  return 0;
257  }
258  }
259 
260  // construct the real kate app object ;)
261  KateApp app (args);
262 
263  // app execution should already end :)
264  if (app.shouldExit())
265  {
266  return 0;
267  }
268 
269  // execute ourself ;)
270  return app.exec();
271 }
272 
273 // kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off;

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
  • kwin
  •   lib
  • libkonq
Generated for kate by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |