konsole.cpp 72.8 KB
Newer Older
1
2
/* ---------------------------------------------------------------------- */
/*                                                                        */
3
/* [konsole.cpp]                   Konsole                                */
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*                                                                        */
/* ---------------------------------------------------------------------- */
/*                                                                        */
/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de>        */
/*                                                                        */
/* This file is part of Konsole, an X terminal.                           */
/*                                                                        */
/* The material contained in here more or less directly orginates from    */
/* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */
/*                                                                        */
/* ---------------------------------------------------------------------- */


/*! \class Konsole

    \brief Konsole's main class and program

    The class Konsole handles the application level. Mainly, it is responsible
    for the configuration, taken from several files, from the command line
    and from the user. It hardly does anything interesting.
    Everything is created as late as possible to make it startup fast.
*/

/*TODO:
  - allow to set codec
  - officially declare this file to be hacked to death. ;^)
  - merge into konsole_part.
*/

/*STATE:

  konsole/kwin session management, parts stuff, config, menues
  are all in bad need for a complete rewrite.

  While the emulation core (TEmulation, TEVt102, TEScreen, TEWidget)
  are pretty stable, the upper level material has certainly drifted.

  Everything related to Sessions, Configuration has to be redesigned.
  It seems that the konsole now falls apart into individual sessions
  and a session manager.

Time to start a requirement list.

  - Rework the Emulation::setConnect logic.
    Together with session changing (Shift-Left/Right, Ctrl-D) it allows
    key events to propagate to other sessions.

  - Get rid of the unconfigurable, uncallable initial "Konsole" session.
    Leads to code replication in konsole_part and other issues. Related
    to the booting of konsole, thus matter of redesign.
*/

/*FIXME:
  - All the material in here badly sufferes from the fact that the
    configuration can originate from many places, so all is duplicated
    and falls out of service. Especially the command line is badly broken.
    The sources are:
    - command line
    - menu
    - configuration files
    - other events (e.g. resizing)
    We have to find a single-place method to better maintain this.
  - In general, the material contained in here and in session.C
    should be rebalanced. Much more material now comes from configuration
    files and the overall routines should better respect this.
  - Font+Size list should go to a configuration file, too.
  - Controlling the widget is currently done by individual attributes.
    This lead to quite some amount of flicker when a whole bunch of
    attributes has to be set, e.g. in session swapping.
*/

#include <config.h>

#include <ktoolbarbutton.h>

#include <qspinbox.h>
#include <qcheckbox.h>
#include <qlayout.h>

#include <stdio.h>
#include <stdlib.h>

86
87
#include <kfiledialog.h>

88
#include <kfontdialog.h>
89
#include <kstandarddirs.h>
90
91
92
93
94
95
96
97
#include <qpainter.h>
#include <kmenubar.h>
#include <kmessagebox.h>
#include <krootpixmap.h>
#include <kstdaction.h>
#include <klineeditdlg.h>
#include <kdebug.h>
#include <kipc.h>
Stephan Binner's avatar
Stephan Binner committed
98
#include <dcopclient.h>
99
100
101
102
103
104
105
106
107
108

#include <klocale.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <signal.h>
#include <dirent.h>
#include <fcntl.h>
#include <assert.h>

#include <kiconloader.h>
109
#include <kstringhandler.h>
Stephan Binner's avatar
Stephan Binner committed
110
#include <ktip.h>
111
112

#include "konsole.h"
113
#include <netwm.h>
114
115
116

#define KONSOLEDEBUG    kdDebug(1211)

117
// KonsoleFontSelectAction is now also used for selectSize!
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
class KonsoleFontSelectAction : public KSelectAction {
public:
    KonsoleFontSelectAction(const QString &text, int accel,
                            const QObject* receiver, const char* slot,
                            QObject* parent, const char* name = 0 )
        : KSelectAction(text, accel, receiver, slot, parent, name) {}
    KonsoleFontSelectAction( const QString &text, const QIconSet& pix,
                             int accel, const QObject* receiver,
                             const char* slot, QObject* parent,
                             const char* name = 0 )
        : KSelectAction(text, pix, accel, receiver, slot, parent, name) {}

    virtual void slotActivated( int index );
};

void KonsoleFontSelectAction::slotActivated(int index) {
    // emit even if it's already activated
    if (currentItem() == index) {
        KSelectAction::slotActivated();
        return;
    } else {
        KSelectAction::slotActivated(index);
    }
}

template class QPtrDict<TESession>;
template class QIntDict<KSimpleConfig>;
template class QPtrDict<KRadioAction>;


const char *fonts[] = {
149
 "13",
150
151
152
153
154
 "7",   // tiny font, never used
 "10",  // small font
 "13",  // medium
 "15",  // large
 "20", // huge
155
156
157
 "-misc-console-medium-r-normal--16-160-72-72-c-160-iso10646-1", // "Linux"
 "-misc-fixed-medium-r-normal--15-140-75-75-c-90-iso10646-1",    // "Unicode"
 };
158
159
#define TOPFONT (sizeof(fonts)/sizeof(char*))
#define DEFAULTFONT TOPFONT
160
161
162
163

#define DEFAULT_HISTORY_SIZE 1000


164
Konsole::Konsole(const char* name, const QString& _program, QStrList & _args, int histon,
165
                 bool menubaron, bool toolbaron, bool frameon, bool scrollbaron, const QString &_icon,
166
                 const QString &_title, QCString type, const QString &_term, bool b_inRestore)
