56
55
void Application::init()
59
57
_backgroundInstance = 0;
61
59
// check for compositing functionality
62
60
TerminalDisplay::setTransparencyEnabled( KWindowSystem::compositingActive() );
63
62
#if defined(Q_WS_MAC) && QT_VERSION >= 0x040600
64
63
// this ensures that Ctrl and Meta are not swapped, so CTRL-C and friends
65
64
// will work correctly in the terminal
66
65
setAttribute(Qt::AA_MacDontSwapCtrlAndMeta);
67
// KDE's menuBar()->isTopLevel() hasn't worked in a while.
68
// For now, put menus inside Konsole window; this also make
69
// the keyboard shortcut to show menus look reasonable.
70
setAttribute(Qt::AA_DontUseNativeMenuBar);
77
81
MainWindow* window = new MainWindow();
78
82
window->setSessionList( new ProfileList(true,window) );
80
connect( window , SIGNAL(newSessionRequest(Profile::Ptr,const QString&,ViewManager*)),
81
this , SLOT(createSession(Profile::Ptr,const QString&,ViewManager*)));
82
connect( window , SIGNAL(newSSHSessionRequest(Profile::Ptr,const KUrl&,ViewManager*)),
83
this , SLOT(createSSHSession(Profile::Ptr,const KUrl&,ViewManager*)));
84
connect( window , SIGNAL(newWindowRequest(Profile::Ptr,const QString&)),
85
this , SLOT(createWindow(Profile::Ptr,const QString&)) );
86
connect( window->viewManager() , SIGNAL(viewDetached(Session*)) , this , SLOT(detachView(Session*)) );
84
connect( window , SIGNAL(newSessionRequest(Profile::Ptr,QString,ViewManager*)),
85
this , SLOT(createSession(Profile::Ptr,QString,ViewManager*)));
86
connect( window , SIGNAL(newSSHSessionRequest(Profile::Ptr,KUrl,ViewManager*)),
87
this , SLOT(createSSHSession(Profile::Ptr,KUrl,ViewManager*)));
88
connect( window , SIGNAL(newWindowRequest(Profile::Ptr,QString)),
89
this , SLOT(createWindow(Profile::Ptr,QString)) );
90
connect( window->viewManager() , SIGNAL(viewDetached(Session*)) ,
91
this , SLOT(detachView(Session*)) );
133
138
// default profile to be changed
134
139
processProfileChangeArgs(args,window);
136
if ( !args->isSet("tabs-from-file") ) {
141
if ( !args->isSet("tabs-from-file") )
137
143
// create new session
138
144
Session* session = createSession(window->defaultProfile(),
141
147
if ( !args->isSet("close") ) {
142
148
session->setAutoClose(false);
151
// run a custom command, don't store it in the default profile.
152
// Otherwise it will become the default for new tabs.
153
if ( args->isSet("e") )
155
QStringList arguments;
156
arguments << args->getOption("e");
157
for ( int i = 0 ; i < args->count() ; i++ )
158
arguments << args->arg(i);
160
QString exec = args->getOption("e");
161
if (exec.startsWith(QLatin1String("./")))
162
exec = QDir::currentPath() + exec.mid(1);
164
session->setProgram(exec);
165
session->setArguments(arguments);
146
170
// create new session(s) as described in file
147
171
processTabsFromFileArgs(args, window);
179
203
* ;; is the token separator
180
204
* # at the beginning of line results in line being ignored
181
205
* tokens are title:, command:, profile: (not used currently)
182
* Note that the title is static and the tab will close when the
206
* Note that the title is static and the tab will close when the
183
207
* command is complete (do not use --noclose). You can start new tabs.
185
209
title: This is the title;; command: ssh jupiter
236
260
QString command = tokens["command"];
237
261
QString profile = tokens["profile"]; // currently not used
239
// TODO: A lot of duplicate code below
263
// FIXME: A lot of duplicate code below
241
265
// Get the default profile
242
266
Profile::Ptr defaultProfile = window->defaultProfile();
253
277
newProfile->setProperty(Profile::Directory,args->getOption("workdir"));
255
279
if(!newProfile->isEmpty()) {
256
window->setDefaultProfile(newProfile);
280
window->setDefaultProfile(newProfile);
259
283
// Create the new session
260
284
Session* session = createSession(window->defaultProfile(), QString(), window->viewManager());
261
285
session->setTabTitleFormat(Session::LocalTabTitle, title);
267
291
if (!window->testAttribute(Qt::WA_Resized)) {
268
292
window->resize(window->sizeHint());
271
295
// Reset the profile to default. Otherwise, the next manually
272
296
// created tab would have the command above!
273
297
newProfile = Profile::Ptr(new Profile(defaultProfile));
274
298
newProfile->setHidden(true);
275
window->setDefaultProfile(newProfile);
299
window->setDefaultProfile(newProfile);
279
303
MainWindow* Application::processWindowArgs(KCmdLineArgs* args)
327
void Application::processProfileChangeArgs(KCmdLineArgs* args,MainWindow* window)
351
void Application::processProfileChangeArgs(KCmdLineArgs* args,MainWindow* window)
329
353
Profile::Ptr defaultProfile = window->defaultProfile();
330
354
if (!defaultProfile)
331
355
defaultProfile = SessionManager::instance()->defaultProfile();
332
356
Profile::Ptr newProfile = Profile::Ptr(new Profile(defaultProfile));
333
357
newProfile->setHidden(true);
334
// run a custom command
335
if ( args->isSet("e") )
337
QStringList arguments;
338
arguments << args->getOption("e");
339
for ( int i = 0 ; i < args->count() ; i++ )
340
arguments << args->arg(i);
342
QString exec = args->getOption("e");
343
if (exec.startsWith(QLatin1String("./")))
344
exec = QDir::currentPath() + exec.mid(1);
345
newProfile->setProperty(Profile::Command,exec);
346
newProfile->setProperty(Profile::Arguments,arguments);
349
359
// change the initial working directory
350
360
if( args->isSet("workdir") )
355
365
// temporary changes to profile options specified on the command line
356
foreach( const QString &value , args->getOptionList("p") )
366
foreach( const QString& value , args->getOptionList("p") )
358
368
ProfileCommandParser parser;
360
370
QHashIterator<Profile::Property,QVariant> iter(parser.parse(value));
361
371
while ( iter.hasNext() )
364
374
newProfile->setProperty(iter.key(),iter.value());
368
378
if (!newProfile->isEmpty())
370
window->setDefaultProfile(newProfile);
380
window->setDefaultProfile(newProfile);
374
384
void Application::startBackgroundMode(MainWindow* window)
376
if ( _backgroundInstance )
381
KAction* action = new KAction(window);
382
KShortcut shortcut = action->shortcut();
383
action->setObjectName( QLatin1String("Konsole Background Mode" ));
384
//TODO - Customizable key sequence for this
385
action->setGlobalShortcut( KShortcut(QKeySequence(Qt::Key_F12)) );
387
_backgroundInstance = window;
389
connect( action , SIGNAL(triggered()) , this , SLOT(toggleBackgroundInstance()) );
386
if ( _backgroundInstance )
391
KAction* action = new KAction(window);
392
action->setObjectName( QLatin1String("Konsole Background Mode" ));
393
//TODO - Customizable key sequence for this
394
action->setGlobalShortcut( KShortcut(QKeySequence(Qt::Key_F12)) );
396
_backgroundInstance = window;
398
connect( action , SIGNAL(triggered()) , this , SLOT(toggleBackgroundInstance()) );
392
401
void Application::toggleBackgroundInstance()
398
407
_backgroundInstance->show();
399
408
// ensure that the active terminal display has the focus.
400
// without this, an odd problem occurred where the focus widgetwould change
401
// each time the background instance was shown
409
// without this, an odd problem occurred where the focus widget would change
410
// each time the background instance was shown
402
411
_backgroundInstance->viewManager()->activeView()->setFocus();
406
415
_backgroundInstance->hide();
410
419
Application::~Application()
412
421
SessionManager::instance()->closeAll();
413
SessionManager::instance()->saveState();
422
SessionManager::instance()->saveSettings();
416
425
void Application::detachView(Session* session)
431
Session* Application::createSession(Profile::Ptr profile, const QString& directory , ViewManager* view)
440
Session* Application::createSession(Profile::Ptr profile, const QString& directory , ViewManager* viewManager)
434
443
profile = SessionManager::instance()->defaultProfile();
439
448
session->setInitialWorkingDirectory(directory);
441
450
// create view before starting the session process so that the session doesn't suffer
442
// a change in terminal size right after the session starts. some applications such as GNU Screen
451
// a change in terminal size right after the session starts. Some applications such as GNU Screen
443
452
// and Midnight Commander don't like this happening
444
view->createView(session);
453
viewManager->createView(session);
450
Session* Application::createSSHSession(Profile::Ptr profile, const KUrl& url, ViewManager* view)
458
Session* Application::createSSHSession(Profile::Ptr profile, const KUrl& url, ViewManager* viewManager)
453
461
profile = SessionManager::instance()->defaultProfile();
466
474
// create view before starting the session process so that the session doesn't suffer
467
475
// a change in terminal size right after the session starts. some applications such as GNU Screen
468
476
// and Midnight Commander don't like this happening
469
view->createView(session);
477
viewManager->createView(session);