akregator/src

addfeeddialog.cpp
1 /*
2  This file is part of Akregator.
3 
4  Copyright (C) 2004 Stanislav Karchebny <Stanislav.Karchebny@kdemail.net>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 #include "feed.h"
26 #include "addfeeddialog.h"
27 
28 #include <tqcheckbox.h>
29 
30 #include <tdeapplication.h>
31 #include <kurl.h>
32 #include <tdelocale.h>
33 #include <klineedit.h>
34 #include <kiconloader.h>
35 #include <kicontheme.h>
36 #include <kdebug.h>
37 #include <ksqueezedtextlabel.h>
38 #include <tdemessagebox.h>
39 
40 namespace Akregator {
41 
42 AddFeedWidget::AddFeedWidget(TQWidget *parent, const char *name)
43  : AddFeedWidgetBase(parent, name)
44 {
45  pixmapLabel1->setPixmap(kapp->iconLoader()->loadIcon( "applications-internet",TDEIcon::Desktop,TDEIcon::SizeHuge, TDEIcon::DefaultState, 0, true));
46  statusLabel->setText(TQString());
47 }
48 
49 AddFeedWidget::~AddFeedWidget()
50 {}
51 
52 AddFeedDialog::AddFeedDialog(TQWidget *parent, const char *name)
53  : KDialogBase(KDialogBase::Swallow, TQt::WStyle_DialogBorder, parent, name, true, i18n("Add Feed"), KDialogBase::Ok|KDialogBase::Cancel)
54 {
55  widget = new AddFeedWidget(this);
56  connect(widget->urlEdit, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(textChanged(const TQString&)));
57  enableButtonOK(false);
58  setMainWidget(widget);
59 }
60 
61 AddFeedDialog::~AddFeedDialog()
62 {}
63 
64 void AddFeedDialog::setURL(const TQString& t)
65 {
66  widget->urlEdit->setText(t);
67 }
68 
69 void AddFeedDialog::slotOk( )
70 {
71  enableButtonOK(false);
72  feedURL = widget->urlEdit->text().stripWhiteSpace();
73 
74  Feed *f=new Feed();
75 
76  feed=f;
77 
78  // HACK: make weird wordpress links ("feed:http://foobar/rss") work
79  if (feedURL.startsWith("feed:"))
80  feedURL = feedURL.right( feedURL.length() - 5 );
81 
82  if (feedURL.find(":/") == -1)
83  feedURL.prepend("http://");
84  f->setXmlUrl(feedURL);
85 
86  widget->statusLabel->setText( i18n("Downloading %1").arg(feedURL) );
87 
88  connect( feed, TQ_SIGNAL(fetched(Feed* )),
89  this, TQ_SLOT(fetchCompleted(Feed *)) );
90  connect( feed, TQ_SIGNAL(fetchError(Feed* )),
91  this, TQ_SLOT(fetchError(Feed *)) );
92  connect( feed, TQ_SIGNAL(fetchDiscovery(Feed* )),
93  this, TQ_SLOT(fetchDiscovery(Feed *)) );
94 
95  f->fetch(true);
96 }
97 
98 void AddFeedDialog::fetchCompleted(Feed */*f*/)
99 {
100  KDialogBase::slotOk();
101 }
102 
103 void AddFeedDialog::fetchError(Feed *)
104 {
105  KMessageBox::error(this, i18n("Feed not found from %1.").arg(feedURL));
106  KDialogBase::slotCancel();
107 }
108 
109 void AddFeedDialog::fetchDiscovery(Feed *f)
110 {
111  widget->statusLabel->setText( i18n("Feed found, downloading...") );
112  feedURL=f->xmlUrl();
113 }
114 
115 void AddFeedDialog::textChanged(const TQString& text)
116 {
117  enableButtonOK(!text.isEmpty());
118 }
119 
120 } // namespace Akregator
121 
122 #include "addfeeddialog.moc"