~ubuntu-branches/ubuntu/precise/konsole/precise-proposed

« back to all changes in this revision

Viewing changes to src/ViewManager.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-16 13:14:43 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: package-import@ubuntu.com-20111216131443-rhdplbmmuxntat3k
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
// Own
21
21
#include "ViewManager.h"
22
22
 
23
 
// System
24
 
#include <assert.h>
25
 
 
26
23
// Qt
27
24
#include <QtCore/QDateTime>
28
25
#include <QtCore/QSignalMapper>
 
26
#include <QtCore/QStringList>
29
27
#include <QtGui/QMenu>
30
28
 
31
29
// KDE
32
 
#include <kdebug.h>
 
30
#include <KDebug>
33
31
#include <KAcceleratorManager>
34
32
#include <KGlobal>
35
33
#include <KLocale>
36
34
#include <KToggleAction>
 
35
#include <KActionCollection>
37
36
#include <KXMLGUIFactory>
38
 
#include <QStringList>
39
37
#include <KConfigGroup>
40
38
 
41
39
// Konsole
 
40
#include <konsoleadaptor.h>
 
41
 
42
42
#include "ColorScheme.h"
43
43
#include "ProfileList.h"
44
44
#include "Session.h"
47
47
#include "SessionManager.h"
48
48
#include "ViewContainer.h"
49
49
#include "ViewSplitter.h"
50
 
#include "konsoleadaptor.h"
51
50
#include "Profile.h"
52
51
 
53
52
using namespace Konsole;
73
72
    _viewSplitter->setRecursiveSplitting(false);
74
73
    _viewSplitter->setFocusPolicy(Qt::NoFocus);
75
74
 
76
 
    // setup actions which relating to the view
 
75
    // setup actions which are related to the views
77
76
    setupActions();
78
77
 
79
78
    // emit a signal when all of the views held by this view manager are destroyed
135
134
{
136
135
    KActionCollection* collection = _actionCollection;
137
136
 
138
 
    KAction* nextViewAction = new KAction( i18n("Next Tab") , this );
139
 
    KAction* previousViewAction = new KAction( i18n("Previous Tab") , this );
140
 
    KAction* nextContainerAction = new KAction( i18n("Next View Container") , this);
141
 
  
142
 
    KAction* moveViewLeftAction = new KAction( i18n("Move Tab Left") , this );
143
 
    KAction* moveViewRightAction = new KAction( i18n("Move Tab Right") , this );
 
137
    KAction* nextViewAction = new KAction( i18nc("@action Shortcut entry", "Next Tab") , this );
 
138
    KAction* previousViewAction = new KAction( i18nc("@action Shortcut entry", "Previous Tab") , this );
 
139
    KAction* lastViewAction = new KAction( i18nc("@action Shortcut entry", "Switch to Last Tab") , this);
 
140
    KAction* nextContainerAction = new KAction( i18nc("@action Shortcut entry", "Next View Container") , this);
 
141
 
 
142
    KAction* moveViewLeftAction = new KAction( i18nc("@action Shortcut entry", "Move Tab Left") , this );
 
143
    KAction* moveViewRightAction = new KAction( i18nc("@action Shortcut entry", "Move Tab Right") , this );
144
144
 
145
145
    // list of actions that should only be enabled when there are multiple view
146
146
    // containers open
181
181
 
182
182
        KAction* detachViewAction = collection->addAction("detach-view");
183
183
        detachViewAction->setIcon(KIcon("tab-detach"));
184
 
        detachViewAction->setText(i18n("D&etach Current Tab"));
 
184
        detachViewAction->setText(i18nc("@action:inmenu", "D&etach Current Tab"));
185
185
        // Ctrl+Shift+D is not used as a shortcut by default because it is too close
186
186
        // to Ctrl+D - which will terminate the session in many cases
187
187
        detachViewAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_H));
192
192
        // Expand & Shrink Active View
193
193
        KAction* expandActiveAction = new KAction( i18nc("@action:inmenu", "Expand View") , this );
194
194
        expandActiveAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_BracketRight) );
 
195
        expandActiveAction->setEnabled(false);
195
196
        collection->addAction("expand-active-view",expandActiveAction);
196
197
        connect( expandActiveAction , SIGNAL(triggered()) , this , SLOT(expandActiveView()) );
197
198
 
199
200
 
200
201
        KAction* shrinkActiveAction = new KAction( i18nc("@action:inmenu", "Shrink View") , this );
