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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8; -*-
/***************************************************************************
Copyright: nspanel.cpp
Marcus Camen <mcamen@mcamen.de>
***************************************************************************/
/*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <qlistview.h>
#include <qfontmetrics.h>
#include <qtimer.h>
#include <kdebug.h>
#include <klistbox.h>
#include "nspanel.h"
namespace KSB_News {
////////////////////////////////////////////////////////////////
// ListBox including ToolTip for item
////////////////////////////////////////////////////////////////
TTListBox::TTListBox(QWidget *parent, const char *name, WFlags f)
: KListBox(parent, name, f),
QToolTip(this) {
}
void TTListBox::clear() {
KListBox::clear();
}
void TTListBox::maybeTip(const QPoint &point) {
QListBoxItem *item = itemAt(point);
if (item) {
QString text = item->text();
if (!text.isEmpty()) {
// Show ToolTip only if necessary
QFontMetrics fm(fontMetrics());
int textWidth = fm.width(text);
int widgetSpace = visibleWidth();
if ((textWidth > widgetSpace) || (contentsX() > 0))
tip(itemRect(item), text);
}
}
}
NSPanel::NSPanel(QObject *parent, const char *name, const QString &key,
DCOPRef *rssservice)
:QObject(parent, name)
,DCOPObject(QString(QString("sidebar-newsticker-")+key).latin1())
,m_listbox()
,m_pixmap()
{
kdDebug(90140) << "NSPanel: CTOR " << key << " " << rssservice << endl;
m_rssservice = rssservice;
m_key = key;
m_rssdocument = m_rssservice->call("document(QString)", m_key);
m_isValid = false;
connectDCOPSignal("rssservice", m_rssdocument.obj(),
"documentUpdated(DCOPRef)",
"emitDocumentUpdated(DCOPRef)", false);
connectDCOPSignal("rssservice", m_rssdocument.obj(),
"documentUpdated(DCOPRef)",
"emitTitleUpdated(DCOPRef)", false);
connectDCOPSignal("rssservice", m_rssdocument.obj(),
"pixmapUpdated(DCOPRef)",
"emitPixmapUpdated(DCOPRef)", false);
// updating of RSS documents
m_timeoutinterval = 10 * 60 * 1000; // 10 mins
m_timer = new QTimer(this);
connect(m_timer, SIGNAL(timeout()), this, SLOT(refresh()));
m_timer->start(m_timeoutinterval);
refresh();
}
void NSPanel::refresh() {
m_rssdocument.call("refresh()");
}
NSPanel::~NSPanel() {
}
void NSPanel::setTitle(const QString &tit) {
m_title = tit;
}
void NSPanel::setListbox(TTListBox *lb) {
m_listbox = lb;
}
void NSPanel::setPixmap(const QPixmap &pm) {
m_pixmap = pm;
}
TTListBox *NSPanel::listbox() const {
return m_listbox;
}
QPixmap NSPanel::pixmap() {
return m_pixmap;
}
QString NSPanel::key() const {
return m_key;
}
QString NSPanel::title() const {
return m_title;
}
QStringList NSPanel::articles() {
return m_articles;
}
QStringList NSPanel::articleLinks() {
return m_articlelinks;
}
bool NSPanel::isValid() const {
return m_isValid;
}
void NSPanel::emitDocumentUpdated(DCOPRef /*dcopref*/) {
kdDebug(90140) << "NSPanel::emitDocumentUpdated" << endl;
m_articles.clear();
m_articlelinks.clear();
m_count = m_rssdocument.call("count()");
QString temp = m_rssdocument.call("title()");
m_title = temp;
m_isValid = true;
for (int idx = 0; idx < m_count; ++idx) {
DCOPRef rss_article = m_rssdocument.call("article(int)", idx);
m_articles.append(rss_article.call("title()"));
m_articlelinks.append(rss_article.call("link()"));
}
emit documentUpdated(this);
}
void NSPanel::emitPixmapUpdated(DCOPRef /*dcopref*/) {
if (m_rssdocument.call("pixmapValid()")) {
QPixmap tmp = m_rssdocument.call("pixmap()");
m_pixmap = tmp;
emit pixmapUpdated(this);
}
}
} // namespace KSB_News
#include "nspanel.moc"
|