예제 #1
0
파일: core.cpp 프로젝트: nstm0/leechcraft
	void Core::Handle (LeechCraft::Entity e)
	{
		QUrl url = e.Entity_.toUrl ();
		if (e.Mime_ == "text/x-opml")
		{
			if (url.scheme () == "file")
				StartAddingOPML (url.toLocalFile ());
			else
			{
				QString name = LeechCraft::Util::GetTemporaryName ();

				LeechCraft::Entity e = Util::MakeEntity (url,
						name,
						LeechCraft::Internal |
							LeechCraft::DoNotNotifyUser |
							LeechCraft::DoNotSaveInHistory |
							LeechCraft::NotPersistent |
							LeechCraft::DoNotAnnounceEntity);
				PendingOPML po =
				{
					name
				};

				int id = -1;
				QObject *pr;
				emit delegateEntity (e, &id, &pr);
				if (id == -1)
				{
					ErrorNotification (tr ("Import error"),
							tr ("Could not find plugin to download OPML %1.")
								.arg (url.toString ()));
					return;
				}

				HandleProvider (pr, id);
				PendingOPMLs_ [id] = po;
			}

			QMap<QString, QVariant> s = e.Additional_;
			if (s.contains ("ShowTrayIcon"))
				XmlSettingsManager::Instance ()->setProperty ("ShowIconInTray",
						s.value ("ShowIconInTray").toBool ());
			if (s.contains ("UpdateOnStartup"))
				XmlSettingsManager::Instance ()->setProperty ("UpdateOnStartup",
						s.value ("UpdateOnStartup").toBool ());
			if (s.contains ("UpdateTimeout"))
				XmlSettingsManager::Instance ()->setProperty ("UpdateInterval",
						s.value ("UpdateTimeout").toInt ());
			if (s.contains ("MaxArticles"))
				XmlSettingsManager::Instance ()->setProperty ("ItemsPerChannel",
						s.value ("MaxArticles").toInt ());
			if (s.contains ("MaxAge"))
				XmlSettingsManager::Instance ()->setProperty ("ItemsMaxAge",
						s.value ("MaxAge").toInt ());
		}
		else
		{
			QString str = url.toString ();
			if (str.startsWith ("feed://"))
				str.replace (0, 4, "http");
			else if (str.startsWith ("feed:"))
				str.remove  (0, 5);
			else if (str.startsWith ("itpc://"))
				str.replace (0, 4, "http");

			LeechCraft::Aggregator::AddFeed af (str);
			if (af.exec () == QDialog::Accepted)
				AddFeed (af.GetURL (),
						af.GetTags ());
		}
	}
예제 #2
0
	void Core::Handle (Entity e)
	{
		QUrl url = e.Entity_.toUrl ();
		if (e.Mime_ == "text/x-opml")
		{
			if (url.scheme () == "file")
				StartAddingOPML (url.toLocalFile ());
			else
			{
				const auto& name = Util::GetTemporaryName ();

				const auto& dlEntity = Util::MakeEntity (url,
						name,
						Internal |
							DoNotNotifyUser |
							DoNotSaveInHistory |
							NotPersistent |
							DoNotAnnounceEntity);

				const auto& handleResult = Proxy_->GetEntityManager ()->DelegateEntity (dlEntity);
				if (!handleResult)
				{
					ErrorNotification (tr ("Import error"),
							tr ("Could not find plugin to download OPML %1.")
								.arg (url.toString ()));
					return;
				}

				HandleProvider (handleResult.Handler_, handleResult.ID_);
				PendingOPMLs_ [handleResult.ID_] = PendingOPML { name };
			}

			const auto& s = e.Additional_;
			if (s.contains ("UpdateOnStartup"))
				XmlSettingsManager::Instance ()->setProperty ("UpdateOnStartup",
						s.value ("UpdateOnStartup").toBool ());
			if (s.contains ("UpdateTimeout"))
				XmlSettingsManager::Instance ()->setProperty ("UpdateInterval",
						s.value ("UpdateTimeout").toInt ());
			if (s.contains ("MaxArticles"))
				XmlSettingsManager::Instance ()->setProperty ("ItemsPerChannel",
						s.value ("MaxArticles").toInt ());
			if (s.contains ("MaxAge"))
				XmlSettingsManager::Instance ()->setProperty ("ItemsMaxAge",
						s.value ("MaxAge").toInt ());
		}
		else
		{
			QString str = url.toString ();
			if (str.startsWith ("feed://"))
				str.replace (0, 4, "http");
			else if (str.startsWith ("feed:"))
				str.remove  (0, 5);
			else if (str.startsWith ("itpc://"))
				str.replace (0, 4, "http");

			class AddFeed af { str };
			if (af.exec () == QDialog::Accepted)
				AddFeed (af.GetURL (),
						af.GetTags ());
		}
	}