Beispiel #1
0
	void TorrentFilesModel::HandleFileActivated (QModelIndex index) const
	{
		if (!index.isValid ())
			return;

		if (index.column () != ColumnPath)
			index = index.sibling (index.row (), ColumnPath);

		const auto item = static_cast<TorrentNodeInfo*> (index.internalPointer ());

		const auto iem = Core::Instance ()->GetProxy ()->GetEntityManager ();
		if (std::abs (item->Progress_ - 1) >= std::numeric_limits<decltype (item->Progress_)>::epsilon ())
			iem->HandleEntity (Util::MakeNotification ("BitTorrent",
					tr ("%1 hasn't finished downloading yet.")
						.arg ("<em>" + item->Name_ + "</em>"),
					Priority::Warning));
		else
		{
			const auto& full = BasePath_ / item->GetFullPath ();
			const auto& path = QString::fromUtf8 (full.string ().c_str ());
			const auto& e = Util::MakeEntity (QUrl::fromLocalFile (path),
					{},
					FromUserInitiated);
			iem->HandleEntity (e);
		}
	}
	void UpdatesNotificationManager::notify ()
	{
		NotifyScheduled_ = false;

		auto em = Proxy_->GetEntityManager ();

		const auto upgradableCount = UpgradablePackages_.size ();
		QString bodyText;
		if (!upgradableCount)
		{
			auto cancel = Util::MakeANCancel ("org.LeechCraft.LackMan", "org.LeechCraft.LackMan");
			em->HandleEntity (cancel);

			return;
		}
		else if (upgradableCount <= 3)
		{
			QStringList names;
			for (auto id : UpgradablePackages_)
				names << Core::Instance ().GetListPackageInfo (id).Name_;
			names.sort ();

			if (upgradableCount == 1)
				bodyText = tr ("A new version of %1 is available.")
						.arg ("<em>" + names.value (0) + "</em>");
			else
			{
				const auto& lastName = names.takeLast ();
				bodyText = tr ("New versions of %1 and %2 are available.")
						.arg ("<em>" + names.join ("</em>, <em>") + "</em>")
						.arg ("<em>" + lastName + "</em>");
			}
		}
		else
			bodyText = tr ("New versions are available for %n package(s).",
					0, upgradableCount);

		auto entity = Util::MakeAN ("Lackman",
				bodyText,
				PInfo_,
				"org.LeechCraft.LackMan",
				AN::CatPackageManager,
				AN::TypePackageUpdated,
				"org.LeechCraft.LackMan",
				{ "Lackman" },
				0,
				upgradableCount);

		auto nah = new Util::NotificationActionHandler (entity, this);
		nah->AddFunction (tr ("Open LackMan"),
				[this, entity, em] () -> void
				{
					emit openLackmanRequested ();
					em->HandleEntity (Util::MakeANCancel (entity));
				});

		em->HandleEntity (entity);
	}
Beispiel #3
0
void Plugin::CheckNotifications (const BatteryInfo& info)
{
    auto check = [&info, this] (std::function<bool (const BatteryInfo&)> f) -> bool
    {
        if (!Battery2LastInfo_.contains (info.ID_))
            return f (info);

        return f (info) && !f (Battery2LastInfo_ [info.ID_]);
    };

    auto checkPerc = [] (const BatteryInfo& b, const QByteArray& prop)
    {
        return b.Percentage_ <= XmlSettingsManager::Instance ()->property (prop).toInt ();
    };

    const bool isExtremeLow = check ([checkPerc] (const BatteryInfo& b)
    {
        return checkPerc (b, "NotifyOnExtremeLowPower");
    });
    const bool isLow = check ([checkPerc] (const BatteryInfo& b)
    {
        return checkPerc (b, "NotifyOnLowPower");
    });

    const auto iem = Proxy_->GetEntityManager ();
    if (isExtremeLow || isLow)
        iem->HandleEntity (Util::MakeNotification ("Liznoo",
                           tr ("Battery charge level is below %1.")
                           .arg (info.Percentage_),
                           isLow ? PWarning_ : PCritical_));

    if (XmlSettingsManager::Instance ()->property ("NotifyOnPowerTransitions").toBool ())
    {
        const bool startedCharging = check ([] (const BatteryInfo& b)
        {
            return b.TimeToFull_ && !b.TimeToEmpty_;
        });
        const bool startedDischarging = check ([] (const BatteryInfo& b)
        {
            return !b.TimeToFull_ && b.TimeToEmpty_;
        });

        if (startedCharging)
            iem->HandleEntity (Util::MakeNotification ("Liznoo",
                               tr ("The device started charging."),
                               PInfo_));
        else if (startedDischarging)
            iem->HandleEntity (Util::MakeNotification ("Liznoo",
                               tr ("The device started discharging."),
                               PWarning_));
    }
}
	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;
	}
