~ubuntu-branches/ubuntu/precise/konsole/precise-proposed

« back to all changes in this revision

Viewing changes to src/Profile.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-16 13:14:43 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: package-import@ubuntu.com-20111216131443-rhdplbmmuxntat3k
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include <QtCore/QPointer>
29
29
#include <QtCore/QStringList>
30
30
#include <QtCore/QVariant>
31
 
 
32
31
#include <QtGui/QFont>
33
32
 
34
33
// KDE
35
34
#include <KSharedPtr>
36
 
#include <KDebug>
37
35
 
38
36
// Konsole
39
37
#include "konsole_export.h"
45
43
class ProfileGroup;
46
44
 
47
45
/**
48
 
 * Represents a terminal set-up which can be used to 
 
46
 * Represents a terminal set-up which can be used to
49
47
 * set the initial state of new terminal sessions or applied
50
48
 * to existing sessions.  Profiles consist of a number of named
51
49
 * properties, which can be retrieved using property() and
55
53
 * Profiles support a simple form of inheritance.  When a new Profile
56
54
 * is constructed, a pointer to a parent profile can be passed to
57
55
 * the constructor.  When querying a particular property of a profile
58
 
 * using property(), the profile will return its own value for that 
 
56
 * using property(), the profile will return its own value for that
59
57
 * property if one has been set or otherwise it will return the
60
 
 * parent's value for that property.  
 
58
 * parent's value for that property.
61
59
 *
62
60
 * Profiles can be loaded from disk using ProfileReader instances
63
61
 * and saved to disk using ProfileWriter instances.
86
84
        Path,   
87
85
        /** (QString) The descriptive name of this profile. */
88
86
        Name,   
89
 
        /** (QString) Title of this profile that will be displayed. */
90
 
        Title, 
91
 
        /** (QString) The name of the icon associated with this profile.  This 
92
 
         * is used in menus and tabs to represent the profile. 
 
87
        /** (QString) The name of the icon associated with this profile.  This
 
88
         * is used in menus and tabs to represent the profile.
93
89
         */
94
90
        Icon, 
95
91
        /** (QString) The command to execute ( excluding arguments ) when creating a new terminal
98
94
        Command,   
99
95
        /** (QStringList) The arguments which are passed to the program specified by
100
96
         * the Command property when creating a new terminal session using this profile.
101
 
         */ 
 
97
         */
102
98
        Arguments,
103
99
        /** (QStringList) Additional environment variables ( in the form of NAME=VALUE pairs )
104
100
         * which are passed to the program specified by the Command property
105
 
         * when creating a new terminal session using this profile. 
106
 
         */ 
 
101
         * when creating a new terminal session using this profile.
 
102
         */
107
103
        Environment,
108
 
        /** (QString) The initial working directory for sessions created using this profile. */ 
 
104
        /** (QString) The initial working directory for sessions created using this profile. */
109
105
        Directory,
110
106
        /** (QString) The format used for tab titles when running normal commands. */
111
107
        LocalTabTitleFormat,   
112
 
        /** (QString) The format used for tab titles when the session is running 
113
 
         * a remote command (eg. SSH) */ 
 
108
        /** (QString) The format used for tab titles when the session is running
 
109
         * a remote command (eg. SSH) */
114
110
        RemoteTabTitleFormat,   
115
111
        /** (bool) Specifies whether the menu bar should be shown in the main application window. */
116
112
        ShowMenuBar,    
 
113
        /** (bool) Specifies whether show hint for terminal size after resizing the application window. */
 
114
        ShowTerminalSizeHint,
 
115
         /** (bool) Specifies whether the geometry information is saved when window is closed. */
117
116
        SaveGeometryOnExit,
118
117
        /** (TabBarModeEnum) Specifies when the tab bar should be shown in
119
 
         * the main application window. */ 
 
118
         * the main application window. */
120
119
        TabBarMode,    
121
120
        /** (QFont) The font to use in terminal displays using this profile. */
122
121
        Font,           
123
 
        /** (QString) 
124
 
         * The name of the color scheme to use in terminal displays using this profile. 
125
 
         * Color schemes are managed by the ColorSchemeManager class. 
 
122
        /** (QString)
 
123
         * The name of the color scheme to use in terminal displays using this profile.
 
124
         * Color schemes are managed by the ColorSchemeManager class.
126
125
         */
127
126
        ColorScheme,   
