File indexing completed on 2024-05-12 05:46:54

0001 //////////////////////////////////////////////////////////////////////////////
0002 // breezeexceptionlist.cpp
0003 // window decoration exceptions
0004 // -------------------
0005 //
0006 // SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0007 //
0008 // Permission is hereby granted, free of charge, to any person obtaining a copy
0009 // of this software and associated documentation files (the "Software"), to
0010 // deal in the Software without restriction, including without limitation the
0011 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
0012 // sell copies of the Software, and to permit persons to whom the Software is
0013 // furnished to do so, subject to the following conditions:
0014 //
0015 // The above copyright notice and this permission notice shall be included in
0016 // all copies or substantial portions of the Software.
0017 //
0018 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0019 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0020 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0021 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0022 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0023 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
0024 // IN THE SOFTWARE.
0025 //////////////////////////////////////////////////////////////////////////////
0026 
0027 #include "breezeexceptionlist.h"
0028 
0029 
0030 namespace Breeze
0031 {
0032 
0033     //______________________________________________________________
0034     void ExceptionList::readConfig( KSharedConfig::Ptr config )
0035     {
0036 
0037         _exceptions.clear();
0038 
0039         QString groupName;
0040         for( int index = 0; config->hasGroup( groupName = exceptionGroupName( index ) ); ++index )
0041         {
0042 
0043             // create exception
0044             InternalSettings exception;
0045 
0046             // reset group
0047             readConfig( &exception, config.data(), groupName );
0048 
0049             // create new configuration
0050             InternalSettingsPtr configuration( new InternalSettings() );
0051             configuration.data()->load();
0052 
0053             // apply changes from exception
0054             configuration->setEnabled( exception.enabled() );
0055             configuration->setExceptionType( exception.exceptionType() );
0056             configuration->setExceptionPattern( exception.exceptionPattern() );
0057             configuration->setMask( exception.mask() );
0058 
0059             // propagate all features found in mask to the output configuration
0060             if( exception.mask() & BorderSize ) configuration->setBorderSize( exception.borderSize() );
0061             configuration->setHideTitleBar( exception.hideTitleBar() );
0062 
0063             // append to exceptions
0064             _exceptions.append( configuration );
0065 
0066         }
0067 
0068     }
0069 
0070     //______________________________________________________________
0071     void ExceptionList::writeConfig( KSharedConfig::Ptr config )
0072     {
0073 
0074         // remove all existing exceptions
0075         QString groupName;
0076         for( int index = 0; config->hasGroup( groupName = exceptionGroupName( index ) ); ++index )
0077         { config->deleteGroup( groupName ); }
0078 
0079         // rewrite current exceptions
0080         int index = 0;
0081         foreach( const InternalSettingsPtr& exception, _exceptions )
0082         {
0083 
0084             writeConfig( exception.data(), config.data(), exceptionGroupName( index ) );
0085             ++index;
0086 
0087         }
0088 
0089     }
0090 
0091     //_______________________________________________________________________
0092     QString ExceptionList::exceptionGroupName( int index )
0093     { return QString( "Windeco Exception %1" ).arg( index ); }
0094 
0095     //______________________________________________________________
0096     void ExceptionList::writeConfig( KCoreConfigSkeleton* skeleton, KConfig* config, const QString& groupName )
0097     {
0098 
0099         // list of items to be written
0100         QStringList keys = { "Enabled", "ExceptionPattern", "ExceptionType", "HideTitleBar", "Mask", "BorderSize"};
0101 
0102         // write all items
0103         foreach( auto key, keys )
0104         {
0105             KConfigSkeletonItem* item( skeleton->findItem( key ) );
0106             if( !item ) continue;
0107 
0108             if( !groupName.isEmpty() ) item->setGroup( groupName );
0109             KConfigGroup configGroup( config, item->group() );
0110             configGroup.writeEntry( item->key(), item->property() );
0111 
0112         }
0113 
0114     }
0115 
0116     //______________________________________________________________
0117     void ExceptionList::readConfig( KCoreConfigSkeleton* skeleton, KConfig* config, const QString& groupName )
0118     {
0119 
0120         foreach( KConfigSkeletonItem* item, skeleton->items() )
0121         {
0122             if( !groupName.isEmpty() ) item->setGroup( groupName );
0123             item->readConfig( config );
0124         }
0125 
0126     }
0127 
0128 }