Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit f38228b8 authored by Robert Knight's avatar Robert Knight

Implement saving, loading and deleting of profiles in the Konsole (KDE 4)...

Implement saving, loading and deleting of profiles in the Konsole (KDE 4) .profile format.  Only the basic options are saved and loaded at present.

svn path=/branches/work/konsole-split-view/; revision=659852
parent 15c38806
......@@ -45,6 +45,8 @@ EditProfileDialog::EditProfileDialog(QWidget* parent)
setCaption("Edit Profile");
setButtons( KDialog::Ok | KDialog::Cancel | KDialog::Apply | KDialog::Default );
connect( this , SIGNAL(applyClicked()) , this , SLOT(save()) );
_ui = new Ui::EditProfileDialog();
_ui->setupUi(mainWidget());
......@@ -55,12 +57,16 @@ EditProfileDialog::~EditProfileDialog()
delete _ui;
delete _tempProfile;
}
void EditProfileDialog::accept()
void EditProfileDialog::save()
{
qDebug() << "Edit profile dialog accepted.";
if ( _tempProfile->isEmpty() )
return;
SessionManager::instance()->changeProfile(_profileKey,_tempProfile->setProperties());
}
void EditProfileDialog::accept()
{
save();
KDialog::accept();
}
void EditProfileDialog::setProfile(const QString& key)
......@@ -80,6 +86,12 @@ void EditProfileDialog::setProfile(const QString& key)
setupKeyboardPage(info);
setupScrollingPage(info);
setupAdvancedPage(info);
if ( _tempProfile )
{
delete _tempProfile;
_tempProfile = new Profile;
}
}
void EditProfileDialog::setupGeneralPage(const Profile* info)
{
......@@ -264,7 +276,7 @@ void ColorSchemeViewDelegate::paint(QPainter* painter, const QStyleOptionViewIte
painter->fillRect( option.rect , brush );
const ColorEntry* entries = scheme->colorTable();
const qreal colorRectWidth = option.rect.width() / TABLE_COLORS;
const qreal colorRectWidth = qMin(option.rect.width(),256) / TABLE_COLORS;
const qreal colorRectHeight = colorRectWidth;
qreal x = 0;
qreal y = option.rect.bottom() - colorRectHeight;
......
......@@ -66,6 +66,9 @@ public slots:
virtual void accept();
private slots:
// saves changes to profile
void save();
// general page
void selectInitialDir();
void selectIcon();
......
......@@ -77,6 +77,9 @@ ManageProfilesDialog::~ManageProfilesDialog()
}
void ManageProfilesDialog::updateTableModel()
{
// ensure profiles list is complete
SessionManager::instance()->loadAllProfiles();
// setup session table
_sessionModel = new QStandardItemModel(this);
_sessionModel->setHorizontalHeaderLabels( QStringList() << "Name"
......@@ -88,6 +91,9 @@ void ManageProfilesDialog::updateTableModel()
Profile* info = SessionManager::instance()->profile(key);
if ( info->isHidden() )
continue;
QList<QStandardItem*> itemList;
QStandardItem* item = new QStandardItem( info->name() );
......@@ -95,7 +101,7 @@ void ManageProfilesDialog::updateTableModel()
item->setIcon( KIcon(info->icon()) );
item->setData(key);
const bool isFavorite = SessionManager::instance()->favorites().contains(key);
const bool isFavorite = SessionManager::instance()->findFavorites().contains(key);
QStandardItem* favoriteItem = new QStandardItem();
if ( isFavorite )
......@@ -182,9 +188,19 @@ void ManageProfilesDialog::setSelectedAsDefault()
void ManageProfilesDialog::newType()
{
EditProfileDialog dialog(this);
// base new type off the default session type
dialog.setProfile(QString());
dialog.exec();
// setup a temporary profile, inheriting from the default profile
Profile* defaultProfile = SessionManager::instance()->defaultProfile();
Profile* newProfile = new Profile(defaultProfile);
newProfile->setProperty(Profile::Name,i18n("New Profile"));
const QString& key = SessionManager::instance()->addProfile(newProfile);
dialog.setProfile(key);
// if the user doesn't accept the dialog, remove the temporary profile
// if they do accept the dialog, it will become a permanent profile
if ( dialog.exec() != QDialog::Accepted )
SessionManager::instance()->deleteProfile(key);
}
void ManageProfilesDialog::editSelected()
{
......@@ -213,7 +229,7 @@ bool ProfileItemDelegate::editorEvent(QEvent* event,QAbstractItemModel* model,
if ( event->type() == QEvent::MouseButtonPress || event->type() == QEvent::KeyPress )
{
const QString& key = index.data(Qt::UserRole + 1).value<QString>();
const bool isFavorite = !SessionManager::instance()->favorites().contains(key);
const bool isFavorite = !SessionManager::instance()->findFavorites().contains(key);
SessionManager::instance()->setFavorite(key,
isFavorite);
......
......@@ -20,7 +20,7 @@ ProfileList::ProfileList(QObject* parent)
// construct the list of favorite session types
_group = new QActionGroup(this);
QList<QString> list = manager->favorites().toList();
QList<QString> list = manager->findFavorites().toList();
qSort(list);
QListIterator<QString> iter(list);
......
......@@ -63,7 +63,7 @@ QString RemoteConnectionDialog::service() const
QString RemoteConnectionDialog::sessionKey() const
{
SessionManager* manager = SessionManager::instance();
// SessionManager* manager = SessionManager::instance();
/*MutableSessionInfo* customSession =
new MutableSessionInfo(manager->defaultSessionType()->path());
......
......@@ -116,13 +116,17 @@ void SessionController::snapshot()
else
process = snapshot;
QString title;
if ( process->name(&ok) == "ssh" && ok )
{
SSHProcessInfo sshInfo(*process);
_session->setTitle( sshInfo.format(_session->tabTitleFormat(Session::RemoteTabTitle)) );
title = sshInfo.format(_session->tabTitleFormat(Session::RemoteTabTitle));
}
else
_session->setTitle( process->format(_session->tabTitleFormat(Session::LocalTabTitle) ) );
title = process->format(_session->tabTitleFormat(Session::LocalTabTitle) ) ;
if ( !title.isEmpty() )
_session->setTitle(title);
if ( snapshot != process )
{
......@@ -465,6 +469,7 @@ void SessionController::debugProcess()
void SessionController::editCurrentProfile()
{
EditProfileDialog dialog(_view);
dialog.setProfile(_session->type());
dialog.exec();
}
......
This diff is collapsed.
......@@ -29,6 +29,7 @@
#include <QSet>
#include <QStringList>
#include <QPair>
#include <QPointer>
#include <QVariant>
class KConfigGroup;
......@@ -40,7 +41,7 @@ namespace Konsole
class Session;
class Profile
class Profile : public QObject
{
public:
enum Property
......@@ -87,7 +88,7 @@ public:
/**
* Constructs a new profile
*/
Profile(const Profile* parent = 0);
Profile(Profile* parent = 0);
virtual ~Profile() {}
/**
......@@ -95,7 +96,7 @@ public:
* 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);
void setParent(Profile* parent);
/** Returns the parent profile. */
const Profile* parent() const;
......@@ -116,6 +117,18 @@ public:
/** Returns a map of the properties set in this Profile instance. */
virtual QHash<Property,QVariant> setProperties() const;
/** Returns true if no properties have been set in this Profile instance. */
bool isEmpty() const;
/**
* Returns true if this is a 'hidden' profile which should not be displayed
* in menus.
*/
bool isHidden() const;
/** Specifies whether this is a hidden profile. See isHidden() */
void setHidden(bool hidden);
//
// Convenience methods for property() and setProperty() go here
//
......@@ -180,27 +193,39 @@ public:
private:
QHash<Property,QVariant> _propertyValues;
const Profile* _parent;
QPointer<Profile> _parent;
bool _hidden;
static QHash<QString,Property> _propertyNames;
};
class FallbackProfile : public Profile
{
public:
FallbackProfile();
};
/** Interface for all classes which can load profile settings from a file. */
class ProfileReader
{
public:
virtual ~ProfileReader() {}
virtual QStringList findProfiles() { return QStringList(); }
virtual bool readProfile(const QString& path , Profile* profile) = 0;
};
/** Reads a KDE 3 profile .desktop file. */
class KDE3ProfileReader : public ProfileReader
{
public:
virtual QStringList findProfiles();
virtual bool readProfile(const QString& path , Profile* profile);
};
/** Reads a KDE 4 profile .desktop file. */
/** Reads a KDE 4 .profile file. */
class KDE4ProfileReader : public ProfileReader
{
public:
virtual QStringList findProfiles();
virtual bool readProfile(const QString& path , Profile* profile);
};
/** Interface for all classes which can write profile settings to a file. */
......@@ -208,13 +233,15 @@ class ProfileWriter
{
public:
virtual ~ProfileWriter() {}
virtual QString getPath(const Profile* profile) = 0;
virtual bool writeProfile(const QString& path , const Profile* profile) = 0;
};
/** Writes a KDE 4 profile .desktop file. */
/** Writes a KDE 4 .profile file. */
class KDE4ProfileWriter : public ProfileWriter
{
public:
virtual bool writeProfile(const QString& path);
virtual QString getPath(const Profile* profile);
virtual bool writeProfile(const QString& path , const Profile* profile);
};
#if 0
......@@ -389,30 +416,6 @@ public:
SessionManager();
virtual ~SessionManager();
/** document me */
enum Setting
{
Font = 0,
InitialWorkingDirectory = 1,
ColorScheme = 2,
HistoryEnabled = 3,
HistorySize = 4 // set to 0 for unlimited history ( stored in a file )
};
/** 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 keys for registered profiles.
*/
......@@ -454,40 +457,6 @@ public:
*/
QString defaultProfileKey() const;
/**
* 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 profile, 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 from the specified profile, using the settings specified
* using addSetting() and from profile associated with the specified key.
......@@ -524,7 +493,7 @@ public:
/**
* Returns the set of keys for the user's favorite profiles.
*/
QSet<QString> favorites() const;
QSet<QString> findFavorites() ;
/**
* Specifies whether a profile should be included in the user's
......@@ -532,6 +501,9 @@ public:
*/
void setFavorite(const QString& key , bool favorite);
/** Loads all available profiles. */
void loadAllProfiles();
/**
* Sets the global session manager instance.
*/
......@@ -565,12 +537,14 @@ protected Q_SLOTS:
void sessionTerminated( Session* session );
private:
//fills the settings store with the settings from the session config file
void pushSessionSettings( const Profile* info );
//loads the set of favorite sessions
//loads the set of favorite sessions
void loadFavorites();
//saves the set of favorite sessions
void saveFavorites();
//loads a profile from a file
QString loadProfile(const QString& path);
// saves a profile to a file
void saveProfile(const QString& path , Profile* profile);
// applies updates to the profile associated with @p key
// to all sessions currently using that profile
......@@ -581,19 +555,17 @@ private:
// if modifiedPropertiesOnly is true, only properties which
// are set in @p info are update ( ie. properties for which info->isPropertySet(<property>)
// returns true )
void applyProfile(Session* session , Profile* info , bool modifiedPropertiesOnly);
void applyProfile(Session* session , const Profile* info , bool modifiedPropertiesOnly);
QHash<QString,Profile*> _types;
QList<Session*> _sessions;
QString _defaultProfile;
typedef QPair<Source,QVariant> SourceVariant;
QHash< Setting , QList< SourceVariant > > _settings;
QSet<QString> _favorites;
bool _loadedAllProfiles;
static SessionManager* _instance;
};
......
......@@ -58,7 +58,13 @@ ShellCommand::ShellCommand(const QString& fullCommand)
ShellCommand::ShellCommand(const QString& command , const QStringList& arguments)
{
_arguments = arguments;
arguments[0] == command;
if ( !_arguments.isEmpty() )
_arguments[0] == command;
}
QString ShellCommand::fullCommand() const
{
return _arguments.join(QChar(' '));
}
QString ShellCommand::command() const
{
......
......@@ -46,6 +46,9 @@ public:
/** Returns the arguments. */
QStringList arguments() const;
/** Returns the full command line. */
QString fullCommand() const;
/** Returns true if this is a root command. */
bool isRootCommand() const;
/** Returns true if the program specified by @p command() exists. */
......
......@@ -373,6 +373,12 @@ void ViewManager::createView(Session* session)
ViewContainer* container = containerIter.next();
TerminalDisplay* display = createTerminalDisplay();
loadViewSettings(display,SessionManager::instance()->profile(session->type()));
// set initial size
// temporary default used for now
display->setSize(80,40);
ViewProperties* properties = createController(session,display);
_sessionMap[display] = session;
......@@ -491,10 +497,7 @@ TerminalDisplay* ViewManager::createTerminalDisplay()
display->setTerminalSizeStartup(false);
display->setScrollBarLocation(TerminalDisplay::SCROLLBAR_RIGHT);
// set initial size
// temporary default used for now
display->setSize(80,40);
return display;
}
......@@ -525,7 +528,7 @@ void ViewManager::profileChanged(const QString& key)
iter.next();
// if session uses this profile, update the display
if ( iter.value()->type() == key )
if ( iter.value() != 0 && iter.value()->type() == key )
{
loadViewSettings(iter.key(),info);
}
......
[General]
Name="Shell"
Command=""
Name=Shell
Icon=konsole
LocalTabTitleFormat=%d : %n
RemoteTabTitleFormat=%h : %u
[Appearence]
ColorScheme= BlackOnWhite
[Scrolling]
ScrollMode=FixedLineCount
ScrollLineCount=1000
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