TDE personal information management 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.

210 lines
5.6KB

  1. /*
  2. This file is part of Akregator.
  3. Copyright (C) 2005 Frank Osterfeld <frank.osterfeld at kdemail.net>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  15. As a special exception, permission is given to link this program
  16. with any edition of TQt, and distribute the resulting executable,
  17. without including the source code for TQt in the source distribution.
  18. */
  19. #include <tqmap.h>
  20. #include <tqstylesheet.h>
  21. #include <klocale.h>
  22. #include <kstaticdeleter.h>
  23. #include <libtdepim/progressmanager.h>
  24. #include "feedlist.h"
  25. #include "feed.h"
  26. #include "treenode.h"
  27. #include "progressmanager.h"
  28. //#include <kdebug.h>
  29. namespace Akregator {
  30. class ProgressManager::ProgressManagerPrivate
  31. {
  32. public:
  33. FeedList* feedList;
  34. TQMap<Feed*, ProgressItemHandler*> handlers;
  35. };
  36. static KStaticDeleter<ProgressManager> progressmanagersd;
  37. ProgressManager* ProgressManager::m_self = 0;
  38. ProgressManager* ProgressManager::self()
  39. {
  40. if (!m_self)
  41. m_self = progressmanagersd.setObject(m_self, new ProgressManager);
  42. return m_self;
  43. }
  44. ProgressManager::ProgressManager() : d(new ProgressManagerPrivate)
  45. {
  46. d->feedList = 0;
  47. }
  48. ProgressManager::~ProgressManager()
  49. {
  50. delete d;
  51. d = 0;
  52. }
  53. void ProgressManager::setFeedList(FeedList* feedList)
  54. {
  55. if (feedList == d->feedList)
  56. return;
  57. if (d->feedList != 0)
  58. {
  59. for (TQMap<Feed*, ProgressItemHandler*>::ConstIterator it = d->handlers.begin(); it != d->handlers.end(); ++it)
  60. delete *it;
  61. d->handlers.clear();
  62. disconnect(d->feedList, TQT_SIGNAL(signalNodeAdded(TreeNode*)), this, TQT_SLOT(slotNodeAdded(TreeNode*)));
  63. disconnect(d->feedList, TQT_SIGNAL(signalNodeRemoved(TreeNode*)), this, TQT_SLOT(slotNodeRemoved(TreeNode*)));
  64. }
  65. d->feedList = feedList;
  66. if (feedList != 0)
  67. {
  68. TQValueList<TreeNode*> list = feedList->asFlatList();
  69. for (TQValueList<TreeNode*>::ConstIterator it = list.begin(); it != list.end(); ++it)
  70. slotNodeAdded(*it);
  71. connect(feedList, TQT_SIGNAL(signalNodeAdded(TreeNode*)), this, TQT_SLOT(slotNodeAdded(TreeNode*)));
  72. connect(feedList, TQT_SIGNAL(signalNodeRemoved(TreeNode*)), this, TQT_SLOT(slotNodeRemoved(TreeNode*)));
  73. }
  74. }
  75. void ProgressManager::slotNodeAdded(TreeNode* node)
  76. {
  77. Feed* feed = dynamic_cast<Feed*>(node);
  78. if (feed)
  79. {
  80. if (!d->handlers.contains(feed))
  81. d->handlers[feed] = new ProgressItemHandler(feed);
  82. connect(feed, TQT_SIGNAL(signalDestroyed(TreeNode*)), this, TQT_SLOT(slotNodeDestroyed(TreeNode*)));
  83. }
  84. }
  85. void ProgressManager::slotNodeRemoved(TreeNode* node)
  86. {
  87. Feed* feed = dynamic_cast<Feed*>(node);
  88. if (feed)
  89. {
  90. disconnect(feed, TQT_SIGNAL(signalDestroyed(TreeNode*)), this, TQT_SLOT(slotNodeDestroyed(TreeNode*)));
  91. delete d->handlers[feed];
  92. d->handlers.remove(feed);
  93. }
  94. }
  95. void ProgressManager::slotNodeDestroyed(TreeNode* node)
  96. {
  97. Feed* feed = dynamic_cast<Feed*>(node);
  98. if (feed)
  99. {
  100. delete d->handlers[feed];
  101. d->handlers.remove(feed);
  102. }
  103. }
  104. class ProgressItemHandler::ProgressItemHandlerPrivate
  105. {
  106. public:
  107. Feed* feed;
  108. KPIM::ProgressItem* progressItem;
  109. };
  110. ProgressItemHandler::ProgressItemHandler(Feed* feed) : d(new ProgressItemHandlerPrivate)
  111. {
  112. d->feed = feed;
  113. d->progressItem = 0;
  114. connect(feed, TQT_SIGNAL(fetchStarted(Feed*)), this, TQT_SLOT(slotFetchStarted()));
  115. connect(feed, TQT_SIGNAL(fetched(Feed*)), this, TQT_SLOT(slotFetchCompleted()));
  116. connect(feed, TQT_SIGNAL(fetchError(Feed*)), this, TQT_SLOT(slotFetchError()));
  117. connect(feed, TQT_SIGNAL(fetchAborted(Feed*)), this, TQT_SLOT(slotFetchAborted()));
  118. }
  119. ProgressItemHandler::~ProgressItemHandler()
  120. {
  121. if (d->progressItem)
  122. {
  123. d->progressItem->setComplete();
  124. d->progressItem = 0;
  125. }
  126. delete d;
  127. d = 0;
  128. }
  129. void ProgressItemHandler::slotFetchStarted()
  130. {
  131. if (d->progressItem)
  132. {
  133. d->progressItem->setComplete();
  134. d->progressItem = 0;
  135. }
  136. d->progressItem = KPIM::ProgressManager::createProgressItem(KPIM::ProgressManager::getUniqueID(), TQStyleSheet::escape( d->feed->title() ), TQString(), true);
  137. connect(d->progressItem, TQT_SIGNAL(progressItemCanceled(KPIM::ProgressItem*)), d->feed, TQT_SLOT(slotAbortFetch()));
  138. }
  139. void ProgressItemHandler::slotFetchCompleted()
  140. {
  141. if (d->progressItem)
  142. {
  143. d->progressItem->setqStatus(i18n("Fetch completed"));
  144. d->progressItem->setComplete();
  145. d->progressItem = 0;
  146. }
  147. }
  148. void ProgressItemHandler::slotFetchError()
  149. {
  150. if (d->progressItem)
  151. {
  152. d->progressItem->setqStatus(i18n("Fetch error"));
  153. d->progressItem->setComplete();
  154. d->progressItem = 0;
  155. }
  156. }
  157. void ProgressItemHandler::slotFetchAborted()
  158. {
  159. if (d->progressItem)
  160. {
  161. d->progressItem->setqStatus(i18n("Fetch aborted"));
  162. d->progressItem->setComplete();
  163. d->progressItem = 0;
  164. }
  165. }
  166. } // namespace Akregator
  167. #include "progressmanager.moc"