1 ////////////////////////////////////////////////////////////////////////////// 2 // breezeexceptionlist.cpp 3 // window decoration exceptions 4 // ------------------- 5 // 6 // SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr> 7 // 8 // SPDX-License-Identifier: MIT 9 ////////////////////////////////////////////////////////////////////////////// 10 11 #include "breezeexceptionlist.h" 12 13 14 namespace Breeze 15 { 16 17 //______________________________________________________________ readConfig(KSharedConfig::Ptr config)18 void ExceptionList::readConfig( KSharedConfig::Ptr config ) 19 { 20 21 _exceptions.clear(); 22 23 QString groupName; 24 for( int index = 0; config->hasGroup( groupName = exceptionGroupName( index ) ); ++index ) 25 { 26 27 // create exception 28 InternalSettings exception; 29 30 // reset group 31 readConfig( &exception, config.data(), groupName ); 32 33 // create new configuration 34 InternalSettingsPtr configuration( new InternalSettings() ); 35 configuration.data()->load(); 36 37 // apply changes from exception 38 configuration->setEnabled( exception.enabled() ); 39 configuration->setExceptionType( exception.exceptionType() ); 40 configuration->setExceptionPattern( exception.exceptionPattern() ); 41 configuration->setMask( exception.mask() ); 42 43 // propagate all features found in mask to the output configuration 44 if( exception.mask() & BorderSize ) configuration->setBorderSize( exception.borderSize() ); 45 configuration->setHideTitleBar( exception.hideTitleBar() ); 46 47 // append to exceptions 48 _exceptions.append( configuration ); 49 50 } 51 52 } 53 54 //______________________________________________________________ writeConfig(KSharedConfig::Ptr config)55 void ExceptionList::writeConfig( KSharedConfig::Ptr config ) 56 { 57 58 // remove all existing exceptions 59 QString groupName; 60 for( int index = 0; config->hasGroup( groupName = exceptionGroupName( index ) ); ++index ) 61 { config->deleteGroup( groupName ); } 62 63 // rewrite current exceptions 64 int index = 0; 65 foreach( const InternalSettingsPtr& exception, _exceptions ) 66 { 67 68 writeConfig( exception.data(), config.data(), exceptionGroupName( index ) ); 69 ++index; 70 71 } 72 73 } 74 75 //_______________________________________________________________________ exceptionGroupName(int index)76 QString ExceptionList::exceptionGroupName( int index ) 77 { return QString( "Windeco Exception %1" ).arg( index ); } 78 79 //______________________________________________________________ writeConfig(KCoreConfigSkeleton * skeleton,KConfig * config,const QString & groupName)80 void ExceptionList::writeConfig( KCoreConfigSkeleton* skeleton, KConfig* config, const QString& groupName ) 81 { 82 83 // list of items to be written 84 QStringList keys = { "Enabled", "ExceptionPattern", "ExceptionType", "HideTitleBar", "Mask", "BorderSize"}; 85 86 // write all items 87 foreach( auto key, keys ) 88 { 89 KConfigSkeletonItem* item( skeleton->findItem( key ) ); 90 if( !item ) continue; 91 92 if( !groupName.isEmpty() ) item->setGroup( groupName ); 93 KConfigGroup configGroup( config, item->group() ); 94 configGroup.writeEntry( item->key(), item->property() ); 95 96 } 97 98 } 99 100 //______________________________________________________________ readConfig(KCoreConfigSkeleton * skeleton,KConfig * config,const QString & groupName)101 void ExceptionList::readConfig( KCoreConfigSkeleton* skeleton, KConfig* config, const QString& groupName ) 102 { 103 104 foreach( KConfigSkeletonItem* item, skeleton->items() ) 105 { 106 if( !groupName.isEmpty() ) item->setGroup( groupName ); 107 item->readConfig( config ); 108 } 109 110 } 111 112 } 113