128
 
        /** (QString) The name of the key bindings. 
129
 
         * Key bindings are managed by the KeyboardTranslatorManager class. 
 
127
        /** (QString) The name of the key bindings.
 
128
         * Key bindings are managed by the KeyboardTranslatorManager class.
130
129
         */
131
130
        KeyBindings, 
132
131
        /** (HistoryModeEnum) Specifies the storage type used for keeping the output produced
138
137
         * Only applicable if the HistoryMode property is FixedSizeHistory
139
138
         */
140
139
        HistorySize,
141
 
        /** (ScrollBarPositionEnum) Specifies the position of the scroll bar in 
 
140
        /** (ScrollBarPositionEnum) Specifies the position of the scroll bar in
142
141
         * terminal displays using this profile.
143
142
         */
144
143
        ScrollBarPosition,  
148
147
        BlinkingTextEnabled,       
149
148
        /** (bool) Specifies whether the flow control keys ( typically Ctrl+S , Ctrl+Q )
150
149
         * have any effect.  Also known as Xon/Xoff
151
 
         */ 
 
150
         */
152
151
        FlowControlEnabled,
153
 
        /** (bool) Specifies whether programs running in the terminal are allowed to 
154
 
         * resize the terminal display. 
 
152
        /** (bool) Specifies whether programs running in the terminal are allowed to
 
153
         * resize the terminal display.
155
154
         */
156
155
        AllowProgramsToResizeWindow,
157
 
        /** (bool) Specifies whether the cursor blinks ( in a manner similar 
 
156
        /** (bool) Specifies whether the cursor blinks ( in a manner similar
158
157
         * to text editing applications )
159
158
         */
160
159
        BlinkingCursorEnabled,
163
162
         * color to match the character underneath it.
164
163
         */
165
164
        UseCustomCursorColor,
166
 
        /** (CursorShapeEnum) The shape used by terminal displays to represent the cursor. */ 
 
165
        /** (CursorShapeEnum) The shape used by terminal displays to represent the cursor. */
167
166
        CursorShape,           
168
167
        /** (QColor) The color used by terminal displays to draw the cursor.  Only applicable
169
 
         * if the UseCustomCursorColor property is true. */ 
 
168
         * if the UseCustomCursorColor property is true. */
170
169
        CustomCursorColor,        
171
170
        /** (QString) A string consisting of the characters used to delimit words when
172
171
         * selecting text in the terminal display.
174
173
        WordCharacters,
175
174
        /** (TabBarPositionEnum) Position of the tab-bar relative to the terminal displays. */
176
175
        TabBarPosition,
177
 
        /** (bool) If true, the triple click selects from current word onwards. Otherwise
178
 
         * selects whole line.
 
176
        /** (NewTabBehaviorEnum) Specifies where the newly created tab should be placed. */
 
177
        NewTabBehavior,
 
178
        /** (TripleClickModeEnum) Specifies which part of current line should be
 
179
         * selected with triple click action.
179
180
         */
180
181
        TripleClickMode,
181
182
        /** (bool) If true, text that matches a link or an email address is underlined when
186
187
        DefaultEncoding,
187
188
        /** (bool) Whether fonts should be aliased or not */
188
189
        AntiAliasFonts,
189
 
        /** (bool) Whether new sessions should be started in the same directory as the 
190
 
         * currently active session. */
191
 
        BoldIntense,
192
190
        /** (bool) Whether character with intense colors should be rendered in bold font
193
191
         * or just in bright color. */
 
192
        BoldIntense,
 
193
        /** (bool) Whether new sessions should be started in the same directory as the
 
194
         * currently active session. */
194
195
        StartInCurrentSessionDir,
195
196
        /** (bool) Whether a 'New Tab' and 'Close Tab' buttons should be shown on the tab bar */
196
197
        ShowNewAndCloseTabButtons,
 
198
        /** (int) Specifies the threshold of detected silence in seconds. */
 
199
        SilenceSeconds,
197
200
        /** Index of profile in the File Menu
198
201
         * In future, format will be #.#.# to account for levels
199
202
         */
200
203
        MenuIndex
201
204
    };
202
205
 
203
 
    /** 
204
 
     * This enum describes the available modes for showing or hiding the tab bar. 
 
206
    /**
 
207
     * This enum describes the available modes for showing or hiding the tab bar.
205
208
     */
206
209
    enum TabBarModeEnum
207
210
    {
213
216
        AlwaysShowTabBar   = 2
214
217
    };
215
218
 
