Commit 5c6531e9 authored by Robert Knight's avatar Robert Knight

Merge from trunk and adapt to API changes

svn path=/branches/work/konsole-split-view/; revision=636041
parent 8c2eb77d
......@@ -29,8 +29,9 @@
#include <klocale.h>
#include <krun.h>
#include <kshell.h>
#include <ksimpleconfig.h>
#include <kconfig.h>
#include <kstandarddirs.h>
#include <kdesktopfile.h>
// Konsole
#include "TESession.h"
......@@ -44,17 +45,17 @@ SessionInfo::SessionInfo(const QString& path)
QString fullPath = KStandardDirs::locate("appdata",fileName);
Q_ASSERT( QFile::exists(fullPath) );
_config = new KSimpleConfig( fullPath , true );
_config->setDesktopGroup();
_desktopFile = new KDesktopFile( fullPath);
_config = new KConfigGroup( _desktopFile->desktopGroup() );
_path = path;
}
SessionInfo::~SessionInfo()
{
delete _config;
_config = 0;
delete _config; _config = 0;
delete _desktopFile; _desktopFile = 0;
}
QString SessionInfo::name() const
......@@ -77,24 +78,24 @@ bool SessionInfo::isRootSession() const
QString SessionInfo::command(bool stripRoot , bool stripArguments) const
{
QString fullCommand = _config->readEntry("Exec");
//if the .desktop file for this session doesn't specify a binary to run
QString fullCommand = _config->readEntry("Exec");
//if the .desktop file for this session doesn't specify a binary to run
//(eg. No 'Exec' entry or empty 'Exec' entry) then use the user's standard SHELL
if ( fullCommand.isEmpty() )
fullCommand = getenv("SHELL");
if ( isRootSession() && stripRoot )
{
//command is of the form "su -flags 'commandname'"
//we need to strip out and return just the command name part.
fullCommand = fullCommand.section('\'',1,1);
}
}
if ( fullCommand.isEmpty() )
fullCommand = getenv("SHELL");
if ( stripArguments )
if ( stripArguments )
return fullCommand.section(QChar(' '),0,0);
else
return fullCommand;
......@@ -106,20 +107,20 @@ QStringList SessionInfo::arguments() const
//FIXME: This wll fail where single arguments contain spaces (because slashes or quotation
//marks are used) - eg. vi My\ File\ Name
return commandString.split(QChar(' '));
return commandString.split(QChar(' '));
}
bool SessionInfo::isAvailable() const
{
//TODO: Is it necessary to cache the result of the search?
//TODO: Is it necessary to cache the result of the search?
QString binary = KRun::binaryName( command(true) , false );
binary = KShell::tildeExpand(binary);
QString fullBinaryPath = KGlobal::dirs()->findExe(binary);
if ( fullBinaryPath.isEmpty() )
return false;
return false;
else
return true;
}
......@@ -133,7 +134,7 @@ QString SessionInfo::path() const
QString SessionInfo::newSessionText() const
{
QString commentEntry = _config->readEntry("Comment");
if ( commentEntry.isEmpty() )
return i18n("New %1",name());
else
......@@ -169,27 +170,27 @@ SessionManager::SessionManager()
{
//locate default session
KSharedConfigPtr appConfig = KGlobal::config();
appConfig->setDesktopGroup();
const KConfigGroup group = appConfig->group( "Desktop Entry" );
QString defaultSessionFilename = appConfig->readEntry("DefaultSession","shell.desktop");
QString defaultSessionFilename = group.readEntry("DefaultSession","shell.desktop");
//locate config files and extract the most important properties of them from
//the config files.
//
//the sessions are only parsed completely when a session of this type
//the sessions are only parsed completely when a session of this type
//is actually created
QList<QString> files = KGlobal::dirs()->findAllResources("appdata", "*.desktop");
QList<QString> files = KGlobal::dirs()->findAllResources("appdata", "*.desktop", KStandardDirs::NoDuplicates);
QListIterator<QString> fileIter(files);
while (fileIter.hasNext())
{
{
QString configFile = fileIter.next();
SessionInfo* newType = new SessionInfo(configFile);
_types << newType;
_types << newType;
if ( QFileInfo(configFile).fileName() == defaultSessionFilename )
_defaultSessionType = newType;
}
......@@ -204,7 +205,7 @@ SessionManager::SessionManager()
SessionManager::~SessionManager()
{
QListIterator<SessionInfo*> infoIter(_types);
while (infoIter.hasNext())
delete infoIter.next();
......@@ -232,7 +233,7 @@ TESession* SessionManager::createSession(QString configPath )
//search for SessionInfo object built from this config path
QListIterator<SessionInfo*> iter(_types);
while (iter.hasNext())
{
const SessionInfo* const info = iter.next();
......@@ -241,7 +242,7 @@ TESession* SessionManager::createSession(QString configPath )
{
//supply settings from session config
pushSessionSettings( info );
//configuration information found, create a new session based on this
session = new TESession();
......@@ -261,17 +262,17 @@ TESession* SessionManager::createSession(QString configPath )
session->setHistory( HistoryTypeBuffer(1000) );
//ask for notification when session dies
connect( session , SIGNAL(done(TESession*)) , SLOT(sessionTerminated(TESession*)) );
connect( session , SIGNAL(done(TESession*)) , SLOT(sessionTerminated(TESession*)) );
//add session to active list
_sessions << session;
//add session to active list
_sessions << session;
break;
break;
}
}
Q_ASSERT( session );
return session;
}
......@@ -283,7 +284,7 @@ void SessionManager::sessionTerminated(TESession* session)
QList<SessionInfo*> SessionManager::availableSessionTypes()
{
return _types;
return _types;
}
SessionInfo* SessionManager::defaultSessionType()
......@@ -301,20 +302,20 @@ 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;
highestPrioritySource = sourceSettingPair.first;
}
}
}
return value;
}
......
......@@ -26,8 +26,8 @@
#include <QList>
#include <QPair>
#include <QVariant>
class KSimpleConfig;
class KConfigGroup;
class KDesktopFile;
class KConfig;
class TESession;
......@@ -40,14 +40,14 @@ class ColorSchemaList;
* as root and whether or not the binary
* for the session is available.
*
* The availability of the session type is not determined until the
* The availability of the session type is not determined until the
* isAvailable() method is called.
*
*/
class SessionInfo
*
*/
class SessionInfo
{
public:
/**
/**
* Construct a new SessionInfo
* to provide information on a session type.
*
......@@ -57,8 +57,8 @@ public:
SessionInfo(const QString& path);
~SessionInfo();
/**
/**
* Returns the path to the session's
* config file
*/
......@@ -66,12 +66,12 @@ public:
/** Returns the title of the session type */
QString name() const;
/**
/**
* Returns the path of an icon associated
* with this session type
*/
QString icon() const;
/**
/**
* Returns the command that will be executed
* when the session is run
*
......@@ -79,24 +79,24 @@ public:
* "su -flags 'commandname'", specifies whether
* to return the whole command string or just
* the 'commandname' part
*
* eg. If the command string is
*
* eg. If the command string is
* "su -c 'screen'", command(true) will
* just return "screen"
*
* @param stripArguments Specifies whether the arguments should be
* @param stripArguments Specifies whether the arguments should be
* removed from the returned string. Anything after the first space
* character in the command string is considered an argument
* character in the command string is considered an argument
*/
QString command(bool stripSu , bool stripArguments = true) const;
/**
/**
* Extracts the arguments from the command string for this session. The first
* argument is always the command name
*/
QStringList arguments() const;
/**
/**
* Returns true if the session will run as
* root
*/
......@@ -105,14 +105,14 @@ public:
* Searches the user's PATH for the binary
* specified in the command string.
*
* TODO: isAvailable() assumes and does not yet verify the
* existence of additional binaries(usually 'su' or 'sudo') required
* TODO: isAvailable() assumes and does not yet verify the
* existence of additional binaries(usually 'su' or 'sudo') required
* to run the command as root.
*/
bool isAvailable() const;
/**
* Returns the terminal-type string which is made available to
/**
* Returns the terminal-type string which is made available to
* programs running in sessions of this type via the $TERM environment variable.
*
* This defaults to "xterm"
......@@ -125,7 +125,7 @@ public:
/** Returns the path of the default colour scheme for sessions of this type */
QString colorScheme() const;
/**
/**
* Returns the default font for sessions of this type.
* If no font is specified in the session's configuration file, @p font will be returned.
*/
......@@ -134,31 +134,32 @@ public:
/** Returns the default working directory for sessions of this type */
QString defaultWorkingDirectory() const;
/**
/**
* Returns the text that should be displayed in menus or in other UI widgets
* which are used to create new instances of this type of session
*/
QString newSessionText() const;
private:
KConfig* _config;
KDesktopFile* _desktopFile;
KConfigGroup* _config;
QString _path;
};
/**
* Creates new terminal sessions using information in configuration files.
* Information about the available session kinds can be obtained using
* availableSessionTypes(). Call createSession() to create a new session.
* The session will automatically notify the SessionManager when it finishes running.
*/
/**
* Creates new terminal sessions using information in configuration files.
* Information about the available session kinds can be obtained using
* availableSessionTypes(). Call createSession() to create a new session.
* The session will automatically notify the SessionManager when it finishes running.
*/
class SessionManager : public QObject
{
Q_OBJECT
Q_OBJECT
public:
SessionManager();
virtual ~SessionManager();
/** document me */
enum Setting
{
......@@ -182,7 +183,7 @@ public:
Action = 4,
SingleShot = 5
};
/**
* Returns a list of session information
* objects which describe the kinds
......@@ -190,33 +191,33 @@ public:
*/
QList<SessionInfo*> availableSessionTypes();
/**
/**
* Returns a SessionInfo object describing the default type of session, which is used
* if createSession() is called with an empty configPath argument.
*/
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
* 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 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.
*
......@@ -225,24 +226,24 @@ public:
*
* 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
* when Konsole is launched will take priority over a setting specified in a
* configuration file.
*/
QVariant activeSetting( Setting setting ) const;
/**
QVariant activeSetting( Setting setting ) const;
/**
* 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 and
* must be created in order to display the output from the terminal session and
* send keyboard or mouse input to it.
*
* @param type Specifies the type of session to create. Passing an empty
* string will create a session using the default configuration.
*/
TESession* createSession(QString configPath = QString());
/**
* Returns a list of active sessions.
*/
......@@ -251,15 +252,15 @@ public:
protected Q_SLOTS:
/**
* Called to inform the manager that a session has finished executing
* Called to inform the manager that a session has finished executing
*/
void sessionTerminated( TESession* session );
private:
//fills the settings store with the settings from the session config file
//fills the settings store with the settings from the session config file
void pushSessionSettings( const SessionInfo* info );
QList<SessionInfo*> _types;
QList<SessionInfo*> _types;
QList<TESession*> _sessions;
SessionInfo* _defaultSessionType;
......
......@@ -108,6 +108,7 @@ TabbedViewContainer::TabbedViewContainer(QObject* parent) :
,_contextMenuTab(0)
{
_tabWidget = new KTabWidget();
_tabWidget->setDrawTabFrame(false);
_tabContextMenu = new KMenu(_tabWidget);
_newSessionButton = new QToolButton(_tabWidget);
......@@ -216,7 +217,7 @@ void TabbedViewContainer::prepareColorCells()
QColor activeTabColor = _tabWidget->tabTextColor( _contextMenuTab );
for (int i=0;i<_tabColorCells->numCells();i++)
for (int i=0;i<_tabColorCells->count();i++)
if ( activeTabColor == _tabColorCells->color(i) )
{
_tabColorCells->setSelected(i);
......@@ -289,7 +290,7 @@ void TabbedViewContainer::selectTabColor()
//default back to showing KDE's color dialog instead.
if ( _tabColorCells )
{
color = _tabColorCells->color(_tabColorCells->getSelected());
color = _tabColorCells->color(_tabColorCells->selectedIndex());
if (!color.isValid())
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