Stephan Binner's avatar
Stephan Binner committed
167
:KMainWindow(0, name),
168
DCOPObject( "konsole" )
169
,m_defaultSession(0)
170
,m_defaultSessionFilename("")
171
172
,te(0)
,se(0)
173
,se_previous(0)
174
175
176
,m_initialSession(0)
,colors(0)
,rootxpm(0)
177
,kWinModule(0)
178
179
,menubar(0)
,statusbar(0)
180
181
182
,m_session(0)
,m_edit(0)
,m_view(0)
183
184
185
186
187
188
,m_options(0)
,m_schema(0)
,m_keytab(0)
,m_toolbarSessionsCommands(0)
,m_signals(0)
,m_help(0)
189
,m_rightButton(0)
190
191
,monitorActivity(0)
,monitorSilence(0)
192
,masterMode(0)
193
194
195
196
197
198
199
,showToolbar(0)
,showMenubar(0)
,showScrollbar(0)
,selectSize(0)
,selectFont(0)
,selectScrollbar(0)
,selectBell(0)
200
,m_clearHistory(0)
201
,m_findHistory(0)
202
,m_saveHistory(0)
203
204
,m_moveSessionLeft(0)
,m_moveSessionRight(0)
205
206
,m_finddialog(0)
,m_find_pattern("")
207
208
209
210
211
212
,cmd_serial(0)
,cmd_first_screen(-1)
,n_keytab(0)
,n_defaultKeytab(0)
,n_render(0)
,curr_schema(0)
213
,wallpaperSource(0)
214
,sessionIdCounter(0)
215
216
217
218
219
,s_kconfigSchema("")
,b_fullscreen(false)
,m_menuCreated(false)
,skip_exit_query(false) // used to skip the query when closed by the session management
,b_warnQuit(false)
220
,m_histSize(DEFAULT_HISTORY_SIZE)
221
222
223
224
225
{
  isRestored = b_inRestore;
  connect( kapp,SIGNAL(backgroundChanged(int)),this, SLOT(slotBackgroundChanged(int)));

  no2command.setAutoDelete(true);
Stephan Binner's avatar
Stephan Binner committed
226
  no2tempFile.setAutoDelete(true);
227
  no2filename.setAutoDelete(true);
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
  menubar = menuBar();

  // create terminal emulation framework ////////////////////////////////////

  te = new TEWidget(this);
  //KONSOLEDEBUG<<"Konsole ctor() after new TEWidget() "<<time.elapsed()<<" msecs elapsed"<<endl;
  te->setMinimumSize(150,70);    // allow resizing, cause resize in TEWidget
  // we need focus so that the auto-hide cursor feature works (Carsten)
  // but a part shouldn't force that it receives the focus, so we do it here (David)
  te->setFocus();

  // Transparency handler ///////////////////////////////////////////////////
  rootxpm = new KRootPixmap(te);
  //KONSOLEDEBUG<<"Konsole ctor() after new RootPixmap() "<<time.elapsed()<<" msecs elapsed"<<endl;

  // create applications /////////////////////////////////////////////////////

  setCentralWidget(te);

  makeBasicGUI();
  //KONSOLEDEBUG<<"Konsole ctor() after makeBasicGUI "<<time.elapsed()<<" msecs elapsed"<<endl;

  colors = new ColorSchemaList();
  colors->checkSchemas();

  KeyTrans::loadAll();
254
  //KONSOLEDEBUG<<"Konsole ctor() after KeyTrans::loadAll() "<<time.elapsed()<<" msecs elapsed"<<endl;
255
256
257
258
259
260
261
262
263
264

  // read and apply default values ///////////////////////////////////////////
  resize(321, 321); // Dummy.
  QSize currentSize = size();
  KConfig * config = KGlobal::config();
  config->setDesktopGroup();
  applyMainWindowSettings(config);
  if (currentSize != size())
     defaultSize = size();
  //KONSOLEDEBUG<<"Konsole ctor(): readProps() type="<<type<<endl;
265
266

  KSimpleConfig *co;
267
268
269
270
  if (!type.isEmpty())
    setDefaultSession(type+".desktop");
  co = defaultSession();

271
272
  co->setDesktopGroup();
  QString schema = co->readEntry("Schema");
273
  //KONSOLEDEBUG << "my Looking for schema " << schema << endl;
274
  readProperties(config, schema, false);
275
276
  //KONSOLEDEBUG<<"Konsole ctor() after readProps "<<time.elapsed()<<" msecs elapsed"<<endl;
  //KONSOLEDEBUG<<"Konsole ctor(): toolbar"<<endl;
277
278
279

  if (!menubaron)
    menubar->hide();
280
281
  if (!toolbaron)
    toolBar()->hide();
Stephan Binner's avatar
Stephan Binner committed
282
  toolBar()->setText(i18n("Session Toolbar"));
283
  if (!frameon) {
284
    b_framevis=false;
285
286
287
288
289
290
    te->setFrameStyle( QFrame::NoFrame );
  }
  if (!scrollbaron) {
    n_scroll = TEWidget::SCRNONE;
    te->setScrollbarLocation(TEWidget::SCRNONE);
  }
291
292
  if (!histon)
    b_histEnabled=false;
293
294
295
296

  // activate and run first session //////////////////////////////////////////
  // FIXME: this slows it down if --type is given, but prevents a crash (malte)
  //KONSOLEDEBUG << "Konsole pgm: " << _program << endl;
297
  newSession(co, _program, _args, _term, _icon, _title);
298
299
300

  //KONSOLEDEBUG<<"Konsole ctor() ends "<<time.elapsed()<<" msecs elapsed"<<endl;
  //KONSOLEDEBUG<<"Konsole ctor(): done"<<endl;
Stephan Binner's avatar
Stephan Binner committed
301

302
  kapp->dcopClient()->setDefaultObject( "konsole" );
303
304
305
306
307
308
309
310
}

Konsole::~Konsole()
{
//FIXME: close all session properly and clean up
    // Delete the session if isn't in the session list any longer.
    sessions.setAutoDelete(true);

Stephan Binner's avatar
Stephan Binner committed
311
    resetScreenSessions();
312
313
314
    if (no2command.isEmpty())
       delete m_defaultSession;

315
316
    delete colors;
    colors=0;
317

318
    delete kWinModule;
319
320
321
322
323
324
    kWinModule = 0;
}

void Konsole::run() {
   kWinModule = new KWinModule();
   connect( kWinModule,SIGNAL(currentDesktopChanged(int)), this,SLOT(currentDesktopChanged(int)) );
325
326
}

Stephan Binner's avatar
Stephan Binner committed
327
328
329
330
331
332
333
334
335
336
void Konsole::showTip()
{
   KTipDialog::showTip(this,QString::null,true);
}

void Konsole::showTipOnStart()
{
   KTipDialog::showTip(this);
}

337
338
339
340
341
342
343
344
345
/* ------------------------------------------------------------------------- */
/*  Make menu                                                                */
/* ------------------------------------------------------------------------- */