216
 
    /** 
217
 
     * This enum describes the available tab bar positions. 
 
219
    /**
 
220
     * This enum describes the available tab bar positions.
218
221
     */
219
222
    enum TabBarPositionEnum
220
223
    {
224
227
        TabBarTop    = 1
225
228
    };
226
229
 
227
 
    /** 
228
 
     * This enum describes the modes available to remember lines of output produced 
229
 
     * by the terminal. 
 
230
    /**
 
231
     * This enum describes where newly created tab should be placed.
 
232
     */
 
233
    enum NewTabBehaviorEnum
 
234
    {
 
235
        /** Put newly created tab at the end. */
 
236
        PutNewTabAtTheEnd = 0,
 
237
        /** Put newly created tab right after current tab. */
 
238
        PutNewTabAfterCurrentTab   = 1
 
239
    };
 
240
 
 
241
    /**
 
242
     * This enum describes the modes available to remember lines of output produced
 
243
     * by the terminal.
230
244
     */
231
245
    enum HistoryModeEnum
232
246
    {
235
249
        /** A fixed number of lines of output are remembered.  Once the limit is reached, the oldest
236
250
         * lines are lost. */
237
251
        FixedSizeHistory = 1,
238
 
        /** All output is remembered for the duration of the session.  
 
252
        /** All output is remembered for the duration of the session.
239
253
         * Typically this means that lines are recorded to
240
254
         * a file as they are scrolled off-screen.
241
255
         */
266
280
        UnderlineCursor = 2
267
281
    };
268
282
 
 
283
    /** This enum describes the behavior of triple click action . */
 
284
    enum TripleClickModeEnum
 
285
    {
 
286
        /** Select the whole line underneath the cursor. */
 
287
        SelectWholeLine = 0,
 
288
        /** Select from the current cursor position to the end of the line. */
 
289
        SelectForwardsFromCursor = 1
 
290
    };
 
291
 
269
292
    /**
270
293
     * Constructs a new profile
271
294
     *
287
310
     */
288
311
    void clone(Ptr profile, bool differentOnly = true);
289
312
 
290
 
    /** 
 
313
    /**
291
314
     * Changes the parent profile.  When calling the property() method,
292
315
     * if the specified property has not been set for this profile,
293
316
     * the parent's value for the property will be returned instead.
301
324
    const GroupPtr asGroup() const;
302
325
    GroupPtr asGroup();
303
326
 
304
 
    /** 
 
327
    /**
305
328
     * Returns the current value of the specified @p property, cast to type T.
306
329
     * Internally properties are stored using the QVariant type and cast to T
307
330
     * using QVariant::value<T>();
312
335
     */
313
336
    template <class T>
314
337
    T property(Property property) const;
315
 
    
 
338
 
316
339
    /** Sets the value of the specified @p property to @p value. */
317
340
    virtual void setProperty(Property property,const QVariant& value);
318
341
    /** Returns true if the specified property has been set in this Profile instance. */
324
347
    /** Returns true if no properties have been set in this Profile instance. */
325
348
    bool isEmpty() const;
326
349
 
327
 
    /** 
 
350
    /**
328
351
     * Returns true if this is a 'hidden' profile which should not be displayed
329
352
     * in menus or saved to disk.
330
353
     *
331
 
     * This is used for the fallback profile, in case there are no profiles on 
 
354
     * This is used for the fallback profile, in case there are no profiles on
332
355
     * disk which can be loaded, or for overlay profiles created to handle
333
356
     * command-line arguments which change profile properties.
334
357
     */
346
369
 
347
370
    /** Convenience method for property<QString>(Profile::Name) */
348
371
    QString name() const { return property<QString>(Profile::Name); }
349
 
    
 
372
 
350
373
    /** Convenience method for property<QString>(Profile::Directory) */
351
374
    QString defaultWorkingDirectory() const 
352
375
            { return property<QString>(Profile::Directory); }
374
397
 
375
398
    int menuIndexAsInt() const;
376
399
 
377
 
    /** Return a list of all properties names and their type 
 
400
    /** Return a list of all properties names and their type
378
401
     *  (for use with -p option).
379
402
     */
380
403
    const QStringList propertiesInfoList() const;
381
404
 
382
405
    /**
383
 
     * Returns true if @p name has been associated with an element
384
 
     * from the Property enum or false otherwise.
385
 
     */
386
 
    static bool isNameRegistered(const QString& name);