201
202
        shrinkActiveAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_BracketLeft) );
 
203
        shrinkActiveAction->setEnabled(false);
202
204
        collection->addAction("shrink-active-view",shrinkActiveAction);
203
205
        connect( shrinkActiveAction , SIGNAL(triggered()) , this , SLOT(shrinkActiveView()) );
204
206
 
207
209
        // Next / Previous View , Next Container
208
210
        collection->addAction("next-view",nextViewAction);
209
211
        collection->addAction("previous-view",previousViewAction);
 
212
        collection->addAction("last-tab",lastViewAction);
210
213
        collection->addAction("next-container",nextContainerAction);
211
214
        collection->addAction("move-view-left",moveViewLeftAction);
212
215
        collection->addAction("move-view-right",moveViewRightAction);
217
220
        connect(switchToTabMapper,SIGNAL(mapped(int)),this,SLOT(switchToView(int)));
218
221
        for (int i=0;i < SWITCH_TO_TAB_COUNT;i++)
219
222
        {
220
 
            KAction* switchToTabAction = new KAction(i18n("Switch to Tab %1",i+1),this);
 
223
            KAction* switchToTabAction = new KAction(i18nc("@action Shortcut entry", "Switch to Tab %1",i+1),this);
221
224
            switchToTabMapper->setMapping(switchToTabAction,i);
222
225
            connect(switchToTabAction,SIGNAL(triggered()),switchToTabMapper,
223
226
                    SLOT(map()));
232
235
    }
233
236
 
234
237
    // keyboard shortcut only actions
235
 
    KShortcut nextViewShortcut = nextViewAction->shortcut();
236
 
    nextViewShortcut.setPrimary( QKeySequence(Qt::SHIFT+Qt::Key_Right) );
237
 
    nextViewShortcut.setAlternate( QKeySequence(Qt::CTRL+Qt::Key_PageDown) );
238
 
    nextViewAction->setShortcut(nextViewShortcut); 
 
238
    nextViewAction->setShortcut( QKeySequence(Qt::SHIFT+Qt::Key_Right) );
239
239
    connect( nextViewAction, SIGNAL(triggered()) , this , SLOT(nextView()) );
240
240
    _viewSplitter->addAction(nextViewAction);
241
241
 
242
 
    KShortcut previousViewShortcut = previousViewAction->shortcut();
243
 
    previousViewShortcut.setPrimary( QKeySequence(Qt::SHIFT+Qt::Key_Left) );
244
 
    previousViewShortcut.setAlternate( QKeySequence(Qt::CTRL+Qt::Key_PageUp) );
245
 
    previousViewAction->setShortcut(previousViewShortcut);
 
242
    previousViewAction->setShortcut( QKeySequence(Qt::SHIFT+Qt::Key_Left) );
246
243
    connect( previousViewAction, SIGNAL(triggered()) , this , SLOT(previousView()) );
247
244
    _viewSplitter->addAction(previousViewAction);
248
245
 
253
250
    moveViewLeftAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_Left) );
254
251
    connect( moveViewLeftAction , SIGNAL(triggered()) , this , SLOT(moveActiveViewLeft()) );
255
252
    _viewSplitter->addAction(moveViewLeftAction);
 
253
 
256
254
    moveViewRightAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_Right) );
257
255
    connect( moveViewRightAction , SIGNAL(triggered()) , this , SLOT(moveActiveViewRight()) );
258
256
    _viewSplitter->addAction(moveViewRightAction);
 
257
 
 
258
    connect( lastViewAction, SIGNAL(triggered()) , this , SLOT(lastView()));
 
259
    _viewSplitter->addAction(lastViewAction);
259
260
}
260
261
void ViewManager::switchToView(int index)
261
262
{
316
317
    container->activatePreviousView();
317
318
}
318
319
 
 
320
void ViewManager::lastView()
 
321
{
 
322
    ViewContainer* container = _viewSplitter->activeContainer();
 
323
 
 
324
    Q_ASSERT( container );
 
325
 
 
326
    container->activateLastView();
 
327
}
 
328
 