void Konsole::makeGUI()
{
   if (m_menuCreated) return;
   //not longer needed
   disconnect(m_toolbarSessionsCommands,SIGNAL(aboutToShow()),this,SLOT(makeGUI()));
346
   disconnect(m_session,SIGNAL(aboutToShow()),this,SLOT(makeGUI()));
347
348
   disconnect(m_options,SIGNAL(aboutToShow()),this,SLOT(makeGUI()));
   disconnect(m_help,SIGNAL(aboutToShow()),this,SLOT(makeGUI()));
349
   disconnect(m_rightButton,SIGNAL(aboutToShow()),this,SLOT(makeGUI()));
350
351
   disconnect(m_edit,SIGNAL(aboutToShow()),this,SLOT(makeGUI()));
   disconnect(m_view,SIGNAL(aboutToShow()),this,SLOT(makeGUI()));
352
353
   //KONSOLEDEBUG<<"Konsole::makeGUI()"<<endl;
   connect(m_toolbarSessionsCommands,SIGNAL(aboutToShow()),this,SLOT(loadScreenSessions()));
354
   connect(m_session,SIGNAL(aboutToShow()),this,SLOT(loadScreenSessions()));
355
356
357
358
359
   m_menuCreated=true;

   // Remove the empty separator Qt inserts if the menu is empty on popup,
   // not sure if this will be "fixed" in Qt, for now use this hack (malte)
   if(!(isRestored)) {
360
     if (sender() && sender()->inherits("QPopupMenu") &&
361
362
363
       static_cast<const QPopupMenu *>(sender())->count() == 1)
       const_cast<QPopupMenu *>(static_cast<const QPopupMenu *>(sender()))->removeItemAt(0);
       }
364
365
366

   KActionCollection* actions = new KActionCollection(this);

367
368
   // Send Signal Menu -------------------------------------------------------------
   m_signals = new KPopupMenu(this);
Stephan Binner's avatar
Stephan Binner committed
369
370
371
372
373
374
   m_signals->insertItem( i18n( "&Suspend Task" )   + " (STOP)", SIGSTOP);
   m_signals->insertItem( i18n( "&Continue Task" )  + " (CONT)", SIGCONT);
   m_signals->insertItem( i18n( "&Hangup" )         + " (HUP)", SIGHUP);
   m_signals->insertItem( i18n( "&Interrupt Task" ) + " (INT)", SIGINT);
   m_signals->insertItem( i18n( "&Terminate Task" ) + " (TERM)", SIGTERM);
   m_signals->insertItem( i18n( "&Kill Task" )      + " (KILL)", SIGKILL);
375
   connect(m_signals, SIGNAL(activated(int)), SLOT(sendSignal(int)));
376

377
   // Edit Menu ----------------------------------------------------------------
378
   KAction *pasteClipboard = new KAction(i18n("&Paste"), "editpaste", 0,
379
     te, SLOT(pasteClipboard()), actions);
380
381
   pasteClipboard->plug(m_edit);

382
383
384
385
   m_edit->setCheckable(TRUE);
   m_edit->insertItem( i18n("&Send Signal"), m_signals );

   m_edit->insertSeparator();
386
   m_findHistory = new KAction(i18n("&Find in History..."), "find", 0, this,
387
                                       SLOT(slotFindHistory()), actions);
388
389
390
   m_findHistory->setEnabled( se->history().isOn() );
   m_findHistory->plug(m_edit);

391
   m_saveHistory = new KAction(i18n("S&ave History As..."), "filesaveas", 0, this,
392
                                       SLOT(slotSaveHistory()), actions);
393
394
395
   m_saveHistory->setEnabled( se->history().isOn() );
   m_saveHistory->plug(m_edit);

396
   m_edit->insertSeparator();
397
   m_clearHistory = new KAction(i18n("Clear &History"), "history_clear", 0, this,
398
                                       SLOT(slotClearHistory()), actions);
399
400
401
   m_clearHistory->setEnabled( se->history().isOn() );
   m_clearHistory->plug(m_edit);

402
   KAction *clearAllSessionHistories = new KAction(i18n("Clear All H&istories"), "history_clear", 0,
403
     this, SLOT(slotClearAllSessionHistories()), actions);
404
405
406
   clearAllSessionHistories->plug(m_edit);

   // View Menu
407
   KAction *renameSession = new KAction(i18n("&Rename Session..."), 0, this,
408
                                        SLOT(slotRenameSession()), actions);
409
   renameSession->plug(m_view);
410

411
   m_view->insertSeparator();
412
   monitorActivity = new KToggleAction ( i18n( "Monitor for &Activity" ), "idea", 0, this,
413
                                     SLOT( slotToggleMonitor() ), this );
414
   monitorActivity->plug ( m_view );
415

416
   monitorSilence = new KToggleAction ( i18n( "Monitor for &Silence" ), "ktip", 0, this,
417
                                     SLOT( slotToggleMonitor() ), this );
418
   monitorSilence->plug ( m_view );
419

420
   masterMode = new KToggleAction ( i18n( "Send &Input to All Sessions" ), "remote", 0, this,
421
422
423
                                     SLOT( slotToggleMasterMode() ), this );
   masterMode->plug ( m_view );

424
   m_view->insertSeparator();
425
   m_moveSessionLeft = new KAction(i18n("&Move Session Left"), QApplication::reverseLayout() ? "forward" : "back", 0, this,
426
                                        SLOT(moveSessionLeft()), actions);
427
   m_moveSessionLeft->setEnabled( false );
428
   m_moveSessionLeft->plug(m_view);
429

430
   m_moveSessionRight = new KAction(i18n("M&ove Session Right"), QApplication::reverseLayout() ? "back" : "forward", 0, this,
431
                                        SLOT(moveSessionRight()), actions);
432
   m_moveSessionRight->setEnabled( false );
433
   m_moveSessionRight->plug(m_view);
434

435
   m_view->insertSeparator();
436
437
//   KRadioAction *ra = session2action.find(m_initialSession);
   KRadioAction *ra = session2action.find(se);
438
   if (ra!=0) ra->plug(m_view);
439
440
441
442
443
444
445
446
447
448
449
450
451
452

   // Schema Options Menu -----------------------------------------------------
   m_schema = new KPopupMenu(this);
   m_schema->setCheckable(TRUE);
   connect(m_schema, SIGNAL(activated(int)), SLOT(schema_menu_activated(int)));
   connect(m_schema, SIGNAL(aboutToShow()), SLOT(schema_menu_check()));

   // Keyboard Options Menu ---------------------------------------------------
   m_keytab = new KPopupMenu(this);
   m_keytab->setCheckable(TRUE);
   connect(m_keytab, SIGNAL(activated(int)), SLOT(keytab_menu_activated(int)));

   //options menu
   // Menubar on/off
453
   showMenubar = new KToggleAction ( i18n( "Show &Menubar" ), "showmenu", 0, this,
454
                                     SLOT( slotToggleMenubar() ), actions );
455
456
457
458
   showMenubar->plug ( m_options );

   // Toolbar on/off
   showToolbar = new KToggleAction ( i18n( "Show &Toolbar" ), 0, this,
459
                                     SLOT( slotToggleToolbar() ), actions );
460
461
462
   showToolbar->plug(m_options);

   // Scrollbar
Stephan Binner's avatar
Stephan Binner committed
463
   selectScrollbar = new KSelectAction(i18n("Sc&rollbar"), 0, this,
464
                                       SLOT(slotSelectScrollbar()), actions);
465
466
467
468
469
470
   QStringList scrollitems;
   scrollitems << i18n("&Hide") << i18n("&Left") << i18n("&Right");
   selectScrollbar->setItems(scrollitems);
   selectScrollbar->plug(m_options);

   // Fullscreen
471
   m_options->insertSeparator();
472
473
474
475
   m_options->insertItem( SmallIconSet( "window_fullscreen" ), i18n("F&ull-Screen"), 5);
   m_options->setItemChecked(5,b_fullscreen);
   m_options->insertSeparator();

476
477
   // Select Bell
   selectBell = new KSelectAction(i18n("&Bell"), SmallIconSet( "bell"), 0 , this,
478
                                  SLOT(slotSelectBell()), actions);
479
480
481
482
483
484
485
   QStringList bellitems;
   bellitems << i18n("&None")
             << i18n("&System Notification")
             << i18n("&Visible Bell");
   selectBell->setItems(bellitems);
   selectBell->plug(m_options);

486
   // Select font
Stephan Binner's avatar
Stephan Binner committed
487
   selectFont = new KonsoleFontSelectAction( i18n( "&Font" ),
488
          SmallIconSet( "text" ), 0, this, SLOT(slotSelectFont()), actions);
489
490
491
492
493
494
495
496
   QStringList it;
   it << i18n("&Normal")
      << i18n("&Tiny")
      << i18n("&Small")
      << i18n("&Medium")
      << i18n("&Large")
      << i18n("&Huge")
      << ""
Stephan Binner's avatar
Stephan Binner committed
497
      << i18n("L&inux")
498
499
500
501
502
503
504
505
506
507
508
      << i18n("&Unicode")
      << ""
      << i18n("&Custom...");
   selectFont->setItems(it);
   selectFont->plug(m_options);

   m_options->insertItem( SmallIconSet( "key_bindings" ), i18n( "&Keyboard" ), m_keytab );

   // Schema
   m_options->insertItem( SmallIconSet( "colorize" ), i18n( "Sch&ema" ), m_schema);

509
   // Select size
510
   selectSize = new KonsoleFontSelectAction(i18n("S&ize"), 0, this,
511
                                  SLOT(slotSelectSize()), actions);
512
513
514
515
516
   QStringList sizeitems;
   sizeitems << i18n("40x15 (&Small)")
      << i18n("80x24 (&VT100)")
      << i18n("80x25 (&IBM PC)")
      << i18n("80x40 (&XTerm)")
517
518
519
      << i18n("80x52 (IBM V&GA)")
      << ""
      << i18n("&Custom...");
520
521
522
   selectSize->setItems(sizeitems);
   selectSize->plug(m_options);

523
   KAction *historyType = new KAction(i18n("&History..."), "history", 0, this,
524
                                      SLOT(slotHistoryType()), actions);
525
   historyType->plug(m_options);
526
527

   m_options->insertSeparator();
528

529
   KAction *save_settings = KStdAction::saveOptions(this, SLOT(slotSaveSettings()), actions);
530
531
532
   save_settings->plug(m_options);

   m_options->insertSeparator();
533

534
   KAction *configure = KStdAction::preferences(this, SLOT(slotConfigure()), actions);
535
   configure->plug(m_options);
536

537
538
   m_options->insertTearOffHandle();

539
540
   connect(m_options, SIGNAL(activated(int)), SLOT(opt_menu_activated(int)));
   m_options->installEventFilter( this );
541

Stephan Binner's avatar
Stephan Binner committed
542
   //help menu
543
   m_help->setAccel(QKeySequence(),m_help->idAt(0));
Stephan Binner's avatar
Stephan Binner committed
544
545
546
   m_help->insertSeparator(1);
   m_help->insertItem(i18n("&Tip of the Day..."), this, SLOT(showTip()), 0, -1, 2);

547
548
549
   //the different session types
   loadSessionCommands();
   loadScreenSessions();
550
551
552

   m_session->insertSeparator();
   KAction *closeSession = new KAction(i18n("&Close Session"), "fileclose", 0, this,
553
                                        SLOT(closeCurrentSession()), actions);
554
   closeSession->plug(m_session);
555

556
557
   m_session->insertSeparator();
   m_session->insertItem( SmallIconSet( "exit" ), i18n("&Quit"), this, SLOT( close() ) );
558
559


560
   connect(m_session, SIGNAL(activated(int)), SLOT(newSession(int)));
561

562
563
564
565
   // Right mouse button menu
   showMenubar->plug ( m_rightButton );
   m_rightButton->insertSeparator();
   pasteClipboard->plug(m_rightButton);
566
567
   m_rightButton->insertItem(i18n("&Send Signal"), m_signals);

568
   m_rightButton->insertSeparator();
569
   renameSession->plug(m_rightButton);
570
   m_rightButton->insertItem(i18n("S&ettings"), m_options);
571
   m_rightButton->insertSeparator();
572
   closeSession->plug(m_rightButton );
573
574
575
   m_rightButton->insertTearOffHandle();


576
577
578
579
   delete colors;
   colors = new ColorSchemaList();
   //KONSOLEDEBUG<<"Konsole::makeGUI(): curr_schema "<<curr_schema<<" path: "<<s_schema<<endl;
   colors->checkSchemas();
Alexander Neundorf's avatar
   
Alexander Neundorf committed
580
   colors->sort();
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
   //KONSOLEDEBUG<<"Konsole::makeGUI() updateSchemas()"<<endl;
   updateSchemaMenu();
   ColorSchema *sch=colors->find(s_schema);
   //KONSOLEDEBUG<<"Konsole::makeGUI(): curr_schema "<<curr_schema<<" path: "<<s_schema<<endl;
   if (sch)
        curr_schema=sch->numb();
   else
        curr_schema = 0;
   for (uint i=0; i<m_schema->count(); i++)
      m_schema->setItemChecked(i,false);

   m_schema->setItemChecked(curr_schema,true);
//   m_initialSession->setSchemaNo(curr_schema);
   while (se == NULL) {}
   se->setSchemaNo(curr_schema);

   // insert keymaps into menu
   //FIXME: sort
   for (int i = 0; i < KeyTrans::count(); i++)
   {
      KeyTrans* ktr = KeyTrans::find(i);
      assert( ktr );
      m_keytab->insertItem(ktr->hdr(),ktr->numb());
   }
   applySettingsToGUI();
   isRestored = false;
};

