akregator/src

frame.cpp

00001 /*
00002     This file is part of Akregator.
00003 
00004     Copyright (C) 2004 Sashmit Bhaduri <smt@vfemail.net>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include <qregexp.h>
00026 #include <qstylesheet.h>
00027 
00028 #include <kactioncollection.h>
00029 #include <kdebug.h>
00030 #include <klocale.h>
00031 #include <kparts/browserextension.h>
00032 #include <kparts/part.h>
00033 
00034 #include <libkdepim/progressmanager.h>
00035 
00036 #include "frame.h"
00037 
00038 namespace Akregator {
00039 
00040 Frame::Frame(QObject * parent, KParts::ReadOnlyPart *p, QWidget *visWidget, const QString& tit, bool watchSignals)
00041    :QObject(parent, "aKregatorFrame")
00042 {
00043     m_autoDeletePart = false;
00044     m_part=p;
00045     m_widget=visWidget;
00046     m_title=tit;
00047     m_state=Idle;
00048     m_progress=-1;
00049     m_progressItem=0;
00050 
00051     if (watchSignals) // e.g, articles tab has no part
00052     {
00053         connect(m_part, SIGNAL(setWindowCaption (const QString &)), this, SLOT(setCaption (const QString &)));
00054         connect(m_part, SIGNAL(setStatusBarText (const QString &)), this, SLOT(setStatusText (const QString &)));
00055 
00056         KParts::BrowserExtension *ext=KParts::BrowserExtension::childObject( p );
00057         if (ext)
00058             connect( ext, SIGNAL(loadingProgress(int)), this, SLOT(setProgress(int)) );
00059 
00060         connect(p, SIGNAL(started(KIO::Job*)), this, SLOT(setStarted()));
00061         connect(p, SIGNAL(completed()), this, SLOT(setCompleted()));
00062         connect(p, SIGNAL(canceled(const QString &)), this, SLOT(setCanceled(const QString&)));
00063         connect(p, SIGNAL(completed(bool)), this, SLOT(setCompleted()));
00064 
00065 /*        KActionCollection *coll=p->actionCollection();
00066         if (coll)
00067         {
00068             connect( coll, SIGNAL( actionStatusText( const QString & ) ),
00069              this, SLOT( slotActionStatusText( const QString & ) ) );
00070             connect( coll, SIGNAL( clearStatusText() ),
00071              this, SLOT( slotClearStatusText() ) );
00072         }
00073 */
00074     }
00075 }
00076 
00077 void Frame::setAutoDeletePart(bool autoDelete)
00078 {
00079     m_autoDeletePart = autoDelete;
00080 }
00081 
00082 Frame::~Frame()
00083 {
00084     if(m_progressItem) 
00085     {
00086         m_progressItem->setComplete();
00087     }
00088     if (m_autoDeletePart)
00089         m_part->deleteLater();
00090 }
00091 
00092 int Frame::state() const
00093 {
00094     return m_state;
00095 }
00096 
00097 KParts::ReadOnlyPart *Frame::part() const
00098 {
00099     return m_part;
00100 }
00101 
00102 QWidget *Frame::widget() const
00103 {
00104     return m_widget;
00105 }
00106 
00107 void Frame::setTitle(const QString &s)
00108 {
00109     if (m_title != s)
00110     {
00111         m_title = s;
00112         emit titleChanged(this, s);
00113     }
00114 }
00115 
00116 void Frame::setCaption(const QString &s)
00117 {
00118     if(m_progressItem) m_progressItem->setLabel(s);
00119     m_caption=s;
00120     emit captionChanged(s);
00121 }
00122 
00123 void Frame::setStatusText(const QString &s)
00124 {
00125     m_statusText=s;
00126     m_statusText.replace(QRegExp("<[^>]*>"), "");
00127     emit statusText(m_statusText);
00128 }
00129 
00130 void Frame::setProgress(int a)
00131 {
00132     if(m_progressItem) {
00133         m_progressItem->setProgress((int)a);
00134     }
00135     m_progress=a;
00136     emit loadingProgress(a);
00137 }
00138 
00139 void Frame::setState(int a)
00140 {
00141     m_state=a;
00142     
00143     switch (m_state)
00144     {
00145         case Frame::Started:
00146             emit started();
00147             break;
00148         case Frame::Canceled:
00149             emit canceled(QString::null);
00150             break;
00151         case Frame::Idle:
00152         case Frame::Completed:
00153         default:
00154             emit completed();
00155     }}
00156 
00157 
00158 
00159 const QString& Frame::title() const
00160 {
00161     return m_title;
00162 }
00163 
00164 const QString& Frame::caption() const
00165 {
00166     return m_caption;
00167 }
00168 
00169 const QString& Frame::statusText() const
00170 {
00171     return m_statusText;
00172 }
00173 
00174 void Frame::setStarted()
00175 {
00176     if(m_progressId.isNull() || m_progressId.isEmpty()) m_progressId = KPIM::ProgressManager::getUniqueID();
00177     m_progressItem = KPIM::ProgressManager::createProgressItem(m_progressId, QStyleSheet::escape( title() ), QString::null, false);
00178     m_progressItem->setStatus(i18n("Loading..."));
00179     //connect(m_progressItem, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)), SLOT(slotAbortFetch()));
00180     m_state=Started;
00181     emit started();
00182 }
00183 
00184 void Frame::setCanceled(const QString &s)
00185 {
00186     if(m_progressItem) {
00187         m_progressItem->setStatus(i18n("Loading canceled"));
00188         m_progressItem->setComplete();
00189         m_progressItem = 0;
00190     }
00191     m_state=Canceled;
00192     emit canceled(s);
00193 }
00194 
00195 void Frame::setCompleted()
00196 {
00197     if(m_progressItem) {
00198         m_progressItem->setStatus(i18n("Loading completed"));
00199         m_progressItem->setComplete();
00200         m_progressItem = 0;
00201     }
00202     m_state=Completed;
00203     emit completed();
00204 }
00205 
00206 int Frame::progress() const
00207 {
00208     return m_progress;
00209 }
00210 
00211 } // namespace Akregator
00212 
00213 #include "frame.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys