bool MythNews::keyPressEvent(QKeyEvent *event) { if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event)) return true; bool handled = false; QStringList actions; handled = GetMythMainWindow()->TranslateKeyPress("News", event, actions); for (int i = 0; i < actions.size() && !handled; i++) { QString action = actions[i]; handled = true; if (action == "RETRIEVENEWS") slotRetrieveNews(); else if (action == "CANCEL") cancelRetrieve(); else if (action == "MENU") ShowMenu(); else if (action == "EDIT") ShowEditDialog(true); else if (action == "DELETE") deleteNewsSite(); else handled = false; } if (!handled && MythScreenType::keyPressEvent(event)) handled = true; return handled; }
bool MythNews::keyPressEvent(QKeyEvent *event) { if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event)) return true; bool handled = false; QStringList actions; handled = GetMythMainWindow()->TranslateKeyPress("News", event, actions); for (int i = 0; i < actions.size() && !handled; i++) { QString action = actions[i]; handled = true; if (action == "RETRIEVENEWS") slotRetrieveNews(); else if (action == "CANCEL") cancelRetrieve(); else if (action == "MENU") ShowMenu(); else if (action == "EDIT") ShowEditDialog(true); else if (action == "DELETE") deleteNewsSite(); else if (action == "ESCAPE") { { QMutexLocker locker(&m_lock); if (m_progressPopup) { m_progressPopup->Close(); m_progressPopup = NULL; } m_RetrieveTimer->stop(); if (m_httpGrabber) m_abortHttp = true; } Close(); } else handled = false; } if (!handled && MythScreenType::keyPressEvent(event)) handled = true; return handled; }
void MythNews::loadSites(void) { QMutexLocker locker(&m_lock); clearSites(); MSqlQuery query(MSqlQuery::InitCon()); query.prepare( "SELECT name, url, ico, updated, podcast " "FROM newssites " "ORDER BY name"); if (!query.exec()) { MythDB::DBError(LOC_ERR + "Could not load sites from DB", query); return; } while (query.next()) { QString name = query.value(0).toString(); QString url = query.value(1).toString(); QString icon = query.value(2).toString(); QDateTime time = MythDate::fromTime_t(query.value(3).toUInt()); bool podcast = query.value(4).toInt(); m_NewsSites.push_back(new NewsSite(name, url, time, podcast)); } NewsSite::List::iterator it = m_NewsSites.begin(); for (; it != m_NewsSites.end(); ++it) { MythUIButtonListItem *item = new MythUIButtonListItem(m_sitesList, (*it)->name()); item->SetData(qVariantFromValue(*it)); connect(*it, SIGNAL(finished(NewsSite*)), this, SLOT(slotNewsRetrieved(NewsSite*))); } slotRetrieveNews(); if (m_nositesText) { if (m_NewsSites.size() == 0) m_nositesText->Show(); else m_nositesText->Hide(); } }
/** \brief Creates a new MythNews Screen * \param parent Pointer to the screen stack * \param name The name of the window */ MythNews::MythNews(MythScreenStack *parent, const QString &name) : MythScreenType(parent, name), m_lock(QMutex::Recursive), m_RetrieveTimer(new QTimer(this)), m_TimerTimeout(10*60*1000), m_UpdateFreq(gCoreContext->GetNumSetting("NewsUpdateFrequency", 30)), m_zoom(gCoreContext->GetSetting("WebBrowserZoomLevel", "1.0")), m_browser(gCoreContext->GetSetting("WebBrowserCommand", "")), m_menuPopup(NULL), m_progressPopup(NULL), m_httpGrabber(NULL), m_abortHttp(false), m_sitesList(NULL), m_articlesList(NULL), m_nositesText(NULL), m_updatedText(NULL), m_titleText(NULL), m_descText(NULL), m_thumbnailImage(NULL), m_downloadImage(NULL), m_enclosureImage(NULL), m_podcastImage(NULL) { // Setup cache directory QString fileprefix = GetConfDir(); QDir dir(fileprefix); if (!dir.exists()) dir.mkdir(fileprefix); fileprefix += "/MythNews"; dir = QDir(fileprefix); if (!dir.exists()) dir.mkdir(fileprefix); connect(m_RetrieveTimer, SIGNAL(timeout()), this, SLOT(slotRetrieveNews())); m_RetrieveTimer->stop(); m_RetrieveTimer->setSingleShot(false); m_RetrieveTimer->start(m_TimerTimeout); }