Changeset 2982
- Timestamp:
- 04/28/06 08:51:49 (3 years ago)
- Files:
-
- hydranode/hngui/hometabs.cpp (modified) (2 diffs)
- hydranode/hngui/newsfeed.cpp (modified) (9 diffs)
- hydranode/hngui/newsfeed.h (modified) (3 diffs)
- hydranode/hngui/transfertabs.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
hydranode/hngui/hometabs.cpp
r2980 r2982 52 52 setActive("Overview"); 53 53 54 m_ui->devFeed->addFeed(55 "Hydranode Development News",56 QUrl("http://hydranode.com/blog/atom.xml"), 557 );58 m_ui->devFeed->setActive("Hydranode Development News");59 m_ui->devFeed->getUpdates();60 61 m_ui->newsFeed->addFeed(62 "Slashdot - Stuff that matters",63 QUrl("http://rss.slashdot.org/Slashdot/slashdot"), 1064 );65 m_ui->newsFeed->addFeed(66 "BBC World News",67 QUrl(68 "http://newsrss.bbc.co.uk/rss/"69 "newsonline_world_edition/front_page/rss.xml"70 ), 1071 );72 m_ui->newsFeed->addFeed(73 "CNN World News",74 QUrl("http://rss.cnn.com/rss/cnn_topstories.rss"), 1075 );76 m_ui->newsFeed->addFeed(77 "Tom's Hardware News",78 QUrl("http://www.pheedo.com/f/toms_hardware"), 1079 );80 m_ui->newsFeed->addFeed(81 "Slyck - File Sharing News",82 QUrl("http://slyck.com/slyckrss.xml"), 3083 );84 m_ui->newsFeed->getUpdates();85 86 QSettings conf(confDir() + "gui.ini", QSettings::IniFormat);87 if (conf.contains("ActiveFeed")) {88 m_ui->newsFeed->setActive(conf.value("ActiveFeed").toString());89 }90 91 54 // make text controls backgrounds 100% transparent to allow background 92 55 // to be displayed below it … … 127 90 SLOT(changePage()) 128 91 ); 92 93 m_ui->devFeed->addFeed( 94 "Hydranode Development News", 95 QUrl("http://hydranode.com/blog/atom.xml"), 5 96 ); 97 m_ui->devFeed->setActive("Hydranode Development News"); 98 99 m_ui->newsFeed->addFeed( 100 "Slashdot - Stuff that matters", 101 QUrl("http://rss.slashdot.org/Slashdot/slashdot"), 10 102 ); 103 m_ui->newsFeed->addFeed( 104 "BBC World News", 105 QUrl( 106 "http://newsrss.bbc.co.uk/rss/" 107 "newsonline_world_edition/front_page/rss.xml" 108 ), 10 109 ); 110 m_ui->newsFeed->addFeed( 111 "CNN World News", 112 QUrl("http://rss.cnn.com/rss/cnn_topstories.rss"), 10 113 ); 114 m_ui->newsFeed->addFeed( 115 "Tom's Hardware News", 116 QUrl("http://www.pheedo.com/f/toms_hardware"), 10 117 ); 118 m_ui->newsFeed->addFeed( 119 "Slyck - File Sharing News", 120 QUrl("http://slyck.com/slyckrss.xml"), 30 121 ); 122 m_ui->devFeed->init(); 123 m_ui->newsFeed->init(); 124 125 QSettings conf(confDir() + "gui.ini", QSettings::IniFormat); 126 if (conf.contains("ActiveFeed")) { 127 m_ui->newsFeed->setActive(conf.value("ActiveFeed").toString()); 128 } 129 129 130 m_actionBack = QPixmap(imgDir() + "actionback.png"); 130 131 m_actionBackOrig = m_actionBack; hydranode/hngui/newsfeed.cpp
r2914 r2982 18 18 19 19 #include "newsfeed.h" 20 #include "main.h" 20 21 #include <QHttp> 21 22 #include <QXmlDefaultHandler> … … 25 26 #include <QSettings> 26 27 #include <QTimer> 28 #include <QDir> 27 29 28 30 // RssReader class … … 187 189 188 190 NewsFeed::NewsFeed(QWidget *parent) : QTextBrowser(parent) { 191 m_timer = new QTimer(this); 192 189 193 connect( 190 194 this, SIGNAL(anchorClicked(const QUrl&)), 191 195 SLOT(linkClicked(const QUrl&)) 192 196 ); 193 QTimer *timer = new QTimer(this); 194 timer->start(1000 * 60 * 60); 195 connect(timer, SIGNAL(timeout()), SLOT(getUpdates())); 197 connect(m_timer, SIGNAL(timeout()), SLOT(getUpdates())); 198 } 199 200 void NewsFeed::init() { 201 QSettings conf(confDir() + "gui.ini", QSettings::IniFormat); 202 QDateTime lastUpdate = QDateTime::fromString( 203 conf.value(objectName() + "Updated", "").toString(), 204 Qt::ISODate 205 ); 206 logDebug("Last update was on " + lastUpdate.toString()); 207 QDateTime current = QDateTime::currentDateTime(); 208 int timeDiff = lastUpdate.secsTo(current); 209 logDebug(QString("Time diff since last update is %1").arg(timeDiff)); 210 if (timeDiff >= 60 * 60) { 211 timeDiff = 1; 212 } 213 m_timer->setSingleShot(true); 214 m_timer->start(1000 * timeDiff); 215 logDebug(QString("Next feeds update in %1 seconds").arg(timeDiff)); 196 216 } 197 217 … … 201 221 m_feeds[title] = QString(); 202 222 if (m_currentActive.isEmpty()) { 203 m_currentActive = title; 223 setActive(title); 224 } 225 226 QFile f(confDir() + "/feeds/" + title + ".xml"); 227 f.open(QIODevice::ReadOnly); 228 if (f.isOpen()) { 229 QString feed(f.readAll()); 230 m_feeds[title] = parseFeed(feed, limit); 204 231 } 205 232 } … … 209 236 while (it != m_urls.end()) { 210 237 QString title = it.key(); 238 logDebug("Getting updates for feed " + title); 211 239 QUrl url = it.value(); 212 240 if (m_links[title]) { … … 225 253 ++it; 226 254 } 255 QSettings conf(confDir() + "gui.ini", QSettings::IniFormat); 256 conf.setValue( 257 objectName() + "Updated", 258 QDateTime::currentDateTime().toString(Qt::ISODate) 259 ); 260 261 if (!m_timer->isActive()) { 262 logDebug("Next feeds update in one hour."); 263 m_timer->start(1000 * 60 * 60); 264 } 227 265 } 228 266 … … 254 292 feed.replace("", "\""); 255 293 feed.replace("", "\""); 256 QXmlSimpleReader reader; 257 RssReader handler(m_limits[m_reqs[code]]); 258 reader.setContentHandler(&handler); 259 QXmlInputSource source; 260 source.setData(feed); 261 reader.parse(&source); 262 m_feeds[m_reqs[code]] = handler.getOutput(); 294 295 m_feeds[m_reqs[code]] = parseFeed(feed, m_limits[m_reqs[code]]); 263 296 if (!m_feeds[m_reqs[code]].size()) { 264 297 m_feeds[m_reqs[code]] = feed; … … 269 302 } 270 303 304 // save cache 305 QDir d(confDir()); 306 if (!d.exists("feeds")) { 307 d.mkdir("feeds"); 308 } 309 QFile f(d.absolutePath() + "/feeds/" + m_reqs[code] + ".xml"); 310 f.open(QIODevice::WriteOnly); 311 if (f.isOpen()) { 312 f.write(feed.toAscii()); 313 } 314 315 // cleanup 271 316 m_links[m_reqs[code]]->deleteLater(); 272 317 m_links.remove(m_reqs[code]); … … 296 341 #endif 297 342 } 343 344 QString NewsFeed::parseFeed(const QString &feed, int limit) { 345 QXmlSimpleReader reader; 346 RssReader handler(limit); 347 reader.setContentHandler(&handler); 348 QXmlInputSource source; 349 source.setData(feed); 350 reader.parse(&source); 351 return handler.getOutput(); 352 } hydranode/hngui/newsfeed.h
r2864 r2982 35 35 public Q_SLOTS: 36 36 void getUpdates(); 37 void init(); 37 38 void setActive(QString title); 38 39 private Q_SLOTS: … … 41 42 void linkClicked(const QUrl &link); 42 43 private: 44 QString parseFeed(const QString &feed, int limit); 45 43 46 QMap<QString, QUrl> m_urls; 44 47 QMap<QString, int> m_limits; … … 47 50 QMap<QString, QString> m_feeds; 48 51 QString m_currentActive; 52 QTimer *m_timer; 49 53 }; 50 54 hydranode/hngui/transfertabs.cpp
r2968 r2982 615 615 void TransferPage::getMoreComments() { 616 616 if (!m_currentActive || !m_currentActive->getData()) { 617 logDebug("Next GetNames in 5 seconds");618 617 m_commentTimer->stop(); 619 618 m_commentTimer->start(5000);