void Konsole::makeBasicGUI()
{
  //KONSOLEDEBUG<<"Konsole::makeBasicGUI()"<<endl;
  KToolBarPopupAction *newsession = new KToolBarPopupAction(i18n("&New"), "filenew",
                0 , this, SLOT(newSession()),this, KStdAction::stdName(KStdAction::New));
  newsession->plug(toolBar());
  toolBar()->insertLineSeparator();
  m_toolbarSessionsCommands = newsession->popupMenu();
617
  connect(m_toolbarSessionsCommands, SIGNAL(activated(int)), SLOT(newSessionToolbar(int)));
618
619
620

  toolBar()->setFullSize( TRUE );

621
622
623
  m_session = new KPopupMenu(this);
  m_edit = new KPopupMenu(this);
  m_view = new KPopupMenu(this);
624
625
  m_options = new KPopupMenu(this);
  m_help =  helpMenu(0, FALSE);
626
  m_rightButton = new KPopupMenu(this);
627
628
629
630
631
632
633

  // For those who would like to add shortcuts here, be aware that
  // ALT-key combinations are heavily used by many programs. Thus,
  // activating shortcuts here means deactivating them in the other
  // programs.

  connect(m_toolbarSessionsCommands,SIGNAL(aboutToShow()),this,SLOT(makeGUI()));
634
  connect(m_session,SIGNAL(aboutToShow()),this,SLOT(makeGUI()));
635
636
  connect(m_options,SIGNAL(aboutToShow()),this,SLOT(makeGUI()));
  connect(m_help,SIGNAL(aboutToShow()),this,SLOT(makeGUI()));
637
  connect(m_rightButton,SIGNAL(aboutToShow()),this,SLOT(makeGUI()));
638
639
  connect(m_edit,SIGNAL(aboutToShow()),this,SLOT(makeGUI()));
  connect(m_view,SIGNAL(aboutToShow()),this,SLOT(makeGUI()));
640

641
642
643
  menubar->insertItem(i18n("Session") , m_session);
  menubar->insertItem(i18n("Edit"), m_edit);
  menubar->insertItem(i18n("View"), m_view);
644
645
646
647
648
649
650
651
652
653
654
655
  menubar->insertItem(i18n("Settings"), m_options);
  menubar->insertItem(i18n("Help"), m_help);
};

