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 278429bb authored by Robert Knight's avatar Robert Knight

Beginning of code to listen for changes made to profiles and apply them to...

Beginning of code to listen for changes made to profiles and apply them to existing sessions and views.

svn path=/branches/work/konsole-split-view/; revision=659579
parent 373c7a17
......@@ -26,6 +26,7 @@
// KDE
#include <KFontDialog>
#include <KIcon>
#include <KIconDialog>
#include <KDirSelectDialog>
// Konsole
......@@ -44,14 +45,25 @@ EditProfileDialog::EditProfileDialog(QWidget* parent)
_ui = new Ui::EditProfileDialog();
_ui->setupUi(mainWidget());
_tempProfile = new Profile;
}
EditProfileDialog::~EditProfileDialog()
{
delete _ui;
delete _tempProfile;
}
void EditProfileDialog::accept()
{
qDebug() << "Edit profile dialog accepted.";
SessionManager::instance()->changeProfile(_profileKey,_tempProfile->setProperties());
KDialog::accept();
}
void EditProfileDialog::setProfile(const QString& key)
{
_profileKey = key;
_profileKey = key;
const Profile* info = SessionManager::instance()->profile(key);
......@@ -69,13 +81,57 @@ void EditProfileDialog::setProfile(const QString& key)
}
void EditProfileDialog::setupGeneralPage(const Profile* info)
{
_ui->sessionNameEdit->setText( info->name() );
_ui->profileNameEdit->setText( info->name() );
_ui->commandEdit->setText( info->command() );
_ui->initialDirEdit->setText( info->defaultWorkingDirectory() );
_ui->iconSelectButton->setIcon( KIcon(info->icon()) );
// signals and slots
connect( _ui->dirSelectButton , SIGNAL(clicked()) , this , SLOT(selectInitialDir()) );
connect( _ui->iconSelectButton , SIGNAL(clicked()) , this , SLOT(selectIcon()) );
connect( _ui->profileNameEdit , SIGNAL(textChanged(const QString&)) , this ,
SLOT(profileNameChanged(const QString&)) );
connect( _ui->initialDirEdit , SIGNAL(textChanged(const QString&)) , this ,
SLOT(initialDirChanged(const QString&)) );
connect(_ui->commandEdit , SIGNAL(textChanged(const QString&)) , this ,
SLOT(commandChanged(const QString&)) );
connect(_ui->tabTitleEdit , SIGNAL(textChanged(const QString&)) , this ,
SLOT(tabTitleFormatChanged(const QString&)) );
connect(_ui->remoteTabTitleEdit , SIGNAL(textChanged(const QString&)) , this ,
SLOT(remoteTabTitleFormatChanged(const QString&)));
}
void EditProfileDialog::tabTitleFormatChanged(const QString& format)
{
_tempProfile->setProperty(Profile::LocalTabTitleFormat,format);
}
void EditProfileDialog::remoteTabTitleFormatChanged(const QString& format)
{
_tempProfile->setProperty(Profile::RemoteTabTitleFormat,format);
}
void EditProfileDialog::selectIcon()
{
const QString& icon = KIconDialog::getIcon();
if (!icon.isEmpty())
{
_ui->iconSelectButton->setIcon( KIcon(icon) );
_tempProfile->setProperty(Profile::Icon,icon);
}
}
void EditProfileDialog::profileNameChanged(const QString& text)
{
_tempProfile->setProperty(Profile::Name,text);
}
void EditProfileDialog::initialDirChanged(const QString& dir)
{
_tempProfile->setProperty(Profile::Directory,dir);
}
void EditProfileDialog::commandChanged(const QString& command)
{
//TODO Split into command and arguments
_tempProfile->setProperty(Profile::Command,command);
}
void EditProfileDialog::selectInitialDir()
{
......@@ -141,6 +197,8 @@ void EditProfileDialog::showFontDialog()
qMax(slider->maximum(),currentFont.pointSize()) );
_ui->fontSizeSlider->setValue(currentFont.pointSize());
_ui->fontPreviewLabel->setFont(currentFont);
_tempProfile->setProperty(Profile::Font,currentFont);
}
}
void EditProfileDialog::setFontSize(int pointSize)
......@@ -148,6 +206,8 @@ void EditProfileDialog::setFontSize(int pointSize)
QFont newFont = _ui->fontPreviewLabel->font();
newFont.setPointSize(pointSize);
_ui->fontPreviewLabel->setFont( newFont );
_tempProfile->setProperty(Profile::Font,newFont);
}
ColorSchemeViewDelegate::ColorSchemeViewDelegate(QObject* parent)
: QAbstractItemDelegate(parent)
......
......@@ -36,7 +36,6 @@ namespace Konsole
{
class Profile;
class MutableSessionInfo;
/**
* A dialog which allows the user to edit a session type.
......@@ -56,18 +55,26 @@ public:
* Initialises the dialog with the settings for the specified session
* type.
*
* When the dialog closes, the profile will be updated in the SessionManager
* with the altered settings.
*
* @param key The key for the session type provided by the SessionManager instance
*/
void setProfile(const QString& key);
/**
* Returns a profile instance representing the new or modified profile.
*/
Profile* newProfile();
public slots:
virtual void accept();
private slots:
// general page
void selectInitialDir();
void selectIcon();
void profileNameChanged(const QString& text);
void initialDirChanged(const QString& text);
void commandChanged(const QString& text);
void tabTitleFormatChanged(const QString& text);
void remoteTabTitleFormatChanged(const QString& text);
// appearence page
void setFontSize(int pointSize);
......@@ -81,14 +88,8 @@ private:
void setupScrollingPage(const Profile* info);
void setupAdvancedPage(const Profile* info);
// apply changes from various pages of the dialog
void applyGeneralPage(MutableSessionInfo* info);
void applyAppearencePage(MutableSessionInfo* info);
void applyKeyboardPage(MutableSessionInfo* info);
void applyScrollingPage(MutableSessionInfo* info);
void applyAdvancedPage(MutableSessionInfo* info);
Ui::EditProfileDialog* _ui;
Profile* _tempProfile;
QString _profileKey;
};
......
......@@ -46,7 +46,7 @@
</widget>
</item>
<item row="0" column="1" colspan="2" >
<widget class="QLineEdit" name="sessionNameEdit" />
<widget class="QLineEdit" name="profileNameEdit" />
</item>
<item row="1" column="0" >
<widget class="QLabel" name="label_3" >
......@@ -143,10 +143,10 @@
</widget>
</item>
<item row="0" column="1" >
<widget class="QLineEdit" name="lineEdit" />
<widget class="QLineEdit" name="tabTitleEdit" />
</item>
<item row="0" column="2" >
<widget class="QPushButton" name="pushButton" >
<widget class="QPushButton" name="tabTitleEditButton" >
<property name="text" >
<string>Edit...</string>
</property>
......@@ -160,10 +160,10 @@
</widget>
</item>
<item row="1" column="1" >
<widget class="QLineEdit" name="lineEdit_2" />
<widget class="QLineEdit" name="remoteTabTitleEdit" />
</item>
<item row="1" column="2" >
<widget class="QPushButton" name="pushButton_2" >
<widget class="QPushButton" name="remoteTabTitleEditButton" >
<property name="text" >
<string>Edit..</string>
</property>
......
......@@ -53,6 +53,8 @@ ManageProfilesDialog::ManageProfilesDialog(QWidget* parent)
SLOT(updateTableModel()) );
connect( SessionManager::instance() , SIGNAL(profileRemoved(const QString&)) , this,
SLOT(updateTableModel()) );
connect( SessionManager::instance() , SIGNAL(profileChanged(const QString&)) , this,
SLOT(updateTableModel()) );
// ensure that session names are fully visible
_ui->sessionTable->resizeColumnToContents(0);
......@@ -88,8 +90,10 @@ void ManageProfilesDialog::updateTableModel()
QList<QStandardItem*> itemList;
QStandardItem* item = new QStandardItem( info->name() );
item->setData(key);
if ( !info->icon().isEmpty() )
item->setIcon( KIcon(info->icon()) );
item->setData(key);
const bool isFavorite = SessionManager::instance()->favorites().contains(key);
......
......@@ -35,6 +35,36 @@ ProfileList::ProfileList(QObject* parent)
// listen for future changes to the session list
connect( manager , SIGNAL(favoriteStatusChanged(const QString&,bool)) , this ,
SLOT(favoriteChanged(const QString&,bool)) );
connect( manager , SIGNAL(profileChanged(const QString&)) , this ,
SLOT(profileChanged(const QString&)) );
}
QAction* ProfileList::actionForKey(const QString& key) const
{
QListIterator<QAction*> iter(_group->actions());
while ( iter.hasNext() )
{
QAction* next = iter.next();
if ( next->data() == key )
return next;
}
return 0; // not found
}
void ProfileList::profileChanged(const QString& key)
{
QAction* action = actionForKey(key);
if ( action )
updateAction(action,SessionManager::instance()->profile(key));
}
void ProfileList::updateAction(QAction* action , Profile* info)
{
Q_ASSERT(action);
Q_ASSERT(info);
action->setText(info->name());
action->setIcon(KIcon(info->icon()));
}
void ProfileList::favoriteChanged(const QString& key,bool isFavorite)
......@@ -43,23 +73,22 @@ void ProfileList::favoriteChanged(const QString& key,bool isFavorite)
{
Profile* info = SessionManager::instance()->profile(key);
QAction* action = _group->addAction(info->name());
action->setIcon( KIcon(info->icon()) );
QAction* action = new QAction(_group);
action->setData( key );
updateAction(action,info);
emit actionsChanged(_group->actions());
}
else
{
QListIterator<QAction*> iter(_group->actions());
while ( iter.hasNext() )
QAction* action = actionForKey(key);
if ( action )
{
QAction* next = iter.next();
if ( next->data() == key )
_group->removeAction(next);
_group->removeAction(action);
emit actionsChanged(_group->actions());
}
emit actionsChanged(_group->actions());
}
}
......
......@@ -11,6 +11,8 @@ class QActionGroup;
namespace Konsole
{
class Profile;
/**
* ProfileList provides a list of actions which represent session profiles that a SessionManager
* can create a session from. These actions can be plugged into a GUI
......@@ -49,8 +51,12 @@ signals:
private slots:
void triggered(QAction* action);
void favoriteChanged(const QString& key , bool isFavorite);
void profileChanged(const QString& key);
private:
QAction* actionForKey(const QString& key) const;
void updateAction(QAction* action , Profile* profile);
QActionGroup* _group;
};
......
......@@ -46,7 +46,6 @@
// Konsole
#include <config-konsole.h>
#include "ColorScheme.h"
//TODO - Re-add adaptors
//#include "sessionadaptor.h"
//#include "sessionscriptingadaptor.h"
......
......@@ -131,7 +131,6 @@ private slots:
void decreaseTextSize();
void renameSession();
void saveSession();
// other
void showDisplayContextMenu(TerminalDisplay* display , int state , int x , int y);
......
......@@ -51,6 +51,11 @@ Profile::Profile(const Profile* parent)
setProperty(Font,QFont("Monospace"));
}
QHash<Profile::Property,QVariant> Profile::setProperties() const
{
return _propertyValues;
}
QVariant Profile::property(Property property) const
{
if ( _propertyValues.contains(property) )
......@@ -476,6 +481,44 @@ QVariant SessionManager::activeSetting( Setting setting ) const
return value;
}
void SessionManager::changeProfile(const QString& key ,
QHash<Profile::Property,QVariant> propertyMap)
{
Profile* info = profile(key);
qDebug() << "Profile changed: " << info->name();
QListIterator<Profile::Property> iter(propertyMap.keys());
while ( iter.hasNext() )
{
const Profile::Property property = iter.next();
info->setProperty(property,propertyMap[property]);
}
applyProfile(key,true);
emit profileChanged(key);
}
void SessionManager::applyProfile(const QString& key , bool modifiedPropertiesOnly)
{
Profile* info = profile(key);
QListIterator<Session*> iter(_sessions);
while ( iter.hasNext() )
{
Session* next = iter.next();
if ( next->type() == key )
applyProfile(next,info,modifiedPropertiesOnly);
}
}
void SessionManager::applyProfile(Session* session, Profile* info , bool modifiedPropertiesOnly)
{
if ( !modifiedPropertiesOnly || info->isPropertySet(Profile::Icon) )
session->setIconName(info->icon());
if ( !modifiedPropertiesOnly || info->isPropertySet(Profile::KeyBindings) )
session->setKeymap(info->property(Profile::KeyBindings).value<QString>());
}
QString SessionManager::addProfile(Profile* type)
{
QString key;
......
......@@ -103,6 +103,9 @@ public:
/** Returns true if the specified property has been set in this Profile instance. */
virtual bool isPropertySet(Property property) const;
/** Returns a map of the properties set in this Profile instance. */
virtual QHash<Property,QVariant> setProperties() const;
//
// Convenience methods for property() and setProperty() go here
//
......@@ -421,6 +424,15 @@ public:
*/
QString addProfile(Profile* type);
/**
* Updates the profile associated with the specified @p key with
* the changes specified in @p propertyMap.
*
* @param key The profile's key
* @param propertyMap A map between profile properties and values describing the changes
*/
void changeProfile(const QString& key , QHash<Profile::Property,QVariant> propertyMap);
/**
* Returns a Profile object describing the default type of session, which is used
* if createSession() is called with an empty configPath argument.
......@@ -524,6 +536,9 @@ signals:
void profileAdded(const QString& key);
/** Emitted when a profile is removed from the manager. */
void profileRemoved(const QString& key);
/** Emitted when a profile's properties are modified. */
void profileChanged(const QString& key);
/**
* Emitted when the favorite status of a profile changes.
*
......@@ -547,6 +562,17 @@ private:
//saves the set of favorite sessions
void saveFavorites();
// applies updates to the profile associated with @p key
// to all sessions currently using that profile
// if modifiedPropertiesOnly is true, only properties which
// are set in the profile @p key are updated
void applyProfile(const QString& key , bool modifiedPropertiesOnly);
// apples updates to the profile @p info to the session @p session
// 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);
QHash<QString,Profile*> _types;
QList<Session*> _sessions;
......
......@@ -68,6 +68,10 @@ ViewManager::ViewManager(QObject* parent , KActionCollection* collection)
// listen for addition or removal of views from associated containers
connect( _containerSignalMapper , SIGNAL(mapped(QObject*)) , this ,
SLOT(containerViewsChanged(QObject*)) );
// listen for profile changes
connect( SessionManager::instance() , SIGNAL(profileChanged(const QString&)) , this,
SLOT(profileChanged(const QString&)) );
}
ViewManager::~ViewManager()
......@@ -283,7 +287,7 @@ void ViewManager::splitView(Qt::Orientation orientation)
{
Session* session = _sessionMap[(TerminalDisplay*)existingViewIter.next()];
TerminalDisplay* display = createTerminalDisplay();
loadViewSettings(display,session);
loadViewSettings(display,SessionManager::instance()->profile(session->type()));
ViewProperties* properties = createController(session,display);
_sessionMap[display] = session;
......@@ -368,7 +372,7 @@ void ViewManager::createView(Session* session)
{
ViewContainer* container = containerIter.next();
TerminalDisplay* display = createTerminalDisplay();
loadViewSettings(display,session);
loadViewSettings(display,SessionManager::instance()->profile(session->type()));
ViewProperties* properties = createController(session,display);
_sessionMap[display] = session;
......@@ -487,12 +491,15 @@ 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;
}
void ViewManager::loadViewSettings(TerminalDisplay* view , Session* session)
void ViewManager::loadViewSettings(TerminalDisplay* view , Profile* info)
{
Profile* info = SessionManager::instance()->profile(session->type());
Q_ASSERT( info );
const ColorScheme* colorScheme = ColorSchemeManager::instance()->
......@@ -503,12 +510,26 @@ void ViewManager::loadViewSettings(TerminalDisplay* view , Session* session)
// load colour scheme
view->setColorTable(colorScheme->colorTable());
// load font, fall back to system monospace font if not specified
// load font
view->setVTFont(info->font());
// set initial size
// temporary default used for now
view->setSize(80,40);
}
void ViewManager::profileChanged(const QString& key)
{
Profile* info = SessionManager::instance()->profile(key);
QHashIterator<TerminalDisplay*,Session*> iter(_sessionMap);
while ( iter.hasNext() )
{
iter.next();
// if session uses this profile, update the display
if ( iter.value()->type() == key )
{
loadViewSettings(iter.key(),info);
}
}
}
QList<ViewProperties*> ViewManager::viewProperties() const
......
......@@ -37,6 +37,7 @@ namespace Konsole
class MainWindow;
class Session;
class TerminalDisplay;
class Profile;
class SessionController;
class ViewProperties;
......@@ -167,6 +168,9 @@ private slots:
// changes
void containerViewsChanged(QObject* container);
// called when a profile changes
void profileChanged(const QString& key);
private:
void setupActions();
void focusActiveView();
......@@ -187,7 +191,7 @@ private:
TerminalDisplay* createTerminalDisplay();
// applies the view-specific settings such as colour scheme associated
// with 'session' to 'view'
void loadViewSettings(TerminalDisplay* view , Session* session);
void loadViewSettings(TerminalDisplay* view , Profile* profile);
// creates a new controller for a session/display pair which provides the menu
// actions associated with that view, and exposes basic information
......
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