settings.cpp
author insilmaril
Mon, 06 Jun 2005 20:27:42 +0000
changeset 105 67a91e28b30f
parent 0 7a96bd401351
child 3 6a0342b3c519
child 55 79b0656dbe7d
child 163 30b22f7bd009
permissions -rw-r--r--
1.6.8 started API to speedup undos
     1 #include <iostream>
     2 #include "settings.h"
     3 #include "misc.h"
     4 
     5 using namespace std;
     6 /////////////////////////////////////////////////////////////////
     7 // Settings
     8 /////////////////////////////////////////////////////////////////
     9 Settings::Settings()
    10 {
    11 	clear();		 
    12 }
    13 
    14 Settings::~Settings()
    15 {
    16 }
    17 
    18 void Settings::clear()
    19 {
    20 	pathlist.clear();
    21 	keylist.clear();
    22 	valuelist.clear();
    23 }
    24 
    25 void Settings::clearLocal(const QString &s)
    26 {
    27 	QStringList::Iterator itp=pathlist.begin();
    28 	QStringList::Iterator itk=keylist.begin();
    29 	QStringList::Iterator itv=valuelist.begin();
    30 
    31 	while (itp !=pathlist.end() )
    32 	{
    33 		if ((*itk).startsWith (s))
    34 		{
    35 			itp=pathlist.remove (itp);
    36 			itk=keylist.remove (itk);
    37 			itv=valuelist.remove (itv);
    38 		}	else
    39 		{
    40 			itp++;
    41 			itk++;
    42 			itv++;
    43 		}
    44 	}
    45 }
    46 
    47 QString Settings::readLocalEntry ( const QString &fpath, const QString & key, const QString & def = QString::null ) 
    48 {
    49 	QStringList::Iterator itp=pathlist.begin();
    50 	QStringList::Iterator itk=keylist.begin();
    51 	QStringList::Iterator itv=valuelist.begin();
    52 
    53 	// First search for value in settings saved in map
    54 	while (itp !=pathlist.end() )
    55 	{
    56 		if (*itp == fpath && *itk == key)
    57 			return *itv;
    58 		itp++;
    59 		itk++;
    60 		itv++;
    61 	}
    62 
    63 	// Fall back to global vym settings
    64 	bool ok;
    65 	return readEntry (key,def, &ok);
    66 }	
    67 
    68 void Settings::setLocalEntry (const QString &fpath, const QString &key, const QString &value)
    69 {
    70 	QStringList::Iterator itp=pathlist.begin();
    71 	QStringList::Iterator itk=keylist.begin();
    72 	QStringList::Iterator itv=valuelist.begin();
    73 
    74 	if (!fpath.isEmpty() && !key.isEmpty() && !value.isEmpty() )
    75 	{
    76 		// Search for existing entry first
    77 		while (itp !=pathlist.end() )
    78 		{
    79 			if (*itp == fpath && *itk == key)
    80 			{
    81 				*itv=value;
    82 				return;
    83 			}
    84 			itp++;
    85 			itk++;
    86 			itv++;
    87 		}
    88 		
    89 		// If no entry exists, append a new one
    90 		pathlist.append (fpath);
    91 		keylist.append (key);
    92 		valuelist.append (value);
    93 	}
    94 }
    95 
    96 QString Settings::getXMLData (const QString &fpath)
    97 {
    98 	QString s;
    99 	QStringList::Iterator itp=pathlist.begin();
   100 	QStringList::Iterator itk=keylist.begin();
   101 	QStringList::Iterator itv=valuelist.begin();
   102 
   103 	while (itp !=pathlist.end() )
   104 	{
   105 		if (*itp == fpath )
   106 			if (!(*itv).isEmpty())
   107 				s+=singleElement (
   108 					"setting",
   109 					attribut ("key",*itk) 
   110 					+attribut ("value",*itv)
   111 				)+"\n";
   112 		itp++;
   113 		itk++;
   114 		itv++;
   115 	}
   116 	return s;
   117 }
   118 
   119 void Settings::write()
   120 {
   121 	QStringList::Iterator itp=pathlist.begin();
   122 	QStringList::Iterator itk=keylist.begin();
   123 	QStringList::Iterator itv=valuelist.begin();
   124 
   125 	while (itp !=pathlist.end() )
   126 	{
   127 		itp++;
   128 		itk++;
   129 		itv++;
   130 	}
   131 }
   132