/**
   Make menubar available via escape sequence (Default: Ctrl+Alt+m)
 */
void Konsole::activateMenu()
{
  menubar->activateItemAt(0);
  if ( !showMenubar->isChecked() ) {
    menubar->show();
656
    showMenubar->setChecked(true);
657
658
659
660
661
662
663
664
665
666
667
668
669
670
  }
}

/**
   Ask for Quit confirmation - Martijn Klingens
   Asks for confirmation if there are still open shells when the 'Warn on
   Quit' option is set.
 */
bool Konsole::queryClose()
{
   if ( (!skip_exit_query) && b_warnQuit)
   {
        if( (sessions.count()>1) &&
            ( KMessageBox::warningYesNo( this,
671
                                         i18n( "You have open sessions (besides the current one). "
Waldo Bastian's avatar
Waldo Bastian committed
672
                                               "These will be killed if you continue.\n"
673
674
675
                                               "Are you sure you want to quit?" ),
					 i18n("Are you sure you want to quit?"),
					 i18n("Quit"), i18n("Cancel") )
676

677
678
679
680
681
              == KMessageBox::No )
            ) {
            return false;
        }
    }
682
    // WABA: Don't close if there are any sessions left.
683
684
685
686
    // Tell them to go away.
    if (!skip_exit_query && sessions.count())
    {
        sessions.first();
687
        bool allOK=true;
688
        while(sessions.current())
689
        {
690
691
 	    if (!sessions.current()->sendSignal(SIGHUP))
              allOK=false;
692
693
            sessions.next();
        }
694
695
696
697
        if (!allOK)
          KMessageBox::information( this, i18n("Not all sessions could be closed. "
                                               "Please end all sessions running under other user IDs. "
                                               "In most cases typing 'exit' at the prompt will end them.") );
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
        return false;
    }
    // If there is no warning requested or required or if warnQuit is a NULL
    // pointer for some reason, just assume closing is safe
    return true;
}

/**
    sets application window to a size based on columns X lines of the te
    guest widget. Call with (0,0) for setting default size.
*/

void Konsole::setColLin(int columns, int lines)
{
  if ((columns==0) || (lines==0))
  {
    if (defaultSize.isEmpty()) // not in config file : set default value
    {
716
      defaultSize = sizeForCentralWidgetSize(te->calcSize(80,24));
717
718
719
720
      notifySize(24,80); // set menu items (strange arg order !)
    }
    resize(defaultSize);
  } else {
721
    resize(sizeForCentralWidgetSize(te->calcSize(columns, lines)));
722
723
724
725
726
727
728
729
730
731
732
733
734
735
    notifySize(lines,columns); // set menu items (strange arg order !)
  }
}

/* ------------------------------------------------------------------------- */
/*                                                                           */
/*                                                                           */
/* ------------------------------------------------------------------------- */

void Konsole::configureRequest(TEWidget* te, int state, int x, int y)
{
//printf("Konsole::configureRequest(_,%d,%d)\n",x,y);
   if (!m_menuCreated)
      makeGUI();
736
  ( (state & ControlButton) ? m_session :
737
                              m_rightButton  )
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
  ->popup(te->mapToGlobal(QPoint(x,y)));
}

/* ------------------------------------------------------------------------- */
/*                                                                           */
/* Configuration                                                             */
/*                                                                           */
/* ------------------------------------------------------------------------- */

void Konsole::saveGlobalProperties(KConfig* config)
{
  config->setGroup("global options");
  config->writeEntry("working directory", QDir::currentDirPath());
}

void Konsole::readGlobalProperties(KConfig* config)
{
  config->setGroup("global options");
  QDir::setCurrent(config->readEntry("working directory", QDir::currentDirPath()));
}

