Commit 0ef9ea5f authored by Robert Knight's avatar Robert Knight

Added 'Change Profile' menu to change the profile used by a running session.

svn path=/trunk/KDE/kdebase/apps/konsole/; revision=667162
parent a0976835
......@@ -26,6 +26,8 @@ The KDE 4.0 TODO List:
of that setting when drawing the terminal
display )
- Input Method Event in terminal display widget
- Ability to define bold or transparent status for each
color in the color scheme. Make the setting of
boldness for characters more intuitive than in the KDE 3
......
......@@ -35,6 +35,7 @@
<Action name="decrease-text-size"/>
</Menu>
<Menu name="settings"><text>Settings</text>
<Action name="change-profile"/>
<Action name="edit-current-profile"/>
</Menu>
<!--<Menu name="debug"><text>Debug</text>
......@@ -47,8 +48,13 @@
<Action name="clear-history-and-reset"/>
<Separator/>
<Action name="show-menubar"/>
<Action name="change-profile"/>
<Action name="edit-current-profile" />
<Separator/>
<Action name="close-session"/>
</Menu>
<Menu name="change-profile">
<text>Change Profile</text>
<ActionList name="profile-list" />
</Menu>
</kpartgui>
......@@ -487,7 +487,11 @@ Session::~Session()
delete _zmodemProc;
}
void Session::setProfileKey(const QString& key) { _profileKey = key; }
void Session::setProfileKey(const QString& key)
{
_profileKey = key;
emit profileChanged(key);
}
QString Session::profileKey() const { return _profileKey; }
void Session::done(int exitStatus)
......
......@@ -374,7 +374,10 @@ signals:
/** Emitted when the session's title has changed. */
void titleChanged();
/** Emitted when the session's profile has changed. */
void profileChanged(const QString& profile);
/**
* Emitted when the activity state of this session changes.
*
......
......@@ -28,6 +28,7 @@
#include <KIcon>
#include <KInputDialog>
#include <KLocale>
#include <KMenu>
#include <KRun>
#include <KToggleAction>
#include <KUrl>
......@@ -44,6 +45,7 @@
#include "ScreenWindow.h"
#include "Session.h"
#include "ProcessInfo.h"
#include "ProfileList.h"
#include "TerminalDisplay.h"
// for SaveHistoryTask
......@@ -75,6 +77,7 @@ SessionController::SessionController(Session* session , TerminalDisplay* view, Q
, _findPreviousAction(0)
, _urlFilterUpdateRequired(false)
, _codecAction(0)
, _changeProfileMenu(0)
{
Q_ASSERT( session );
Q_ASSERT( view );
......@@ -459,19 +462,33 @@ void SessionController::setupActions()
action->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_X) );
connect( action , SIGNAL(triggered()) , this , SLOT(clearHistoryAndReset()) );
// Terminal Options
// Profile Options
action = collection->addAction("edit-current-profile");
action->setText( i18n("Edit Current Profile...") );
connect( action , SIGNAL(triggered()) , this , SLOT(editCurrentProfile()) );
action = collection->addAction("change-profile");
action->setText( i18n("Change Profile") );
_changeProfileMenu = new KMenu(i18n("Change Profile"));
collection->addAction("change-profile",_changeProfileMenu->menuAction());
connect( _changeProfileMenu , SIGNAL(aboutToShow()) , this , SLOT(prepareChangeProfileMenu()) );
// debugging tools
//action = collection->addAction("debug-process");
//action->setText( "Get Foreground Process" );
//connect( action , SIGNAL(triggered()) , this , SLOT(debugProcess()) );
}
void SessionController::changeProfile(const QString& key)
{
_session->setProfileKey(key);
}
void SessionController::prepareChangeProfileMenu()
{
if ( _changeProfileMenu->isEmpty() )
{
ProfileList* list = new ProfileList(this);
connect( list , SIGNAL(profileSelected(const QString&)) , this , SLOT(changeProfile(const QString&)) );
_changeProfileMenu->addActions(list->actions());
}
}
void SessionController::updateCodecAction()
{
_codecAction->setCurrentCodec( QString(_session->emulation()->codec()->name()) );
......@@ -800,6 +817,7 @@ void SessionController::showDisplayContextMenu(TerminalDisplay* /*display*/ , in
{
QMenu* popup = dynamic_cast<QMenu*>(factory()->container("session-popup-menu",this));
Q_ASSERT( popup );
popup->exec( _view->mapToGlobal(QPoint(x,y)) );
......
......@@ -44,6 +44,7 @@ namespace KIO
class QAction;
class QTextCodec;
class KCodecAction;
class KMenu;
class KToggleAction;
class KUrl;
class KJob;
......@@ -154,8 +155,10 @@ private slots:
void decreaseTextSize();
void renameSession();
void saveSession();
void changeProfile(const QString& key);
// other
void prepareChangeProfileMenu();
void updateCodecAction();
void showDisplayContextMenu(TerminalDisplay* display , int state , int x , int y);
void sessionStateChanged(int state);
......@@ -208,6 +211,8 @@ private:
QPointer<IncrementalSearchBar> _searchBar;
KCodecAction* _codecAction;
KMenu* _changeProfileMenu;
};
/**
......
......@@ -179,6 +179,10 @@ void SessionManager::updateSession(Session* session)
Q_ASSERT( info );
applyProfile(session,info,false);
// FIXME - This may update a lot more than just the session
// of interest.
emit sessionUpdated(session);
}
Session* SessionManager::createSession(const QString& key )
......@@ -195,9 +199,11 @@ Session* SessionManager::createSession(const QString& key )
//configuration information found, create a new session based on this
session = new Session();
session->setProfileKey(key);
applyProfile(session,info,false);
connect( session , SIGNAL(profileChanged(const QString&)) , this ,
SLOT(sessionProfileChanged()) );
//ask for notification when session dies
_sessionMapper->setMapping(session,session);
connect( session , SIGNAL(finished()) , _sessionMapper ,
......@@ -323,7 +329,9 @@ void SessionManager::applyProfile(const QString& key , bool modifiedPropertiesOn
}
void SessionManager::applyProfile(Session* session, const Profile* info , bool modifiedPropertiesOnly)
{
session->setProfileKey( _types.key((Profile*)info) );
QString key = _types.key((Profile*)info);
if ( session->profileKey() != key )
session->setProfileKey(key);
// Basic session settings
if ( !modifiedPropertiesOnly || info->isPropertySet(Profile::Name) )
......@@ -615,6 +623,15 @@ QString SessionManager::findByShortcut(const QKeySequence& shortcut)
return _shortcuts[shortcut].profileKey;
}
void SessionManager::sessionProfileChanged()
{
Session* session = qobject_cast<Session*>(sender());
Q_ASSERT( session );
updateSession(session);
}
QKeySequence SessionManager::shortcut(const QString& profileKey) const
{
Profile* info = profile(profileKey);
......
......@@ -222,6 +222,12 @@ signals:
/** Emitted when a profile's properties are modified. */
void profileChanged(const QString& key);
/**
* Emitted when a session's settings are updated to match
* its current profile.
*/
void sessionUpdated(Session* session);
/**
* Emitted when the favorite status of a profile changes.
*
......@@ -247,6 +253,9 @@ protected Q_SLOTS:
*/
void sessionTerminated( QObject* session );
private slots:
void sessionProfileChanged();
private:
// loads the mappings between shortcut key sequences and
// profile paths
......
......@@ -74,6 +74,8 @@ ViewManager::ViewManager(QObject* parent , KActionCollection* collection)
// listen for profile changes
connect( SessionManager::instance() , SIGNAL(profileChanged(const QString&)) , this,
SLOT(profileChanged(const QString&)) );
connect( SessionManager::instance() , SIGNAL(sessionUpdated(Session*)) , this,
SLOT(updateViewsForSession(Session*)) );
}
ViewManager::~ViewManager()
......@@ -557,6 +559,15 @@ void ViewManager::applyProfile(TerminalDisplay* view , const QString& profileKey
view->setWordCharacters( info->property(Profile::WordCharacters).value<QString>() );
}
void ViewManager::updateViewsForSession(Session* session)
{
QListIterator<QPointer<TerminalDisplay> > iter(_sessionMap.keys(session));
while ( iter.hasNext() )
{
applyProfile(iter.next(),session->profileKey());
}
}
void ViewManager::profileChanged(const QString& key)
{
QHashIterator<QPointer<TerminalDisplay>,QPointer<Session> > iter(_sessionMap);
......
......@@ -176,6 +176,8 @@ private slots:
// called when a profile changes
void profileChanged(const QString& key);
void updateViewsForSession(Session* session);
private:
void setupActions();
void focusActiveView();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment