summaryrefslogtreecommitdiffstats
path: root/knewsticker/kntsrcfilepropsdlg/kntsrcfilepropsdlg.cpp
blob: 14ca80d0a84719f7c32c414099a73afb81748100 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * kntsrcfilepropsdlg.cpp
 *
 * Copyright (c) 2001, 2002, 2003 Frerich Raabe <raabe@kde.org>
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. For licensing and distribution details, check the
 * accompanying file 'COPYING'.
 */
#include "kntsrcfilepropsdlg.h"
#include "kntsrcfilepropsdlgwidget.h"
#include "xmlnewsaccess.h"
#include "newsiconmgr.h"

#include <article.h>
#include <document.h>
#include <loader.h>

#include <kapplication.h>
#include <klistbox.h>
#include <klocale.h>
#include <kurl.h>
#include <kurllabel.h>
#include <kstandarddirs.h>
#include <kglobal.h>

#include <tqmultilineedit.h>
#include <tqvbox.h>

using namespace RSS;

class ArticleListBoxItem : public QListBoxText
{
	public:
		ArticleListBoxItem( TQListBox *listbox, const Article &article );

		const Article &article() const { return m_article; }

	private:
		Article m_article;
};

ArticleListBoxItem::ArticleListBoxItem( TQListBox *listbox, const Article &article )
	: TQListBoxText( listbox ),
	m_article( article )
{
	setText( article.title() );
}

KntSrcFilePropsDlg::KntSrcFilePropsDlg(KPropertiesDialog *props)
	: KPropsDlgPlugin(props)
{
	m_child = new KntSrcFilePropsDlgWidget(properties->addVBoxPage(i18n("News Resource")));
	connect(m_child->urlName, TQT_SIGNAL(leftClickedURL(const TQString &)),
	        TQT_SLOT(slotOpenURL(const TQString &)));
	connect(m_child->lbArticles, TQT_SIGNAL(executed(TQListBoxItem *)),
	        TQT_SLOT(slotClickedArticle(TQListBoxItem *)));

	Loader *loader = Loader::create();
	connect(loader, TQT_SIGNAL(loadingComplete(Loader *, Document, Status)),
	        TQT_SLOT(slotConstructUI(Loader *, Document, Status)));
	loader->loadFrom(props->item()->url(), new FileRetriever);

	connect(NewsIconMgr::self(), TQT_SIGNAL(gotIcon(const KURL &, const TQPixmap &)),
	        TQT_SLOT(slotGotIcon(const KURL &, const TQPixmap &)));

	m_child->show();
}

void KntSrcFilePropsDlg::slotConstructUI(Loader *, Document doc, Status status)
{
	if (status != RSS::Success)
		return;

	KURL iconURL = doc.link();
	iconURL.setEncodedPathAndQuery(TQString::fromLatin1("/favicon.ico"));
	NewsIconMgr::self()->getIcon(iconURL);

	m_child->urlName->setText(doc.title());
	m_child->urlName->setURL(doc.link().url());

	m_child->mleDescription->setText(doc.description());

	Article::List::ConstIterator it = doc.articles().begin();
	Article::List::ConstIterator end = doc.articles().end();
	for (; it != end; ++it)
		new ArticleListBoxItem(m_child->lbArticles, *it);
}

void KntSrcFilePropsDlg::slotOpenURL(const TQString &url)
{
	kapp->invokeBrowser(url);
}

void KntSrcFilePropsDlg::slotGotIcon(const KURL &, const TQPixmap &pixmap)
{
	m_child->pixmapIcon->setPixmap(pixmap);
}

void KntSrcFilePropsDlg::slotClickedArticle(TQListBoxItem *item)
{
	ArticleListBoxItem *articleItem = static_cast<ArticleListBoxItem *>(item);
	slotOpenURL(articleItem->article().link().url());
}

TQObject *KntSrcFilePropsFactory::createObject(TQObject *parent, const char *,
		const char *classname, const TQStringList &)
{
	if (TQString::fromLatin1(classname) == "KPropsDlgPlugin")
	{
		if (!parent->inherits("KPropertiesDialog"))
			return 0L;

		TQObject *obj = new KntSrcFilePropsDlg(static_cast<KPropertiesDialog *>(parent));
		return obj;
	}
	return 0L;
}

extern "C"
{
	KDE_EXPORT void *init_libkntsrcfilepropsdlg()
	{
        KGlobal::locale()->insertCatalogue( "knewsticker" );
		return new KntSrcFilePropsFactory();
	}
}

#include "kntsrcfilepropsdlg.moc"