settings.cpp
branchvendor
changeset 0 7a96bd401351
child 3 6a0342b3c519
child 55 79b0656dbe7d
child 163 30b22f7bd009
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/settings.cpp	Sun Jan 30 12:58:47 2005 +0000
     1.3 @@ -0,0 +1,132 @@
     1.4 +#include <iostream>
     1.5 +#include "settings.h"
     1.6 +#include "misc.h"
     1.7 +
     1.8 +using namespace std;
     1.9 +/////////////////////////////////////////////////////////////////
    1.10 +// Settings
    1.11 +/////////////////////////////////////////////////////////////////
    1.12 +Settings::Settings()
    1.13 +{
    1.14 +	clear();		 
    1.15 +}
    1.16 +
    1.17 +Settings::~Settings()
    1.18 +{
    1.19 +}
    1.20 +
    1.21 +void Settings::clear()
    1.22 +{
    1.23 +	pathlist.clear();
    1.24 +	keylist.clear();
    1.25 +	valuelist.clear();
    1.26 +}
    1.27 +
    1.28 +void Settings::clearLocal(const QString &s)
    1.29 +{
    1.30 +	QStringList::Iterator itp=pathlist.begin();
    1.31 +	QStringList::Iterator itk=keylist.begin();
    1.32 +	QStringList::Iterator itv=valuelist.begin();
    1.33 +
    1.34 +	while (itp !=pathlist.end() )
    1.35 +	{
    1.36 +		if ((*itk).startsWith (s))
    1.37 +		{
    1.38 +			itp=pathlist.remove (itp);
    1.39 +			itk=keylist.remove (itk);
    1.40 +			itv=valuelist.remove (itv);
    1.41 +		}	else
    1.42 +		{
    1.43 +			itp++;
    1.44 +			itk++;
    1.45 +			itv++;
    1.46 +		}
    1.47 +	}
    1.48 +}
    1.49 +
    1.50 +QString Settings::readLocalEntry ( const QString &fpath, const QString & key, const QString & def = QString::null ) 
    1.51 +{
    1.52 +	QStringList::Iterator itp=pathlist.begin();
    1.53 +	QStringList::Iterator itk=keylist.begin();
    1.54 +	QStringList::Iterator itv=valuelist.begin();
    1.55 +
    1.56 +	// First search for value in settings saved in map
    1.57 +	while (itp !=pathlist.end() )
    1.58 +	{
    1.59 +		if (*itp == fpath && *itk == key)
    1.60 +			return *itv;
    1.61 +		itp++;
    1.62 +		itk++;
    1.63 +		itv++;
    1.64 +	}
    1.65 +
    1.66 +	// Fall back to global vym settings
    1.67 +	bool ok;
    1.68 +	return readEntry (key,def, &ok);
    1.69 +}	
    1.70 +
    1.71 +void Settings::setLocalEntry (const QString &fpath, const QString &key, const QString &value)
    1.72 +{
    1.73 +	QStringList::Iterator itp=pathlist.begin();
    1.74 +	QStringList::Iterator itk=keylist.begin();
    1.75 +	QStringList::Iterator itv=valuelist.begin();
    1.76 +
    1.77 +	if (!fpath.isEmpty() && !key.isEmpty() && !value.isEmpty() )
    1.78 +	{
    1.79 +		// Search for existing entry first
    1.80 +		while (itp !=pathlist.end() )
    1.81 +		{
    1.82 +			if (*itp == fpath && *itk == key)
    1.83 +			{
    1.84 +				*itv=value;
    1.85 +				return;
    1.86 +			}
    1.87 +			itp++;
    1.88 +			itk++;
    1.89 +			itv++;
    1.90 +		}
    1.91 +		
    1.92 +		// If no entry exists, append a new one
    1.93 +		pathlist.append (fpath);
    1.94 +		keylist.append (key);
    1.95 +		valuelist.append (value);
    1.96 +	}
    1.97 +}
    1.98 +
    1.99 +QString Settings::getXMLData (const QString &fpath)
   1.100 +{
   1.101 +	QString s;
   1.102 +	QStringList::Iterator itp=pathlist.begin();
   1.103 +	QStringList::Iterator itk=keylist.begin();
   1.104 +	QStringList::Iterator itv=valuelist.begin();
   1.105 +
   1.106 +	while (itp !=pathlist.end() )
   1.107 +	{
   1.108 +		if (*itp == fpath )
   1.109 +			if (!(*itv).isEmpty())
   1.110 +				s+=singleElement (
   1.111 +					"setting",
   1.112 +					attribut ("key",*itk) 
   1.113 +					+attribut ("value",*itv)
   1.114 +				)+"\n";
   1.115 +		itp++;
   1.116 +		itk++;
   1.117 +		itv++;
   1.118 +	}
   1.119 +	return s;
   1.120 +}
   1.121 +
   1.122 +void Settings::write()
   1.123 +{
   1.124 +	QStringList::Iterator itp=pathlist.begin();
   1.125 +	QStringList::Iterator itk=keylist.begin();
   1.126 +	QStringList::Iterator itv=valuelist.begin();
   1.127 +
   1.128 +	while (itp !=pathlist.end() )
   1.129 +	{
   1.130 +		itp++;
   1.131 +		itk++;
   1.132 +		itv++;
   1.133 +	}
   1.134 +}
   1.135 +