319
329
void ViewManager::detachActiveView()
320
330
{
321
331
    // find the currently active view and remove it from its container 
333
343
        return;
334
344
 
335
345
    emit viewDetached(_sessionMap[viewToDetach]);
336
 
    
 
346
 
337
347
    _sessionMap.remove(viewToDetach);
338
348
 
339
349
    // remove the view from this window
427
437
    // iterate over each session which has a view in the current active
428
438
    // container and create a new view for that session in a new container 
429
439
    QListIterator<QWidget*> existingViewIter(_viewSplitter->activeContainer()->views());
430
 
    
 
440
 
431
441
    ViewContainer* container = 0; 
432
442
 
433
443
    while (existingViewIter.hasNext())
434
444
    {
435
445
        Session* session = _sessionMap[(TerminalDisplay*)existingViewIter.next()];
436
446
        TerminalDisplay* display = createTerminalDisplay(session);
437
 
        const Profile::Ptr info = SessionManager::instance()->sessionProfile(session);
438
 
        applyProfile(display, info, false);
 
447
        const Profile::Ptr profile = SessionManager::instance()->sessionProfile(session);
 
448
        applyProfileToView(display, profile);
439
449
        ViewProperties* properties = createController(session,display);
440
450
 
441
451
        _sessionMap[display] = session;
443
453
        // create a container using settings from the first 
444
454
        // session in the previous container
445
455
        if ( !container )
446
 
            container = createContainer(info);
 
456
        {
 
457
            container = createContainer(profile);
 
458
            applyProfileToContainer(container, profile);
 
459
        }
447
460
 
448
 
        int tabBarMode = info->property<int>(Profile::TabBarMode);
449
 
        if ( tabBarMode == Profile::AlwaysHideTabBar )
450
 
            container->setNavigationDisplayMode(ViewContainer::AlwaysHideNavigation);
451
 
        else if ( tabBarMode == Profile::AlwaysShowTabBar )
452
 
            container->setNavigationDisplayMode(ViewContainer::AlwaysShowNavigation);
453
 
        else if ( tabBarMode == Profile::ShowTabBarAsNeeded )
454
 
            container->setNavigationDisplayMode(ViewContainer::ShowNavigationAsNeeded);
455
461
        container->addView(display,properties);
456
462
        session->addView( display );
457
463
    }
526
532
    SessionController* controller = new SessionController(session,view,this);
527
533
    connect( controller , SIGNAL(focused(SessionController*)) , this , SLOT(controllerChanged(SessionController*)) );
528
534
    connect( session , SIGNAL(destroyed()) , controller , SLOT(deleteLater()) );
 
535
    connect( session , SIGNAL(primaryScreenInUse(bool)) ,
 
536
             controller , SLOT(setupPrimaryScreenSpecificActions(bool)) );
 
537
    connect( session , SIGNAL(selectedText(QString)) ,
 
538
             controller , SLOT(updateCopyAction(QString)) );
529
539
    connect( view , SIGNAL(destroyed()) , controller , SLOT(deleteLater()) );
530
540
 
531
541
    // if this is the first controller created then set it as the active controller
565
575
    disconnect( session , SIGNAL(finished()) , this , SLOT(sessionFinished()) );
566
576
    connect( session , SIGNAL(finished()) , this , SLOT(sessionFinished()) );
567
577
 
 
578
     TerminalDisplay* display = createTerminalDisplay(session);
 
579
     const Profile::Ptr profile = SessionManager::instance()->sessionProfile(session);
 
580
     applyProfileToView(display, profile);
 
581
 
568
582
     bool isFirst = _sessionMap.isEmpty();
569
 
     TerminalDisplay* display = createTerminalDisplay(session);
570
 
     applyProfile(display,SessionManager::instance()->sessionProfile(session),isFirst);
571
 
     
 
583
     if ( isFirst)
 
584
         applyProfileToContainer(container, profile);
 
585
 
572
586
     // set initial size
573
587
     display->setSize(80,40);
574
588
 
579
593
     session->addView(display);
580
594
 
581
595
     // tell the session whether it has a light or dark background
582
 
     const Profile::Ptr profile = SessionManager::instance()->sessionProfile(session);
583
596
     session->setDarkBackground( colorSchemeForProfile(profile)->hasDarkBackground() );
584
597
 
585
598
     if ( container == _viewSplitter->activeContainer() ) 
587
600
         container->setActiveView(display);
588
601
         display->setFocus( Qt::OtherFocusReason );
589
602
     }
590
 
    
 
603
 
591
604
     updateDetachViewState();
592
605
}
593
606
 
601
614
        emit splitViewToggle(false);
602
615
    }
603
616
 
604
 
       
 
617
    // new tab will be put at the end by default.
 
