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.

214 lines
5.3KB

  1. /*
  2. This file is part of Akregator.
  3. Copyright (C) 2004 Sashmit Bhaduri <smt@vfemail.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 <tqregexp.h>
  20. #include <tqstylesheet.h>
  21. #include <kactioncollection.h>
  22. #include <kdebug.h>
  23. #include <klocale.h>
  24. #include <kparts/browserextension.h>
  25. #include <kparts/part.h>
  26. #include <libtdepim/progressmanager.h>
  27. #include "frame.h"
  28. namespace Akregator {
  29. Frame::Frame(TQObject * parent, KParts::ReadOnlyPart *p, TQWidget *visWidget, const TQString& tit, bool watchSignals)
  30. :TQObject(parent, "aKregatorFrame")
  31. {
  32. m_autoDeletePart = false;
  33. m_part=p;
  34. m_widget=visWidget;
  35. m_title=tit;
  36. m_state=Idle;
  37. m_progress=-1;
  38. m_progressItem=0;
  39. if (watchSignals) // e.g, articles tab has no part
  40. {
  41. connect(m_part, TQT_SIGNAL(setWindowCaption (const TQString &)), this, TQT_SLOT(setCaption (const TQString &)));
  42. connect(m_part, TQT_SIGNAL(seStatusBarText (const TQString &)), this, TQT_SLOT(seStatusText (const TQString &)));
  43. KParts::BrowserExtension *ext=KParts::BrowserExtension::childObject( p );
  44. if (ext)
  45. connect( ext, TQT_SIGNAL(loadingProgress(int)), this, TQT_SLOT(setProgress(int)) );
  46. connect(p, TQT_SIGNAL(started(KIO::Job*)), this, TQT_SLOT(setStarted()));
  47. connect(p, TQT_SIGNAL(completed()), this, TQT_SLOT(setCompleted()));
  48. connect(p, TQT_SIGNAL(canceled(const TQString &)), this, TQT_SLOT(setCanceled(const TQString&)));
  49. connect(p, TQT_SIGNAL(completed(bool)), this, TQT_SLOT(setCompleted()));
  50. /* KActionCollection *coll=p->actionCollection();
  51. if (coll)
  52. {
  53. connect( coll, TQT_SIGNAL( actionStatusText( const TQString & ) ),
  54. this, TQT_SLOT( slotActionStatusText( const TQString & ) ) );
  55. connect( coll, TQT_SIGNAL( clearStatusText() ),
  56. this, TQT_SLOT( slotClearStatusText() ) );
  57. }
  58. */
  59. }
  60. }
  61. void Frame::setAutoDeletePart(bool autoDelete)
  62. {
  63. m_autoDeletePart = autoDelete;
  64. }
  65. Frame::~Frame()
  66. {
  67. if(m_progressItem)
  68. {
  69. m_progressItem->setComplete();
  70. }
  71. if (m_autoDeletePart)
  72. m_part->deleteLater();
  73. }
  74. int Frame::state() const
  75. {
  76. return m_state;
  77. }
  78. KParts::ReadOnlyPart *Frame::part() const
  79. {
  80. return m_part;
  81. }
  82. TQWidget *Frame::widget() const
  83. {
  84. return m_widget;
  85. }
  86. void Frame::setTitle(const TQString &s)
  87. {
  88. if (m_title != s)
  89. {
  90. m_title = s;
  91. emit titleChanged(this, s);
  92. }
  93. }
  94. void Frame::setCaption(const TQString &s)
  95. {
  96. if(m_progressItem) m_progressItem->setLabel(s);
  97. m_caption=s;
  98. emit captionChanged(s);
  99. }
  100. void Frame::seStatusText(const TQString &s)
  101. {
  102. m_statusText=s;
  103. m_statusText.replace(TQRegExp("<[^>]*>"), "");
  104. emit statusText(m_statusText);
  105. }
  106. void Frame::setProgress(int a)
  107. {
  108. if(m_progressItem) {
  109. m_progressItem->setProgress((int)a);
  110. }
  111. m_progress=a;
  112. emit loadingProgress(a);
  113. }
  114. void Frame::setState(int a)
  115. {
  116. m_state=a;
  117. switch (m_state)
  118. {
  119. case Frame::Started:
  120. emit started();
  121. break;
  122. case Frame::Canceled:
  123. emit canceled(TQString());
  124. break;
  125. case Frame::Idle:
  126. case Frame::Completed:
  127. default:
  128. emit completed();
  129. }}
  130. const TQString& Frame::title() const
  131. {
  132. return m_title;
  133. }
  134. const TQString& Frame::caption() const
  135. {
  136. return m_caption;
  137. }
  138. const TQString& Frame::statusText() const
  139. {
  140. return m_statusText;
  141. }
  142. void Frame::setStarted()
  143. {
  144. if(m_progressId.isNull() || m_progressId.isEmpty()) m_progressId = KPIM::ProgressManager::getUniqueID();
  145. m_progressItem = KPIM::ProgressManager::createProgressItem(m_progressId, TQStyleSheet::escape( title() ), TQString(), false);
  146. m_progressItem->setqStatus(i18n("Loading..."));
  147. //connect(m_progressItem, TQT_SIGNAL(progressItemCanceled(KPIM::ProgressItem*)), TQT_SLOT(slotAbortFetch()));
  148. m_state=Started;
  149. emit started();
  150. }
  151. void Frame::setCanceled(const TQString &s)
  152. {
  153. if(m_progressItem) {
  154. m_progressItem->setqStatus(i18n("Loading canceled"));
  155. m_progressItem->setComplete();
  156. m_progressItem = 0;
  157. }
  158. m_state=Canceled;
  159. emit canceled(s);
  160. }
  161. void Frame::setCompleted()
  162. {
  163. if(m_progressItem) {
  164. m_progressItem->setqStatus(i18n("Loading completed"));
  165. m_progressItem->setComplete();
  166. m_progressItem = 0;
  167. }
  168. m_state=Completed;
  169. emit completed();
  170. }
  171. int Frame::progress() const
  172. {
  173. return m_progress;
  174. }
  175. } // namespace Akregator
  176. #include "frame.moc"