Commit 933f433c authored by Robert Knight's avatar Robert Knight

Add class to parse command lines.

svn path=/branches/work/konsole-split-view/; revision=659615
parent 68760bdb
......@@ -69,6 +69,7 @@ set(konsole_KDEINIT_SRCS
ProcessInfo.cpp
ScreenWindow.cpp
SessionController.cpp
ShellCommand.cpp
ProfileList.cpp
ProfileListWidget.cpp
SessionManager.cpp
......@@ -142,6 +143,7 @@ set(konsolepart_PART_SRCS
ScreenWindow.cpp
Session.cpp
SessionController.cpp
ShellCommand.cpp
ProfileList.cpp
ProfileListWidget.cpp
SessionManager.cpp
......
......@@ -34,6 +34,7 @@
#include "ui_EditProfileDialog.h"
#include "EditProfileDialog.h"
#include "SessionManager.h"
#include "ShellCommand.h"
using namespace Konsole;
......@@ -134,8 +135,11 @@ void EditProfileDialog::initialDirChanged(const QString& dir)
}
void EditProfileDialog::commandChanged(const QString& command)
{
ShellCommand shellCommand(command);
//TODO Split into command and arguments
_tempProfile->setProperty(Profile::Command,command);
_tempProfile->setProperty(Profile::Command,shellCommand.command());
_tempProfile->setProperty(Profile::Arguments,shellCommand.arguments());
}
void EditProfileDialog::selectInitialDir()
{
......
......@@ -51,6 +51,9 @@ Profile::Profile(const Profile* parent)
setProperty(Font,QFont("Monospace"));
}
void Profile::setParent(const Profile* parent) { _parent = parent; }
const Profile* Profile::parent() const { return _parent; }
QHash<Profile::Property,QVariant> Profile::setProperties() const
{
return _propertyValues;
......
......@@ -90,6 +90,16 @@ public:
Profile(const Profile* parent = 0);
virtual ~Profile() {}
/**
* Changes the parent profile. When calling the property() method,
* if the specified property has not been set for this profile,
* the parent's value for the property will be returned instead.
*/
void setParent(const Profile* parent);
/** Returns the parent profile. */
const Profile* parent() const;
/**
* Returns the current value of the specified @p property.
*
......@@ -170,7 +180,7 @@ public:
private:
QHash<Property,QVariant> _propertyValues;
const Profile* const _parent;
const Profile* _parent;
static QHash<QString,Property> _propertyNames;
};
......
/*
Copyright (C) 2007 by Robert Knight <robertknight@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
// Qt
#include <QtDebug>
// Konsole
#include "ShellCommand.h"
using namespace Konsole;
ShellCommand::ShellCommand(const QString& fullCommand)
{
bool inQuotes = false;
QString builder;
for ( int i = 0 ; i < fullCommand.count() ; i++ )
{
QChar ch = fullCommand[i];
const bool isLastChar = ( i == fullCommand.count() - 1 );
const bool isQuote = ( ch == '\'' || ch == '\"' );
if ( !isLastChar && isQuote )
inQuotes = !inQuotes;
else
{
if ( (!ch.isSpace() || inQuotes) && !isQuote )
builder.append(ch);
if ( (ch.isSpace() && !inQuotes) || ( i == fullCommand.count()-1 ) )
{
_arguments << builder;
builder.clear();
}
}
}
//qDebug() << "Arguments:" << _arguments;
}
ShellCommand::ShellCommand(const QString& command , const QStringList& arguments)
{
_arguments = arguments;
arguments[0] == command;
}
QString ShellCommand::command() const
{
if ( !_arguments.isEmpty() )
return _arguments[0];
else
return QString::null;
}
QStringList ShellCommand::arguments() const
{
return _arguments;
}
bool ShellCommand::isRootCommand() const
{
Q_ASSERT(0); // not implemented yet
return false;
}
bool ShellCommand::isAvailable() const
{
Q_ASSERT(0); // not implemented yet
return false;
}
/*
Copyright (C) 2007 by Robert Knight <robertknight@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
#ifndef SHELLCOMMAND_H
#define SHELLCOMMAND_H
// Qt
#include <QStringList>
namespace Konsole
{
/** A class to parse and extract information about shell commands. */
class ShellCommand
{
public:
/**
* Constructs a ShellCommand from a command line.
*
* @param fullCommand The command line to parse.
*/
ShellCommand(const QString& fullCommand);
/**
* Constructs a ShellCommand with the specified @p command and @p arguments.
*/
ShellCommand(const QString& command , const QStringList& arguments);
/** Returns the command. */
QString command() const;
/** Returns the arguments. */
QStringList arguments() const;
/** Returns true if this is a root command. */
bool isRootCommand() const;
/** Returns true if the program specified by @p command() exists. */
bool isAvailable() const;
private:
QStringList _arguments;
};
};
#endif // SHELLCOMMAND_H
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