QString QQnxFilePicker::filePickerType() const
{
    bool images = false;
    bool video = false;
    bool music = false;
    QMimeDatabase mimeDb;
    for (int i = 0; i < m_filters.count(); i++) {
        QList<QMimeType> mimeTypes = mimeDb.mimeTypesForFileName(m_filters.at(i));
        if (mimeTypes.isEmpty())
            return QStringLiteral("Other");

        if (mimeTypes.first().name().startsWith(QLatin1String("image")))
            images = true;
        else if (mimeTypes.first().name().startsWith(QLatin1String("audio")))
            music = true;
        else if (mimeTypes.first().name().startsWith(QLatin1String("video")))
            video = true;
        else
            return QStringLiteral("Other");
    }

    if (!video && !music)
        return QStringLiteral("Picture");

    if (!images && !music)
        return QStringLiteral("Video");

    if (!images && !video)
        return QStringLiteral("Music");

    return QStringLiteral("Other");
}
Ejemplo n.º 2
0
HttpResponse StaticFileServer::operator()(const HttpRequest &req)
{
	if(req.method() != HttpRequest::GET && req.method() != HttpRequest::HEAD)
		return HttpResponse::MethodNotAllowed(QStringList() << "HEAD" << "GET");

	if(_root.isEmpty())
		return HttpResponse::NotFound();

	QString path = QDir::cleanPath(_root + req.pathMatch().captured(1));
	if(!path.startsWith(_root))
		return HttpResponse::NotFound();

	if(QFileInfo(path).isDir())
		path.append("/index.html");

	QFile file(path);
	if(!file.open(QFile::ReadOnly)) {
		logger::warning() << path << file.errorString();
		return HttpResponse::NotFound();
	}

	// TODO handle HEAD type request
	HttpResponse resp(200);

	QMimeDatabase mimedb;
	QList<QMimeType> mimetypes = mimedb.mimeTypesForFileName(path);

	if(mimetypes.isEmpty())
		resp.setHeader("Content-Type", "application/octet-stream");
	else
		resp.setHeader("Content-Type", mimetypes.first().name());


	if(req.method() == HttpRequest::GET)
		resp.setBody(file.readAll());
	else
		resp.setHeader("Content-Length", QString::number(file.size()));

	file.close();
	return resp;
}