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

kate

  • kate
  • app
kateapp.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#include "kateapp.moc"
22
23#include "katedocmanager.h"
24#include "katepluginmanager.h"
25#include "kateviewmanager.h"
26#include "kateappIface.h"
27#include "katesession.h"
28#include "katemainwindow.h"
29
30#include "../interfaces/application.h"
31
32#include <tdecmdlineargs.h>
33#include <dcopclient.h>
34#include <tdeconfig.h>
35#include <twin.h>
36#include <ktip.h>
37#include <kdebug.h>
38#include <klibloader.h>
39#include <tdemessagebox.h>
40#include <tdelocale.h>
41#include <ksimpleconfig.h>
42#include <tdestartupinfo.h>
43
44#include <tqfile.h>
45#include <tqtimer.h>
46#include <tqdir.h>
47#include <tqtextcodec.h>
48
49#include <stdlib.h>
50#include <unistd.h>
51#include <sys/types.h>
52
53KateApp::KateApp (TDECmdLineArgs *args)
54 : TDEApplication ()
55 , m_args (args)
56 , m_shouldExit (false)
57{
58 // Don't handle DCOP requests yet
59 dcopClient()->suspend();
60
61 // insert right translations for the katepart
62 TDEGlobal::locale()->insertCatalogue("katepart");
63
64 // some global default
65 Kate::Document::setFileChangedDialogsActivated (true);
66
67 // application interface
68 m_application = new Kate::Application (this);
69
70 // doc + project man
71 m_docManager = new KateDocManager (this);
72
73 // init all normal plugins
74 m_pluginManager = new KatePluginManager (this);
75
76 // session manager up
77 m_sessionManager = KateSessionManager::self();
78
79 // application dcop interface
80 m_obj = new KateAppDCOPIface (this);
81
82 kdDebug()<<"Setting KATE_PID: '"<<getpid()<<"'"<<endl;
83 ::setenv( "KATE_PID", TQString(TQString("%1").arg(getpid())).latin1(), 1 );
84
85 // handle restore different
86 if (isRestored())
87 {
88 restoreKate ();
89 }
90 else
91 {
92 // let us handle our command line args and co ;)
93 // we can exit here if session chooser decides
94 if (!startupKate ())
95 {
96 m_shouldExit = true;
97 return;
98 }
99 }
100
101 // Ok. We are ready for DCOP requests.
102 dcopClient()->resume();
103}
104
105KateApp::~KateApp ()
106{
107 delete m_obj; // cu dcop interface
108 delete m_pluginManager; // cu plugin manager
109 delete m_sessionManager; // delete session manager
110 delete m_docManager; // delete document manager. Do this now, or we crash
111}
112
113KateApp *KateApp::self ()
114{
115 return (KateApp *) kapp;
116}
117
118Kate::Application *KateApp::application ()
119{
120 return m_application;
121}
122
127TQString KateApp::kateVersion (bool fullVersion)
128{
129// return fullVersion ? TQString ("%1.%2.%3").arg(KDE::versionMajor() - 1).arg(KDE::versionMinor()).arg(KDE::versionRelease())
130// : TQString ("%1.%2").arg(KDE::versionMajor() - 1).arg(KDE::versionMinor());
134 return fullVersion ? TQString ("2.5.%1").arg(KDE::versionMajor()) : TQString ("%1.%2").arg(2.5);
135}
136
137void KateApp::restoreKate()
138{
139 // restore the nice files ;) we need it
140 Kate::Document::setOpenErrorDialogsActivated(false);
141
142 // restore last session
143 sessionManager()->restoreLastSession();
144 m_docManager->restoreDocumentList(sessionConfig());
145
146 Kate::Document::setOpenErrorDialogsActivated(true);
147
148 // no mainwindow, create one, should not happen, but make sure ;)
149 if (mainWindows() == 0)
150 newMainWindow();
151
152 // Do not notify about start there: this makes kicker crazy and kate go to a wrong desktop.
153 // TDEStartupInfo::setNewStartupId( activeMainWindow(), startupId());
154}
155
156bool KateApp::startupKate()
157{
158 if (m_args->isSet("start"))
159 {
160 // the user has specified the session to open. If the session does not exist,
161 // a new session with the specified name will be created
162 TQCString sessName = m_args->getOption("start");
163 int sessId = sessionManager()->getSessionIdFromName(sessName);
164 if (sessId != KateSessionManager::INVALID_SESSION)
165 {
166 sessionManager()->activateSession(sessId);
167 }
168 else
169 {
170 sessionManager()->newSession(sessName);
171 }
172 }
173 else
174 {
175 // check Kate session startup options
176 int startupOption = sessionManager()->getStartupOption();
177 if (startupOption == KateSessionManager::STARTUP_NEW)
178 {
179 sessionManager()->newSession();
180 }
181 else if (startupOption == KateSessionManager::STARTUP_LAST)
182 {
183 sessionManager()->restoreLastSession();
184 }
185 else // startupOption == KateSessionManager::STARTUP_MANUAL
186 {
187 KateSessionChooser *chooser = new KateSessionChooser(NULL);
188 int result = chooser->exec();
189 switch (result)
190 {
191 case KateSessionChooser::RESULT_OPEN_NEW:
192 sessionManager()->newSession();
193 break;
194
195 case KateSessionChooser::RESULT_OPEN_EXISTING:
196 if (!m_sessionManager->activateSession(chooser->getSelectedSessionId()))
197 {
198 // Open a new session in case of error
199 sessionManager()->newSession();
200 }
201 break;
202
203 default: // KateSessionChooser::RESULT_QUIT_KATE:
204 // Kate will exit now and notify it is done
205 TDEStartupInfo::appStarted(startupId());
206 return false;
207 break;
208 }
209 delete chooser;
210 }
211 }
212
213 // oh, no mainwindow, create one, should not happen, but make sure ;)
214 if (mainWindows() == 0)
215 newMainWindow ();
216
217 // notify about start
218 TDEStartupInfo::setNewStartupId( activeMainWindow(), startupId());
219
220 TQTextCodec *codec = m_args->isSet("encoding") ? TQTextCodec::codecForName(m_args->getOption("encoding")) : 0;
221
222 bool tempfileSet = TDECmdLineArgs::isTempFileSet();
223
224 Kate::Document::setOpenErrorDialogsActivated (false);
225 uint id = 0;
226 for (int z=0; z<m_args->count(); z++)
227 {
228 // this file is no local dir, open it, else warn
229 bool noDir = !m_args->url(z).isLocalFile() || !TQDir (m_args->url(z).path()).exists();
230
231 if (noDir)
232 {
233 // open a normal file
234 if (codec)
235 id = activeMainWindow()->viewManager()->openURL( m_args->url(z), codec->name(), false, tempfileSet );
236 else
237 id = activeMainWindow()->viewManager()->openURL( m_args->url(z), TQString::null, false, tempfileSet );
238 }
239 else
240 KMessageBox::sorry( activeMainWindow(),
241 i18n("The file '%1' could not be opened: it is not a normal file, it is a folder.").arg(m_args->url(z).pathOrURL()) );
242 }
243
244 Kate::Document::setOpenErrorDialogsActivated (true);
245
246 // handle stdin input
247 if( m_args->isSet( "stdin" ) )
248 {
249 TQTextIStream input(stdin);
250
251 // set chosen codec
252 if (codec)
253 input.setCodec (codec);
254
255 TQString line;
256 TQString text;
257
258 do
259 {
260 line = input.readLine();
261 text.append( line + "\n" );
262 } while( !line.isNull() );
263
264 openInput (text);
265 }
266 else if ( id )
267 activeMainWindow()->viewManager()->activateView( id );
268
269 if ( activeMainWindow()->viewManager()->viewCount () == 0 )
270 activeMainWindow()->viewManager()->activateView(m_docManager->firstDocument()->documentNumber());
271
272 int line = 0;
273 int column = 0;
274 bool nav = false;
275
276 if (m_args->isSet ("line"))
277 {
278 line = m_args->getOption ("line").toInt();
279 nav = true;
280 }
281
282 if (m_args->isSet ("column"))
283 {
284 column = m_args->getOption ("column").toInt();
285 nav = true;
286 }
287
288 if (nav)
289 activeMainWindow()->viewManager()->activeView ()->setCursorPosition (line, column);
290
291 // show the nice tips
292 KTipDialog::showTip(activeMainWindow());
293
294 return true;
295}
296
297void KateApp::shutdownKate(KateMainWindow *win)
298{
299 if (!win->queryClose_internal())
300 return;
301
302 // detach the dcopClient
303 dcopClient()->detach();
304
305 // cu main windows
306 while (!m_mainWindows.isEmpty())
307 delete m_mainWindows[0];
308
309 quit();
310}
311
312bool KateApp::query_session_close()
313{
314 bool saveSessions = false;
315 int switchOption = m_sessionManager->getSwitchOption();
316 if (switchOption == KateSessionManager::SWITCH_SAVE)
317 {
318 saveSessions = true;
319 }
320 else if (switchOption == KateSessionManager::SWITCH_ASK)
321 {
322 KDialogBase *dlg = new KDialogBase(i18n("Save Sessions"),
323 KDialogBase::Yes | KDialogBase::No | KDialogBase::Cancel,
324 KDialogBase::Cancel, KDialogBase::Cancel, NULL, NULL, true, false,
325 KStdGuiItem::save(), KStdGuiItem::del(), KStdGuiItem::cancel());
326 bool dontAgain = false;
327 int res = KMessageBox::createKMessageBox(dlg, TQMessageBox::Warning,
328 i18n("<p>Do you want to save the existing sessions?<p>!!NOTE!!"
329 "<p>All existing sessions will be removed "
330 "if you choose \"Delete\""), TQStringList(),
331 i18n("Do not ask again"), &dontAgain, KMessageBox::Notify);
332 if (res == KDialogBase::Cancel)
333 {
334 return false;
335 }
336 if (dontAgain)
337 {
338 if (res == KDialogBase::No)
339 {
340 m_sessionManager->setSwitchOption(KateSessionManager::SWITCH_DISCARD);
341 }
342 else
343 {
344 m_sessionManager->setSwitchOption(KateSessionManager::SWITCH_SAVE);
345 }
346 }
347 if (res == KDialogBase::Yes)
348 {
349 saveSessions = true;
350 }
351 }
352
353 if (saveSessions)
354 {
355 m_sessionManager->saveActiveSession();
356 }
357 m_sessionManager->saveConfig(saveSessions);
358 return true;
359}
360
361void KateApp::reparse_config()
362{
363 emit optionsChanged();
364}
365
366KatePluginManager *KateApp::pluginManager()
367{
368 return m_pluginManager;
369}
370
371KateDocManager *KateApp::documentManager ()
372{
373 return m_docManager;
374}
375
376KateSessionManager* KateApp::sessionManager()
377{
378 return m_sessionManager;
379}
380
381bool KateApp::openURL (const KURL &url, const TQString &encoding, bool isTempFile)
382{
383 KateMainWindow *mainWindow = activeMainWindow ();
384
385 if (!mainWindow)
386 return false;
387
388 TQTextCodec *codec = encoding.isEmpty() ? 0 : TQTextCodec::codecForName(encoding.latin1());
389
390 kdDebug () << "OPEN URL "<< encoding << endl;
391
392 // this file is no local dir, open it, else warn
393 bool noDir = !url.isLocalFile() || !TQDir (url.path()).exists();
394
395 if (noDir)
396 {
397 // open a normal file
398 if (codec)
399 mainWindow->viewManager()->openURL( url, codec->name(), true, isTempFile );
400 else
401 mainWindow->viewManager()->openURL( url, TQString::null, true, isTempFile );
402 }
403 else
404 KMessageBox::sorry( mainWindow,
405 i18n("The file '%1' could not be opened: it is not a normal file, it is a folder.").arg(url.pathOrURL()) );
406
407 return true;
408}
409
410bool KateApp::setCursor (int line, int column)
411{
412 KateMainWindow *mainWindow = activeMainWindow ();
413
414 if (!mainWindow)
415 return false;
416
417 mainWindow->viewManager()->activeView ()->setCursorPosition (line, column);
418
419 return true;
420}
421
422bool KateApp::openInput (const TQString &text)
423{
424 activeMainWindow()->viewManager()->openURL( "", "", true );
425
426 if (!activeMainWindow()->viewManager()->activeView ())
427 return false;
428
429 activeMainWindow()->viewManager()->activeView ()->getDoc()->setText (text);
430
431 return true;
432}
433
434KateMainWindow *KateApp::newMainWindow (TDEConfig *sconfig, const TQString &sgroup)
435{
436 KateMainWindow *mainWindow = new KateMainWindow (sconfig, sgroup);
437 m_mainWindows.push_back (mainWindow);
438
439 if ((mainWindows() > 1) && m_mainWindows[m_mainWindows.count()-2]->viewManager()->activeView())
440 mainWindow->viewManager()->activateView ( m_mainWindows[m_mainWindows.count()-2]->viewManager()->activeView()->getDoc()->documentNumber() );
441 else if ((mainWindows() > 1) && (m_docManager->documents() > 0))
442 mainWindow->viewManager()->activateView ( (m_docManager->document(m_docManager->documents()-1))->documentNumber() );
443 else if ((mainWindows() > 1) && (m_docManager->documents() < 1))
444 mainWindow->viewManager()->openURL ( KURL() );
445
446 mainWindow->show ();
447
448 return mainWindow;
449}
450
451void KateApp::removeMainWindow (KateMainWindow *mainWindow)
452{
453 m_mainWindows.remove (mainWindow);
454}
455
456KateMainWindow *KateApp::activeMainWindow ()
457{
458 if (m_mainWindows.isEmpty())
459 return 0;
460
461 int n = m_mainWindows.findIndex ((KateMainWindow *)activeWindow());
462
463 if (n < 0)
464 n=0;
465
466 return m_mainWindows[n];
467}
468
469uint KateApp::mainWindows () const
470{
471 return m_mainWindows.size();
472}
473
474KateMainWindow *KateApp::mainWindow (uint n)
475{
476 if (n < m_mainWindows.size())
477 return m_mainWindows[n];
478
479 return 0;
480}
KateApp
Kate Application This class represents the core kate application object.
Definition kateapp.h:43
KateApp::query_session_close
bool query_session_close()
to be called when the application is about to quit
Definition kateapp.cpp:312
KateApp::optionsChanged
void optionsChanged()
Emitted when the configuration has or may have been changed.
KateApp::reparse_config
void reparse_config()
called after the config dialog has been closed.
Definition kateapp.cpp:361
KateApp::application
Kate::Application * application()
accessor to the Kate::Application plugin interface
Definition kateapp.cpp:118
KateApp::newMainWindow
KateMainWindow * newMainWindow(TDEConfig *sconfig=0, const TQString &sgroup="")
window management
Definition kateapp.cpp:434
KateApp::shutdownKate
void shutdownKate(KateMainWindow *win)
kate shutdown
Definition kateapp.cpp:297
KateApp::mainWindow
KateMainWindow * mainWindow(uint n)
give back the window you want
Definition kateapp.cpp:474
KateApp::~KateApp
~KateApp()
application destructor
Definition kateapp.cpp:105
KateApp::self
static KateApp * self()
static accessor to avoid casting ;)
Definition kateapp.cpp:113
KateApp::documentManager
KateDocManager * documentManager()
accessor to document manager
Definition kateapp.cpp:371
KateApp::kateVersion
static TQString kateVersion(bool fullVersion=true)
Returns the current Kate version (X.Y) or (X.Y.Z)
Definition kateapp.cpp:127
KateApp::activeMainWindow
KateMainWindow * activeMainWindow()
give back current active main window can only be 0 at app start or exit
Definition kateapp.cpp:456
KateApp::pluginManager
KatePluginManager * pluginManager()
other accessors for global unique instances
Definition kateapp.cpp:366
KateApp::openURL
bool openURL(const KURL &url, const TQString &encoding, bool isTempFile)
some stuff for the dcop API
Definition kateapp.cpp:381
KateApp::KateApp
KateApp(TDECmdLineArgs *args)
constructors & accessor to app object + plugin interface for it
Definition kateapp.cpp:53
KateApp::mainWindows
uint mainWindows() const
give back number of existing main windows
Definition kateapp.cpp:469
KateApp::setCursor
bool setCursor(int line, int column)
position cursor in current active view
Definition kateapp.cpp:410
KateApp::openInput
bool openInput(const TQString &text)
helper to handle stdin input open a new document/view, fill it with the text given
Definition kateapp.cpp:422
KateApp::sessionManager
KateSessionManager * sessionManager()
accessor to session manager
Definition kateapp.cpp:376
KateApp::removeMainWindow
void removeMainWindow(KateMainWindow *mainWindow)
removes the mainwindow given, DOES NOT DELETE IT
Definition kateapp.cpp:451
KateSessionManager
The Kate session manager.
Definition katesession.h:177
KateSessionManager::saveActiveSession
void saveActiveSession()
Definition katesession.h:339
KateSessionManager::getSessionIdFromName
int getSessionIdFromName(const TQString &name)
Return the session id of the first session whose name matches the provided one.
Definition katesession.cpp:568
KateSessionManager::self
static KateSessionManager * self()
get a pointer to the unique KateSessionManager instance.
Definition katesession.cpp:321
KateSessionManager::newSession
int newSession(const TQString &sessionName=TQString::null, bool saveCurr=true)
Definition katesession.cpp:636
KateSessionManager::restoreLastSession
bool restoreLastSession()
Restore the last saved session.
Definition katesession.cpp:673
KateSessionManager::getSwitchOption
const int getSwitchOption()
Definition katesession.cpp:531
KateSessionManager::saveConfig
void saveConfig(bool saveSessions)
Save session manager info.
Definition katesession.cpp:481
KateSessionManager::getStartupOption
const int getStartupOption()
Definition katesession.cpp:524
KateSessionManager::activateSession
bool activateSession(int sessionId, bool saveCurr=true)
Activate the selected session.
Definition katesession.cpp:583
KateSessionManager::setSwitchOption
void setSwitchOption(int option)
Set the new session switch preference.
Definition katesession.cpp:538
Kate::Application
Interface to the application, beside some global methodes to access other objects like document/proje...
Definition application.h:39

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.8
This website is maintained by Timothy Pearson.