Commit 6f150bf7 authored by Robert Knight's avatar Robert Knight

Add settings store to SessionManager, use it for handling new shell from bookmark.

svn path=/trunk/KDE/kdebase/apps/konsole/; revision=590202
parent 8193d212
......@@ -184,7 +184,12 @@ SessionManager::~SessionManager()
delete infoIter.next();
}
TESession* SessionManager::createSession(QString configPath , const QString& initialDir)
void SessionManager::pushSessionSettings( const SessionInfo* info )
{
addSetting( InitialWorkingDirectory , SessionConfig , info->defaultWorkingDirectory() );
}
TESession* SessionManager::createSession(QString configPath )
{
TESession* session = 0;
......@@ -201,22 +206,20 @@ TESession* SessionManager::createSession(QString configPath , const QString& ini
if ( info->path() == configPath )
{
//supply settings from session config
pushSessionSettings( info );
//configuration information found, create a new session based on this
session = new TESession();
QListIterator<QString> iter(info->arguments());
while (iter.hasNext())
kDebug() << "running " << info->command(false) << ": argument " << iter.next() << endl;
session->setWorkingDirectory( activeSetting(InitialWorkingDirectory).toString() );
session->setProgram( info->command(false) );
session->setArguments( info->arguments() );
//use initial directory
if ( initialDir.isEmpty() )
session->setWorkingDirectory( info->defaultWorkingDirectory() );
else
session->setWorkingDirectory( initialDir );
session->setTitle( info->name() );
session->setIconName( info->icon() );
......@@ -252,4 +255,34 @@ SessionInfo* SessionManager::defaultSessionType()
return _defaultSessionType;
}
void SessionManager::addSetting( Setting setting, Source source, const QVariant& value)
{
_settings[setting] << SourceVariant(source,value);
}
QVariant SessionManager::activeSetting( Setting setting ) const
{
QListIterator<SourceVariant> sourceIter( _settings[setting] );
Source highestPrioritySource = ApplicationDefault;
QVariant value;
while (sourceIter.hasNext())
{
QPair<Source,QVariant> sourceSettingPair = sourceIter.next();
if ( sourceSettingPair.first >= highestPrioritySource )
{
value = sourceSettingPair.second;
highestPrioritySource = sourceSettingPair.first;
}
}
kDebug() << "active setting for " << setting << ": " << value << endl;
return value;
}
#include <SessionManager.moc>
#ifndef SESSIONMANAGER_H
#define SESSIONMANAGER_H
class KSimpleConfig;
#include <QVariant>
#include <QList>
class KSimpleConfig;
class TESession;
/**
......@@ -130,6 +133,27 @@ Q_OBJECT
public:
SessionManager();
virtual ~SessionManager();
/** document me */
enum Setting
{
Font = 0,
InitialWorkingDirectory = 1
};
/** document me */
//The values of these settings are significant, higher priority sources
//have higher values
enum Source
{
ApplicationDefault = 0,
GlobalConfig = 1,
SessionConfig = 2,
Commandline = 3,
Action = 4,
SingleShot = 5
};
/**
* Returns a list of session information
......@@ -138,20 +162,58 @@ public:
*/
QList<SessionInfo*> availableSessionTypes();
/**
* Returns a SessionInfo object describing the default type of session, as
* which is created if createSession() is called with an empty configPath
*/
SessionInfo* defaultSessionType();
/**
*
* Adds a setting which will be considered when creating new sessions.
* Each setting ( such as terminal font , initial working directory etc. )
* can be specified by multiple different sources. The
*
* For example, the working directory in which a new session starts is specified
* in the configuration file for that session type, but can be overridden
* by creating a new session from a bookmark or specifying what to use on
* the command line.
*
* The active value for a setting (ie. the one which will actually be used when
* creating the session) can be found using activeSetting()
*
* @p setting The setting to change
* @p source Specifies where the setting came from.
* @p value The new value for this setting,source pair
*/
void addSetting( Setting setting , Source source , const QVariant& value );
/**
* Returns the value for a particular setting which will be used
* when a new session is created.
*
* Values for settings come from different places, such as the command-line,
* config files and menu options.
*
* The active setting is the value for the setting which comes from the source
* with the highest priority. For example, a setting specified on the command-line
* when Konsole is launched will take priority over a setting specified in a
* configuration file.
*/
QVariant activeSetting( Setting setting ) const;
/**
* Creates a new session of the specified type.
* Creates a new session of the specified type, using the settings specified
* using addSetting() and from the configuration file for this session type.
*
* The new session has no views associated with it. A new TEWidget view
* must be created in order to display the output from the terminal session.
*
* @param type Specifies the type of session to create. Passing an empty
* string will create a session using the default configuration.
* @param initialDir Specifies the initial working directory for the new
* session. This may be an empty string, in which case the default
* directory
*/
TESession* createSession(QString configPath = QString() , const QString& initialDir = QString());
TESession* createSession(QString configPath = QString());
/**
* Returns a list of active sessions.
......@@ -166,10 +228,18 @@ protected Q_SLOTS:
void sessionTerminated( TESession* session );
private:
//fills the settings store with the settings from the session config file
void pushSessionSettings( const SessionInfo* info );
QList<SessionInfo*> _types;
QList<TESession*> _sessions;
SessionInfo* _defaultSessionType;
typedef QPair<Source,QVariant> SourceVariant;
QHash< Setting , QList< SourceVariant > > _settings;
};
#endif //SESSIONMANAGER_H
......@@ -2837,8 +2837,7 @@ TESession* Konsole::newSession(SessionInfo* type)
}
//create a session and attach the display to it
TESession* session = sessionManager()->createSession( type->path() ,
type->defaultWorkingDirectory() );
TESession* session = sessionManager()->createSession( type->path() );
session->setAddToUtmp(b_addToUtmp);
session->setXonXoff(true);
......@@ -2934,8 +2933,12 @@ void Konsole::newSession(const QString& sURL, const QString& /*title*/)
//TODO - Make use of session properties here
Q_ASSERT( 0 /* WARNING - New Session from URL Not Enabled Yet */ );
sessionManager()->addSetting( SessionManager::InitialWorkingDirectory ,
SessionManager::SingleShot ,
path );
newSession();
/* newSession(co, QString(), QStringList(), QString(), QString(),
title.isEmpty() ? path : title, path);*/
return;
......
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