618
    int index = -1;
 
619
 
 
620
    // TODO: currently, whether new tab should be put after current tab is a per
 
621
    // profile setting, while in concept it should be per ViewManager or global
 
622
    // setting. The current implementation is limited by the design of Profile.h
 
623
    // It should be re-implmented at some appropriate time in the future.
 
624
    // comment by jekyllwu
 
625
    Profile::Ptr profile = SessionManager::instance()->sessionProfile(session);
 
626
    int newTabBehavior = profile->property<int>(Profile::NewTabBehavior);
 
627
    if ( newTabBehavior == Profile::PutNewTabAfterCurrentTab )
 
628
    {
 
629
        QWidget* view = activeView();
 
630
        if (view)
 
631
        {
 
632
            QList<QWidget*> views =  _viewSplitter->activeContainer()->views();
 
633
            index = views.indexOf(view) + 1;
 
634
        }
 
635
    }
 
636
 
605
637
    // iterate over the view containers owned by this view manager
606
638
    // and create a new terminal display for the session in each of them, along with
607
639
    // a controller for the session/display pair 
608
640
    QListIterator<ViewContainer*> containerIter(_viewSplitter->containers());
609
 
 
610
641
    while ( containerIter.hasNext() )
611
642
    {
612
643
        ViewContainer* container = containerIter.next();
613
 
        createView(session,container,-1);
 
644
        createView(session, container, index);
614
645
    }
615
 
 
616
646
}
617
647
 
618
 
ViewContainer* ViewManager::createContainer(const Profile::Ptr info)
 
648
ViewContainer* ViewManager::createContainer(const Profile::Ptr profile)
619
649
{
620
 
    Q_ASSERT( info );
 
650
    Q_ASSERT( profile );
621
651
 
622
 
    const int tabPosition = info->property<int>(Profile::TabBarPosition);
 
652
    const int tabPosition = profile->property<int>(Profile::TabBarPosition);
623
653
 
624
654
    ViewContainer::NavigationPosition position = ( tabPosition == Profile::TabBarTop ) ?
625
655
                                                   ViewContainer::NavigationPositionTop :
635
665
                    new TabbedViewContainer(position,_viewSplitter);
636
666
 
637
667
                connect(container,
638
 
                    SIGNAL(detachTab(ViewContainer*, QWidget*)),
 
668
                    SIGNAL(detachTab(ViewContainer*,QWidget*)),
639
669
                    this,
640
 
                    SLOT(detachView(ViewContainer*, QWidget*))
 
670
                    SLOT(detachView(ViewContainer*,QWidget*))
641
671
                    );
642
672
                connect(container,
643
 
                    SIGNAL(closeTab(ViewContainer*, QWidget*)),
 
673
                    SIGNAL(closeTab(ViewContainer*,QWidget*)),
644
674
                    this,
645
 
                    SLOT(closeTabFromContainer(ViewContainer*, QWidget*)));
 
675
                    SLOT(closeTabFromContainer(ViewContainer*,QWidget*)));
646
676
 
647
677
            }
648
678
            break;
651
681
            container = new StackedViewContainer(_viewSplitter);
652
682
    }
653
683
 
 
684
    applyProfileToContainer(container, profile);
 
685
 
654
686
    // connect signals and slots
655
687
    connect( container , SIGNAL(viewAdded(QWidget*,ViewProperties*)) , _containerSignalMapper ,
656
688
           SLOT(map()) );
664
696
    connect( container , SIGNAL(viewRemoved(QWidget*)) , this , SLOT(viewCloseRequest(QWidget*)) );
665
697
    connect( container , SIGNAL(closeRequest(QWidget*)) , this , SLOT(viewCloseRequest(QWidget*)) );
666
698
    connect( container , SIGNAL(activeViewChanged(QWidget*)) , this , SLOT(viewActivated(QWidget*)));
667
 
    
 
699
 
668
700
    return container;
669
701
}
670
702
void ViewManager::containerMoveViewRequest(int index, int id, bool& moved)
696
728
        // a method should be devised to only enable those that are used, perhaps
697
729
        // by using a separate action collection.
698
730
 
 
731
        const bool enable = (_navigationMethod != NoNavigation) ;
699
732
        QAction* action;
700
733
 
701
734
        action = collection->action( "next-view" );
702
 
        if ( action ) action->setEnabled( _navigationMethod != NoNavigation );
 
735
        if ( action ) action->setEnabled( enable );
703
736
 
704
737
        action = collection->action( "previous-view" );
705
 
        if ( action ) action->setEnabled( _navigationMethod != NoNavigation );
 
738
        if ( action ) action->setEnabled( enable );
 
739
 
 
740
        action = collection->action( "last-tab" );
 
741
        if ( action ) action->setEnabled( enable );
706
742
 
707
743
        action = collection->action( "split-view-left-right" );
708
 
        if ( action ) action->setEnabled( _navigationMethod != NoNavigation );
 
744
        if ( action ) action->setEnabled( enable );
709
745
 
710
746
        action = collection->action( "split-view-top-bottom" );
711
 
        if ( action ) action->setEnabled( _navigationMethod != NoNavigation );
 
747
        if ( action ) action->setEnabled( enable );
712
748
 
713
749
        action = collection->action( "rename-session" );
714
 
        if ( action ) action->setEnabled( _navigationMethod != NoNavigation );
 
750
        if ( action ) action->setEnabled( enable );
715
751
 
716
752
        action = collection->action( "move-view-left" );
717
 
        if ( action ) action->setEnabled( _navigationMethod != NoNavigation );
 
753
        if ( action ) action->setEnabled( enable );
718
754
 
719
755
        action = collection->action( "move-view-right" );
720
 
        if ( action ) action->setEnabled( _navigationMethod != NoNavigation );
 
756
        if ( action ) action->setEnabled( enable );
721
757
    }
722
758
}
723
759
 
