blob: 54e987b2b2f3f52bb6f229b182810f9ecaef4098 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/* $Id$ */
/***************************************************************************
service.cpp - A DCOP Service to provide RSS data
-------------------
begin : Saturday 15 February 2003
copyright : (C) 2003 by Ian Reinhart Geiser
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <kdebug.h>
#include <kapplication.h>
#include <kconfig.h>
#include "service.h"
#include "cache.h"
RSSService::RSSService() :
DCOPObject("RSSService")
{
m_list.setAutoDelete( true );
loadLinks();
}
RSSService::~RSSService()
{
}
TQStringList RSSService::list()
{
TQStringList lst;
TQDictIterator<RSSDocument> itr(m_list);
for(; itr.current(); ++itr)
lst.append(itr.currentKey());
return lst;
}
DCOPRef RSSService::add(TQString id)
{
if(m_list.find(id) == 0L) { // add a new one only if we need to
m_list.insert(id, new RSSDocument(id));
added(id);
saveLinks();
}
return document(id);
}
void RSSService::remove(TQString id)
{
m_list.remove(id);
removed(id);
saveLinks();
}
DCOPRef RSSService::document(TQString id)
{
if( m_list[id] )
return DCOPRef(m_list[id]);
else
return DCOPRef();
}
void RSSService::exit()
{
//Save all current RSS links.
saveLinks();
Cache::self().save();
kapp->quit();
}
void RSSService::loadLinks()
{
KConfig *conf = kapp->config();
conf->setGroup("RSS Links");
const TQStringList links = conf->readListEntry ("links");
TQStringList::ConstIterator it = links.begin();
TQStringList::ConstIterator end = links.end();
for ( ; it != end; ++it )
add( *it );
}
void RSSService::saveLinks()
{
KConfig *conf = kapp->config();
conf->setGroup("RSS Links");
TQStringList lst;
TQDictIterator<RSSDocument> itr(m_list);
for(; itr.current(); ++itr)
lst.append(itr.currentKey());
conf->writeEntry("links", lst);
conf->sync();
}
|