void Konsole::saveProperties(KConfig* config) {
  uint counter=0;
761
  uint active=0;
762
763
764
  QString key;
  config->setDesktopGroup();

765
  if (config != KGlobal::config())
766
767
768
769
770
  {
     // called by the session manager
     skip_exit_query = true;
     config->writeEntry("numSes",sessions.count());
     sessions.first();
771
     while(counter < sessions.count())
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
     {
        key = QString("Title%1").arg(counter);
        config->writeEntry(key, sessions.current()->Title());
        key = QString("Schema%1").arg(counter);
        config->writeEntry(key, sessions.current()->schemaNo());
        key = QString("Args%1").arg(counter);
        config->writeEntry(key, sessions.current()->getArgs());
        key = QString("Pgm%1").arg(counter);
        config->writeEntry(key, sessions.current()->getPgm());
        key = QString("Font%1").arg(counter);
        config->writeEntry(key, sessions.current()->fontNo());
        key = QString("Term%1").arg(counter);
        config->writeEntry(key, sessions.current()->Term());
        key = QString("KeyTab%1").arg(counter);
        config->writeEntry(key, sessions.current()->keymap());
787
788
        key = QString("Icon%1").arg(counter);
        config->writeEntry(key, sessions.current()->IconName());
789
790
791
792
793
794
        key = QString("MonitorActivity%1").arg(counter);
        config->writeEntry(key, sessions.current()->isMonitorActivity());
        key = QString("MonitorSilence%1").arg(counter);
        config->writeEntry(key, sessions.current()->isMonitorSilence());
        key = QString("MasterMode%1").arg(counter);
        config->writeEntry(key, sessions.current()->isMasterMode());
795
796
        if (sessions.current()==se)
	  active=counter;
797
798
799
800
801
802
803
804
805
806
807
808
        sessions.next();
        counter++;
     }
  }
  config->setDesktopGroup();
  config->writeEntry("Fullscreen",b_fullscreen);
  config->writeEntry("font",n_defaultFont);
  config->writeEntry("defaultfont", defaultFont);
  config->writeEntry("schema",s_kconfigSchema);
  config->writeEntry("scrollbar",n_scroll);
  config->writeEntry("bellmode",n_bell);
  config->writeEntry("keytab",n_defaultKeytab);
809
  config->writeEntry("ActiveSession", active);
810
  config->writeEntry("DefaultSession", m_defaultSessionFilename);
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825

  if (se) {
    config->writeEntry("history", se->history().getSize());
    config->writeEntry("historyenabled", b_histEnabled);
  }

  config->writeEntry("class",name());
}


// Called by constructor (with config = KGlobal::config())
// and by session-management (with config = sessionconfig).
// So it has to apply the settings when reading them.
void Konsole::readProperties(KConfig* config)
{
826
    readProperties(config, QString::null, false);
827
828
829
830
}

// If --type option was given, load the corresponding schema instead of
// default
831
//
832
// When globalConfigOnly is true only the options that are shared among all
833
834
// konsoles are being read.
void Konsole::readProperties(KConfig* config, const QString &schema, bool globalConfigOnly)
835
836
837
{
   config->setDesktopGroup();
   //KONSOLEDEBUG<<"Konsole::readProps()"<<endl;
838

839
840
841
842
843
844
845
846
847
848
849
   if (config==KGlobal::config())
   {
     b_warnQuit=config->readBoolEntry( "WarnQuit", TRUE );

     s_word_seps= config->readEntry("wordseps",":@-./_~");
     te->setWordCharacters(s_word_seps);

     b_framevis = config->readBoolEntry("has frame",TRUE);
     te->setFrameStyle( b_framevis?(QFrame::WinPanel|QFrame::Sunken):QFrame::NoFrame );

     te->setBlinkingCursor(config->readBoolEntry("BlinkingCursor",FALSE));
850
     te->setCtrlDrag(config->readBoolEntry("CtrlDrag",FALSE));
851
852
853
854
855
     te->setTerminalSizeHint( config->readBoolEntry("TerminalSizeHint",true) );
     te->setLineSpacing( config->readUnsignedNumEntry( "LineSpacing", 0 ) );
   }

   ColorSchema* sch = 0;
856
857
858
859
860
861
862
   if (!globalConfigOnly)
   {
      n_defaultKeytab=config->readNumEntry("keytab",0); // act. the keytab for this session
      b_fullscreen = config->readBoolEntry("Fullscreen",FALSE);
      n_defaultFont = n_font = QMIN(config->readUnsignedNumEntry("font",3),TOPFONT);
      n_scroll   = QMIN(config->readUnsignedNumEntry("scrollbar",TEWidget::SCRRIGHT),2);
      n_bell = QMIN(config->readUnsignedNumEntry("bellmode",TEWidget::BELLSYSTEM),2);
863

864
865
      // Options that should be applied to all sessions /////////////
      // (1) set menu items and Konsole members
866
      QFont tmpFont("fixed");
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
      defaultFont = config->readFontEntry("defaultfont", &tmpFont);
      setFont(QMIN(config->readUnsignedNumEntry("font",3),TOPFONT));

      //set the schema
      s_kconfigSchema=config->readEntry("schema", "");
      sch = colors->find(schema.isEmpty() ? s_kconfigSchema : schema);
      if (!sch)
      {
         kdWarning() << "Could not find schema named " <<s_kconfigSchema<< endl;
         sch=(ColorSchema*)colors->at(0);  //the default one
      }
      if (sch->hasSchemaFileChanged()) sch->rereadSchemaFile();
      s_schema = sch->relPath();
      curr_schema = sch->numb();
      pmPath = sch->imagePath();
      te->setColorTable(sch->table()); //FIXME: set twice here to work around a bug
883

884
885
886
887
888
889
890
891
892
893
894
895
896
      if (sch->useTransparency())
      {
         //KONSOLEDEBUG << "Setting up transparency" << endl;
         rootxpm->setFadeEffect(sch->tr_x(), QColor(sch->tr_r(), sch->tr_g(), sch->tr_b()));
         rootxpm->start();
         rootxpm->repaint(true);
      }
      else
      {
         //KONSOLEDEBUG << "Stopping transparency" << endl;
         rootxpm->stop();
         pixmap_menu_activated(sch->alignment());
      }
897

898
899
900
901
902
903
904
905
906
      te->setColorTable(sch->table());
      te->setScrollbarLocation(n_scroll);
      te->setBellMode(n_bell);

      // History
      m_histSize = config->readNumEntry("history",DEFAULT_HISTORY_SIZE);
      b_histEnabled = config->readBoolEntry("historyenabled",true);
      //KONSOLEDEBUG << "Hist size : " << m_histSize << endl;
   }
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992

   if (m_menuCreated)
   {
      applySettingsToGUI();
      activateSession();
   };
}

void Konsole::applySettingsToGUI()
{
   if (!m_menuCreated) return;
   selectFont->setCurrentItem(n_font);
   notifySize(te->Lines(),te->Columns());
   showToolbar->setChecked(!toolBar()->isHidden());
   showMenubar->setChecked(!menuBar()->isHidden());
   selectScrollbar->setCurrentItem(n_scroll);
   selectBell->setCurrentItem(n_bell);
   updateKeytabMenu();
};


/* ------------------------------------------------------------------------- */
/*                                                                           */
/*                                                                           */
/* ------------------------------------------------------------------------- */

