2
This source file is part of Konsole, a terminal emulator.
4
Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26
#include <QtCore/QHash>
27
#include <QtCore/QStringList>
28
#include <QtCore/QVariant>
29
#include <QtGui/QFont>
30
#include <QtGui/QColor>
36
#include "konsole_export.h"
43
* Represents a terminal set-up which can be used to
44
* set the initial state of new terminal sessions or applied
45
* to existing sessions. Profiles consist of a number of named
46
* properties, which can be retrieved using property() and
47
* set using setProperty(). isPropertySet() can be used to check
48
* whether a particular property has been set in a profile.
50
* Profiles support a simple form of inheritance. When a new Profile
51
* is constructed, a pointer to a parent profile can be passed to
52
* the constructor. When querying a particular property of a profile
53
* using property(), the profile will return its own value for that
54
* property if one has been set or otherwise it will return the
55
* parent's value for that property.
57
* Profiles can be loaded from disk using ProfileReader instances
58
* and saved to disk using ProfileWriter instances.
60
class KONSOLEPRIVATE_EXPORT Profile : public QSharedData
62
friend class KDE4ProfileReader;
63
friend class KDE4ProfileWriter;
64
friend class ProfileGroup;
67
typedef KSharedPtr<Profile> Ptr;
68
typedef KSharedPtr<ProfileGroup> GroupPtr;
71
* This enum describes the available properties
72
* which a Profile may consist of.
74
* Properties can be set using setProperty() and read
78
/** (QString) Path to the profile's configuration file on-disk. */
80
/** (QString) The descriptive name of this profile. */
82
/** (QString) The untranslted name of this profile.
83
* Warning: this is an internal property. Do not touch it.
86
/** (QString) The name of the icon associated with this profile.
87
* This is used in menus and tabs to represent the profile.
90
/** (QString) The command to execute ( excluding arguments ) when
91
* creating a new terminal session using this profile.
94
/** (QStringList) The arguments which are passed to the program
95
* specified by the Command property when creating a new terminal
96
* session using this profile.
99
/** (QStringList) Additional environment variables (in the form of
100
* NAME=VALUE pairs) which are passed to the program specified by
101
* the Command property when creating a new terminal session using
105
/** (QString) The initial working directory for sessions created
106
* using this profile.
109
/** (QString) The format used for tab titles when running normal
113
/** (QString) The format used for tab titles when the session is
114
* running a remote command (eg. SSH)
116
RemoteTabTitleFormat,
117
/** (bool) Specifies whether show hint for terminal size after
118
* resizing the application window.
120
ShowTerminalSizeHint,
121
/** (bool) Specifies whether the geometry information is saved when
125
/** (QFont) The font to use in terminal displays using this profile. */
127
/** (QString) The name of the color scheme to use in terminal
128
* displays using this profile.
129
* Color schemes are managed by the ColorSchemeManager class.
132
/** (QString) The name of the key bindings.
133
* Key bindings are managed by the KeyboardTranslatorManager class.
136
/** (HistoryModeEnum) Specifies the storage type used for keeping
137
* the output produced by terminal sessions using this profile.
139
* See Enum::HistoryModeEnum
142
/** (int) Specifies the number of lines of output to remember in
143
* terminal sessions using this profile. Once the limit is reached,
144
* the oldest lines are lost if the HistoryMode property is
148
/** (ScrollBarPositionEnum) Specifies the position of the scroll bar
149
* in terminal displays using this profile.
151
* See Enum::ScrollBarPositionEnum
154
/** (bool) Specifies whether the terminal will enable Bidirectional
157
BidiRenderingEnabled,
158
/** (bool) Specifies whether text in terminal displays is allowed
162
/** (bool) Specifies whether the flow control keys (typically Ctrl+S,
163
* Ctrl+Q) have any effect. Also known as Xon/Xoff
166
/** (bool) Specifies whether the cursor blinks ( in a manner similar
167
* to text editing applications )
169
BlinkingCursorEnabled,
170
/** (bool) If true, terminal displays use a fixed color to draw the
171
* cursor, specified by the CustomCursorColor property. Otherwise
172
* the cursor changes color to match the character underneath it.
174
UseCustomCursorColor,
175
/** (CursorShapeEnum) The shape used by terminal displays to
176
* represent the cursor.
178
* See Enum::CursorShapeEnum
181
/** (QColor) The color used by terminal displays to draw the cursor.
182
* Only applicable if the UseCustomCursorColor property is true.
185
/** (QString) A string consisting of the characters used to delimit
186
* words when selecting text in the terminal display.
189
/** (TripleClickModeEnum) Specifies which part of current line should
190
* be selected with triple click action.
192
* See Enum::TripleClickModeEnum
195
/** (bool) If true, text that matches a link or an email address is
196
* underlined when hovered by the mouse pointer.
198
UnderlineLinksEnabled,
199
/** (bool) If true, automatically copy selected text into the clipboard */
200
AutoCopySelectedText,
201
/** (bool) If true, middle mouse button pastes from X Selection */
202
PasteFromSelectionEnabled,
203
/** (bool) If true, middle mouse button pastes from Clipboard */
204
PasteFromClipboardEnabled,
205
/** (MiddleClickPasteModeEnum) Specifies the source from which mouse
206
* middle click pastes data.
208
* See Enum::MiddleClickPasteModeEnum
210
MiddleClickPasteMode,
211
/** (String) Default text codec */
213
/** (bool) Whether fonts should be aliased or not */
215
/** (bool) Whether character with intense colors should be rendered
216
* in bold font or just in bright color. */
218
/** (bool) Whether new sessions should be started in the same
219
* directory as the currently active session.
221
StartInCurrentSessionDir,
222
/** (int) Specifies the threshold of detected silence in seconds. */
224
/** (BellModeEnum) Specifies the behavior of bell.
226
* See Enum::BellModeEnum
229
/** (int) Specifies the preferred columns. */
231
/** (int) Specifies the preferred rows. */
233
/** Index of profile in the File Menu
234
* WARNING: this is currently an internal field, which is
235
* expected to be zero on disk. Do not modify it manually.
237
* In future, the format might be #.#.# to account for levels
243
* Constructs a new profile
245
* @param parent The parent profile. When querying the value of a
246
* property using property(), if the property has not been set in this
247
* profile then the parent's value for the property will be returned.
249
explicit Profile(Ptr parent = Ptr());
253
* Copies all properties except Name and Path from the specified @p
254
* profile into this profile
256
* @param profile The profile to copy properties from
257
* @param differentOnly If true, only properties in @p profile which have
258
* a different value from this profile's current value (either set via
259
* setProperty() or inherited from the parent profile) will be set.
261
void clone(Ptr profile, bool differentOnly = true);
264
* Changes the parent profile. When calling the property() method,
265
* if the specified property has not been set for this profile,
266
* the parent's value for the property will be returned instead.
268
void setParent(Ptr parent);
270
/** Returns the parent profile. */
271
const Ptr parent() const;
273
/** Returns this profile as a group or null if this profile is not a
276
const GroupPtr asGroup() const;
280
* Returns the current value of the specified @p property, cast to type T.
281
* Internally properties are stored using the QVariant type and cast to T
282
* using QVariant::value<T>();
284
* If the specified @p property has not been set in this profile,
285
* and a non-null parent was specified in the Profile's constructor,
286
* the parent's value for @p property will be returned.
289
T property(Property property) const;
291
/** Sets the value of the specified @p property to @p value. */
292
virtual void setProperty(Property property, const QVariant& value);
293
/** Returns true if the specified property has been set in this Profile
296
virtual bool isPropertySet(Property property) const;
298
/** Returns a map of the properties set in this Profile instance. */
299
virtual QHash<Property, QVariant> setProperties() const;
301
/** Returns true if no properties have been set in this Profile instance. */
302
bool isEmpty() const;
305
* Returns true if this is a 'hidden' profile which should not be
306
* displayed in menus or saved to disk.
308
* This is used for the fallback profile, in case there are no profiles on
309
* disk which can be loaded, or for overlay profiles created to handle
310
* command-line arguments which change profile properties.
312
bool isHidden() const;
314
/** Specifies whether this is a hidden profile. See isHidden() */
315
void setHidden(bool hidden);
318
// Convenience methods for property() and setProperty() go here
321
/** Convenience method for property<QString>(Profile::Path) */
322
QString path() const {
323
return property<QString>(Profile::Path);
326
/** Convenience method for property<QString>(Profile::Name) */
327
QString name() const {
328
return property<QString>(Profile::Name);
331
/** Convenience method for property<QString>(Profile::UntranslatedName) */
332
QString untranslatedName() const {
333
return property<QString>(Profile::UntranslatedName);
336
/** Convenience method for property<QString>(Profile::Directory) */
337
QString defaultWorkingDirectory() const {
338
return property<QString>(Profile::Directory);
341
/** Convenience method for property<QString>(Profile::Icon) */
342
QString icon() const {
343
return property<QString>(Profile::Icon);
346
/** Convenience method for property<QString>(Profile::Command) */
347
QString command() const {
348
return property<QString>(Profile::Command);
351
/** Convenience method for property<QStringList>(Profile::Arguments) */
352
QStringList arguments() const {
353
return property<QStringList>(Profile::Arguments);
356
/** Convenience method for property<QString>(Profile::LocalTabTitleFormat) */
357
QString localTabTitleFormat() const {
358
return property<QString>(Profile::LocalTabTitleFormat);
361
/** Convenience method for property<QString>(Profile::RemoteTabTitleFormat) */
362
QString remoteTabTitleFormat() const {
363
return property<QString>(Profile::RemoteTabTitleFormat);
366
/** Convenience method for property<bool>(Profile::ShowTerminalSizeHint) */
367
bool showTerminalSizeHint() const {
368
return property<bool>(Profile::ShowTerminalSizeHint);
371
/** Convenience method for property<bool>(Profile::SaveGeometryOnExit) */
372
bool saveGeometryOnExit() const {
373
return property<bool>(Profile::SaveGeometryOnExit);
376
/** Convenience method for property<QFont>(Profile::Font) */
378
return property<QFont>(Profile::Font);
381
/** Convenience method for property<QString>(Profile::ColorScheme) */
382
QString colorScheme() const {
383
return property<QString>(Profile::ColorScheme);
386
/** Convenience method for property<QStringList>(Profile::Environment) */
387
QStringList environment() const {
388
return property<QStringList>(Profile::Environment);
391
/** Convenience method for property<QString>(Profile::KeyBindings) */
392
QString keyBindings() const {
393
return property<QString>(Profile::KeyBindings);
396
/** Convenience method for property<QString>(Profile::HistorySize) */
397
int historySize() const {
398
return property<int>(Profile::HistorySize);
401
/** Convenience method for property<bool>(Profile::BidiRenderingEnabled) */
402
bool bidiRenderingEnabled() const {
403
return property<bool>(Profile::BidiRenderingEnabled);
406
/** Convenience method for property<bool>(Profile::BlinkingTextEnabled) */
407
bool blinkingTextEnabled() const {
408
return property<bool>(Profile::BlinkingTextEnabled);
411
/** Convenience method for property<bool>(Profile::BlinkingCursorEnabled) */
412
bool blinkingCursorEnabled() const {
413
return property<bool>(Profile::BlinkingCursorEnabled);
416
/** Convenience method for property<bool>(Profile::FlowControlEnabled) */
417
bool flowControlEnabled() const {
418
return property<bool>(Profile::FlowControlEnabled);
421
/** Convenience method for property<bool>(Profile::UseCustomCursorColor) */
422
bool useCustomCursorColor() const {
423
return property<bool>(Profile::UseCustomCursorColor);
426
/** Convenience method for property<bool>(Profile::CustomCursorColor) */
427
QColor customCursorColor() const {
428
return property<QColor>(Profile::CustomCursorColor);
431
/** Convenience method for property<QString>(Profile::WordCharacters) */
432
QString wordCharacters() const {
433
return property<QString>(Profile::WordCharacters);
436
/** Convenience method for property<bool>(Profile::UnderlineLinksEnabled) */
437
bool underlineLinksEnabled() const {
438
return property<bool>(Profile::UnderlineLinksEnabled);
441
bool autoCopySelectedText() const {
442
return property<bool>(Profile::AutoCopySelectedText);
445
/** Convenience method for property<QString>(Profile::DefaultEncoding) */
446
QString defaultEncoding() const {
447
return property<QString>(Profile::DefaultEncoding);
450
/** Convenience method for property<bool>(Profile::AntiAliasFonts) */
451
bool antiAliasFonts() const {
452
return property<bool>(Profile::AntiAliasFonts);
455
/** Convenience method for property<bool>(Profile::BoldIntense) */
456
bool boldIntense() const {
457
return property<bool>(Profile::BoldIntense);
460
/** Convenience method for property<bool>(Profile::StartInCurrentSessionDir) */
461
bool startInCurrentSessionDir() const {
462
return property<bool>(Profile::StartInCurrentSessionDir);
465
/** Convenience method for property<QString>(Profile::SilenceSeconds) */
466
int silenceSeconds() const {
467
return property<int>(Profile::SilenceSeconds);
470
/** Convenience method for property<QString>(Profile::MenuIndex) */
471
QString menuIndex() const {
472
return property<QString>(Profile::MenuIndex);
475
int menuIndexAsInt() const;
477
/** Return a list of all properties names and their type
478
* (for use with -p option).
480
const QStringList propertiesInfoList() const;
483
* Returns the element from the Property enum associated with the
486
* @param name The name of the property to look for, this is case
489
static Property lookupByName(const QString& name);
493
// Defines a new property, this property is then available
494
// to all Profile instances.
495
static void registerProperty(const PropertyInfo& info);
497
// fills the table with default names for profile properties
498
// the first time it is called.
499
// subsequent calls return immediately
500
static void fillTableWithDefaultNames();
502
// returns true if the property can be inherited
503
static bool canInheritProperty(Property property);
505
QHash<Property, QVariant> _propertyValues;
510
static QHash<QString, PropertyInfo> PropertyInfoByName;
511
static QHash<Property, PropertyInfo> PropertyInfoByProperty;
513
// Describes a property. Each property has a name and group
514
// which is used when saving/loading the profile.
515
struct PropertyInfo {
521
static const PropertyInfo DefaultPropertyNames[];
524
inline bool Profile::canInheritProperty(Property aProperty)
526
return aProperty != Name && aProperty != Path;
530
inline T Profile::property(Property aProperty) const
532
return property<QVariant>(aProperty).value<T>();
535
inline QVariant Profile::property(Property aProperty) const
537
if (_propertyValues.contains(aProperty)) {
538
return _propertyValues[aProperty];
539
} else if (_parent && canInheritProperty(aProperty)) {
540
return _parent->property<QVariant>(aProperty);
547
* A profile which contains a number of default settings for various
548
* properties. This can be used as a parent for other profiles or a
549
* fallback in case a profile cannot be loaded from disk.
551
class FallbackProfile : public Profile
558
* A composite profile which allows a group of profiles to be treated as one.
559
* When setting a property, the new value is applied to all profiles in the
560
* group. When reading a property, if all profiles in the group have the same
561
* value then that value is returned, otherwise the result is null.
563
* Profiles can be added to the group using addProfile(). When all profiles
564
* have been added updateValues() must be called
565
* to sync the group's property values with those of the group's profiles.
567
* The Profile::Name and Profile::Path properties are unique to individual
568
* profiles, setting these properties on a ProfileGroup has no effect.
570
class KONSOLEPRIVATE_EXPORT ProfileGroup : public Profile
573
typedef KSharedPtr<ProfileGroup> Ptr;
575
/** Construct a new profile group, which is hidden by default. */
576
ProfileGroup(Profile::Ptr parent = Profile::Ptr());
578
/** Add a profile to the group. Calling setProperty() will update this
579
* profile. When creating a group, add the profiles to the group then
580
* call updateValues() to make the group's property values reflect the
581
* profiles currently in the group.
583
void addProfile(Profile::Ptr profile) {
584
_profiles.append(profile);
587
/** Remove a profile from the group. Calling setProperty() will no longer
588
* affect this profile. */
589
void removeProfile(Profile::Ptr profile) {
590
_profiles.removeAll(profile);
593
/** Returns the profiles in this group .*/
594
QList<Profile::Ptr> profiles() const {
599
* Updates the property values in this ProfileGroup to match those from
600
* the group's profiles()
602
* For each available property, if each profile in the group has the same
603
* value then the ProfileGroup will use that value for the property.
604
* Otherwise the value for the property will be set to a null QVariant
606
* Some properties such as the name and the path of the profile
607
* will always be set to null if the group has more than one profile.
611
/** Sets the value of @p property in each of the group's profiles to
614
void setProperty(Property property, const QVariant& value);
617
QList<Profile::Ptr> _profiles;
619
inline ProfileGroup::ProfileGroup(Profile::Ptr profileParent)
620
: Profile(profileParent)
624
inline const Profile::GroupPtr Profile::asGroup() const
626
const Profile::GroupPtr ptr(dynamic_cast<ProfileGroup*>(
627
const_cast<Profile*>(this)));
630
inline Profile::GroupPtr Profile::asGroup()
632
return Profile::GroupPtr(dynamic_cast<ProfileGroup*>(this));
636
* Parses an input string consisting of property names
637
* and assigned values and returns a table of properties
640
* The input string will typically look like this:
643
* PropertyName=Value;PropertyName=Value ...
649
* Icon=konsole;Directory=/home/bob
652
class KONSOLEPRIVATE_EXPORT ProfileCommandParser
656
* Parses an input string consisting of property names
657
* and assigned values and returns a table of
658
* properties and values.
660
QHash<Profile::Property, QVariant> parse(const QString& input);
663
Q_DECLARE_METATYPE(Konsole::Profile::Ptr)