bool DBUpdateThreadWorker::AddItem (const Item_ptr& item, const Channel_ptr& channel, const Feed::FeedSettings& settings) { if (item->PubDate_.isValid ()) { if (item->PubDate_.daysTo (QDateTime::currentDateTime ()) >= settings.ItemAge_) return false; } else item->FixDate (); item->ChannelID_ = channel->ChannelID_; SB_->AddItem (item); emit hookGotNewItems (std::make_shared<Util::DefaultHookProxy> (), { item }); const auto iem = Proxy_->GetEntityManager (); if (settings.AutoDownloadEnclosures_) for (const auto& e : item->Enclosures_) { auto de = Util::MakeEntity (QUrl (e.URL_), XmlSettingsManager::Instance ()-> property ("EnclosuresDownloadPath").toString (), 0, e.Type_); de.Additional_ [" Tags"] = channel->Tags_; iem->HandleEntity (de); } return true; }
bool DBUpdateThreadWorker::AddItem (const Item_ptr& item, const Channel_ptr& channel, const QVariantMap& channelDataMap, const Feed::FeedSettings& settings) { if (item->PubDate_.isValid ()) { if (item->PubDate_.daysTo (QDateTime::currentDateTime ()) >= settings.ItemAge_) return false; } else item->FixDate (); item->ChannelID_ = channel->ChannelID_; SB_->AddItem (item); RegexpMatcherManager::Instance ().HandleItem (item); QVariantList itemData; itemData << GetItemMapItemPart (item).unite (channelDataMap); emit hookGotNewItems (Util::DefaultHookProxy_ptr (new Util::DefaultHookProxy), itemData); if (settings.AutoDownloadEnclosures_) for (const auto& e : item->Enclosures_) { auto de = Util::MakeEntity (QUrl (e.URL_), XmlSettingsManager::Instance ()-> property ("EnclosuresDownloadPath").toString (), 0, e.Type_); de.Additional_ [" Tags"] = channel->Tags_; emit gotEntity (de); } return true; }
bool Core::DoDelayedInit () { bool result = true; ShortcutMgr_ = new Util::ShortcutManager (Proxy_, this); QDir dir = QDir::home (); if (!dir.cd (".leechcraft/aggregator") && !dir.mkpath (".leechcraft/aggregator")) { qCritical () << Q_FUNC_INFO << "could not create necessary " "directories for Aggregator"; result = false; } ChannelsModel_ = new ChannelsModel (); if (!ReinitStorage ()) result = false; ChannelsFilterModel_ = new ChannelsFilterModel (); ChannelsFilterModel_->setSourceModel (ChannelsModel_); ChannelsFilterModel_->setFilterKeyColumn (0); JobHolderRepresentation_ = new JobHolderRepresentation (); DBUpThread_ = std::make_shared<DBUpdateThread> (Proxy_); DBUpThread_->start (QThread::LowestPriority); DBUpThread_->ScheduleImpl (&DBUpdateThreadWorker::WithWorker, [this] (DBUpdateThreadWorker *worker) { connect (worker, SIGNAL (gotNewChannel (ChannelShort)), this, SLOT (handleDBUpGotNewChannel (ChannelShort)), Qt::QueuedConnection); connect (worker, SIGNAL (hookGotNewItems (LeechCraft::IHookProxy_ptr, QList<Item_cptr>)), this, SIGNAL (hookGotNewItems (LeechCraft::IHookProxy_ptr, QList<Item_cptr>))); }); connect (&StorageBackendManager::Instance (), SIGNAL (channelDataUpdated (Channel_ptr)), this, SLOT (handleChannelDataUpdated (Channel_ptr)), Qt::QueuedConnection); ParserFactory::Instance ().Register (&RSS20Parser::Instance ()); ParserFactory::Instance ().Register (&Atom10Parser::Instance ()); ParserFactory::Instance ().Register (&RSS091Parser::Instance ()); ParserFactory::Instance ().Register (&Atom03Parser::Instance ()); ParserFactory::Instance ().Register (&RSS10Parser::Instance ()); ReprWidget_ = new ItemsWidget (); ReprWidget_->SetChannelsFilter (JobHolderRepresentation_); ReprWidget_->RegisterShortcuts (); ChannelsModel_->SetWidgets (ReprWidget_->GetToolBar (), ReprWidget_); JobHolderRepresentation_->setSourceModel (ChannelsModel_); CustomUpdateTimer_ = new QTimer (this); CustomUpdateTimer_->start (60 * 1000); connect (CustomUpdateTimer_, SIGNAL (timeout ()), this, SLOT (handleCustomUpdates ())); UpdateTimer_ = new QTimer (this); UpdateTimer_->setSingleShot (true); QDateTime currentDateTime = QDateTime::currentDateTime (); QDateTime lastUpdated = XmlSettingsManager::Instance ()-> Property ("LastUpdateDateTime", currentDateTime).toDateTime (); connect (UpdateTimer_, SIGNAL (timeout ()), this, SLOT (updateFeeds ())); int updateDiff = lastUpdated.secsTo (currentDateTime); int interval = XmlSettingsManager::Instance ()-> property ("UpdateInterval").toInt (); if (interval) { if ((XmlSettingsManager::Instance ()-> property ("UpdateOnStartup").toBool ()) || (updateDiff > interval * 60)) QTimer::singleShot (7000, this, SLOT (updateFeeds ())); else UpdateTimer_->start (updateDiff * 1000); } XmlSettingsManager::Instance ()-> RegisterObject ("UpdateInterval", this, "updateIntervalChanged"); Initialized_ = true; PluginManager_ = new PluginManager (); PluginManager_->RegisterHookable (this); PluginManager_->RegisterHookable (StorageBackend_.get ()); return result; }