diff --git a/src/Profile.cpp b/src/Profile.cpp index 14d71dd82..c74fe036e 100644 --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -52,48 +52,69 @@ using namespace Konsole; // // the other names are usually shorter versions for convenience // when parsing konsoleprofile commands -const Profile::PropertyNamePair Profile::DefaultPropertyNames[] = +static const char* GENERAL_GROUP = "General"; +static const char* KEYBOARD_GROUP = "Keyboard"; +static const char* APPEARANCE_GROUP = "Appearance"; +static const char* SCROLLING_GROUP = "Scrolling"; +static const char* TERMINAL_GROUP = "Terminal Features"; +static const char* CURSOR_GROUP = "Cursor Options"; +static const char* INTERACTION_GROUP = "Interaction Options"; +static const char* ENCODING_GROUP = "Encoding Options"; + +const Profile::PropertyInfo Profile::DefaultPropertyNames[] = { - { Path , "Path" } - , { Name , "Name" } - , { Title , "Title" } - , { Icon , "Icon" } - , { Command , "Command" } - , { Arguments , "Arguments" } - , { Environment , "Environment" } - , { Directory , "Directory" } - - , { LocalTabTitleFormat , "LocalTabTitleFormat" } - , { LocalTabTitleFormat , "tabtitle"} + // General + { Path , "Path" , 0} + , { Name , "Name" , GENERAL_GROUP } + , { Title , "Title" , 0 } + , { Icon , "Icon" , GENERAL_GROUP } + , { Command , "Command" , GENERAL_GROUP } + , { Arguments , "Arguments" , 0 } + , { Environment , "Environment" , GENERAL_GROUP } + , { Directory , "Directory" , GENERAL_GROUP } + , { LocalTabTitleFormat , "LocalTabTitleFormat" , GENERAL_GROUP } + , { LocalTabTitleFormat , "tabtitle" , 0 } + , { RemoteTabTitleFormat , "RemoteTabTitleFormat" , GENERAL_GROUP } + , { ShowMenuBar , "ShowMenuBar" , GENERAL_GROUP } + , { TabBarMode , "TabBarMode" , GENERAL_GROUP } + , { TabBarPosition , "TabBarPosition" , GENERAL_GROUP } - , { RemoteTabTitleFormat , "RemoteTabTitleFormat" } - , { ShowMenuBar , "ShowMenuBar" } - , { TabBarMode , "TabBarMode" } - , { Font , "Font" } - - , { ColorScheme , "ColorScheme" } - , { ColorScheme , "colors" } + // Appearance + , { Font , "Font" , APPEARANCE_GROUP } + , { ColorScheme , "ColorScheme" , APPEARANCE_GROUP } + , { ColorScheme , "colors" , 0 } + , { AntiAliasFonts, "AntiAliasFonts" , APPEARANCE_GROUP } - , { KeyBindings , "KeyBindings" } - , { HistoryMode , "HistoryMode" } - , { HistorySize , "HistorySize" } - , { ScrollBarPosition , "ScrollBarPosition" } - , { BlinkingTextEnabled , "BlinkingTextEnabled" } - , { FlowControlEnabled , "FlowControlEnabled" } - , { AllowProgramsToResizeWindow , "AllowProgramsToResizeWindow" } - , { BlinkingCursorEnabled , "BlinkingCursorEnabled" } - , { UseCustomCursorColor , "UseCustomCursorColor" } - , { CursorShape , "CursorShape" } - , { CustomCursorColor , "CustomCursorColor" } - , { WordCharacters , "WordCharacters" } - , { TabBarPosition , "TabBarPosition" } - , { DefaultEncoding , "DefaultEncoding" } - , { AntiAliasFonts, "AntiAliasFonts" } - , { (Property)0 , 0 } + // Keyboard + , { KeyBindings , "KeyBindings" , KEYBOARD_GROUP } + + // Scrolling + , { HistoryMode , "HistoryMode" , SCROLLING_GROUP } + , { HistorySize , "HistorySize" , SCROLLING_GROUP } + , { ScrollBarPosition , "ScrollBarPosition" , SCROLLING_GROUP } + + // Terminal Features + , { BlinkingTextEnabled , "BlinkingTextEnabled" , TERMINAL_GROUP } + , { FlowControlEnabled , "FlowControlEnabled" , TERMINAL_GROUP } + , { AllowProgramsToResizeWindow , "AllowProgramsToResizeWindow" , TERMINAL_GROUP } + , { BlinkingCursorEnabled , "BlinkingCursorEnabled" , TERMINAL_GROUP } + + // Cursor + , { UseCustomCursorColor , "UseCustomCursorColor" , CURSOR_GROUP } + , { CursorShape , "CursorShape" , CURSOR_GROUP } + , { CustomCursorColor , "CustomCursorColor" , CURSOR_GROUP } + + // Interaction + , { WordCharacters , "WordCharacters" , INTERACTION_GROUP } + + // Encoding + , { DefaultEncoding , "DefaultEncoding" , ENCODING_GROUP } + + , { (Property)0 , 0 , 0} }; -QHash Profile::_propertyByName; -QHash Profile::_nameByProperty; +QHash Profile::_propertyInfoByName; +QHash Profile::_infoByProperty; void Profile::fillTableWithDefaultNames() { @@ -102,10 +123,10 @@ void Profile::fillTableWithDefaultNames() if ( filledDefaults ) return; - const PropertyNamePair* iter = DefaultPropertyNames; + const PropertyInfo* iter = DefaultPropertyNames; while ( iter->name != 0 ) { - registerName(iter->property,iter->name); + registerProperty(*iter); iter++; } @@ -189,7 +210,7 @@ bool Profile::isNameRegistered(const QString& name) // insert default names into table the first time this is called fillTableWithDefaultNames(); - return _propertyByName.contains(name); + return _propertyInfoByName.contains(name); } Profile::Property Profile::lookupByName(const QString& name) @@ -197,14 +218,14 @@ Profile::Property Profile::lookupByName(const QString& name) // insert default names into table the first time this is called fillTableWithDefaultNames(); - return _propertyByName[name.toLower()]; + return _propertyInfoByName[name.toLower()].property; } QString Profile::primaryNameForProperty(Property property) { // insert default names into table the first time this is called fillTableWithDefaultNames(); - return _nameByProperty[property]; + return _infoByProperty[property].name; } QList Profile::namesForProperty(Property property) { @@ -213,14 +234,14 @@ QList Profile::namesForProperty(Property property) return QList() << primaryNameForProperty(property); } -void Profile::registerName(Property property , const QString& name) +void Profile::registerProperty(const PropertyInfo& info) { - _propertyByName.insert(name.toLower(),property); + _propertyInfoByName.insert(QString(info.name).toLower(),info); // only allow one property -> name map // (multiple name -> property mappings are allowed though) - if ( !_nameByProperty.contains(property) ) - _nameByProperty.insert(property,name); + if ( !_infoByProperty.contains(info.property) ) + _infoByProperty.insert(info.property,info); } QString KDE4ProfileWriter::getPath(const Profile* info) @@ -255,7 +276,7 @@ bool KDE4ProfileWriter::writeProfile(const QString& path , const Profile* profil KConfig config(path,KConfig::NoGlobals); // Basic Profile Settings - KConfigGroup general = config.group("General"); + KConfigGroup general = config.group(GENERAL_GROUP); // Parent profile if set, when loading the profile in future, the parent // must be loaded as well if it exists. @@ -286,43 +307,43 @@ bool KDE4ProfileWriter::writeProfile(const QString& path , const Profile* profil writeStandardElement( general , profile , Profile::ShowMenuBar ); // Keyboard - KConfigGroup keyboard = config.group("Keyboard"); + KConfigGroup keyboard = config.group(KEYBOARD_GROUP); writeStandardElement( keyboard , profile , Profile::KeyBindings ); // Appearance - KConfigGroup appearance = config.group("Appearance"); + KConfigGroup appearance = config.group(APPEARANCE_GROUP); writeStandardElement( appearance , profile , Profile::ColorScheme ); writeStandardElement( appearance , profile , Profile::Font ); writeStandardElement( appearance , profile , Profile::AntiAliasFonts ); // Scrolling - KConfigGroup scrolling = config.group("Scrolling"); + KConfigGroup scrolling = config.group(SCROLLING_GROUP); writeStandardElement( scrolling , profile , Profile::HistoryMode ); writeStandardElement( scrolling , profile , Profile::HistorySize ); writeStandardElement( scrolling , profile , Profile::ScrollBarPosition ); // Terminal Features - KConfigGroup terminalFeatures = config.group("Terminal Features"); + KConfigGroup terminalFeatures = config.group(TERMINAL_GROUP); writeStandardElement( terminalFeatures , profile , Profile::FlowControlEnabled ); writeStandardElement( terminalFeatures , profile , Profile::BlinkingCursorEnabled ); // Cursor - KConfigGroup cursorOptions = config.group("Cursor Options"); + KConfigGroup cursorOptions = config.group(CURSOR_GROUP); writeStandardElement( cursorOptions , profile , Profile::UseCustomCursorColor ); writeStandardElement( cursorOptions , profile , Profile::CustomCursorColor ); writeStandardElement( cursorOptions , profile , Profile::CursorShape ); // Interaction - KConfigGroup interactionOptions = config.group("Interaction Options"); + KConfigGroup interactionOptions = config.group(INTERACTION_GROUP); writeStandardElement( interactionOptions , profile , Profile::WordCharacters ); // Encoding - KConfigGroup encodingOptions = config.group("Encoding Options"); + KConfigGroup encodingOptions = config.group(ENCODING_GROUP); writeStandardElement( encodingOptions , profile , Profile::DefaultEncoding ); return true; @@ -340,7 +361,7 @@ bool KDE4ProfileReader::readProfile(const QString& path , Profile* profile , QSt KConfig config(path,KConfig::NoGlobals); // general - KConfigGroup general = config.group("General"); + KConfigGroup general = config.group(GENERAL_GROUP); if ( general.hasKey("Parent") ) parentProfile = general.readEntry("Parent"); @@ -369,43 +390,43 @@ bool KDE4ProfileReader::readProfile(const QString& path , Profile* profile , QSt readStandardElement(general,profile,Profile::ShowMenuBar); // keyboard - KConfigGroup keyboard = config.group("Keyboard"); + KConfigGroup keyboard = config.group(KEYBOARD_GROUP); readStandardElement(keyboard,profile,Profile::KeyBindings); // appearance - KConfigGroup appearance = config.group("Appearance"); + KConfigGroup appearance = config.group(APPEARANCE_GROUP); readStandardElement(appearance,profile,Profile::ColorScheme); readStandardElement(appearance,profile,Profile::Font); readStandardElement(appearance,profile,Profile::AntiAliasFonts); // scrolling - KConfigGroup scrolling = config.group("Scrolling"); + KConfigGroup scrolling = config.group(SCROLLING_GROUP); readStandardElement(scrolling,profile,Profile::HistoryMode); readStandardElement(scrolling,profile,Profile::HistorySize); readStandardElement(scrolling,profile,Profile::ScrollBarPosition); // terminal features - KConfigGroup terminalFeatures = config.group("Terminal Features"); + KConfigGroup terminalFeatures = config.group(TERMINAL_GROUP); readStandardElement(terminalFeatures,profile,Profile::FlowControlEnabled); readStandardElement(terminalFeatures,profile,Profile::BlinkingCursorEnabled); // cursor settings - KConfigGroup cursorOptions = config.group("Cursor Options"); + KConfigGroup cursorOptions = config.group(CURSOR_GROUP); readStandardElement(cursorOptions,profile,Profile::UseCustomCursorColor); readStandardElement(cursorOptions,profile,Profile::CustomCursorColor); readStandardElement(cursorOptions,profile,Profile::CursorShape); // interaction options - KConfigGroup interactionOptions = config.group("Interaction Options"); + KConfigGroup interactionOptions = config.group(INTERACTION_GROUP); readStandardElement(interactionOptions,profile,Profile::WordCharacters); // encoding - KConfigGroup encodingOptions = config.group("Encoding Options"); + KConfigGroup encodingOptions = config.group(ENCODING_GROUP); readStandardElement(encodingOptions,profile,Profile::DefaultEncoding); return true; diff --git a/src/Profile.h b/src/Profile.h index 56d074696..6f3e23636 100644 --- a/src/Profile.h +++ b/src/Profile.h @@ -363,15 +363,17 @@ public: */ static QString primaryNameForProperty(Property property); + +private: + struct PropertyInfo; /** * Adds an association between a string @p name and a @p property. * Subsequent calls to lookupByName() with @p name as the argument * will return @p property. */ - static void registerName(Property property , const QString& name); + static void registerProperty(const PropertyInfo& info); -private: - // fills the table with default names for profile properties + // fills the table with default names for profile properties // the first time it is called. // subsequent calls return immediately static void fillTableWithDefaultNames(); @@ -381,14 +383,15 @@ private: bool _hidden; - static QHash _propertyByName; - static QHash _nameByProperty; - struct PropertyNamePair + static QHash _propertyInfoByName; + static QHash _infoByProperty; + struct PropertyInfo { Property property; const char* name; + const char* group; }; - static const PropertyNamePair DefaultPropertyNames[]; + static const PropertyInfo DefaultPropertyNames[]; }; template