Commit de005e17 authored by Robert Knight's avatar Robert Knight

Load, apply and save history mode and size, scrollbar position. Refactor out duplicate code.

svn path=/branches/work/konsole-split-view/; revision=660228
parent a428afdf
......@@ -123,6 +123,32 @@ void EditProfileDialog::setupGeneralPage(const Profile* info)
SLOT(editTabTitle()) );
connect(_ui->remoteTabTitleEditButton , SIGNAL(clicked()) , this ,
SLOT(editRemoteTabTitle()) );
connect(_ui->showMenuBarButton , SIGNAL(toggled(bool)) , this ,
SLOT(showMenuBar(bool)) );
connect(_ui->alwaysHideTabBarButton , SIGNAL(clicked()) , this ,
SLOT(alwaysHideTabBar()) );
connect(_ui->autoShowTabBarButton , SIGNAL(clicked()) , this ,
SLOT(showTabBarAsNeeded()) );
connect(_ui->alwaysShowTabBarButton , SIGNAL(clicked()) , this ,
SLOT(alwaysShowTabBar()) );
}
void EditProfileDialog::showMenuBar(bool show)
{
_tempProfile->setProperty(Profile::ShowMenuBar,show);
}
void EditProfileDialog::alwaysHideTabBar()
{
_tempProfile->setProperty(Profile::TabBarMode,Profile::AlwaysHideTabBar);
}
void EditProfileDialog::alwaysShowTabBar()
{
_tempProfile->setProperty(Profile::TabBarMode,Profile::AlwaysShowTabBar);
}
void EditProfileDialog::showTabBarAsNeeded()
{
_tempProfile->setProperty(Profile::TabBarMode,Profile::ShowTabBarAsNeeded);
}
void EditProfileDialog::editTabTitle()
{
......@@ -222,13 +248,116 @@ void EditProfileDialog::setupAppearencePage(const Profile* info)
void EditProfileDialog::setupKeyboardPage(const Profile* )
{
}
void EditProfileDialog::setupScrollingPage(const Profile* )
void EditProfileDialog::setupRadio( RadioInt* possible , int actual )
{
while (possible->first != 0)
{
if ( possible->second == actual )
possible->first->setChecked(true);
else
possible->first->setChecked(false);
++possible;
}
}
void EditProfileDialog::setupAdvancedPage(const Profile* )
void EditProfileDialog::setupScrollingPage(const Profile* profile)
{
// setup scrollbar radio
int scrollBarPosition = profile->property(Profile::ScrollBarPosition).value<int>();
RadioInt possibleScrollBarPositions[] = { RadioInt(_ui->scrollBarHiddenButton,Profile::ScrollBarHidden),
RadioInt(_ui->scrollBarLeftButton,Profile::ScrollBarLeft),
RadioInt(_ui->scrollBarRightButton,Profile::ScrollBarRight),
RadioInt(0,0) };
setupRadio( possibleScrollBarPositions , scrollBarPosition );
// setup scrollback type radio
int scrollBackType = profile->property(Profile::HistoryMode).value<int>();
RadioInt possibleScrollBackTypes[] = { RadioInt(_ui->disableScrollbackButton,Profile::DisableHistory),
RadioInt(_ui->fixedScrollbackButton,Profile::FixedSizeHistory),
RadioInt(_ui->unlimitedScrollbackButton,Profile::UnlimitedHistory),
RadioInt(0,0) };
setupRadio( possibleScrollBackTypes , scrollBackType );
// setup scrollback line count spinner
_ui->scrollBackLinesSpinner->setValue( profile->property(Profile::HistorySize).value<int>() );
// signals and slots
connect( _ui->scrollBarHiddenButton , SIGNAL(clicked()) , this ,
SLOT(hideScrollBar()) );
connect( _ui->scrollBarLeftButton , SIGNAL(clicked()) , this ,
SLOT(showScrollBarLeft()) );
connect( _ui->scrollBarRightButton , SIGNAL(clicked()) , this ,
SLOT(showScrollBarRight()) );
connect( _ui->scrollBackLinesSpinner , SIGNAL(valueChanged(int)) , this ,
SLOT(scrollBackLinesChanged(int)) );
connect( _ui->disableScrollbackButton , SIGNAL(clicked()) , this ,
SLOT(noScrollBack()) );
connect(_ui->fixedScrollbackButton , SIGNAL(clicked()) , this ,
SLOT(fixedScrollBack()) );
connect(_ui->unlimitedScrollbackButton , SIGNAL(clicked()) , this ,
SLOT(unlimitedScrollBack()) );
}
void EditProfileDialog::scrollBackLinesChanged(int lineCount)
{
_tempProfile->setProperty(Profile::HistorySize , lineCount);
}
void EditProfileDialog::noScrollBack()
{
_tempProfile->setProperty(Profile::HistoryMode , Profile::DisableHistory);
}
void EditProfileDialog::fixedScrollBack()
{
_tempProfile->setProperty(Profile::HistoryMode , Profile::FixedSizeHistory);
}
void EditProfileDialog::unlimitedScrollBack()
{
_tempProfile->setProperty(Profile::HistoryMode , Profile::UnlimitedHistory );
}
void EditProfileDialog::hideScrollBar()
{
_tempProfile->setProperty(Profile::ScrollBarPosition , Profile::ScrollBarHidden );
}
void EditProfileDialog::showScrollBarLeft()
{
_tempProfile->setProperty(Profile::ScrollBarPosition , Profile::ScrollBarLeft );
}
void EditProfileDialog::showScrollBarRight()
{
_tempProfile->setProperty(Profile::ScrollBarPosition , Profile::ScrollBarRight );
}
void EditProfileDialog::setupAdvancedPage(const Profile* profile)
{
_ui->enableBlinkingTextButton->setChecked( profile->property(Profile::BlinkingTextEnabled).value<bool>() );
_ui->enableFlowControlButton->setChecked( profile->property(Profile::FlowControlEnabled).value<bool>() );
_ui->enableResizeWindowButton->setChecked( profile->property(Profile::AllowProgramsToResizeWindow)
.value<bool>() );
// signals and slots
connect( _ui->enableBlinkingTextButton , SIGNAL(toggled(bool)) , this ,
SLOT(toggleBlinkingText(bool)) );
connect( _ui->enableFlowControlButton , SIGNAL(toggled(bool)) , this ,
SLOT(toggleFlowControl(bool)) );
connect( _ui->enableResizeWindowButton , SIGNAL(toggled(bool)) , this ,
SLOT(toggleResizeWindow(bool)) );
}
void EditProfileDialog::toggleBlinkingText(bool enable)
{
_tempProfile->setProperty(Profile::BlinkingTextEnabled,enable);
}
void EditProfileDialog::toggleFlowControl(bool enable)
{
_tempProfile->setProperty(Profile::FlowControlEnabled,enable);
}
void EditProfileDialog::toggleResizeWindow(bool enable)
{
_tempProfile->setProperty(Profile::AllowProgramsToResizeWindow,enable);
}
void EditProfileDialog::showFontDialog()
{
//TODO Only permit selection of mono-spaced fonts.
......
......@@ -22,10 +22,12 @@
// Qt
#include <QAbstractItemDelegate>
#include <QPair>
// KDE
#include <KDialog>
class QAbstractButton;
namespace Ui
{
......@@ -82,10 +84,31 @@ private slots:
void editTabTitle();
void editRemoteTabTitle();
void showMenuBar(bool);
void alwaysHideTabBar();
void alwaysShowTabBar();
void showTabBarAsNeeded();
// appearence page
void setFontSize(int pointSize);
void showFontDialog();
// scrolling page
void noScrollBack();
void fixedScrollBack();
void unlimitedScrollBack();
void scrollBackLinesChanged(int);
void hideScrollBar();
void showScrollBarLeft();
void showScrollBarRight();
// advanced page
void toggleBlinkingText(bool);
void toggleFlowControl(bool);
void toggleResizeWindow(bool);
private:
// initialize various pages of the dialog
void setupGeneralPage(const Profile* info);
......@@ -94,6 +117,9 @@ private:
void setupScrollingPage(const Profile* info);
void setupAdvancedPage(const Profile* info);
typedef QPair<QAbstractButton*,int> RadioInt;
void setupRadio(RadioInt* possible,int actual);
Ui::EditProfileDialog* _ui;
Profile* _tempProfile;
QString _profileKey;
......
......@@ -463,7 +463,14 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_4" />
<widget class="QSpinBox" name="scrollBackLinesSpinner" >
<property name="minimum" >
<number>1</number>
</property>
<property name="maximum" >
<number>10000</number>
</property>
</widget>
</item>
<item>
<spacer>
......@@ -553,21 +560,21 @@
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QCheckBox" name="checkBox_2" >
<widget class="QCheckBox" name="enableBlinkingTextButton" >
<property name="text" >
<string>Allow blinking text</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_3" >
<widget class="QCheckBox" name="enableFlowControlButton" >
<property name="text" >
<string>Enable flow control using Ctrl+S , Ctrl+Q</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_5" >
<widget class="QCheckBox" name="enableResizeWindowButton" >
<property name="text" >
<string>Allow programs to resize terminal window</string>
</property>
......
......@@ -134,7 +134,12 @@ QString KDE4ProfileWriter::getPath(const Profile* info)
return newPath;
}
void KDE4ProfileWriter::writeStandardElement(KConfigGroup& group , char* name , const Profile* profile ,
Profile::Property attribute)
{
if ( profile->isPropertySet(attribute) )
group.writeEntry(name,profile->property(attribute));
}
bool KDE4ProfileWriter::writeProfile(const QString& path , const Profile* profile)
{
KConfig config(path,KConfig::NoGlobals);
......@@ -143,31 +148,33 @@ bool KDE4ProfileWriter::writeProfile(const QString& path , const Profile* profil
if ( profile->isPropertySet(Profile::Name) )
general.writeEntry("Name",profile->name());
if ( profile->isPropertySet(Profile::Command)
|| profile->isPropertySet(Profile::Arguments) )
general.writeEntry("Command",
ShellCommand(profile->command(),profile->arguments()).fullCommand());
if ( profile->isPropertySet(Profile::Icon) )
general.writeEntry("Icon",profile->icon());
if ( profile->isPropertySet(Profile::LocalTabTitleFormat) )
general.writeEntry("LocalTabTitleFormat",
profile->property(Profile::LocalTabTitleFormat).value<QString>());
writeStandardElement( general , "Icon" , profile , Profile::Icon );
writeStandardElement( general , "LocalTabTitleFormat" , profile , Profile::LocalTabTitleFormat );
writeStandardElement( general , "RemoteTabTitleFormat" , profile , Profile::RemoteTabTitleFormat );
if ( profile->isPropertySet(Profile::RemoteTabTitleFormat) )
general.writeEntry("RemoteTabTitleFormat",
profile->property(Profile::RemoteTabTitleFormat).value<QString>());
KConfigGroup keyboard = config.group("Keyboard");
writeStandardElement( keyboard , "KeyBindings" , profile , Profile::KeyBindings );
KConfigGroup appearence = config.group("Appearence");
if ( profile->isPropertySet(Profile::ColorScheme) )
appearence.writeEntry("ColorScheme",profile->colorScheme());
writeStandardElement( appearence , "ColorScheme" , profile , Profile::ColorScheme );
writeStandardElement( appearence , "Font" , profile , Profile::Font );
KConfigGroup scrolling = config.group("Scrolling");
if ( profile->isPropertySet(Profile::Font) )
appearence.writeEntry("Font",profile->font());
writeStandardElement( scrolling , "HistoryMode" , profile , Profile::HistoryMode );
writeStandardElement( scrolling , "HistorySize" , profile , Profile::HistorySize );
writeStandardElement( scrolling , "ScrollBarPosition" , profile , Profile::ScrollBarPosition );
KConfigGroup terminalFeatures = config.group("TerminalFeatures");
writeStandardElement( terminalFeatures , "FlowControl" , profile , Profile::FlowControlEnabled );
return true;
}
......@@ -198,25 +205,39 @@ bool KDE4ProfileReader::readProfile(const QString& path , Profile* profile)
profile->setProperty(Profile::Arguments,shellCommand.arguments());
}
if ( general.hasKey("Icon") )
profile->setProperty(Profile::Icon,general.readEntry("Icon"));
if ( general.hasKey("LocalTabTitleFormat") )
profile->setProperty(Profile::LocalTabTitleFormat,general.readEntry("LocalTabTitleFormat"));
if ( general.hasKey("RemoteTabTitleFormat") )
profile->setProperty(Profile::RemoteTabTitleFormat,
general.readEntry("RemoteTabTitleFormat"));
qDebug() << "local tabs:" << general.readEntry("LocalTabTitleFormat");
readStandardElement(general,"Icon",profile,Profile::Icon);
readStandardElement(general,"LocalTabTitleFormat",profile,Profile::LocalTabTitleFormat);
readStandardElement(general,"RemoteTabTitleFormat",profile,Profile::RemoteTabTitleFormat);
KConfigGroup keyboard = config.group("Keyboard");
readStandardElement(keyboard,"KeyBindings",profile,Profile::KeyBindings);
KConfigGroup appearence = config.group("Appearence");
if ( appearence.hasKey("ColorScheme") )
profile->setProperty(Profile::ColorScheme,appearence.readEntry("Color Scheme"));
if ( appearence.hasKey("Font") )
profile->setProperty(Profile::Font,appearence.readEntry("Font"));
readStandardElement(appearence,"ColorScheme",profile,Profile::ColorScheme);
readStandardElement(appearence,"Font",profile,Profile::Font);
KConfigGroup scrolling = config.group("Scrolling");
readStandardElement(scrolling,"HistoryMode",profile,Profile::HistoryMode);
readStandardElement(scrolling,"HistorySize",profile,Profile::HistorySize);
readStandardElement(scrolling,"ScrollBarPosition",profile,Profile::ScrollBarPosition);
KConfigGroup terminalFeatures = config.group("Terminal Features");
readStandardElement(terminalFeatures,"FlowControl",profile,Profile::FlowControlEnabled);
return true;
}
void KDE4ProfileReader::readStandardElement(const KConfigGroup& group ,
char* name ,
Profile* info ,
Profile::Property property)
{
if ( group.hasKey(name) )
info->setProperty(property,group.readEntry(name));
}
QStringList KDE3ProfileReader::findProfiles()
{
return KGlobal::dirs()->findAllResources("data", "konsole/*.desktop",
......@@ -533,6 +554,7 @@ void SessionManager::applyProfile(Session* session, const Profile* info , bool m
{
session->setType( _types.key((Profile*)info) );
// Basic session settings
if ( !modifiedPropertiesOnly || info->isPropertySet(Profile::Command) )
session->setProgram(info->command());
......@@ -545,15 +567,44 @@ void SessionManager::applyProfile(Session* session, const Profile* info , bool m
if ( !modifiedPropertiesOnly || info->isPropertySet(Profile::Icon) )
session->setIconName(info->icon());
// Key bindings
if ( !modifiedPropertiesOnly || info->isPropertySet(Profile::KeyBindings) )
session->setKeymap(info->property(Profile::KeyBindings).value<QString>());
// Tab formats
if ( !modifiedPropertiesOnly || info->isPropertySet(Profile::LocalTabTitleFormat) )
session->setTabTitleFormat( Session::LocalTabTitle ,
info->property(Profile::LocalTabTitleFormat).value<QString>());
if ( !modifiedPropertiesOnly || info->isPropertySet(Profile::RemoteTabTitleFormat) )
session->setTabTitleFormat( Session::RemoteTabTitle ,
info->property(Profile::RemoteTabTitleFormat).value<QString>());
// Scrollback / history
if ( !modifiedPropertiesOnly
|| info->isPropertySet(Profile::HistoryMode)
|| info->isPropertySet(Profile::HistorySize) )
{
int mode = info->property(Profile::HistoryMode).value<int>();
switch ((Profile::HistoryModeEnum)mode)
{
case Profile::DisableHistory:
session->setHistory( HistoryTypeNone() );
break;
case Profile::FixedSizeHistory:
{
int lines = info->property(Profile::HistorySize).value<int>();
session->setHistory( HistoryTypeBuffer(lines) );
}
break;
case Profile::UnlimitedHistory:
session->setHistory( HistoryTypeFile() );
break;
}
}
// Terminal features
if ( !modifiedPropertiesOnly || info->isPropertySet(Profile::FlowControlEnabled) )
session->setXonXoff( info->property(Profile::FlowControlEnabled).value<bool>() );
}
QString SessionManager::addProfile(Profile* type)
......
......@@ -47,44 +47,66 @@ public:
enum Property
{
// Path to profile's config file
Path,
Path, // QString
// General profile options
Name,
Title,
Icon,
Command,
Arguments,
Environment,
Directory,
Name, // QString
Title, // QString
Icon, // QString
Command, // QString
Arguments, // QStringList
Environment, // QStringList
Directory, // QString
// Tab Title Formats
LocalTabTitleFormat,
RemoteTabTitleFormat,
LocalTabTitleFormat, // QString
RemoteTabTitleFormat, // QString
// Window & Tab Bar
ShowMenuBar,
TabBarMode,
ShowMenuBar, // bool
TabBarMode, // TabBarMode
// Appearence
Font,
ColorScheme,
Font, // QFont
ColorScheme, // QString
// Keyboard
KeyBindings,
KeyBindings, // QString
// Scrolling
ScrollingMode,
ScrollBarPosition,
HistoryMode, // HistoryMode
HistorySize, // int
ScrollBarPosition, // ScrollBarPosition
// Terminal Features
SelectWordCharacters,
BlinkingTextEnabled,
FlowControlEnabled,
AllowProgramsToResizeWindow
SelectWordCharacters, // QString
BlinkingTextEnabled, // bool
FlowControlEnabled, // bool
AllowProgramsToResizeWindow // bool
};
enum TabBarModeEnum
{
AlwaysHideTabBar,
ShowTabBarAsNeeded,
AlwaysShowTabBar
};
enum HistoryModeEnum
{
DisableHistory,
FixedSizeHistory,
UnlimitedHistory
};
enum ScrollBarPositionEnum
{
ScrollBarLeft,
ScrollBarRight,
ScrollBarHidden
};
/**
* Constructs a new profile
*/
......@@ -227,6 +249,11 @@ class KDE4ProfileReader : public ProfileReader
public:
virtual QStringList findProfiles();
virtual bool readProfile(const QString& path , Profile* profile);
private:
void readStandardElement(const KConfigGroup& group ,
char* name ,
Profile* info ,
Profile::Property property);
};
/** Interface for all classes which can write profile settings to a file. */
class ProfileWriter
......@@ -242,6 +269,12 @@ class KDE4ProfileWriter : public ProfileWriter
public:
virtual QString getPath(const Profile* profile);
virtual bool writeProfile(const QString& path , const Profile* profile);
private:
void writeStandardElement(KConfigGroup& group,
char* name,
const Profile* profile,
Profile::Property property);
};
#if 0
......
......@@ -515,6 +515,16 @@ void ViewManager::loadViewSettings(TerminalDisplay* view , Profile* info)
// load font
view->setVTFont(info->font());
// set scroll-bar position
int scrollBarPosition = info->property(Profile::ScrollBarPosition).value<int>();
if ( scrollBarPosition == Profile::ScrollBarHidden )
view->setScrollBarLocation(TerminalDisplay::SCROLLBAR_NONE);
else if ( scrollBarPosition == Profile::ScrollBarLeft )
view->setScrollBarLocation(TerminalDisplay::SCROLLBAR_LEFT);
else if ( scrollBarPosition == Profile::ScrollBarRight )
view->setScrollBarLocation(TerminalDisplay::SCROLLBAR_RIGHT);
}
void ViewManager::profileChanged(const QString& key)
......
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