735
771
{
736
772
    //FIXME Check that this cast is actually legal
737
773
    TerminalDisplay* display = (TerminalDisplay*)view;
738
 
  
 
774
 
739
775
    Q_ASSERT(display);
740
776
 
741
777
    // 1. detach view from session
762
798
 
763
799
TerminalDisplay* ViewManager::createTerminalDisplay(Session* session)
764
800
{
765
 
   TerminalDisplay* display = new TerminalDisplay(0);
766
 
 
767
 
   //TODO Temporary settings used here
768
 
   display->setBellMode(TerminalDisplay::NotifyBell);
769
 
   display->setTerminalSizeHint(true);
770
 
   display->setTripleClickMode(TerminalDisplay::SelectWholeLine);
771
 
   display->setTerminalSizeStartup(true);
772
 
   display->setScrollBarPosition(TerminalDisplay::ScrollBarRight);
773
 
   display->setRandomSeed(session->sessionId() * 31);
774
 
 
775
 
   return display;
 
801
    TerminalDisplay* display = new TerminalDisplay(0);
 
802
    display->setRandomSeed(session->sessionId() * 31);
 
803
 
 
804
    return display;
776
805
}
777
806
 
778
 
const ColorScheme* ViewManager::colorSchemeForProfile(const Profile::Ptr info) const
 
807
const ColorScheme* ViewManager::colorSchemeForProfile(const Profile::Ptr profile) const
779
808
{
780
809
    const ColorScheme* colorScheme = ColorSchemeManager::instance()->
781
 
                                            findColorScheme(info->colorScheme());
 
810
                                            findColorScheme(profile->colorScheme());
782
811
    if ( !colorScheme )
783
812
       colorScheme = ColorSchemeManager::instance()->defaultColorScheme(); 
784
813
    Q_ASSERT( colorScheme );
786
815
    return colorScheme;
787
816
}
788
817
 
789
 
void ViewManager::applyProfile(TerminalDisplay* view , const Profile::Ptr info, 
790
 
                               bool applyContainerSettings) 
 
818
void ViewManager::applyProfileToView(TerminalDisplay* view , const Profile::Ptr profile)
791
819
{
792
 
    Q_ASSERT( info );
793
 
    
794
 
    const ColorScheme* colorScheme = colorSchemeForProfile(info);
 
820
    Q_ASSERT( profile );
795
821
 
796
822
    // menu bar visibility
797
 
    emit setMenuBarVisibleRequest( info->property<bool>(Profile::ShowMenuBar) );
 
823
    emit setMenuBarVisibleRequest( profile->property<bool>(Profile::ShowMenuBar) );
798
824
 
799
 
    emit setSaveGeometryOnExitRequest( info->property<bool>(Profile::SaveGeometryOnExit) );
 
825
    emit setSaveGeometryOnExitRequest( profile->property<bool>(Profile::SaveGeometryOnExit) );
800
826
 
801
827
    emit updateWindowIcon();
802
828
 
803
 
    // tab bar visibility
804
 
    if (applyContainerSettings)
805
 
    {
806
 
        ViewContainer* container = _viewSplitter->activeContainer();
807
 
        int tabBarMode = info->property<int>(Profile::TabBarMode);
808
 
        int tabBarPosition = info->property<int>(Profile::TabBarPosition);
809
 
        bool showNewCloseButtons = info->property<bool>(Profile::ShowNewAndCloseTabButtons);
810
 
 
811
 
        if ( tabBarMode == Profile::AlwaysHideTabBar )
812
 
            container->setNavigationDisplayMode(ViewContainer::AlwaysHideNavigation);
813
 
        else if ( tabBarMode == Profile::AlwaysShowTabBar )
814
 
            container->setNavigationDisplayMode(ViewContainer::AlwaysShowNavigation);
815
 
        else if ( tabBarMode == Profile::ShowTabBarAsNeeded )
816
 
            container->setNavigationDisplayMode(ViewContainer::ShowNavigationAsNeeded);
817
 
 
818
 
        ViewContainer::NavigationPosition position = container->navigationPosition();
819
 
 
820
 
        if ( tabBarPosition == Profile::TabBarTop )
821
 
            position = ViewContainer::NavigationPositionTop;
822
 
        else if ( tabBarPosition == Profile::TabBarBottom )
823
 
            position = ViewContainer::NavigationPositionBottom; 
824
 
 
825
 
        if ( container->supportedNavigationPositions().contains(position) )
826
 
            container->setNavigationPosition(position);
827
 
       
828
 
        if (showNewCloseButtons)
829
 
        {
830
 
            container->setFeatures(container->features() 
831
 
                               | ViewContainer::QuickNewView | ViewContainer::QuickCloseView);
832
 
            container->setNewViewMenu(createNewViewMenu());
833
 
        }
834
 
        else
835
 
            container->setFeatures(container->features() 
836
 
                            & ~ViewContainer::QuickNewView & ~ViewContainer::QuickCloseView);
837
 
    }
838
 
 
839
 
    // load colour scheme
 
829
    // load color scheme
840
830
    ColorEntry table[TABLE_COLORS];
841
 
    
 
831
    const ColorScheme* colorScheme = colorSchemeForProfile(profile);
842
832
    colorScheme->getColorTable(table , view->randomSeed() );
843
833
    view->setColorTable(table);
844
834
    view->setOpacity(colorScheme->opacity());
845
 
  
 
835
    view->setWallpaper(colorScheme->wallpaper());
 
836
 
846
837
    // load font 
847
 
    view->setAntialias(info->property<bool>(Profile::AntiAliasFonts));
848
 
    view->setBoldIntense(info->property<bool>(Profile::BoldIntense));
849
 
    view->setVTFont(info->font());
 
838
    view->setAntialias(profile->property<bool>(Profile::AntiAliasFonts));
 
839
    view->setBoldIntense(profile->property<bool>(Profile::BoldIntense));
 
840
    view->setVTFont(profile->font());
850
841
 
851
842
    // set scroll-bar position
852
 
    int scrollBarPosition = info->property<int>(Profile::ScrollBarPosition);
 
843
    int scrollBarPosition = profile->property<int>(Profile::ScrollBarPosition);
853
844
 
854
 
    if ( scrollBarPosition == Profile::ScrollBarHidden )
855
 
       view->setScrollBarPosition(TerminalDisplay::NoScrollBar);
856
 
    else if ( scrollBarPosition == Profile::ScrollBarLeft )
 
845
    if ( scrollBarPosition == Profile::ScrollBarLeft )
857
846
       view->setScrollBarPosition(TerminalDisplay::ScrollBarLeft);
858
847
    else if ( scrollBarPosition == Profile::ScrollBarRight )
859
848
       view->setScrollBarPosition(TerminalDisplay::ScrollBarRight);
 
849
    else if ( scrollBarPosition == Profile::ScrollBarHidden )
 
850
       view->setScrollBarPosition(TerminalDisplay::ScrollBarHidden);
 
851
 
 
852
    // show hint about termianl size after resizing
 
853
    view->setShowTerminalSizeHint(profile->property<bool>(Profile::ShowTerminalSizeHint));
860
854
 
861
855
    // terminal features
862
 
    bool blinkingCursor = info->property<bool>(Profile::BlinkingCursorEnabled);
863
 
    view->setBlinkingCursor(blinkingCursor);  
 
856
    bool blinkingCursor = profile->property<bool>(Profile::BlinkingCursorEnabled);
 
857
    view->setBlinkingCursorEnabled(blinkingCursor);
864
858
 
865
 
    bool blinkingText = info->property<bool>(Profile::BlinkingTextEnabled);
 
859
    bool blinkingText = profile->property<bool>(Profile::BlinkingTextEnabled);
866
860
    view->setBlinkingTextEnabled(blinkingText);
867
861
 
868
 
    bool tripleClickMode = info->property<bool>(Profile::TripleClickMode);
869
 
    view->setTripleClickMode(tripleClickMode ? TerminalDisplay::SelectForwardsFromCursor : TerminalDisplay::SelectWholeLine);
870
 
    
871
 
    view->setUnderlineLinks(info->property<bool>(Profile::UnderlineLinksEnabled));
872
 
 
873
 
    bool bidiEnabled = info->property<bool>(Profile::BidiRenderingEnabled);
 
862
    int tripleClickMode = profile->property<int>(Profile::TripleClickMode);
 
863
    view->setTripleClickMode( TerminalDisplay::TripleClickMode(tripleClickMode) );
 
864
 
 
865
    view->setUnderlineLinks(profile->property<bool>(Profile::UnderlineLinksEnabled));
 
866
 
 
867
    bool bidiEnabled = profile->property<bool>(Profile::BidiRenderingEnabled);
874
868
    view->setBidiEnabled(bidiEnabled);
875
869
 
876
870
    // cursor shape
877
 
    int cursorShape = info->property<int>(Profile::CursorShape);
 
871
    int cursorShape = profile->property<int>(Profile::CursorShape);
878
872
 
879
873
    if ( cursorShape == Profile::BlockCursor )
880
874
        view->setKeyboardCursorShape(TerminalDisplay::BlockCursor);  
884
878
        view->setKeyboardCursorShape(TerminalDisplay::UnderlineCursor);
885
879
 
886
880
    // cursor color
887
 
    bool useCustomColor = info->property<bool>(Profile::UseCustomCursorColor);
888
 
    const QColor& cursorColor = info->property<QColor>(Profile::CustomCursorColor);
889
 
        
 
881
    bool useCustomColor = profile->property<bool>(Profile::UseCustomCursorColor);
 
882
    const QColor& cursorColor = profile->property<QColor>(Profile::CustomCursorColor);
 
883
 
890
884
    view->setKeyboardCursorColor(!useCustomColor,cursorColor);
891
885
 
892
886
    // word characters
893
 
    view->setWordCharacters( info->property<QString>(Profile::WordCharacters) );
 
887
    view->setWordCharacters( profile->property<QString>(Profile::WordCharacters) );
 
888
}
 
889
 
 
890
void ViewManager::applyProfileToContainer(ViewContainer* container , const Profile::Ptr profile)
 
891
{
 
892
    int tabBarMode = profile->property<int>(Profile::TabBarMode);
 
893
    int tabBarPosition = profile->property<int>(Profile::TabBarPosition);
 
894
    bool showNewCloseButtons = profile->property<bool>(Profile::ShowNewAndCloseTabButtons);
 
895
 
 
896
    if ( tabBarMode == Profile::AlwaysHideTabBar )
 
897
        container->setNavigationDisplayMode(ViewContainer::AlwaysHideNavigation);
 
898
    else if ( tabBarMode == Profile::AlwaysShowTabBar )
 
899
        container->setNavigationDisplayMode(ViewContainer::AlwaysShowNavigation);
 
900
    else if ( tabBarMode == Profile::ShowTabBarAsNeeded )
 
901
        container->setNavigationDisplayMode(ViewContainer::ShowNavigationAsNeeded);
 
902
 
 
903
    ViewContainer::NavigationPosition position = container->navigationPosition();
 
904
    if ( tabBarPosition == Profile::TabBarTop )
 
905
        position = ViewContainer::NavigationPositionTop;
 
906
    else if ( tabBarPosition == Profile::TabBarBottom )
 
907
        position = ViewContainer::NavigationPositionBottom;
 
908
 
 
909
    if ( container->supportedNavigationPositions().contains(position) )
 
910
        container->setNavigationPosition(position);
 
911
 
 
912
    if (showNewCloseButtons)
 
913
    {
 
914
        container->setFeatures(container->features()
 
915
                | ViewContainer::QuickNewView | ViewContainer::QuickCloseView);
 
916
        container->setNewViewMenu(createNewViewMenu());
 
917
    }
 
918
    else
 
919
    {
 
920
        container->setFeatures(container->features()
 
921
                & ~ViewContainer::QuickNewView & ~ViewContainer::QuickCloseView);
 
922
    }
894
923
}
895
924
 
896
925
void ViewManager::updateViewsForSession(Session* session)
898
927
    QListIterator<TerminalDisplay*> iter(_sessionMap.keys(session));
899
928
    while ( iter.hasNext() )
900
929
    {
901
 
        applyProfile(iter.next(),SessionManager::instance()->sessionProfile(session),false);
 
930
        applyProfileToView(iter.next(),SessionManager::instance()->sessionProfile(session));
902
931
    }
903
932
}
904
933
 