Beispiel #5
0
	bool CustomWebPage::acceptNavigationRequest (QWebFrame *frame,
			const QNetworkRequest& other, QWebPage::NavigationType type)
	{
		Util::DefaultHookProxy_ptr proxy (new Util::DefaultHookProxy);
		QNetworkRequest request = other;
		emit hookAcceptNavigationRequest (proxy, this, frame, request, type);
		if (proxy->IsCancelled ())
			return proxy->GetReturnValue ().toBool ();

		proxy->FillValue ("request", request);

		QString scheme = request.url ().scheme ();
		if (scheme == "mailto" ||
				scheme == "ftp")
		{
			const auto& e = Util::MakeEntity (request.url (),
					QString (),
					FromUserInitiated);
			auto em = Core::Instance ().GetProxy ()->GetEntityManager ();
			if (em->CouldHandle (e))
				em->HandleEntity (e);
			else
				QDesktopServices::openUrl (request.url ());
			return false;
		}

		if (frame)
			HandleForms (frame, request, type);

		if (type == NavigationTypeLinkClicked &&
				(MouseButtons_ == Qt::MidButton ||
					Modifiers_ & Qt::ControlModifier))
		{
			bool invert = Modifiers_ & Qt::ShiftModifier;

			CustomWebView *view = Core::Instance ().MakeWebView (invert);
			view->Load (request);

			MouseButtons_ = Qt::NoButton;
			Modifiers_ = Qt::NoModifier;
			return false;
		}

		if (frame == mainFrame ())
			LoadingURL_ = request.url ();

		return QWebPage::acceptNavigationRequest (frame, request, type);
	}
Beispiel #6
0
void CHttpClient::Process()
{
	int   header_len;
	char  *request_head;

	if(!Connect(m_Request.host,m_Request.port)) {
		return;
	}

	// Build the HTTP Header
	switch(m_Request.rtype)
	{
		case HTTP_GET:
			header_len = strlen(m_Request.file)+strlen(m_Request.host)+
				(strlen(GET_FORMAT)-8)+strlen(USER_AGENT)+
				strlen(m_Request.referer);
			request_head = (char *)malloc(header_len+1);
			sprintf(request_head,GET_FORMAT,m_Request.file,USER_AGENT,m_Request.referer,m_Request.host);
			break;

		case HTTP_HEAD:
			header_len = strlen(m_Request.file)+strlen(m_Request.host)+
				(strlen(HEAD_FORMAT)-8)+strlen(USER_AGENT)+
				strlen(m_Request.referer);
			request_head = (char *)malloc(header_len+1);
			sprintf(request_head,HEAD_FORMAT,m_Request.file,USER_AGENT,m_Request.referer,m_Request.host);
			break;

		case HTTP_POST:
			header_len = strlen(m_Request.data)+strlen(m_Request.file)+
				strlen(m_Request.host)+strlen(POST_FORMAT)+
				strlen(USER_AGENT)+strlen(m_Request.referer);
			request_head = (char *)malloc(header_len+1);
			sprintf(request_head,POST_FORMAT,m_Request.file,USER_AGENT,m_Request.referer,m_Request.host,strlen(m_Request.data),m_Request.data);
			break;	
	}

	if(!Send(request_head)) {	
		free(request_head);
		return;
	}

	free(request_head);

	HandleEntity();
}
//-------------------------------------------------------
void
PersistenceHandler::OnUpdatedEntity(const Safir::Dob::EntityProxy entityProxy)
{
    HandleEntity(entityProxy, true);
}
//-------------------------------------------------------
void
PersistenceHandler::OnNewEntity(const Safir::Dob::EntityProxy entityProxy)
{
    HandleEntity(entityProxy, false);
}