kitchensync Library API Documentation

qtopia/md5map.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., 59 Temple Place - Suite 330,
00019     Boston, MA 02111-1307, USA.
00020 */
00021 
00022 #include <kconfig.h>
00023 
00024 #include "md5map.h"
00025 
00026 using namespace OpieHelper;
00027 
00028 MD5Map::MD5Map( const QString& file)
00029     : m_conf(0l)
00030 {
00031     load( file );
00032 }
00033 MD5Map::~MD5Map() {
00034     delete m_conf;
00035 }
00036 void MD5Map::load( const QString& file ) {
00037     m_file = file;
00038     /* return here cause reading is not possible */
00039     if (m_file.isEmpty() ) return;
00040 
00041     KConfig* conf = config();
00042     QStringList list = conf->groupList();
00043     for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
00044         conf->setGroup( (*it) );
00045         insert( (*it), conf->readEntry("sum") );
00046     }
00047 }
00048 void MD5Map::save() {
00049     KConfig* conf = config();
00050 
00051     QStringList groups = conf->groupList();
00052     for (QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) {
00053         conf->deleteGroup( (*it) );
00054     }
00055 
00056     Iterator it;
00057     for ( it = m_map.begin(); it != m_map.end(); ++it ) {
00058         conf->setGroup( it.key() );
00059         conf->writeEntry( "sum", it.data() );
00060     }
00061     conf->sync();
00062     qWarning("save %s",  m_file.latin1() );
00063 }
00064 void MD5Map::setFileName( const QString& file ) {
00065     m_file = file;
00066 }
00067 QString MD5Map::md5sum(const QString& uid )const {
00068     return m_map[uid];
00069 }
00070 bool MD5Map::contains( const QString& uid )const {
00071     return m_map.contains( uid );
00072 }
00073 void MD5Map::insert( const QString& uid, const QString& str) {
00074     m_map.insert( uid, str );
00075 }
00076 void MD5Map::set( const Map& map) {
00077     m_map = map;
00078 }
00079 MD5Map::Map MD5Map::map()const{
00080     return m_map;
00081 }
00082 void MD5Map::clear() {
00083     m_map.clear();
00084     KConfig* conf = config();
00085     QStringList groups = conf->groupList();
00086     for (QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) {
00087         conf->deleteGroup( (*it) );
00088     }
00089 }
00090 KConfig* MD5Map::config() {
00091     if (!m_conf ) {
00092         m_conf = new KConfig( m_file, false, false );
00093     }
00094     return m_conf;
00095 }
KDE Logo
This file is part of the documentation for kitchensync Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 22:41:41 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003