addfeeddialog.cpp
00001 /* 00002 This file is part of Akregator. 00003 00004 Copyright (C) 2004 Stanislav Karchebny <Stanislav.Karchebny@kdemail.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 TQt, and distribute the resulting executable, 00022 without including the source code for TQt in the source distribution. 00023 */ 00024 00025 #include "feed.h" 00026 #include "addfeeddialog.h" 00027 00028 #include <tqcheckbox.h> 00029 00030 #include <tdeapplication.h> 00031 #include <kurl.h> 00032 #include <tdelocale.h> 00033 #include <klineedit.h> 00034 #include <kiconloader.h> 00035 #include <kicontheme.h> 00036 #include <kdebug.h> 00037 #include <ksqueezedtextlabel.h> 00038 #include <tdemessagebox.h> 00039 00040 namespace Akregator { 00041 00042 AddFeedWidget::AddFeedWidget(TQWidget *parent, const char *name) 00043 : AddFeedWidgetBase(parent, name) 00044 { 00045 pixmapLabel1->setPixmap(kapp->iconLoader()->loadIcon( "applications-internet",TDEIcon::Desktop,TDEIcon::SizeHuge, TDEIcon::DefaultState, 0, true)); 00046 statusLabel->setText(TQString()); 00047 } 00048 00049 AddFeedWidget::~AddFeedWidget() 00050 {} 00051 00052 AddFeedDialog::AddFeedDialog(TQWidget *parent, const char *name) 00053 : KDialogBase(KDialogBase::Swallow, TQt::WStyle_DialogBorder, parent, name, true, i18n("Add Feed"), KDialogBase::Ok|KDialogBase::Cancel) 00054 { 00055 widget = new AddFeedWidget(this); 00056 connect(widget->urlEdit, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(textChanged(const TQString&))); 00057 enableButtonOK(false); 00058 setMainWidget(widget); 00059 } 00060 00061 AddFeedDialog::~AddFeedDialog() 00062 {} 00063 00064 void AddFeedDialog::setURL(const TQString& t) 00065 { 00066 widget->urlEdit->setText(t); 00067 } 00068 00069 void AddFeedDialog::slotOk( ) 00070 { 00071 enableButtonOK(false); 00072 feedURL = widget->urlEdit->text().stripWhiteSpace(); 00073 00074 Feed *f=new Feed(); 00075 00076 feed=f; 00077 00078 // HACK: make weird wordpress links ("feed:http://foobar/rss") work 00079 if (feedURL.startsWith("feed:")) 00080 feedURL = feedURL.right( feedURL.length() - 5 ); 00081 00082 if (feedURL.find(":/") == -1) 00083 feedURL.prepend("http://"); 00084 f->setXmlUrl(feedURL); 00085 00086 widget->statusLabel->setText( i18n("Downloading %1").arg(feedURL) ); 00087 00088 connect( feed, TQT_SIGNAL(fetched(Feed* )), 00089 this, TQT_SLOT(fetchCompleted(Feed *)) ); 00090 connect( feed, TQT_SIGNAL(fetchError(Feed* )), 00091 this, TQT_SLOT(fetchError(Feed *)) ); 00092 connect( feed, TQT_SIGNAL(fetchDiscovery(Feed* )), 00093 this, TQT_SLOT(fetchDiscovery(Feed *)) ); 00094 00095 f->fetch(true); 00096 } 00097 00098 void AddFeedDialog::fetchCompleted(Feed */*f*/) 00099 { 00100 KDialogBase::slotOk(); 00101 } 00102 00103 void AddFeedDialog::fetchError(Feed *) 00104 { 00105 KMessageBox::error(this, i18n("Feed not found from %1.").arg(feedURL)); 00106 KDialogBase::slotCancel(); 00107 } 00108 00109 void AddFeedDialog::fetchDiscovery(Feed *f) 00110 { 00111 widget->statusLabel->setText( i18n("Feed found, downloading...") ); 00112 feedURL=f->xmlUrl(); 00113 } 00114 00115 void AddFeedDialog::textChanged(const TQString& text) 00116 { 00117 enableButtonOK(!text.isEmpty()); 00118 } 00119 00120 } // namespace Akregator 00121 00122 #include "addfeeddialog.moc" 00123 // vim: ts=4 sw=4 et