TDE network applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

service.cpp 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* $Id$ */
  2. /***************************************************************************
  3. service.cpp - A DCOP Service to provide RSS data
  4. -------------------
  5. begin : Saturday 15 February 2003
  6. copyright : (C) 2003 by Ian Reinhart Geiser
  7. email : geiseri@kde.org
  8. ***************************************************************************/
  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 <tdeapplication.h>
  19. #include <tdeconfig.h>
  20. #include "service.h"
  21. #include "cache.h"
  22. RSSService::RSSService() :
  23. DCOPObject("RSSService")
  24. {
  25. m_list.setAutoDelete( true );
  26. loadLinks();
  27. }
  28. RSSService::~RSSService()
  29. {
  30. }
  31. TQStringList RSSService::list()
  32. {
  33. TQStringList lst;
  34. TQDictIterator<RSSDocument> itr(m_list);
  35. for(; itr.current(); ++itr)
  36. lst.append(itr.currentKey());
  37. return lst;
  38. }
  39. DCOPRef RSSService::add(TQString id)
  40. {
  41. if(m_list.find(id) == 0L) { // add a new one only if we need to
  42. m_list.insert(id, new RSSDocument(id));
  43. added(id);
  44. saveLinks();
  45. }
  46. return document(id);
  47. }
  48. void RSSService::remove(TQString id)
  49. {
  50. m_list.remove(id);
  51. removed(id);
  52. saveLinks();
  53. }
  54. DCOPRef RSSService::document(TQString id)
  55. {
  56. if( m_list[id] )
  57. return DCOPRef(m_list[id]);
  58. else
  59. return DCOPRef();
  60. }
  61. void RSSService::exit()
  62. {
  63. //Save all current RSS links.
  64. saveLinks();
  65. Cache::self().save();
  66. kapp->quit();
  67. }
  68. void RSSService::loadLinks()
  69. {
  70. TDEConfig *conf = kapp->config();
  71. conf->setGroup("RSS Links");
  72. const TQStringList links = conf->readListEntry ("links");
  73. TQStringList::ConstIterator it = links.begin();
  74. TQStringList::ConstIterator end = links.end();
  75. for ( ; it != end; ++it )
  76. add( *it );
  77. }
  78. void RSSService::saveLinks()
  79. {
  80. TDEConfig *conf = kapp->config();
  81. conf->setGroup("RSS Links");
  82. TQStringList lst;
  83. TQDictIterator<RSSDocument> itr(m_list);
  84. for(; itr.current(); ++itr)
  85. lst.append(itr.currentKey());
  86. conf->writeEntry("links", lst);
  87. conf->sync();
  88. }