File indexing completed on 2024-05-05 05:53:51

0001 /*
0002     This source file is part of Konsole, a terminal emulator.
0003 
0004     SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef PROFILE_H
0010 #define PROFILE_H
0011 
0012 // Qt
0013 #include <QColor>
0014 #include <QFont>
0015 #include <QHash>
0016 #include <QKeySequence>
0017 #include <QStringList>
0018 #include <QVariant>
0019 
0020 // Konsole
0021 #include "konsoleprivate_export.h"
0022 #include "Enumeration.h"
0023 
0024 #include <map>
0025 #include <vector>
0026 
0027 namespace Konsole
0028 {
0029 class ProfileGroup;
0030 
0031 /**
0032  * Represents a terminal set-up which can be used to
0033  * set the initial state of new terminal sessions or applied
0034  * to existing sessions.  Profiles consist of a number of named
0035  * properties, which can be retrieved using property() and
0036  * set using setProperty().  isPropertySet() can be used to check
0037  * whether a particular property has been set in a profile.
0038  *
0039  * Profiles support a simple form of inheritance.  When a new Profile
0040  * is constructed, a pointer to a parent profile can be passed to
0041  * the constructor.  When querying a particular property of a profile
0042  * using property(), the profile will return its own value for that
0043  * property if one has been set or otherwise it will return the
0044  * parent's value for that property.
0045  *
0046  * Profiles can be loaded from disk using ProfileReader instances
0047  * and saved to disk using ProfileWriter instances.
0048  */
0049 class KONSOLEPRIVATE_EXPORT Profile : public QSharedData
0050 {
0051     Q_GADGET
0052 
0053     friend class ProfileReader;
0054     friend class ProfileWriter;
0055     friend class ProfileGroup;
0056 
0057 public:
0058     using Ptr = QExplicitlySharedDataPointer<Profile>;
0059     using GroupPtr = QExplicitlySharedDataPointer<ProfileGroup>;
0060 
0061     /**
0062      * This enum describes the available properties
0063      * which a Profile may consist of.
0064      *
0065      * Properties can be set using setProperty() and read
0066      * using property()
0067      */
0068     enum Property {
0069         /** (QString) Path to the profile's configuration file on-disk. */
0070         Path,
0071         /** (QString) The descriptive name of this profile. */
0072         Name,
0073         /** (QString) The untranslated name of this profile.
0074          * Warning: this is an internal property. Do not touch it.
0075          */
0076         UntranslatedName,
0077         /** (QString) The name of the icon associated with this profile.
0078          * This is used in menus and tabs to represent the profile.
0079          */
0080         Icon,
0081         /** (QString) The command to execute ( excluding arguments ) when
0082          * creating a new terminal session using this profile.
0083          */
0084         Command,
0085         /** (QStringList) The arguments which are passed to the program
0086          * specified by the Command property when creating a new terminal
0087          * session using this profile.
0088          */
0089         Arguments,
0090         /** (QStringList) Additional environment variables (in the form of
0091          * NAME=VALUE pairs) which are passed to the program specified by
0092          * the Command property when creating a new terminal session using
0093          * this profile.
0094          */
0095         Environment,
0096         /** (QString) The initial working directory for sessions created
0097          * using this profile.
0098          */
0099         Directory,
0100         /** (QString) The format used for tab titles when running normal
0101          * commands.
0102          */
0103         LocalTabTitleFormat,
0104         /** (QString) The format used for tab titles when the session is
0105          * running a remote command (eg. SSH)
0106          */
0107         RemoteTabTitleFormat,
0108         /** (bool) Specifies whether show hint for terminal size after
0109          * resizing the application window.
0110          */
0111         ShowTerminalSizeHint,
0112         /** (bool) If the background color should change to indicate if the window is active
0113          */
0114         DimWhenInactive,
0115         /** (bool) If a border should be drawn to indicate if the window is active
0116          */
0117         BorderWhenActive,
0118         /**
0119          * (bool) Whether to always invert the colors for text selection.
0120          */
0121         InvertSelectionColors,
0122         /** (QFont) The font to use in terminal displays using this profile. */
0123         Font,
0124         /** (QString) The name of the color scheme to use in terminal
0125          * displays using this profile.
0126          * Color schemes are managed by the ColorSchemeManager class.
0127          */
0128         ColorScheme,
0129         /** (QString) The name of the key bindings.
0130          * Key bindings are managed by the KeyboardTranslatorManager class.
0131          */
0132         KeyBindings,
0133         /** (HistoryModeEnum) Specifies the storage type used for keeping
0134          * the output produced by terminal sessions using this profile.
0135          *
0136          * See Enum::HistoryModeEnum
0137          */
0138         HistoryMode,
0139         /** (int) Specifies the number of lines of output to remember in
0140          * terminal sessions using this profile.  Once the limit is reached,
0141          * the oldest lines are lost if the HistoryMode property is
0142          * FixedSizeHistory
0143          */
0144         HistorySize,
0145         /** (ScrollBarPositionEnum) Specifies the position of the scroll bar
0146          * in terminal displays using this profile.
0147          *
0148          * See Enum::ScrollBarPositionEnum
0149          */
0150         ScrollBarPosition,
0151         /** (bool) Specifies whether the PageUp/Down will scroll the full
0152          * height or half height.
0153          */
0154         ScrollFullPage,
0155         /** (bool) Specifies whether the lines that are scrolled into view
0156          * should be highlighted.
0157          */
0158         HighlightScrolledLines,
0159         /** (bool) Specifies whether the terminal will enable Reflow of
0160          * lines when terminal resizes.
0161          */
0162         ReflowLines,
0163         /** (bool) Specifies whether the terminal will enable Bidirectional
0164          * text display
0165          */
0166         BidiRenderingEnabled,
0167         /** (bool) If true, lines are always LTR. Otherwise, decided by
0168          * first strong character as defined by the BiDi algorithm.
0169          */
0170         BidiLineLTR,
0171         /** (bool) Specifies whether the table drawing characters will be
0172          * considered strong LTR by the BiDi algorithm.
0173          */
0174         BidiTableDirOverride,
0175         /** (bool) Specifies whether text in terminal displays is allowed
0176          * to blink.
0177          */
0178         BlinkingTextEnabled,
0179         /** (bool) Specifies whether the flow control keys (typically Ctrl+S,
0180          * Ctrl+Q) have any effect.  Also known as Xon/Xoff
0181          */
0182         FlowControlEnabled,
0183         /** (int) Specifies the pixels between the terminal lines.
0184          */
0185         LineSpacing,
0186         /** (bool) Specifies whether the cursor blinks ( in a manner similar
0187          * to text editing applications )
0188          */
0189         BlinkingCursorEnabled,
0190         /** (bool) If true, terminal displays use a fixed color to draw the
0191          * cursor, specified by the CustomCursorColor property.  Otherwise
0192          * the cursor changes color to match the character underneath it.
0193          */
0194         UseCustomCursorColor,
0195         /** (CursorShapeEnum) The shape used by terminal displays to
0196          * represent the cursor.
0197          *
0198          * See Enum::CursorShapeEnum
0199          */
0200         CursorShape,
0201         /** (QColor) The color used by terminal displays to draw the cursor.
0202          * Only applicable if the UseCustomCursorColor property is true.
0203          */
0204         CustomCursorColor,
0205         /** (QColor) The color used by terminal displays to draw the character
0206          * underneath the cursor. Only applicable if the UseCustomCursorColor
0207          * property is true and CursorShape property is Enum::BlockCursor.
0208          */
0209         CustomCursorTextColor,
0210         /** (QString) A string consisting of the characters used to delimit
0211          * words when selecting text in the terminal display.
0212          */
0213         WordCharacters,
0214         /** (TripleClickModeEnum) Specifies which part of current line should
0215          * be selected with triple click action.
0216          *
0217          * See Enum::TripleClickModeEnum
0218          */
0219         TripleClickMode,
0220         /** (bool) If true, text that matches a link or an email address is
0221          * underlined when hovered by the mouse pointer.
0222          */
0223         UnderlineLinksEnabled,
0224         /** (bool) If true, text that matches a file is
0225          * underlined when hovered by the mouse pointer.
0226          */
0227         UnderlineFilesEnabled,
0228 
0229         /**
0230          * (Enum::TextEditorCmd) Text editor command used to open local
0231          * text file URLs at a given line/column. There is a default list
0232          * of editors that the user can select from, and a CustomTextEditor
0233          * option if the user wants to use a different editor.
0234          *
0235          * See Enum::TextEditorCmd
0236          */
0237         TextEditorCmd,
0238         /**
0239          * (QString) This is the command string corresponding to Enum::CustomTextEditor.
0240          *
0241          * See TextEditorCmd and Enum::TextEditorCmd
0242          */
0243         TextEditorCmdCustom,
0244 
0245         /** (bool) If true, links can be opened by direct mouse click.*/
0246         OpenLinksByDirectClickEnabled,
0247         /** (bool) If true, control key must be pressed to click and drag selected text. */
0248         CtrlRequiredForDrag,
0249         /** (bool) If true, automatically copy selected text into the clipboard */
0250         AutoCopySelectedText,
0251         /** (bool) The QMimeData object used when copying text always
0252          * has the plain/text MIME set and if this is @c true then the
0253          * text/html MIME is set too in that object i.e. the copied
0254          * text will include formatting, font faces, colors... etc; users
0255          * can paste the text as HTML (default) or as plain/text by using
0256          * e.g. the "Paste Special" functionality in LibreOffice.
0257          */
0258         CopyTextAsHTML,
0259         /** (bool) If true, leading spaces are trimmed in selected text */
0260         TrimLeadingSpacesInSelectedText,
0261         /** (bool) If true, trailing spaces are trimmed in selected text */
0262         TrimTrailingSpacesInSelectedText,
0263         /** (bool) If true, then dropped URLs will be pasted as text without asking */
0264         DropUrlsAsText,
0265         /** (bool) If true, middle mouse button pastes from X Selection */
0266         PasteFromSelectionEnabled,
0267         /** (bool) If true, middle mouse button pastes from Clipboard */
0268         PasteFromClipboardEnabled,
0269         /** (MiddleClickPasteModeEnum) Specifies the source from which mouse
0270          * middle click pastes data.
0271          *
0272          * See Enum::MiddleClickPasteModeEnum
0273          */
0274         MiddleClickPasteMode,
0275         /** (String) Default text codec */
0276         DefaultEncoding,
0277         /** (bool) Whether fonts should be aliased or not */
0278         AntiAliasFonts,
0279         /** (bool) Whether character with intense colors should be rendered
0280          * in bold font or just in bright color. */
0281         BoldIntense,
0282         /** (bool) Whether to use font's line characters instead of the
0283          * builtin code. */
0284         UseFontLineCharacters,
0285         /** (bool) Whether new sessions should be started in the same
0286          * directory as the currently active session.
0287          */
0288         StartInCurrentSessionDir,
0289         /** (int) Specifies the threshold of detected silence in seconds. */
0290         SilenceSeconds,
0291         /** (BellModeEnum) Specifies the behavior of bell.
0292          *
0293          * See Enum::BellModeEnum
0294          */
0295         BellMode,
0296         /** (int) Specifies the preferred columns. */
0297         TerminalColumns,
0298         /** (int) Specifies the preferred rows. */
0299         TerminalRows,
0300         /** Index of profile in the File Menu
0301          * WARNING: this is currently an internal field, which is
0302          * expected to be zero on disk. Do not modify it manually.
0303          *
0304          * In future, the format might be #.#.# to account for levels
0305          */
0306         MenuIndex,
0307         /** (int) Margin width in pixels */
0308         TerminalMargin,
0309         /** (bool) Center terminal when there is a margin */
0310         TerminalCenter,
0311         /** (bool) If true, mouse wheel scroll with Ctrl key pressed
0312          * increases/decreases the terminal font size.
0313          */
0314         MouseWheelZoomEnabled,
0315         /** (bool) Specifies whether emulated up/down key press events are
0316          * sent, for mouse scroll wheel events, to programs using the
0317          * Alternate Screen buffer; this is mainly for the benefit of
0318          * programs that don't natively support mouse scroll events, e.g.
0319          * less.
0320          *
0321          * This also works for scrolling in applications that support Mouse
0322          * Tracking events but don't indicate they're interested in those
0323          * events; for example, when vim doesn't indicate it's interested
0324          * in Mouse Tracking events (i.e. when the mouse is in Normal
0325          * (not Visual) mode): https://vimhelp.org/intro.txt.html#vim-modes-intro
0326          * mouse wheel scroll events will send up/down key press events.
0327          *
0328          * Default value is true.
0329          * See also, MODE_Mouse1007 in the Emulation header, which toggles
0330          * Alternate Scrolling with escape sequences.
0331          */
0332         AlternateScrolling,
0333         /** (int) Keyboard modifiers to show URL hints */
0334         UrlHintsModifiers,
0335         /** (bool) Reverse the order of URL hints */
0336         ReverseUrlHints,
0337         /** (QColor) used in tab color */
0338         TabColor,
0339         /** (int) Value of the Dimm Effect */
0340         DimValue,
0341         /** (QColor) Color for focus border */
0342         FocusBorderColor,
0343         /** (bool) Allow Escape sequence for Links.
0344          * this allows applications to use links in the form of
0345          * printf '\e]8;;https://www.example.org\e\\example text\e]8;;\e\\\n'
0346          */
0347         AllowEscapedLinks,
0348         /** (String) Escape Sequence for Links schema,
0349          * This tell us what kind of links are accepted, for security reason we can't accept
0350          * some weird ones like git:// and ssh:// but if the user wants he can enable.
0351          */
0352         EscapedLinksSchema,
0353         /** Use Vertical Line At */
0354         VerticalLine,
0355         /** Vertical Line Pixel at */
0356         VerticalLineAtChar,
0357 
0358         /** Shortcut for peeking primary screen */
0359         PeekPrimaryKeySequence,
0360 
0361         /** (bool) If true, text that matches a color in hex format
0362          *  when hovered by the mouse pointer.
0363          */
0364         ColorFilterEnabled,
0365 
0366         /** (bool) Allows mouse tracking */
0367         AllowMouseTracking,
0368 
0369         /** (int) Show semantic hints (lines between commands, lighter input):
0370          * 0 for Never, 1 when showing URL hints, 2 for always
0371          */
0372         SemanticHints,
0373         /** (bool) If true, convert Up/Down arrows when in input mode to Left/Right
0374          * key presses that emulate the same cursor movement
0375          */
0376         SemanticUpDown,
0377         /** (bool) If true, move cursor with Left/Right keys when mouse clicks in input area
0378          */
0379         SemanticInputClick,
0380         /** (QFont) Emoji font override
0381          */
0382         EmojiFont,
0383         /** When to show line numbers.
0384          * 0 for Never, 1 when showing URL hints, 2 for always
0385          */
0386         LineNumbers,
0387         /** When to show Red error bars
0388          */
0389         ErrorBars,
0390         /** When to show Red error background
0391          */
0392         ErrorBackground,
0393         /** When to show alternating gray bars
0394          */
0395         AlternatingBars,
0396         /** When to show alternating background
0397          */
0398         AlternatingBackground,
0399         /** Render some sequences of characters with a single drawText() call
0400          */
0401         WordMode,
0402         /** Attribute changes breaks words
0403          */
0404         WordModeAttr,
0405         /** Use word mode for ASCII characters
0406          * Used for performance and ligatures
0407          */
0408         WordModeAscii,
0409         /** Use word mode for Brahmic scripts
0410          * Improves display when the font is not strictly monospace
0411          */
0412         WordModeBrahmic,
0413         /** Use wcwidth() for problematic characters
0414          * soft hyphen (\u00ad) has wcwidth=1, but should not be displayed per Unicode.
0415          */
0416         IgnoreWcWidth,
0417     };
0418 
0419     Q_ENUM(Property)
0420 
0421     using PropertyMap = std::map<Property, QVariant>;
0422 
0423     /**
0424      * Constructs a new profile
0425      *
0426      * @param parent The parent profile.  When querying the value of a
0427      * property using property(), if the property has not been set in this
0428      * profile then the parent's value for the property will be returned.
0429      */
0430     explicit Profile(const Ptr &parent = Ptr());
0431     virtual ~Profile();
0432 
0433     /**
0434      * Copies all properties except Name and Path from the specified @p
0435      * profile into this profile
0436      *
0437      * @param profile The profile to copy properties from
0438      * @param differentOnly If true, only properties in @p profile which have
0439      * a different value from this profile's current value (either set via
0440      * setProperty() or inherited from the parent profile) will be set.
0441      */
0442     void clone(Ptr profile, bool differentOnly = true);
0443 
0444     /**
0445      * A profile which contains a number of default settings for various
0446      * properties.  This can be used as a parent for other profiles or as a
0447      * fallback in case a profile cannot be loaded from disk.
0448      */
0449     void useBuiltin();
0450 
0451     /**
0452      * Changes the parent profile.  When calling the property() method,
0453      * if the specified property has not been set for this profile,
0454      * the parent's value for the property will be returned instead.
0455      */
0456     void setParent(const Ptr &parent);
0457 
0458     /** Returns the parent profile. */
0459     const Ptr parent() const;
0460 
0461     /** Returns this profile as a group or null if this profile is not a
0462      * group.
0463      */
0464     const GroupPtr asGroup() const;
0465     GroupPtr asGroup();
0466 
0467     /**
0468      * Returns the current value of the specified @p property, cast to type T.
0469      * Internally properties are stored using the QVariant type and cast to T
0470      * using QVariant::value<T>();
0471      *
0472      * If the specified @p property has not been set in this profile,
0473      * and a non-null parent was specified in the Profile's constructor,
0474      * the parent's value for @p property will be returned.
0475      */
0476     template<class T>
0477     T property(Property p) const;
0478 
0479     /** Sets the value of the specified @p property to @p value. */
0480     virtual void setProperty(Property p, const QVariant &value);
0481 
0482     void setProperty(Property p, QVariant &&value);
0483 
0484     /** Sets the Property/value pairs from @p map on this Profile */
0485     void assignProperties(const PropertyMap &map);
0486     void assignProperties(PropertyMap &&map);
0487 
0488     /** Returns true if the specified property has been set in this Profile
0489      * instance.
0490      */
0491     virtual bool isPropertySet(Property p) const;
0492 
0493     /** Returns a map of the properties set in this Profile instance. */
0494     virtual const PropertyMap &properties() const;
0495 
0496     /** Returns true if no properties have been set in this Profile instance. */
0497     bool isEmpty() const;
0498 
0499     /**
0500      * Clears all set properties in this profile. Afte calling this, isEmpty()
0501      * will return true.
0502      */
0503     void clear()
0504     {
0505         _propertyValues.clear();
0506     }
0507 
0508     /**
0509      * Returns true if this profile is the built-in profile.
0510      */
0511     bool isBuiltin() const;
0512 
0513     /**
0514      * Returns true if this profile is editable.
0515      */
0516     bool isEditable() const;
0517 
0518     /**
0519      * Returns true if this profile can be deleted.
0520      */
0521     bool isDeletable() const;
0522 
0523     /**
0524      * Returns true if this is a 'hidden' profile which should not be
0525      * displayed in menus or saved to disk.
0526      *
0527      * This is true for the built-in profile, in case there are no profiles on
0528      * disk which can be loaded, or for overlay profiles created to handle
0529      * command-line arguments which change profile properties.
0530      */
0531     bool isHidden() const;
0532 
0533     /** Specifies whether this is a hidden profile.  See isHidden() */
0534     void setHidden(bool hidden);
0535 
0536     //
0537     // Convenience methods for property() and setProperty() go here
0538     //
0539 
0540     /** Convenience method for property<QString>(Profile::Path) */
0541     QString path() const
0542     {
0543         return property<QString>(Profile::Path);
0544     }
0545 
0546     /** Convenience method for property<QString>(Profile::Name) */
0547     QString name() const
0548     {
0549         return property<QString>(Profile::Name);
0550     }
0551 
0552     /** Convenience method for property<QString>(Profile::UntranslatedName) */
0553     QString untranslatedName() const
0554     {
0555         return property<QString>(Profile::UntranslatedName);
0556     }
0557 
0558     /** Convenience method for property<QString>(Profile::Directory) */
0559     QString defaultWorkingDirectory() const
0560     {
0561         return property<QString>(Profile::Directory);
0562     }
0563 
0564     /** Convenience method for property<QString>(Profile::Icon) */
0565     QString icon() const
0566     {
0567         return property<QString>(Profile::Icon);
0568     }
0569 
0570     /** Convenience method for property<QString>(Profile::Command) */
0571     QString command() const
0572     {
0573         return property<QString>(Profile::Command);
0574     }
0575 
0576     /** Convenience method for property<QStringList>(Profile::Arguments) */
0577     QStringList arguments() const
0578     {
0579         return property<QStringList>(Profile::Arguments);
0580     }
0581 
0582     /** Convenience method for property<QString>(Profile::LocalTabTitleFormat) */
0583     QString localTabTitleFormat() const
0584     {
0585         return property<QString>(Profile::LocalTabTitleFormat);
0586     }
0587 
0588     /** Convenience method for property<QString>(Profile::RemoteTabTitleFormat) */
0589     QString remoteTabTitleFormat() const
0590     {
0591         return property<QString>(Profile::RemoteTabTitleFormat);
0592     }
0593 
0594     /** Convenience method for property<QColor>(Profile::TabColor) */
0595     QColor tabColor() const
0596     {
0597         return property<QColor>(Profile::TabColor);
0598     }
0599 
0600     bool allowEscapedLinks() const
0601     {
0602         return property<bool>(Profile::AllowEscapedLinks);
0603     }
0604 
0605     QStringList escapedLinksSchema() const
0606     {
0607         return property<QString>(Profile::EscapedLinksSchema).split(QLatin1Char(';'));
0608     }
0609 
0610     /** Convenience method for property<bool>(Profile::ShowTerminalSizeHint) */
0611     bool showTerminalSizeHint() const
0612     {
0613         return property<bool>(Profile::ShowTerminalSizeHint);
0614     }
0615 
0616     /** Convenience method for property<bool>(Profile::DimWhenInactive) */
0617     bool dimWhenInactive() const
0618     {
0619         return property<bool>(Profile::DimWhenInactive);
0620     }
0621 
0622     int dimValue() const
0623     {
0624         return property<int>(Profile::DimValue);
0625     }
0626 
0627     /** Convenience method for property<bool>(Profile::BorderWhenActive) */
0628     bool borderWhenActive() const
0629     {
0630         return property<bool>(Profile::BorderWhenActive);
0631     }
0632 
0633     QColor focusBorderColor() const
0634     {
0635         return property<QColor>(Profile::FocusBorderColor);
0636     }
0637 
0638     /** Convenience method for property<QFont>(Profile::Font) */
0639     QFont font() const
0640     {
0641         return property<QFont>(Profile::Font);
0642     }
0643 
0644     /** Convenience method for property<QFont>(Profile::EmojiFont) */
0645     QFont emojiFont() const
0646     {
0647         return property<QFont>(Profile::EmojiFont);
0648     }
0649 
0650     /** Convenience method for property<QString>(Profile::ColorScheme) */
0651     QString colorScheme() const
0652     {
0653         return property<QString>(Profile::ColorScheme);
0654     }
0655 
0656     /** Convenience method for property<QStringList>(Profile::Environment) */
0657     QStringList environment() const
0658     {
0659         return property<QStringList>(Profile::Environment);
0660     }
0661 
0662     /** Convenience method for property<QString>(Profile::KeyBindings) */
0663     QString keyBindings() const
0664     {
0665         return property<QString>(Profile::KeyBindings);
0666     }
0667 
0668     /** Convenience method for property<QString>(Profile::HistorySize) */
0669     int historySize() const
0670     {
0671         return property<int>(Profile::HistorySize);
0672     }
0673 
0674     /** Convenience method for property<bool>(Profile::BidiRenderingEnabled) */
0675     bool bidiRenderingEnabled() const
0676     {
0677         return property<bool>(Profile::BidiRenderingEnabled);
0678     }
0679 
0680     /** Convenience method for property<bool>(Profile::BidiLineLTR) */
0681     bool bidiLineLTR() const
0682     {
0683         return property<bool>(Profile::BidiLineLTR);
0684     }
0685 
0686     /** Convenience method for property<bool>(Profile::BidiTableDirOverride) */
0687     bool bidiTableDirOverride() const
0688     {
0689         return property<bool>(Profile::BidiTableDirOverride);
0690     }
0691 
0692     /** Convenience method for property<bool>(Profile::LineSpacing) */
0693     int lineSpacing() const
0694     {
0695         return property<int>(Profile::LineSpacing);
0696     }
0697 
0698     /** Convenience method for property<bool>(Profile::BlinkingTextEnabled) */
0699     bool blinkingTextEnabled() const
0700     {
0701         return property<bool>(Profile::BlinkingTextEnabled);
0702     }
0703 
0704     /** Convenience method for property<bool>(Profile::MouseWheelZoomEnabled) */
0705     bool mouseWheelZoomEnabled() const
0706     {
0707         return property<bool>(Profile::MouseWheelZoomEnabled);
0708     }
0709 
0710     /** Convenience method for property<bool>(Profile::BlinkingCursorEnabled) */
0711     bool blinkingCursorEnabled() const
0712     {
0713         return property<bool>(Profile::BlinkingCursorEnabled);
0714     }
0715 
0716     /** Convenience method for property<bool>(Profile::FlowControlEnabled) */
0717     bool flowControlEnabled() const
0718     {
0719         return property<bool>(Profile::FlowControlEnabled);
0720     }
0721 
0722     /** Convenience method for property<int>(Profile::CursorShape) */
0723     Enum::CursorShapeEnum cursorShape() const
0724     {
0725         return static_cast<Enum::CursorShapeEnum>(property<int>(Profile::CursorShape));
0726     }
0727 
0728     /** Convenience method for property<bool>(Profile::UseCustomCursorColor) */
0729     bool useCustomCursorColor() const
0730     {
0731         return property<bool>(Profile::UseCustomCursorColor);
0732     }
0733 
0734     /** Convenience method for property<QColor>(Profile::CustomCursorColor) */
0735     QColor customCursorColor() const
0736     {
0737         return property<QColor>(Profile::CustomCursorColor);
0738     }
0739 
0740     /** Convenience method for property<QColor>(Profile::CustomCursorTextColor) */
0741     QColor customCursorTextColor() const
0742     {
0743         return property<QColor>(Profile::CustomCursorTextColor);
0744     }
0745 
0746     /** Convenience method for property<QString>(Profile::WordCharacters) */
0747     QString wordCharacters() const
0748     {
0749         return property<QString>(Profile::WordCharacters);
0750     }
0751 
0752     /** Convenience method for property<bool>(Profile::UnderlineLinksEnabled) */
0753     bool underlineLinksEnabled() const
0754     {
0755         return property<bool>(Profile::UnderlineLinksEnabled);
0756     }
0757 
0758     /** Convenience method for property<bool>(Profile::UnderlineFilesEnabled) */
0759     bool underlineFilesEnabled() const
0760     {
0761         return property<bool>(Profile::UnderlineFilesEnabled);
0762     }
0763 
0764     /**
0765      * Returns the command line that will be used with the current text
0766      * editor setting.
0767      */
0768     QString textEditorCmd() const;
0769     /**
0770      * Convenience method to get the text editor command corresponding to
0771      * Enum::TextEditorCmdCustom.
0772      */
0773     QString customTextEditorCmd() const
0774     {
0775         return property<QString>(Profile::TextEditorCmdCustom);
0776     }
0777 
0778     bool autoCopySelectedText() const
0779     {
0780         return property<bool>(Profile::AutoCopySelectedText);
0781     }
0782 
0783     /** Convenience method for property<QString>(Profile::DefaultEncoding) */
0784     QString defaultEncoding() const
0785     {
0786         return property<QString>(Profile::DefaultEncoding);
0787     }
0788 
0789     /** Convenience method for property<bool>(Profile::AntiAliasFonts) */
0790     bool antiAliasFonts() const
0791     {
0792         return property<bool>(Profile::AntiAliasFonts);
0793     }
0794 
0795     /** Convenience method for property<bool>(Profile::BoldIntense) */
0796     bool boldIntense() const
0797     {
0798         return property<bool>(Profile::BoldIntense);
0799     }
0800 
0801     /** Convenience method for property<bool>(Profile::UseFontLineCharacters)*/
0802     bool useFontLineCharacters() const
0803     {
0804         return property<bool>(Profile::UseFontLineCharacters);
0805     }
0806 
0807     /** Convenience method for property<bool>(Profile::StartInCurrentSessionDir) */
0808     bool startInCurrentSessionDir() const
0809     {
0810         return property<bool>(Profile::StartInCurrentSessionDir);
0811     }
0812 
0813     /** Convenience method for property<QString>(Profile::SilenceSeconds) */
0814     int silenceSeconds() const
0815     {
0816         return property<int>(Profile::SilenceSeconds);
0817     }
0818 
0819     /** Convenience method for property<QString>(Profile::TerminalColumns) */
0820     int terminalColumns() const
0821     {
0822         return property<int>(Profile::TerminalColumns);
0823     }
0824 
0825     /** Convenience method for property<QString>(Profile::TerminalRows) */
0826     int terminalRows() const
0827     {
0828         return property<int>(Profile::TerminalRows);
0829     }
0830 
0831     /** Convenience method for property<int>(Profile::TerminalMargin) */
0832     int terminalMargin() const
0833     {
0834         return property<int>(Profile::TerminalMargin);
0835     }
0836 
0837     /** Convenience method for property<bool>(Profile::TerminalCenter) */
0838     bool terminalCenter() const
0839     {
0840         return property<bool>(Profile::TerminalCenter);
0841     }
0842 
0843     /** Convenience method for property<QString>(Profile::MenuIndex) */
0844     QString menuIndex() const
0845     {
0846         return property<QString>(Profile::MenuIndex);
0847     }
0848 
0849     bool verticalLine() const
0850     {
0851         return property<bool>(Profile::VerticalLine);
0852     }
0853 
0854     int verticalLineAtChar() const
0855     {
0856         return property<int>(Profile::VerticalLineAtChar);
0857     }
0858 
0859     /** Convenience method for property<bool>(Profile::colorFilterEnabled) */
0860     bool colorFilterEnabled() const
0861     {
0862         return property<bool>(Profile::ColorFilterEnabled);
0863     }
0864 
0865     QKeySequence peekPrimaryKeySequence() const
0866     {
0867         return QKeySequence::fromString(property<QString>(Profile::PeekPrimaryKeySequence));
0868     }
0869 
0870     int semanticHints() const
0871     {
0872         return property<int>(Profile::SemanticHints);
0873     }
0874 
0875     int lineNumbers() const
0876     {
0877         return property<int>(Profile::LineNumbers);
0878     }
0879 
0880     bool semanticUpDown() const
0881     {
0882         return property<bool>(Profile::SemanticUpDown);
0883     }
0884 
0885     bool semanticInputClick() const
0886     {
0887         return property<bool>(Profile::SemanticInputClick);
0888     }
0889 
0890     /** Return a list of all properties names and their type
0891      *  (for use with -p option).
0892      */
0893     static const std::vector<std::string> &propertiesInfoList();
0894 
0895     /**
0896      * Returns the element from the Property enum associated with the
0897      * specified @p name.
0898      *
0899      * @param name The name of the property to look for, this is case
0900      * insensitive.
0901      */
0902     static Property lookupByName(const QString &name);
0903 
0904 private:
0905     struct PropertyInfo;
0906     // Defines a new property, this property is then available
0907     // to all Profile instances.
0908     static void registerProperty(const PropertyInfo &info);
0909 
0910     // fills the table with default names for profile properties
0911     // the first time it is called.
0912     // subsequent calls return immediately
0913     static void fillTableWithDefaultNames();
0914 
0915     // returns true if the property can be inherited
0916     static bool canInheritProperty(Property p);
0917 
0918     PropertyMap _propertyValues;
0919     Ptr _parent;
0920 
0921     bool _hidden;
0922 
0923     static QHash<QString, PropertyInfo> PropertyInfoByName;
0924 
0925     // Describes a property.  Each property has a name and group
0926     // which is used when saving/loading the profile.
0927     struct PropertyInfo {
0928         Property property;
0929         const char *name;
0930         const char *group;
0931         QVariant defaultValue;
0932     };
0933     static const std::vector<PropertyInfo> DefaultProperties;
0934 };
0935 
0936 inline bool Profile::canInheritProperty(Property p)
0937 {
0938     return p != Name && p != Path;
0939 }
0940 
0941 template<class T>
0942 inline T Profile::property(Property p) const
0943 {
0944     auto getVariant = [this, p]() {
0945         auto it = _propertyValues.find(p);
0946         if (it != _propertyValues.end()) {
0947             return it->second;
0948         } else if (_parent && canInheritProperty(p)) {
0949             return _parent->property<QVariant>(p);
0950         } else {
0951             return QVariant();
0952         }
0953     };
0954 
0955     if constexpr (std::is_same_v<T, QVariant>) {
0956         return getVariant();
0957     }
0958 
0959     const QVariant variant = getVariant();
0960     return variant.value<T>();
0961 }
0962 }
0963 
0964 #endif // PROFILE_H