kitchensync

pluckerfilehandle.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2004 Holger Hans Peter Freyther <freyther@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program 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
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 */
00020 
00021 
00022 #include "pluckerfilehandle.h"
00023 #include "pluckerconfig.h"
00024 
00025 #include <konnector.h>
00026 #include <kstandarddirs.h>
00027 
00028 #include <qfile.h>
00029 #include <qtextstream.h>
00030 
00031 namespace KSPlucker {
00032 
00033 void PluckerFileHandle::addFile( const KURL& url, const QString& uid, bool site )
00034 {
00035   QString md5 = KSync::Konnector::generateMD5Sum( url.path() );
00036   QString file = locateLocal( "appdata", "plucker-"+uid+"/"+md5+".jxl" );
00037   QString name = site ? "site" : "feed";
00038 
00039   QFile f( file );
00040 
00041   if ( f.exists() || !f.open( IO_WriteOnly) )
00042     return;
00043 
00044   QTextStream str( &f );
00045   str.setEncoding( QTextStream::UnicodeUTF8 );
00046   str << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
00047   str << "<jxl lastEdited=\"2004-08-31T11:12:03\" "
00048     "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
00049     "xsi:noNamespaceSchemaLocation=\"http://jpluck.sourceforge.net/jxl/jxl-2.1.xsd\">\n";
00050   str << "\t<"+name+">\n\t\t<name>KitchenSync Added URL"+md5+"</name>\n";
00051   str << "\t\t<uri>"+url.url()+"</uri>\n";
00052   str << "\t</"+name+">\n</jxl>\n";
00053 
00054 
00055   PluckerConfig* conf = PluckerConfig::self();
00056   QStringList lst = conf->pluckerFiles();
00057   if ( !lst.contains( file ) )
00058     lst.append( file );
00059 
00060   conf->setPluckerFiles( lst );
00061   conf->save( uid );
00062 }
00063 
00064 }
KDE Home | KDE Accessibility Home | Description of Access Keys