kitchensync

extramap.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2002,2003 Holger Freyther <freyther@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include <qdom.h>
00023 #include <qstylesheet.h>
00024 #include <qstringlist.h>
00025 
00026 #include "extramap.h"
00027 
00028 using namespace OpieHelper;
00029 
00033 CustomExtraItem::~CustomExtraItem() {}
00034 
00035 
00036 ExtraMap::~ExtraMap()
00037 {
00038   clear();
00039 }
00040 
00041 void ExtraMap::clear()
00042 {
00043   ExtraMapBase::clear();
00044 
00045   for ( QMap<CUID, CustomExtraItem*>::Iterator it = m_custom.begin();
00046         it != m_custom.end(); ++it )
00047     delete it.data();
00048 
00049   m_custom.clear();
00050 }
00051 
00052 
00053 QString ExtraMap::toString( const CUID& cuid)
00054 {
00055     if (!contains( cuid ) ) return QString::null;
00056 
00057     KeyValue val = (*this)[cuid];
00058     KeyValue::Iterator it;
00059     QString str;
00060     for (it = val.begin(); it != val.end(); ++it )
00061         str += " "+it.key()+"=\""+escape( it.data() )+"\"";
00062 
00063 
00064     return str;
00065 }
00066 QString ExtraMap::toString( const QString& app, const QString& uid )
00067 {
00068     return toString(app+uid);
00069 }
00070 
00071 void ExtraMap::add( const QString& app, const QString& uid, const QDomNamedNodeMap& map, const QStringList& lst )
00072 {
00073     KeyValue val;
00074     uint count =  map.count();
00075     for ( uint i = 0; i < count; i++ ) {
00076         QDomAttr attr = map.item( i ).toAttr();
00077         if (!attr.isNull() ) {
00078             if (!lst.contains(attr.name() ) ) {
00079                 val.insert( attr.name(), attr.value() );
00080             }
00081         }
00082     }
00083     insert(app+uid, val );
00084 }
00085 
00086 QString ExtraMap::escape( const QString& str )
00087 {
00088     return QStyleSheet::escape( str );
00089 }
00090 
00091 
00092 void ExtraMap::add( const QString& app, const QString& type,
00093                     const QString& uid, CustomExtraItem* item )
00094 {
00095   m_custom.insert(app+type+uid, item );
00096 }
00097 
00098 CustomExtraItem* ExtraMap::item( const QString& app,
00099                                  const QString& type,
00100                                  const QString& uid )
00101 {
00102   return m_custom[app+type+uid];
00103 }
KDE Home | KDE Accessibility Home | Description of Access Keys