katemain.cpp
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 <tdelocale.h> 00024 #include <tdecmdlineargs.h> 00025 #include <tdeaboutdata.h> 00026 #include <tdeglobal.h> 00027 #include <tdeconfig.h> 00028 #include <kinstance.h> 00029 #include <tdestartupinfo.h> 00030 #include <dcopclient.h> 00031 #include <dcopref.h> 00032 #include <kdebug.h> 00033 00034 #include <tqtextcodec.h> 00035 00036 #include <stdlib.h> 00037 00038 static TDECmdLineOptions 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 { "f", 0, 0 }, 00045 { "force-sdi", I18N_NOOP("Force single document mode if the MDI setting is enabled."), 0 }, 00046 { "p", 0, 0 }, 00047 { "pid <pid>", I18N_NOOP("Only try to reuse kate instance with this pid"), 0 }, 00048 { "e", 0, 0 }, 00049 { "encoding <name>", I18N_NOOP("Set encoding for the file to open"), 0 }, 00050 { "l", 0, 0 }, 00051 { "line <line>", I18N_NOOP("Navigate to this line"), 0 }, 00052 { "c", 0, 0 }, 00053 { "column <column>", I18N_NOOP("Navigate to this column"), 0 }, 00054 { "i", 0, 0 }, 00055 { "stdin", I18N_NOOP("Read the contents of stdin"), 0 }, 00056 { "+[URL]", I18N_NOOP("Document to open"), 0 }, 00057 TDECmdLineLastOption 00058 }; 00059 00060 extern "C" KDE_EXPORT int kdemain( int argc, char **argv ) 00061 { 00062 TDEConfig * config = NULL; 00063 bool alwaysUseInstance; 00064 // here we go, construct the Kate version 00065 TQString kateVersion = KateApp::kateVersion(); 00066 00067 TDEAboutData aboutData ("kate", I18N_NOOP("Kate"), kateVersion.latin1(), 00068 I18N_NOOP( "Kate - Advanced Text Editor" ), TDEAboutData::License_LGPL_V2, 00069 I18N_NOOP( "(c) 2000-2005 The Kate Authors" ), 0); 00070 00071 aboutData.addAuthor ("Christoph Cullmann", I18N_NOOP("Maintainer"), "cullmann@kde.org", "http://www.babylon2k.de"); 00072 aboutData.addAuthor ("Anders Lund", I18N_NOOP("Core Developer"), "anders@alweb.dk", "http://www.alweb.dk"); 00073 aboutData.addAuthor ("Joseph Wenninger", I18N_NOOP("Core Developer"), "jowenn@kde.org","http://stud3.tuwien.ac.at/~e9925371"); 00074 aboutData.addAuthor ("Hamish Rodda",I18N_NOOP("Core Developer"), "rodda@kde.org"); 00075 aboutData.addAuthor ("Waldo Bastian", I18N_NOOP( "The cool buffersystem" ), "bastian@kde.org" ); 00076 aboutData.addAuthor ("Charles Samuels", I18N_NOOP("The Editing Commands"), "charles@kde.org"); 00077 aboutData.addAuthor ("Matt Newell", I18N_NOOP("Testing, ..."), "newellm@proaxis.com"); 00078 aboutData.addAuthor ("Michael Bartl", I18N_NOOP("Former Core Developer"), "michael.bartl1@chello.at"); 00079 aboutData.addAuthor ("Michael McCallum", I18N_NOOP("Core Developer"), "gholam@xtra.co.nz"); 00080 aboutData.addAuthor ("Jochen Wilhemly", I18N_NOOP( "KWrite Author" ), "digisnap@cs.tu-berlin.de" ); 00081 aboutData.addAuthor ("Michael Koch",I18N_NOOP("KWrite port to KParts"), "koch@kde.org"); 00082 aboutData.addAuthor ("Christian Gebauer", 0, "gebauer@kde.org" ); 00083 aboutData.addAuthor ("Simon Hausmann", 0, "hausmann@kde.org" ); 00084 aboutData.addAuthor ("Glen Parker",I18N_NOOP("KWrite Undo History, Kspell integration"), "glenebob@nwlink.com"); 00085 aboutData.addAuthor ("Scott Manson",I18N_NOOP("KWrite XML Syntax highlighting support"), "sdmanson@alltel.net"); 00086 aboutData.addAuthor ("John Firebaugh",I18N_NOOP("Patches and more"), "jfirebaugh@kde.org"); 00087 aboutData.addAuthor ("Dominik Haumann", I18N_NOOP("Developer & Highlight wizard"), "dhdev@gmx.de"); 00088 00089 aboutData.addCredit ("Matteo Merli",I18N_NOOP("Highlighting for RPM Spec-Files, Perl, Diff and more"), "merlim@libero.it"); 00090 aboutData.addCredit ("Rocky Scaletta",I18N_NOOP("Highlighting for VHDL"), "rocky@purdue.edu"); 00091 aboutData.addCredit ("Yury Lebedev",I18N_NOOP("Highlighting for SQL"),""); 00092 aboutData.addCredit ("Chris Ross",I18N_NOOP("Highlighting for Ferite"),""); 00093 aboutData.addCredit ("Nick Roux",I18N_NOOP("Highlighting for ILERPG"),""); 00094 aboutData.addCredit ("Carsten Niehaus", I18N_NOOP("Highlighting for LaTeX"),""); 00095 aboutData.addCredit ("Per Wigren", I18N_NOOP("Highlighting for Makefiles, Python"),""); 00096 aboutData.addCredit ("Jan Fritz", I18N_NOOP("Highlighting for Python"),""); 00097 aboutData.addCredit ("Daniel Naber","",""); 00098 aboutData.addCredit ("Roland Pabel",I18N_NOOP("Highlighting for Scheme"),""); 00099 aboutData.addCredit ("Cristi Dumitrescu",I18N_NOOP("PHP Keyword/Datatype list"),""); 00100 aboutData.addCredit ("Carsten Pfeiffer", I18N_NOOP("Very nice help"), ""); 00101 aboutData.addCredit (I18N_NOOP("All people who have contributed and I have forgotten to mention"),"",""); 00102 00103 aboutData.setTranslator(I18N_NOOP2("NAME OF TRANSLATORS","Your names"), I18N_NOOP2("EMAIL OF TRANSLATORS","Your emails")); 00104 00105 TDEInstance instance( &aboutData ); 00106 00107 // command line args init and co 00108 TDECmdLineArgs::init (argc, argv, &aboutData); 00109 TDECmdLineArgs::addCmdLineOptions (options); 00110 TDECmdLineArgs::addTempFileOption(); 00111 KateApp::addCmdLineOptions (); 00112 00113 // get our command line args ;) 00114 TDECmdLineArgs* args = TDECmdLineArgs::parsedArgs(); 00115 00116 config = TDEGlobal::config(); 00117 config->setGroup("General"); 00118 alwaysUseInstance = config->readBoolEntry("UseInstance"); 00119 00120 // now, first try to contact running kate instance if needed 00121 if ( ((args->isSet("use") || alwaysUseInstance) && 00122 !(args->isSet("force-sdi"))) || (::getenv("KATE_PID")!=0) ) 00123 { 00124 DCOPClient client; 00125 client.attach (); 00126 00127 // get all attached clients ;) 00128 QCStringList allClients = client.registeredApplications(); 00129 00130 // search for a kate app client, use the first found 00131 TQCString kateApp; 00132 00133 if ( args->isSet("start") ) 00134 { 00135 for (unsigned int i=0; i < allClients.count(); i++) 00136 { 00137 if (allClients[i] == "kate" || allClients[i].left(5) == "kate-") 00138 { 00139 DCOPRef ref( allClients[i], "KateApplication" ); 00140 TQString s = ref.call( "session" ); 00141 if ( TQString(args->getOption("start")) == s ) 00142 { 00143 kateApp = allClients[i]; 00144 break; 00145 } 00146 } 00147 } 00148 } 00149 else if ( (args->isSet("pid")) || (::getenv("KATE_PID") !=0 ) ) 00150 { 00151 TQCString tryApp; 00152 if ( args->isSet("pid") ) 00153 tryApp = args->getOption("pid"); 00154 else 00155 tryApp = ::getenv("KATE_PID"); 00156 00157 if ( client.isApplicationRegistered( tryApp.prepend("kate-") ) ) 00158 kateApp = tryApp; 00159 } 00160 else 00161 { 00162 for (unsigned int i=0; i < allClients.count(); ++i) 00163 { 00164 if (allClients[i] == "kate" || allClients[i].left(5) == "kate-") 00165 { 00166 kateApp = allClients[i]; 00167 break; 00168 } 00169 } 00170 } 00171 00172 // found a matching kate client ;) 00173 if (!kateApp.isEmpty()) 00174 { 00175 kdDebug () << "kate app: " << kateApp << endl; 00176 // make tdeinit happy 00177 client.registerAs( "kate" ); 00178 00179 DCOPRef kRef (kateApp, "KateApplication"); 00180 00181 if (args->isSet ("start")) 00182 kRef.call( "activateSession", TQString (args->getOption("start")) ); 00183 00184 TQString enc = args->isSet("encoding") ? args->getOption("encoding") : TQCString(""); 00185 00186 bool tempfileSet = TDECmdLineArgs::isTempFileSet(); 00187 00188 for (int z=0; z<args->count(); z++) 00189 kRef.call( "openURL", args->url(z), enc, tempfileSet ); 00190 00191 if( args->isSet( "stdin" ) ) 00192 { 00193 TQTextIStream input(stdin); 00194 00195 // set chosen codec 00196 TQTextCodec *codec = args->isSet("encoding") ? TQTextCodec::codecForName(args->getOption("encoding")) : 0; 00197 00198 if (codec) 00199 input.setCodec (codec); 00200 00201 TQString line; 00202 TQString text; 00203 00204 do 00205 { 00206 line = input.readLine(); 00207 text.append( line + "\n" ); 00208 } while( !line.isNull() ); 00209 00210 kRef.call( "openInput", text ); 00211 } 00212 00213 int line = 0; 00214 int column = 0; 00215 bool nav = false; 00216 00217 if (args->isSet ("line")) 00218 { 00219 line = args->getOption ("line").toInt(); 00220 nav = true; 00221 } 00222 00223 if (args->isSet ("column")) 00224 { 00225 column = args->getOption ("column").toInt(); 00226 nav = true; 00227 } 00228 00229 if (nav) 00230 kRef.call( "setCursor", line, column ); 00231 00232 // since the user tried to open a document, let us assume [s]he 00233 // wants to see that document. 00234 // ### what to do about the infamous focus stealing prevention? 00235 uint mwn = kRef.call("activeMainWindowNumber"); 00236 TQCString smwn; 00237 DCOPRef wRef( kateApp, TQCString( "__KateMainWindow#") + smwn.setNum(mwn) ); 00238 if ( wRef.call("minimized") ) 00239 { 00240 if ( wRef.call( "maximized" ) ) 00241 wRef.call( "maximize" ); 00242 else 00243 wRef.call("restore"); 00244 } 00245 wRef.call( "setActiveWindowFocused" ); 00246 00247 // stop startup notification 00248 TDEStartupInfo::appStarted( ); 00249 00250 return 0; 00251 } 00252 } 00253 00254 // construct the real kate app object ;) 00255 KateApp app (args); 00256 00257 // app execution should already end :) 00258 if (app.shouldExit()) 00259 { 00260 return 0; 00261 } 00262 00263 // execute ourself ;) 00264 return app.exec(); 00265 } 00266 00267 // kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off;