905
934
void ViewManager::profileChanged(Profile::Ptr profile)
906
935
{
 
936
    // update all views associated with this profile
907
937
    QHashIterator<TerminalDisplay*,Session*> iter(_sessionMap);
908
 
 
909
938
    while ( iter.hasNext() )
910
939
    {
911
940
        iter.next();
915
944
             iter.value() != 0 && 
916
945
             SessionManager::instance()->sessionProfile(iter.value()) == profile ) 
917
946
        {
918
 
            applyProfile(iter.key(),profile,true);
 
947
            applyProfileToView(iter.key(),profile);
 
948
        }
 
949
    }
 
950
 
 
951
    // update containers only when this view manager only contains one session and
 
952
    // that session is associated with this profile
 
953
    //
 
954
    // FIXME: this is over complex and still not ideal.
 
955
    // TODO: settings influcing containers really should be moved out from profile.
 
956
    QList<Session*> sessions = _sessionMap.values().toSet().toList();
 
957
    if ( sessions.count() == 1 &&
 
958
         SessionManager::instance()->sessionProfile(sessions[0]) == profile )
 
959
    {
 
960
        QListIterator<ViewContainer*> containerIter(_viewSplitter->containers());
 
961
        while ( containerIter.hasNext() )
 
962
        {
 
963
            ViewContainer* container = containerIter.next();
 
964
            applyProfileToContainer(container, profile);
919
965
        }
920
966
    }