387
 
 
388
 
    /** 
389
 
     * Returns the element from the Property enum associated with the 
 
406
     * Returns the element from the Property enum associated with the
390
407
     * specified @p name.
391
408
     *
392
409
     * @param name The name of the property to look for, this is case insensitive.
393
410
     */
394
411
    static Property lookupByName(const QString& name);
395
 
    /**
396
 
     * Returns the string names associated with the specified @p property from
397
 
     * the Property enum, in the order the associations were created using
398
 
     * registerName()
399
 
     */
400
 
    static QList<QString> namesForProperty(Property property);
401
 
 
402
 
    /** 
403
 
     * Returns the primary name for the specified @p property.
404
 
     * TODO More documentation
405
 
     */
406
 
    static QString primaryNameForProperty(Property property);
407
412
 
408
413
private:
409
414
    struct PropertyInfo;
426
431
 
427
432
    static QHash<QString,PropertyInfo> _propertyInfoByName;
428
433
    static QHash<Property,PropertyInfo> _infoByProperty;
429
 
    
 
434
 
430
435
    // Describes a property.  Each property has a name and group
431
436
    // which is used when saving/loading the profile.
432
437
    struct PropertyInfo
461
466
{ return property != Name && property != Path; }
462
467
 
463
468
 
464
 
/** 
 
469
/**
465
470
 * A profile which contains a number of default settings for various properties.
466
471
 * This can be used as a parent for other profiles or a fallback in case
467
472
 * a profile cannot be loaded from disk.
472
477
    FallbackProfile();
473
478
};
474
479
 
475
 
/** 
 
480
/**
476
481
 * A composite profile which allows a group of profiles to be treated as one.
477
482
 * When setting a property, the new value is applied to all profiles in the group.
478
483
 * When reading a property, if all profiles in the group have the same value
494
499
    ProfileGroup(Profile::Ptr parent = Profile::Ptr());
495
500
 
496
501
    /** Add a profile to the group.  Calling setProperty() will update this profile.
497
 
     * When creating a group, add the profiles to the group then call updateValues() to 
 
502
     * When creating a group, add the profiles to the group then call updateValues() to
498
503
     * make the group's property values reflect the profiles currently in the group. */
499
504
    void addProfile(Profile::Ptr profile)
500
505
    { _profiles.append(profile); }
508
513
    QList<Profile::Ptr> profiles() const
509
514
    { return _profiles; }
510
515
 
511
 
    /** 
512
 
     * Updates the property values in this ProfileGroup to match those from 
513
 
     * the group's profiles() 
 
516
    /**
 
517
     * Updates the property values in this ProfileGroup to match those from
 
518
     * the group's profiles()
514
519
     *
515
520
     * For each available property, if each profile in the group has the same value then
516
521
     * the ProfileGroup will use that value for the property.  Otherwise the value for the property
550
555
    virtual ~ProfileReader() {}
551
556
    /** Returns a list of paths to profiles which this reader can read. */
552
557
    virtual QStringList findProfiles() { return QStringList(); }
553
 
    /** 
554
 
     * Attempts to read a profile from @p path and 
 
558
    /**
 
559
     * Attempts to read a profile from @p path and
555
560
     * save the property values described into @p profile.
556
561
     *
557
562
     * Returns true if the profile was successfully read or false otherwise.
584
589
{
585
590
public:
586
591
    virtual ~ProfileWriter() {}
587
 
    /** 
588
 
     * Returns a suitable path-name for writing 
 
592
    /**
 
593
     * Returns a suitable path-name for writing
589
594
     * @p profile to. The path-name should be accepted by
590
595
     * the corresponding ProfileReader class.
591
596
     */
608
613
                         const Profile::PropertyInfo* properties);
609
614
};
610
615
 
611
 
/** 
 
616
/**
612
617
 * Parses an input string consisting of property names
613
618
 * and assigned values and returns a table of properties
614
619
 * and values.
617
622
 *
618
623
 * @code
619
624
 *   PropertyName=Value;PropertyName=Value ...
620
 
 * @endcode 
 
625
 * @endcode
621
626
 *
622
627
 * For example:
623
628
 *
630
635
public:
631
636
    /**
632
637
     * Parses an input string consisting of property names
633
 
     * and assigned values and returns a table of 
 
638
     * and assigned values and returns a table of
634
639
     * properties and values.
635
640
     */
636
641
    QHash<Profile::Property,QVariant> parse(const QString& input);