Пример #1
0
RequestResponse AlbumRequest::invoke(const QStringList &arguments, const QString &who, const RequestInvocationContext &context)
{
	Q_UNUSED(who);

	const QString &id = arguments.join(QChar::Space);

	InformationResourceRepository &repository = context.informationResourceRepository();
	IdGenerator &idGenerator = context.idGenerator();

	IInformationResource *resource = repository.get(id);

	if (resource)
	{
		IIterator<Album> *iterator = resource->iterator<Album>();

		if (iterator)
		{
			Album *album = iterator->next(resource, repository, idGenerator);

			if (album)
			{
				return RequestResponse("templates/Album.qml", album);
			}

			return RequestResponse("templates/NoMoreData.qml", nullptr);
		}
	}

	return RequestResponse();
}
Пример #2
0
RequestResponse ArtistRequest::invoke(const QStringList &arguments, const QString &who, const RequestInvocationContext &context)
{
	const QString &id = arguments.join(QChar::Space);

	InformationResourceRepository &repository = context.informationResourceRepository();
	IdGenerator &idGenerator = context.idGenerator();

	IInformationResource *resource = repository.get(id);

	if (resource)
	{
		IIterator<Artist> *iterator = resource->iterator<Artist>();

		if (iterator)
		{
			Artist *artist = iterator->next(resource, repository, idGenerator);

			if (artist)
			{
				return RequestResponse("templates/Artist.qml", artist);
			}

			return RequestResponse("templates/NoMoreData.qml", nullptr);
		}
	}
	else
	{
		RequestHandler requestHandler(repository, idGenerator);

		Artist *artist = requestHandler
			.get<Artist>("artist.getInfo"
				, as::artist = arguments.join(QChar::Space)
				, as::username = who
			);

		if (artist)
		{
			return RequestResponse("templates/Artist.qml", artist);
		}

		NotFound *notFound = new NotFound();
		notFound->setTypeName("Artist");

		return RequestResponse("templates/NotFound.qml", notFound);
	}

	return RequestResponse();
}
Пример #3
0
RequestResponse NowPlayingRequest::invoke(const QStringList &arguments, const QString &who, const RequestInvocationContext &context)
{
	const QString &nick = arguments.value(0, who);

	Track *nowPlaying = getRecentTrack(nick, context, &TrackFilter::nowPlaying);

	if (nowPlaying)
	{
		return RequestResponse("templates/NowPlaying.qml", nowPlaying);
	}

	NotPlaying *notPlaying = new NotPlaying();
	notPlaying->setUser(nick);

	return RequestResponse("templates/NotPlaying.qml", notPlaying);
}
Пример #4
0
    bool ClientAdapter::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser, CefRefPtr<CefRequest> request, CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream, CefRefPtr<CefResponse> response, int loadFlags)
    {
        IBeforeResourceLoad^ handler = _browserControl->BeforeResourceLoadHandler;
        if(handler != nullptr)
        {
            CefRequestWrapper^ wrapper = gcnew CefRequestWrapper(request);
            RequestResponse^ requestResponse = gcnew RequestResponse(wrapper);
            
            handler->HandleBeforeResourceLoad(_browserControl, requestResponse);

            if(requestResponse->Action == ResponseAction::Respond)
            {
                CefRefPtr<StreamAdapter> adapter = new StreamAdapter(requestResponse->ResponseStream);
                resourceStream = CefStreamReader::CreateForHandler(static_cast<CefRefPtr<CefReadHandler>>(adapter));
                //mimeType = toNative(requestResponse->MimeType);
                return false;
            }
            else if(requestResponse->Action == ResponseAction::Cancel)
            {
                return true;
            }
            else if(requestResponse->Action == ResponseAction::Redirect)
            {
                redirectUrl = toNative(requestResponse->RedirectUrl);
            }
        }

        return false; 
    }
Пример #5
0
    CefHandler::RetVal HandlerAdapter::HandleBeforeResourceLoad(CefRefPtr<CefBrowser> browser, CefRefPtr<CefRequest> request, CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream, CefString& mimeType, int loadFlags) 
    {
        IBeforeResourceLoad^ handler = _browserControl->BeforeResourceLoadHandler;
        if(handler != nullptr)
        {
            CefRequestWrapper^ wrapper = gcnew CefRequestWrapper(request);
            RequestResponse^ requestResponse = gcnew RequestResponse(wrapper);
            
            handler->HandleBeforeResourceLoad(_browserControl, requestResponse);

            if(requestResponse->Action == ResponseAction::Respond)
            {
                CefRefPtr<StreamAdapter> adapter = new StreamAdapter(requestResponse->ResponseStream);
                resourceStream = CefStreamReader::CreateForHandler(static_cast<CefRefPtr<CefReadHandler>>(adapter));
                mimeType = convertFromString(requestResponse->MimeType);
                return RV_CONTINUE;
            }
            else if(requestResponse->Action == ResponseAction::Cancel)
            {
                return RV_HANDLED;
            }
            else if(requestResponse->Action == ResponseAction::Redirect)
            {
                redirectUrl = convertFromString(requestResponse->RedirectUrl);
            }
        }
        return RV_CONTINUE; 
    }
Пример #6
0
RequestResponse TagsRequest::invoke(const QStringList &arguments, const QString &who, const RequestInvocationContext &context)
{
	Q_UNUSED(who);

	const QString &id = arguments.join(QChar::Space);

	InformationResourceRepository &repository = context.informationResourceRepository();
	IdGenerator &idGenerator = context.idGenerator();

	IInformationResource *resource = repository.get(id);

	if (resource)
	{
		IIterator<Tag> *iterator = resource->iterator<Tag>();

		if (iterator)
		{
			QList<QObject *> tags;

			for (int i = 0; i < 10; i++)
			{
				Tag *tag = iterator->next(resource, repository, idGenerator);

				if (!tag)
				{
					if (!i)
					{
						return RequestResponse("templates/NoMoreData.qml", nullptr);
					}

					break;
				}
				else
				{
					tags << tag;
				}
			}

			Tags *envelope = new Tags();
			envelope->setTags(tags);

			return RequestResponse("templates/Tags.qml", envelope);
		}
	}

	return RequestResponse();
}