Port KProgressBar's to QProgressBar's.
[kdenetwork.git] / dcoprss / service.cpp
blob8320ee12d6276a7bf056b8135e0e31cb92e84bc2
1 /***************************************************************************
2 service.cpp - A DCOP Service to provide RSS data
3 -------------------
4 begin : Saturday 15 February 2003
5 copyright : (C) 2003 by Ian Reinhart Geiser
6 email : geiseri@kde.org
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17 #include <kdebug.h>
18 #include <kapplication.h>
19 #include <kconfig.h>
20 #include <kglobal.h>
21 #include "service.h"
22 #include "cache.h"
24 RSSService::RSSService() :
25 DCOPObject("RSSService")
27 m_list.setAutoDelete( true );
29 loadLinks();
32 RSSService::~RSSService()
37 QStringList RSSService::list()
39 QStringList lst;
40 Q3DictIterator<RSSDocument> itr(m_list);
41 for(; itr.current(); ++itr)
42 lst.append(itr.currentKey());
43 return lst;
46 DCOPRef RSSService::add(QString id)
48 if(m_list.find(id) == 0L) { // add a new one only if we need to
49 m_list.insert(id, new RSSDocument(id));
50 added(id);
51 saveLinks();
53 return document(id);
56 void RSSService::remove(QString id)
58 m_list.remove(id);
59 removed(id);
60 saveLinks();
63 DCOPRef RSSService::document(QString id)
65 if( m_list[id] )
66 return DCOPRef(m_list[id]);
67 else
68 return DCOPRef();
71 void RSSService::exit()
73 //Save all current RSS links.
74 saveLinks();
75 Cache::self().save();
76 kapp->quit();
80 void RSSService::loadLinks()
82 KConfig *conf = KGlobal::config();
83 conf->setGroup("RSS Links");
84 const QStringList links = conf->readEntry ("links",QStringList());
85 QStringList::ConstIterator it = links.begin();
86 QStringList::ConstIterator end = links.end();
87 for ( ; it != end; ++it )
88 add( *it );
91 void RSSService::saveLinks()
93 KConfig *conf = KGlobal::config();
94 conf->setGroup("RSS Links");
95 QStringList lst;
96 Q3DictIterator<RSSDocument> itr(m_list);
97 for(; itr.current(); ++itr)
98 lst.append(itr.currentKey());
100 conf->writeEntry("links", lst);
101 conf->sync();