• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kate

katemain.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
00003    Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kateapp.h"
00021 
00022 #include <kstandarddirs.h>
00023 #include <klocale.h>
00024 #include <kcmdlineargs.h>
00025 #include <kaboutdata.h>
00026 #include <kglobal.h>
00027 #include <kconfig.h>
00028 #include <kinstance.h>
00029 #include <kstartupinfo.h>
00030 #include <dcopclient.h>
00031 #include <dcopref.h>
00032 #include <kdebug.h>
00033 
00034 #include <qtextcodec.h>
00035 
00036 #include <stdlib.h>
00037 
00038 static KCmdLineOptions options[] =
00039 {
00040     { "s", 0 , 0 },
00041     { "start <name>", I18N_NOOP("Start Kate with a given session"), 0 },
00042     { "u", 0, 0 },
00043     { "use", I18N_NOOP("Use a already running kate instance (if possible)"), 0 },
00044     { "p", 0, 0 },
00045     { "pid <pid>", I18N_NOOP("Only try to reuse kate instance with this pid"), 0 },
00046     { "e", 0, 0 },
00047     { "encoding <name>", I18N_NOOP("Set encoding for the file to open"), 0 },
00048     { "l", 0, 0 },
00049     { "line <line>", I18N_NOOP("Navigate to this line"), 0 },
00050     { "c", 0, 0 },
00051     { "column <column>", I18N_NOOP("Navigate to this column"), 0 },
00052     { "i", 0, 0 },
00053     { "stdin", I18N_NOOP("Read the contents of stdin"), 0 },
00054     { "+[URL]", I18N_NOOP("Document to open"), 0 },
00055     KCmdLineLastOption
00056 };
00057 
00058 extern "C" KDE_EXPORT int kdemain( int argc, char **argv )
00059 {
00060   // here we go, construct the Kate version
00061   QString kateVersion = KateApp::kateVersion();
00062 
00063   KAboutData aboutData ("kate", I18N_NOOP("Kate"), kateVersion.latin1(),
00064                         I18N_NOOP( "Kate - Advanced Text Editor" ), KAboutData::License_LGPL_V2,
00065                         I18N_NOOP( "(c) 2000-2005 The Kate Authors" ), 0, "http://kate.kde.org");
00066 
00067   aboutData.addAuthor ("Christoph Cullmann", I18N_NOOP("Maintainer"), "cullmann@kde.org", "http://www.babylon2k.de");
00068   aboutData.addAuthor ("Anders Lund", I18N_NOOP("Core Developer"), "anders@alweb.dk", "http://www.alweb.dk");
00069   aboutData.addAuthor ("Joseph Wenninger", I18N_NOOP("Core Developer"), "jowenn@kde.org","http://stud3.tuwien.ac.at/~e9925371");
00070   aboutData.addAuthor ("Hamish Rodda",I18N_NOOP("Core Developer"), "rodda@kde.org");
00071   aboutData.addAuthor ("Waldo Bastian", I18N_NOOP( "The cool buffersystem" ), "bastian@kde.org" );
00072   aboutData.addAuthor ("Charles Samuels", I18N_NOOP("The Editing Commands"), "charles@kde.org");
00073   aboutData.addAuthor ("Matt Newell", I18N_NOOP("Testing, ..."), "newellm@proaxis.com");
00074   aboutData.addAuthor ("Michael Bartl", I18N_NOOP("Former Core Developer"), "michael.bartl1@chello.at");
00075   aboutData.addAuthor ("Michael McCallum", I18N_NOOP("Core Developer"), "gholam@xtra.co.nz");
00076   aboutData.addAuthor ("Jochen Wilhemly", I18N_NOOP( "KWrite Author" ), "digisnap@cs.tu-berlin.de" );
00077   aboutData.addAuthor ("Michael Koch",I18N_NOOP("KWrite port to KParts"), "koch@kde.org");
00078   aboutData.addAuthor ("Christian Gebauer", 0, "gebauer@kde.org" );
00079   aboutData.addAuthor ("Simon Hausmann", 0, "hausmann@kde.org" );
00080   aboutData.addAuthor ("Glen Parker",I18N_NOOP("KWrite Undo History, Kspell integration"), "glenebob@nwlink.com");
00081   aboutData.addAuthor ("Scott Manson",I18N_NOOP("KWrite XML Syntax highlighting support"), "sdmanson@alltel.net");
00082   aboutData.addAuthor ("John Firebaugh",I18N_NOOP("Patches and more"), "jfirebaugh@kde.org");
00083   aboutData.addAuthor ("Dominik Haumann", I18N_NOOP("Developer & Highlight wizard"), "dhdev@gmx.de");
00084 
00085   aboutData.addCredit ("Matteo Merli",I18N_NOOP("Highlighting for RPM Spec-Files, Perl, Diff and more"), "merlim@libero.it");
00086   aboutData.addCredit ("Rocky Scaletta",I18N_NOOP("Highlighting for VHDL"), "rocky@purdue.edu");
00087   aboutData.addCredit ("Yury Lebedev",I18N_NOOP("Highlighting for SQL"),"");
00088   aboutData.addCredit ("Chris Ross",I18N_NOOP("Highlighting for Ferite"),"");
00089   aboutData.addCredit ("Nick Roux",I18N_NOOP("Highlighting for ILERPG"),"");
00090   aboutData.addCredit ("Carsten Niehaus", I18N_NOOP("Highlighting for LaTeX"),"");
00091   aboutData.addCredit ("Per Wigren", I18N_NOOP("Highlighting for Makefiles, Python"),"");
00092   aboutData.addCredit ("Jan Fritz", I18N_NOOP("Highlighting for Python"),"");
00093   aboutData.addCredit ("Daniel Naber","","");
00094   aboutData.addCredit ("Roland Pabel",I18N_NOOP("Highlighting for Scheme"),"");
00095   aboutData.addCredit ("Cristi Dumitrescu",I18N_NOOP("PHP Keyword/Datatype list"),"");
00096   aboutData.addCredit ("Carsten Pfeiffer", I18N_NOOP("Very nice help"), "");
00097   aboutData.addCredit (I18N_NOOP("All people who have contributed and I have forgotten to mention"),"","");
00098 
00099   aboutData.setTranslator(I18N_NOOP2("NAME OF TRANSLATORS","Your names"), I18N_NOOP2("EMAIL OF TRANSLATORS","Your emails"));
00100 
00101   // command line args init and co
00102   KCmdLineArgs::init (argc, argv, &aboutData);
00103   KCmdLineArgs::addCmdLineOptions (options);
00104   KCmdLineArgs::addTempFileOption();
00105   KateApp::addCmdLineOptions ();
00106 
00107   // get our command line args ;)
00108   KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
00109 
00110   // now, first try to contact running kate instance if needed
00111   if ( args->isSet("use") || (::getenv("KATE_PID")!=0) )
00112   {
00113     DCOPClient client;
00114     client.attach ();
00115 
00116     // get all attached clients ;)
00117     QCStringList allClients = client.registeredApplications();
00118 
00119     // search for a kate app client, use the first found
00120     QCString kateApp;
00121 
00122     if ( args->isSet("start") )
00123     {
00124       for (unsigned int i=0; i < allClients.count(); i++)
00125       {
00126         if (allClients[i] == "kate" || allClients[i].left(5) == "kate-")
00127         {
00128           DCOPRef ref( allClients[i], "KateApplication" );
00129           QString s = ref.call( "session" );
00130           if ( QString(args->getOption("start")) == s )
00131           {
00132             kateApp = allClients[i];
00133             break;
00134           }
00135         }
00136       }
00137     }
00138     else if ( (args->isSet("pid")) || (::getenv("KATE_PID") !=0 ) )
00139     {
00140       QCString tryApp;
00141       if ( args->isSet("pid") )
00142         tryApp = args->getOption("pid");
00143       else
00144         tryApp = ::getenv("KATE_PID");
00145 
00146       if ( client.isApplicationRegistered( tryApp.prepend("kate-") ) )
00147         kateApp = tryApp;
00148     }
00149     else
00150     {
00151       for (unsigned int i=0; i < allClients.count(); ++i)
00152       {
00153         if (allClients[i] == "kate" || allClients[i].left(5) == "kate-")
00154         {
00155           kateApp = allClients[i];
00156           break;
00157         }
00158       }
00159     }
00160 
00161     // found a matching kate client ;)
00162     if (!kateApp.isEmpty())
00163     {
00164       kdDebug () << "kate app: " << kateApp << endl;
00165       // make kdeinit happy
00166       client.registerAs( "kate" );
00167 
00168       DCOPRef kRef (kateApp, "KateApplication");
00169 
00170       if (args->isSet ("start"))
00171         kRef.call( "activateSession", QString (args->getOption("start")) );
00172 
00173       QString enc = args->isSet("encoding") ? args->getOption("encoding") : QCString("");
00174 
00175       bool tempfileSet = KCmdLineArgs::isTempFileSet();
00176 
00177       for (int z=0; z<args->count(); z++)
00178         kRef.call( "openURL", args->url(z), enc, tempfileSet );
00179 
00180       if( args->isSet( "stdin" ) )
00181       {
00182         QTextIStream input(stdin);
00183 
00184         // set chosen codec
00185         QTextCodec *codec = args->isSet("encoding") ? QTextCodec::codecForName(args->getOption("encoding")) : 0;
00186 
00187         if (codec)
00188           input.setCodec (codec);
00189 
00190         QString line;
00191         QString text;
00192 
00193         do
00194         {
00195           line = input.readLine();
00196           text.append( line + "\n" );
00197         } while( !line.isNull() );
00198 
00199         kRef.call( "openInput", text );
00200       }
00201 
00202       int line = 0;
00203       int column = 0;
00204       bool nav = false;
00205 
00206       if (args->isSet ("line"))
00207       {
00208         line = args->getOption ("line").toInt();
00209         nav = true;
00210       }
00211 
00212       if (args->isSet ("column"))
00213       {
00214         column = args->getOption ("column").toInt();
00215         nav = true;
00216       }
00217 
00218       if (nav)
00219          kRef.call( "setCursor", line, column );
00220 
00221       // since the user tried to open a document, let us assume [s]he
00222       // wants to see that document.
00223       // ### what to do about the infamous focus stealing prevention?
00224       uint mwn = kRef.call("activeMainWindowNumber");
00225       QCString smwn;
00226       DCOPRef wRef( kateApp, QCString( "__KateMainWindow#") + smwn.setNum(mwn) );
00227       if ( wRef.call("minimized") )
00228       {
00229         if ( wRef.call( "maximized" ) )
00230           wRef.call( "maximize" );
00231         else
00232           wRef.call("restore");
00233       }
00234       wRef.call( "raise" );
00235 
00236       // stop startup notification
00237       KStartupInfo::appStarted(  );
00238 
00239       return 0;
00240     }
00241   }
00242 
00243   // construct the real kate app object ;)
00244   KateApp app (args);
00245 
00246   // app execution should already end :)
00247   if (app.shouldExit())
00248   {
00249     return 0;
00250   }
00251 
00252   // execute ourself ;)
00253   return app.exec();
00254 }
00255 
00256 // 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

API Reference

Skip menu "API Reference"
  • kate
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal