Commit 373c7a17 authored by Robert Knight's avatar Robert Knight

Fall back to value of SHELL environment variable if no command or arguments...

Fall back to value of SHELL environment variable if no command or arguments are specified for a process.  Continue work on Profile class.w

svn path=/branches/work/konsole-split-view/; revision=659346
parent 4f71fabf
......@@ -70,7 +70,7 @@ void EditProfileDialog::setProfile(const QString& key)
void EditProfileDialog::setupGeneralPage(const Profile* info)
{
_ui->sessionNameEdit->setText( info->name() );
_ui->commandEdit->setText( info->command(false,false) );
_ui->commandEdit->setText( info->command() );
_ui->initialDirEdit->setText( info->defaultWorkingDirectory() );
_ui->iconSelectButton->setIcon( KIcon(info->icon()) );
......@@ -107,7 +107,7 @@ void EditProfileDialog::setupAppearencePage(const Profile* info)
_ui->colorSchemeList->setItemDelegate(new ColorSchemeViewDelegate(this));
// setup font preview
const QFont& font = info->defaultFont();
const QFont& font = info->font();
_ui->fontPreviewLabel->setFont( font );
_ui->fontSizeSlider->setValue( font.pointSize() );
......
......@@ -233,6 +233,16 @@ void Session::run()
// Upon a KPty error, there is no description on what that error was...
// Check to see if the given program is executable.
QString exec = QFile::encodeName(_program);
// if 'exec' is not specified, fall back to shell
if ( exec.isEmpty() )
exec = getenv("SHELL");
// if no arguments are specified, fall back to shell
QStringList arguments = _arguments.join(QChar(' ')).isEmpty() ?
QStringList() << exec : _arguments;
exec = KRun::binaryName(exec, false);
exec = KShell::tildeExpand(exec);
QString pexec = KGlobal::dirs()->findExe(exec);
......@@ -249,7 +259,7 @@ void Session::run()
_shellProcess->setXonXoff(_flowControl);
int result = _shellProcess->run(QFile::encodeName(_program),
_arguments,
arguments,
_term.toLatin1(),
_winId,
_addToUtmp,
......
......@@ -41,35 +41,86 @@
using namespace Konsole;
SessionManager* SessionManager::_instance = 0;
QHash<QString,SessionSettings::Property> SessionSettings::_propertyNames;
QHash<QString,Profile::Property> Profile::_propertyNames;
QVariant SessionSettings::property(Property property) const
Profile::Profile(const Profile* parent)
: _parent(parent)
{
return _propertyValues[property];
setProperty(Command,getenv("SHELL"));
setProperty(Arguments,QStringList() << getenv("SHELL"));
setProperty(Font,QFont("Monospace"));
}
void SessionSettings::setProperty(Property property , const QVariant& value)
QVariant Profile::property(Property property) const
{
if ( _propertyValues.contains(property) )
return _propertyValues[property];
else if ( _parent )
return _parent->property(property);
else
return QVariant();
}
void Profile::setProperty(Property property , const QVariant& value)
{
_propertyValues.insert(property,value);
}
bool SessionSettings::isNameRegistered(const QString& name)
bool Profile::isPropertySet(Property property) const
{
return _propertyValues.contains(property);
}
bool Profile::isNameRegistered(const QString& name)
{
return _propertyNames.contains(name);
}
SessionSettings::Property SessionSettings::lookupByName(const QString& name)
Profile::Property Profile::lookupByName(const QString& name)
{
return _propertyNames[name];
}
QList<QString> SessionSettings::namesForProperty(Property property)
QList<QString> Profile::namesForProperty(Property property)
{
return _propertyNames.keys(property);
}
void SessionSettings::registerName(Property property , const QString& name)
void Profile::registerName(Property property , const QString& name)
{
_propertyNames.insert(name,property);
}
bool KDE3ProfileReader::readProfile(const QString& path , Profile* profile)
{
if (!QFile::exists(path))
return false;
KDesktopFile* desktopFile = new KDesktopFile(path);
KConfigGroup* config = new KConfigGroup( desktopFile->desktopGroup() );
if ( config->hasKey("Name") )
profile->setProperty(Profile::Name,config->readEntry("Name"));
qDebug() << "reading KDE 3 profile " << profile->name();
if ( config->hasKey("Icon") )
profile->setProperty(Profile::Icon,config->readEntry("Icon"));
if ( config->hasKey("Exec") )
{
const QString& fullCommand = config->readEntry("Exec");
qDebug() << "full command = " << fullCommand;
profile->setProperty(Profile::Command,fullCommand.section(QChar(' '),0,0));
profile->setProperty(Profile::Arguments,QStringList() << profile->command());//fullCommand.split(QChar(' ')));
qDebug() << "command = " << profile->command();
qDebug() << "argumetns = " << profile->arguments();
}
delete desktopFile;
delete config;
return true;
}
#if 0
Profile::Profile(const QString& path)
{
//QString fileName = QFileInfo(path).fileName();
......@@ -242,9 +293,12 @@ QString Profile::defaultWorkingDirectory() const
{
return _config->readPathEntry("Cwd");
}
#endif
SessionManager::SessionManager()
{
ProfileReader* kde3Reader = new KDE3ProfileReader;
//locate default session
KSharedConfigPtr appConfig = KGlobal::config();
//KConfig* appConfig = new KConfig("konsolerc");
......@@ -265,7 +319,10 @@ SessionManager::SessionManager()
{
QString configFile = fileIter.next();
Profile* newType = new Profile(configFile);
Profile* newType = new Profile();
newType->setProperty(Profile::Path,configFile);
kde3Reader->readProfile(configFile,newType);
QString sessionKey = addProfile( newType );
......@@ -279,6 +336,8 @@ SessionManager::SessionManager()
// now that the session types have been loaded,
// get the list of favorite sessions
loadFavorites();
delete kde3Reader;
}
SessionManager::~SessionManager()
......@@ -330,10 +389,10 @@ Session* SessionManager::createSession(QString key )
QListIterator<QString> iter(info->arguments());
while (iter.hasNext())
kDebug() << "running " << info->command(false) << ": argument " << iter.next() << endl;
kDebug() << "running " << info->command() << ": argument " << iter.next() << endl;
session->setInitialWorkingDirectory( activeSetting(InitialWorkingDirectory).toString() );
session->setProgram( info->command(false) );
session->setProgram( info->command() );
session->setArguments( info->arguments() );
session->setTitle( info->name() );
session->setIconName( info->icon() );
......
......@@ -40,13 +40,15 @@ namespace Konsole
class Session;
/** Replacement for Profile */
class SessionSettings
class Profile
{
public:
enum Property
{
// General session options
// Path to profile's config file
Path,
// General profile options
Name,
Title,
Icon,
......@@ -55,6 +57,14 @@ public:
Environment,
Directory,
// Tab Title Formats
LocalTabTitleFormat,
RemoteTabTitleFormat,
// Window & Tab Bar
ShowMenuBar,
TabBarMode,
// Appearence
Font,
ColorScheme,
......@@ -62,23 +72,75 @@ public:
// Keyboard
KeyBindings,
// Scrolling
ScrollingMode,
ScrollBarPosition,
// Terminal Features
SelectWordCharacters
SelectWordCharacters,
BlinkingTextEnabled,
FlowControlEnabled,
AllowProgramsToResizeWindow
};
virtual ~SessionSettings() {}
/**
* Constructs a new profile
*/
Profile(const Profile* parent = 0);
virtual ~Profile() {}
/** Returns the current value of the specified @p property. */
/**
* Returns the current value of the specified @p property.
*
* If the specified @p property has not been set in this profile,
* and a non-null parent was specified in the Profile's constructor,
* the parent's value for @p property will be returned.
*/
virtual QVariant property(Property property) const;
/** Sets the value of the specified @p property to @p value. */
virtual void setProperty(Property property,const QVariant& value);
/** Returns true if the specified property has been set in this Profile instance. */
virtual bool isPropertySet(Property property) const;
//
// Convenience methods for property() and setProperty() go here
//
/** Convenience method for property(Profile::Path) */
QString path() const { return property(Profile::Path).value<QString>(); }
/** Convenience method for property(Profile::Name) */
QString name() const { return property(Profile::Name).value<QString>(); }
/** Convenience method for property(Profile::Directory) */
QString defaultWorkingDirectory() const
{ return property(Profile::Directory).value<QString>(); }
/** Convenience method for property(Profile::Icon) */
QString icon() const { return property(Profile::Icon).value<QString>(); }
/** Convenience method for property(Profile::Command) */
QString command() const { return property(Profile::Command).value<QString>(); }
/** Convenience method for property(Profile::Arguments) */
QStringList arguments() const { return property(Profile::Arguments).value<QStringList>(); }
/** Convenience method for property(Profile::Font) */
QFont font() const { return property(Profile::Font).value<QFont>(); }
/** Convenience method for property(Profile::ColorScheme) */
QString colorScheme() const { return property(Profile::ColorScheme).value<QString>(); }
/** Convenience method for property(Profile::Environment) */
QStringList environment() const { return property(Profile::Environment).value<QStringList>(); }
/**
* Convenience method.
* Returns the value of the "TERM" value in the environment list.
*/
QString terminal() const { return "xterm"; }
/**
* Returns true if @p name has been associated with an element
* from the Property enum or false otherwise.
......@@ -105,10 +167,44 @@ public:
private:
QHash<Property,QVariant> _propertyValues;
const Profile* const _parent;
static QHash<QString,Property> _propertyNames;
};
/** Interface for all classes which can load profile settings from a file. */
class ProfileReader
{
public:
virtual ~ProfileReader() {}
virtual bool readProfile(const QString& path , Profile* profile) = 0;
};
/** Reads a KDE 3 profile .desktop file. */
class KDE3ProfileReader : public ProfileReader
{
public:
virtual bool readProfile(const QString& path , Profile* profile);
};
/** Reads a KDE 4 profile .desktop file. */
class KDE4ProfileReader : public ProfileReader
{
virtual bool readProfile(const QString& path , Profile* profile);
};
/** Interface for all classes which can write profile settings to a file. */
class ProfileWriter
{
public:
virtual ~ProfileWriter() {}
virtual bool writeProfile(const QString& path , const Profile* profile) = 0;
};
/** Writes a KDE 4 profile .desktop file. */
class KDE4ProfileWriter : public ProfileWriter
{
public:
virtual bool writeProfile(const QString& path);
};
#if 0
/**
* Provides information about a type of
* session, including the title of the session
......@@ -255,6 +351,7 @@ private:
QHash<Property,QVariant> _properties;
};
#endif
/**
* Creates new terminal sessions using information in configuration files.
......
......@@ -504,7 +504,7 @@ void ViewManager::loadViewSettings(TerminalDisplay* view , Session* session)
view->setColorTable(colorScheme->colorTable());
// load font, fall back to system monospace font if not specified
view->setVTFont(info->defaultFont());
view->setVTFont(info->font());
// set initial size
// temporary default used for now
......
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