00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
00102 KCmdLineArgs::init (argc, argv, &aboutData);
00103 KCmdLineArgs::addCmdLineOptions (options);
00104 KCmdLineArgs::addTempFileOption();
00105 KateApp::addCmdLineOptions ();
00106
00107
00108 KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
00109
00110
00111 if ( args->isSet("use") || (::getenv("KATE_PID")!=0) )
00112 {
00113 DCOPClient client;
00114 client.attach ();
00115
00116
00117 QCStringList allClients = client.registeredApplications();
00118
00119
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
00162 if (!kateApp.isEmpty())
00163 {
00164 kdDebug () << "kate app: " << kateApp << endl;
00165
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
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
00222
00223
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
00237 KStartupInfo::appStarted( );
00238
00239 return 0;
00240 }
00241 }
00242
00243
00244 KateApp app (args);
00245
00246
00247 if (app.shouldExit())
00248 {
00249 return 0;
00250 }
00251
00252
00253 return app.exec();
00254 }
00255
00256