921
967
}
954
1000
    int tab = 1;
955
1001
    while (viewIter.hasNext())
956
1002
    {
957
 
        TerminalDisplay *view = dynamic_cast<TerminalDisplay*>(viewIter.next());
 
1003
        TerminalDisplay* view = dynamic_cast<TerminalDisplay*>(viewIter.next());
958
1004
        Q_ASSERT(view);
959
 
        Session *session = _sessionMap[view];
 
1005
        Session* session = _sessionMap[view];
960
1006
        ids << SessionManager::instance()->getRestoreId(session);
961
1007
        if (view == activeview) group.writeEntry("Active", tab);
962
1008
        unique.insert(session, 1);
979
1025
{
980
1026
    QList<int> ids = group.readEntry("Sessions", QList<int>());
981
1027
    int activeTab  = group.readEntry("Active", 0);
982
 
    TerminalDisplay *display = 0;
 
1028
    TerminalDisplay* display = 0;
983
1029
 
984
1030
    int tab = 1;
985
1031
    foreach(int id, ids)
986
1032
    {
987
 
        Session *session = SessionManager::instance()->idToSession(id);
 
1033
        Session* session = SessionManager::instance()->idToSession(id);
988
1034
        createView(session);
989
1035
        if (!session->isRunning())
990
1036
            session->run();
1108
1154
    container->setNavigationTextMode(useTextWidth);
1109
1155
}
1110
1156
 
1111
 
void ViewManager::closeTabFromContainer(ViewContainer *container, QWidget *tab)
 
1157
void ViewManager::closeTabFromContainer(ViewContainer* container, QWidget* tab)
1112
1158
{
1113
 
    SessionController *controller = dynamic_cast<SessionController*>(container->viewProperties(tab));
 
1159
    SessionController* controller = dynamic_cast<SessionController*>(container->viewProperties(tab));
1114
1160
    Q_ASSERT(controller);
1115
 
    if (controller && controller->confirmClose())
1116
 
        controller->session()->close();
 
1161
    if (controller)
 
1162
        controller->closeSession() ;
1117
1163
}
1118
1164
 
1119
1165
#include "ViewManager.moc"