void Konsole::pixmap_menu_activated(int item)
{
  if (item <= 1) pmPath = "";
  QPixmap pm(pmPath);
  if (pm.isNull()) {
    pmPath = "";
    item = 1;
    te->setBackgroundColor(te->getDefaultBackColor());
    return;
  }
  // FIXME: respect scrollbar (instead of te->size)
  n_render= item;
  switch (item)
  {
    case 1: // none
    case 2: // tile
            te->setBackgroundPixmap(pm);
    break;
    case 3: // center
            { QPixmap bgPixmap;
              bgPixmap.resize(te->size());
              bgPixmap.fill(te->getDefaultBackColor());
              bitBlt( &bgPixmap, ( te->size().width() - pm.width() ) / 2,
                                ( te->size().height() - pm.height() ) / 2,
                      &pm, 0, 0,
                      pm.width(), pm.height() );

              te->setBackgroundPixmap(bgPixmap);
            }
    break;
    case 4: // full
            {
              float sx = (float)te->size().width() / pm.width();
              float sy = (float)te->size().height() / pm.height();
              QWMatrix matrix;
              matrix.scale( sx, sy );
              te->setBackgroundPixmap(pm.xForm( matrix ));
            }
    break;
    default: // oops
             n_render = 1;
  }
}

void Konsole::slotSelectBell() {
  n_bell = selectBell->currentItem();
  te->setBellMode(n_bell);
}

void Konsole::slotSelectScrollbar() {
   if (m_menuCreated)
      n_scroll = selectScrollbar->currentItem();
   te->setScrollbarLocation(n_scroll);
   activateSession(); // maybe helps in bg
}

void Konsole::slotSelectFont() {
  assert(se);
  int item = selectFont->currentItem();
  // KONSOLEDEBUG << "slotSelectFont " << item << endl;
993
  if (item == DEFAULTFONT)
994
  {
995
996
997
    if ( KFontDialog::getFont(defaultFont, true) == QDialog::Rejected )
    {
      selectFont->setCurrentItem(n_font);
998
      return;
999
    }
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
  }
  setFont(item);
  n_defaultFont = n_font; // This is the new default
  activateSession(); // activates the current
}

void Konsole::schema_menu_activated(int item)
{
  assert(se);
  //FIXME: save schema name
//        KONSOLEDEBUG << "Item " << item << " selected from schema menu"
//                << endl;
  setSchema(item);
  s_kconfigSchema = s_schema; // This is the new default
  activateSession(); // activates the current
}

/* slot */ void Konsole::schema_menu_check()
{
        if (colors->checkSchemas())
        {
Alexander Neundorf's avatar
   
Alexander Neundorf committed
1021
                colors->sort();
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
                updateSchemaMenu();
        }
}

void Konsole::updateSchemaMenu()
{
//        KONSOLEDEBUG << "Updating schema menu with "
//                << colors->count()
//                << " items."
//                << endl;

  m_schema->clear();
  for (int i = 0; i < (int) colors->count(); i++)
  {
     ColorSchema* s = (ColorSchema*)colors->at(i);
    assert( s );
    m_schema->insertItem(s->title(),s->numb(),0);
  }

  if (te && te->currentSession)
  {
//        KONSOLEDEBUG << "Current session has schema "
//                << te->currentSession->schemaNo()
//                << endl;
        m_schema->setItemChecked(te->currentSession->schemaNo(),true);
  }

}

void Konsole::updateKeytabMenu()
{
  if (m_menuCreated)
  {
     m_keytab->setItemChecked(n_keytab,FALSE);
     m_keytab->setItemChecked(se->keymapNo(),TRUE);
  };
  n_keytab = se->keymapNo();
}

void Konsole::keytab_menu_activated(int item)
{
  se->setKeymapNo(item);
  n_defaultKeytab = item;
  updateKeytabMenu();
}

void Konsole::setFont(int fontno)
{
  QFont f;
1071
  if (fontno == DEFAULTFONT)
1072
1073
1074
    f = defaultFont;
  else
  if (fonts[fontno][0] == '-')
1075
  {
1076
    f.setRawName( fonts[fontno] );
1077
1078
1079
1080
1081
1082
1083
1084
    if ( !f.exactMatch() && fontno != DEFAULTFONT)
    {
      // Ugly hack to prevent bug #20487
      fontNotFound_par=fonts[fontno];
      QTimer::singleShot(1,this,SLOT(fontNotFound()));
      return;
    }
  }
1085
1086
  else
  {
1087
    f.setFamily("fixed");
1088
1089
    f.setFixedPitch(true);
    f.setPixelSize(QString(fonts[fontno]).toInt());
1090
1091
1092
1093
1094
1095
1096
1097
  }
  if (se) se->setFontNo(fontno);
  if (m_menuCreated)
     selectFont->setCurrentItem(fontno);
  te->setVTFont(f);
  n_font = fontno;
}

1098
1099
1100
1101
1102
1103
void Konsole::fontNotFound()
{
  QString msg = i18n("Font `%1' not found.\nCheck README.linux.console for help.").arg(fontNotFound_par);
  KMessageBox::error(this,  msg);
}

1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
/**
     Toggle the Menubar visibility
 */
void Konsole::slotToggleMenubar() {
  if ( showMenubar->isChecked() )
     menubar->show();
  else
     menubar->hide();
  if (!showMenubar->isChecked()) {
    setCaption(i18n("Use the right mouse button to bring back the menu"));
    QTimer::singleShot(5000,this,SLOT(updateTitle()));
  }
}

/**
    Toggle the Toolbar visibility
 */
void Konsole::slotToggleToolbar() {
  if (showToolbar->isChecked())
     toolBar()->show();
  else
     toolBar()->hide();
}

void Konsole::opt_menu_activated(int item)
{
  switch( item )  {
    case 5: setFullScreen(!b_fullscreen);
            break;
  }
}

1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
void Konsole::slotSaveSettings()
{
  KConfig *config = KGlobal::config();
  config->setDesktopGroup();
  saveProperties(config);
  saveMainWindowSettings(config);
  config->sync();
}

void Konsole::slotConfigure()
{
  QStringList args;
  args << "kcmkonsole";
  KApplication::kdeinitExec( "kcmshell", args );
}

void Konsole::reparseConfiguration()
{
  KGlobal::config()->reparseConfiguration();
  readProperties(KGlobal::config(), QString::null, true);
}

1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
// --| color selection |-------------------------------------------------------

void Konsole::changeColumns(int columns)
{
  setColLin(columns,te->Lines());
  te->update();
}

void Konsole::slotSelectSize() {
    int item = selectSize->currentItem();
    switch (item) {
    case 0: setColLin(40,15); break;
    case 1: setColLin(80,24); break;
    case 2: setColLin(80,25); break;
    case 3: setColLin(80,40); break;
    case 4: setColLin(80,52); break;
1174
    case 5: SizeDialog dlg(te->Columns(), te->Lines(), this);
1175
1176
1177
1178
            if (dlg.exec())
              setColLin(dlg.columns(),dlg.lines());
            break;
   }
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
}


