From 47d455dd55be855e4cc691c32f687f723d9247ee Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- libkscan/kscanoptset.cpp | 221 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 libkscan/kscanoptset.cpp (limited to 'libkscan/kscanoptset.cpp') diff --git a/libkscan/kscanoptset.cpp b/libkscan/kscanoptset.cpp new file mode 100644 index 00000000..ac30ae40 --- /dev/null +++ b/libkscan/kscanoptset.cpp @@ -0,0 +1,221 @@ +/* This file is part of the KDE Project + Copyright (C) 2000 Klaas Freitag + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include +#include +#include + +#include "kscandevice.h" +#include "kscanoption.h" +#include "kscanoptset.h" + +KScanOptSet::KScanOptSet( const QCString& setName ) +{ + name = setName; + + setAutoDelete( false ); + + description = ""; + + strayCatsList.setAutoDelete( true ); +} + + + +KScanOptSet::~KScanOptSet() +{ + /* removes all deep copies from backupOption */ + strayCatsList.clear(); +} + + + +KScanOption *KScanOptSet::get( const QCString name ) const +{ + KScanOption *ret = 0; + + ret = (*this) [name]; + + return( ret ); +} + +QCString KScanOptSet::getValue( const QCString name ) const +{ + KScanOption *re = get( name ); + QCString retStr = ""; + + if( re ) + { + retStr = re->get(); + } + else + { + kdDebug(29000) << "option " << name << " from OptionSet is not available" << endl; + } + return( retStr ); +} + + +bool KScanOptSet::backupOption( const KScanOption& opt ) +{ + bool retval = true; + + /** Allocate a new option and store it **/ + const QCString& optName = opt.getName(); + if( !optName ) + retval = false; + + if( retval ) + { + KScanOption *newopt = find( optName ); + + if( newopt ) + { + /** The option already exists **/ + /* Copy the new one into the old one. TODO: checken Zuweisungoperatoren OK ? */ + *newopt = opt; + } + else + { + const QCString& qq = opt.get(); + kdDebug(29000) << "Value is now: <" << qq << ">" << endl; + const KScanOption *newopt = new KScanOption( opt ); + + strayCatsList.append( newopt ); + + if( newopt ) + { + insert( optName, newopt ); + } else { + retval = false; + } + } + } + + return( retval ); + +} + +QString KScanOptSet::getDescription() const +{ + return description; +} + +void KScanOptSet::slSetDescription( const QString& str ) +{ + description = str; +} + +void KScanOptSet::backupOptionDict( const QAsciiDict& optDict ) +{ + QAsciiDictIterator it( optDict ); + + while ( it.current() ) + { + kdDebug(29000) << "Dict-Backup of Option <" << it.currentKey() << ">" << endl; + backupOption( *(it.current())); + ++it; + } + + +} + +/* */ +void KScanOptSet::saveConfig( const QString& scannerName, const QString& configName, + const QString& descr ) +{ + QString confFile = SCANNER_DB_FILE; + kdDebug( 29000) << "Creating scan configuration file <" << confFile << ">" << endl; + + KConfig *scanConfig = new KConfig( confFile ); + QString cfgName = configName; + + if( configName.isNull() || configName.isEmpty() ) + cfgName = "default"; + + scanConfig->setGroup( cfgName ); + + scanConfig->writeEntry( "description", descr ); + scanConfig->writeEntry( "scannerName", scannerName ); + QAsciiDictIterator it( *this); + + while ( it.current() ) + { + const QString line = it.current() -> configLine(); + const QString name = it.current()->getName(); + + kdDebug(29000) << "writing " << name << " = <" << line << ">" << endl; + + scanConfig->writeEntry( name, line ); + + ++it; + } + + scanConfig->sync(); + delete( scanConfig ); +} + +bool KScanOptSet::load( const QString& /*scannerName*/ ) +{ + QString confFile = SCANNER_DB_FILE; + kdDebug( 29000) << "** Reading from scan configuration file <" << confFile << ">" << endl; + bool ret = true; + + KConfig *scanConfig = new KConfig( confFile, true ); + QString cfgName = name; /* of the KScanOptSet, given in constructor */ + + if( cfgName.isNull() || cfgName.isEmpty() ) + cfgName = "default"; + + if( ! scanConfig->hasGroup( name ) ) + { + kdDebug(29000) << "Group " << name << " does not exist in configuration !" << endl; + ret = false; + } + else + { + scanConfig->setGroup( name ); + + typedef QMap StringMap; + + StringMap strMap = scanConfig->entryMap( name ); + + StringMap::Iterator it; + for( it = strMap.begin(); it != strMap.end(); ++it ) + { + QCString optName = it.key().latin1(); + KScanOption optset( optName ); + + QCString val = it.data().latin1(); + kdDebug(29000) << "Reading for " << optName << " value " << val << endl; + + optset.set( val ); + + backupOption( optset ); + } + } + delete( scanConfig ); + + return( ret ); +} + +/* END */ -- cgit v1.2.1