void Konsole::notifySize(int lines, int columns)
{
   if (!m_menuCreated) return;

    selectSize->blockSignals(true);
    selectSize->setCurrentItem(-1);
    if (columns==40&&lines==15)
        selectSize->setCurrentItem(0);
1190
    else if (columns==80&&lines==24)
1191
        selectSize->setCurrentItem(1);
1192
    else if (columns==80&&lines==25)
1193
        selectSize->setCurrentItem(2);
1194
    else if (columns==80&&lines==40)
1195
        selectSize->setCurrentItem(3);
1196
    else if (columns==80&&lines==52)
1197
        selectSize->setCurrentItem(4);
1198
1199
    else
        selectSize->setCurrentItem(5);
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
    selectSize->blockSignals(false);
    if (n_render >= 3) pixmap_menu_activated(n_render);
}

void Konsole::updateTitle()
{
  setCaption( te->currentSession->fullTitle() );
  setIconText( te->currentSession->IconText() );
}

void Konsole::initFullScreen()
{
1212
  //This function is to be called from main.C to initialize the state of the Konsole (fullscreen or not).  It doesn't appear to work
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
  //from inside the Konsole constructor
  if (b_fullscreen) {
   setColLin(0,0);
   }
  setFullScreen(b_fullscreen);
}

void Konsole::initSessionSchema(int schemaNo) {
  setSchema(schemaNo);
}

void Konsole::initSessionFont(int fontNo) {
  if (fontNo == -1) return; // Don't change
  setFont(fontNo);
}

void Konsole::initSessionKeyTab(const QString &keyTab) {
  se->setKeymap(keyTab);
}

void Konsole::setFullScreen(bool on)
{
//  if (on == b_fullscreen) {
//    KONSOLEDEBUG << "On and b_Fullscreen both equal " << b_fullscreen << "." << endl;
//    }
    if (on) {
1239
      showFullScreen();
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
      b_fullscreen = on;
      }
    else {
      showNormal();
      updateTitle(); // restore caption of window
      b_fullscreen = false;
//      KONSOLEDEBUG << "On is false, b_fullscreen is " << b_fullscreen << ". Set to Normal view and set caption." << endl;
    }
//  return;
    m_options->setItemChecked(5,b_fullscreen);

}

/* --| sessions |------------------------------------------------------------ */

//FIXME: activating sessions creates a lot flicker in the moment.
//       it comes from setting the attributes of a session individually.
//       ONE setImage call should actually be enough to match all cases.
//       These can be quite different:
//       - The screen size might have changed while the session was
//         detached. A propagation of the resize should in this case
//         make the drawEvent.
//       - font, background image and color palette should be set in one go.

1264
1265
1266
1267
1268
void Konsole::clearAllListenToKeyPress()
{
  for (TESession *ses = sessions.first(); ses; ses = sessions.next())
    ses->setListenToKeyPress(false);
}
1269

1270
1271
1272
1273
1274
1275
1276
1277
1278
void Konsole::restoreAllListenToKeyPress()
{
  if(se->isMasterMode())
    for (TESession *ses = sessions.first(); ses; ses = sessions.next())
      ses->setListenToKeyPress(TRUE);
  else
    se->setListenToKeyPress(TRUE);
}

1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
void Konsole::feedAllSessions(const QString &text)
{
  for (TESession *ses = sessions.first(); ses; ses = sessions.next())
    ses->setListenToKeyPress(TRUE);
  if (te)
    te->emitText(text);
  if(!se->isMasterMode()) {
    for (TESession *ses = sessions.first(); ses; ses = sessions.next())
      ses->setListenToKeyPress(FALSE);
    se->setListenToKeyPress(TRUE);
  }
}

void Konsole::sendAllSessions(const QString &text)
{
  QString newtext=text;
  newtext.append("\r");
  feedAllSessions(newtext);
}

1299
void Konsole::sendSignal(int sn)
1300
{
1301
  if (se) se->sendSignal(sn);
1302
}
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322

void Konsole::runSession(TESession* s)
{
    KRadioAction *ra = session2action.find(s);
    ra->setChecked(true);
    activateSession();

    // give some time to get through the
    // resize events before starting up.
    QTimer::singleShot(100,s,SLOT(run()));
}

void Konsole::addSession(TESession* s)
{
  QString newTitle = s->Title();

  bool nameOk;
  int count = 1;
  do {
     nameOk = true;
1323
     for (TESession *ses = sessions.first(); ses; ses = sessions.next())
1324
     {
1325
        if (newTitle == ses->Title())
1326
1327
1328
1329
1330
1331
1332
1333
        {
           nameOk = false;
           break;
        }
     }
     if (!nameOk)
     {
       count++;
1334
       newTitle = i18n("%1 No. %2").arg(s->Title()).arg(count);
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
     }
  }
  while (!nameOk);

  s->setTitle(newTitle);

  // create an action for the session
  //  char buffer[30];
  //  int acc = CTRL+SHIFT+Key_0+session_no; // Lars: keys stolen by kwin.
  KRadioAction *ra = new KRadioAction(newTitle,
1345
                                      s->IconName(),
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
                                      0,
                                      this,
                                      SLOT(activateSession()),
                                      this);
                                      //                                      buffer);
  ra->setExclusiveGroup("sessions");
  ra->setChecked(true);
  // key accelerator
  //  accel->connectItem(accel->insertItem(acc), ra, SLOT(activate()));

  action2session.insert(ra, s);
  session2action.insert(s,ra);
  sessions.append(s);
  if (m_menuCreated)
1360
     ra->plug(m_view);
1361
1362

  int button_id=ra->itemId( ra->plug(toolBar()) );
1363
  KToolBarButton* ktb=toolBar()->getButton(button_id);
1364
  connect(ktb,SIGNAL(doubleClicked(int)), this,SLOT(slotRenameSession(int)));
1365
  session2button.insert(s,ktb);
1366
1367
}

1368
QString Konsole::currentSession()
1369
{
1370
1371
  return se->SessionId();
}
Stephan Binner's avatar
Stephan Binner committed
1372

1373
1374
1375
1376
QString Konsole::sessionId(const int position)
{
  if (position<=0 || position>sessions.count())
    return "";
1377

1378
  return sessions.at(position-1)->SessionId();
Stephan Binner's avatar
Stephan Binner committed
1379
1380
}

1381
void Konsole::activateSession(const int position)
Stephan Binner's avatar
Stephan Binner committed
1382
{
1383
  if (position<=0 || position>sessions.count())
1384
    return;
1385
1386
1387
1388
1389
1390
1391
1392
1393
<