本文整理汇总了C++中QMimeDatabase::mimeTypeForUrl方法的典型用法代码示例。如果您正苦于以下问题:C++ QMimeDatabase::mimeTypeForUrl方法的具体用法?C++ QMimeDatabase::mimeTypeForUrl怎么用?C++ QMimeDatabase::mimeTypeForUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMimeDatabase
的用法示例。
在下文中一共展示了QMimeDatabase::mimeTypeForUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: urlSelected
bool DocumentationViewer::urlSelected(const QString &url, int button, int state, const QString &_target, const KParts::OpenUrlArguments &args, const KParts::BrowserArguments & /* browserArgs */)
{
QUrl cURL = completeURL(url);
QMimeDatabase db;
QString mime = db.mimeTypeForUrl(cURL).name();
//load this URL in the embedded viewer if KHTML can handle it, or when mimetype detection failed
KService::Ptr service = KService::serviceByDesktopName("khtml");
if (db.mimeTypeForUrl(cURL).isDefault() || (service && service->hasServiceType(mime))) {
KHTMLPart::urlSelected(url, button, state, _target, args);
openUrl(cURL);
addToHistory(cURL.url());
}
//KHTML can't handle it, look for an appropriate application
else {
KService::List offers = KMimeTypeTrader::self()->query(mime, "Type == 'Application'");
if(offers.isEmpty()) {
KMessageBox::error(view(), i18n("No KDE service found for the MIME type \"%1\".", mime));
return false;
}
QList<QUrl> lst;
lst.append(cURL);
KRun::runService(*(offers.first()), lst, view());
}
return true;
}
示例2: slotClicked
void ProjectView::slotClicked(QTreeWidgetItem *item)
{
if(!item) {
item = currentItem();
}
ProjectViewItem *itm = static_cast<ProjectViewItem*>(item);
if(itm) {
if(itm->type() == KileType::File) {
emit(fileSelected(itm->url()));
}
else if(itm->type() == KileType::ProjectItem) {
emit(fileSelected(itm->projectItem()));
}
else if(itm->type() != KileType::Folder) {
// don't open project configuration files (*.kilepr)
if(itm->url().toLocalFile().right(7) != ".kilepr") {
//determine mimeType and open file with preferred application
QMimeDatabase db;
QMimeType pMime = db.mimeTypeForUrl(itm->url());
if(pMime.name().startsWith("text/")) {
emit(fileSelected(itm->url()));
}
else {
KRun::runUrl(itm->url(), pMime.name(), this);
}
}
}
clearSelection();
}
}
示例3: if
const QString& vfile::vfile_getMime()
{
if (vfile_mimeType.isEmpty()) {
if(vfile_isdir)
vfile_mimeType = "inode/directory";
else if(vfile_isBrokenLink())
vfile_mimeType = "unknown";
else {
QMimeDatabase db;
QMimeType mt = db.mimeTypeForUrl(vfile_getUrl());
vfile_mimeType = mt.isValid() ? mt.name() : "unknown";
if (mt.isValid())
vfile_icon = mt.iconName();
if (vfile_mimeType == "inode/directory") {
vfile_perm[0] = 'd';
vfile_isdir = true;
}
}
if (vfile_isdir && vfile_userDefinedFolderIcons) {
QUrl url = vfile_getUrl();
if (url.isLocalFile()) {
QString file = url.toLocalFile() + "/.directory";
KDesktopFile cfg(file);
QString icon = cfg.readIcon();
if(icon.startsWith(QLatin1String("./"))) // relative path
icon = url.toLocalFile() + '/' + icon;
if (!icon.isEmpty())
vfile_icon = icon;
}
}
}
return vfile_mimeType;
}
示例4: mimeType
QString AnimationResult::mimeType()
{
QMimeDatabase db;
QMimeType type = db.mimeTypeForUrl(d->url);
return type.name();
}
示例5: determineMimeType
QMimeType KFileItem::determineMimeType() const
{
if (!d) {
return QMimeType();
}
if (!d->m_mimeType.isValid() || !d->m_bMimeTypeKnown) {
QMimeDatabase db;
if (isDir()) {
d->m_mimeType = db.mimeTypeForName(QStringLiteral("inode/directory"));
} else {
bool isLocalUrl;
const QUrl url = mostLocalUrl(&isLocalUrl);
d->m_mimeType = db.mimeTypeForUrl(url);
// was: d->m_mimeType = KMimeType::findByUrl( url, d->m_fileMode, isLocalUrl );
// => we are no longer using d->m_fileMode for remote URLs.
Q_ASSERT(d->m_mimeType.isValid());
//qDebug() << d << "finding final mimetype for" << url << ":" << d->m_mimeType.name();
}
d->m_bMimeTypeKnown = true;
}
if (d->m_delayedMimeTypes) { // if we delayed getting the iconName up till now, this is the right point in time to do so
d->m_delayedMimeTypes = false;
d->m_useIconNameCache = false;
(void)iconName();
}
return d->m_mimeType;
}
示例6: initialize
void PlacesItemEditDialog::initialize()
{
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
m_okButton = buttonBox->button(QDialogButtonBox::Ok);
m_okButton->setDefault(true);
m_okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::accepted, this, &PlacesItemEditDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &PlacesItemEditDialog::reject);
setModal(true);
m_okButton->setDefault(true);
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);
QWidget* mainWidget = new QWidget(this);
mainLayout->addWidget(mainWidget);
mainLayout->addWidget(buttonBox);
QVBoxLayout* vBox = new QVBoxLayout(mainWidget);
QFormLayout* formLayout = new QFormLayout();
vBox->addLayout( formLayout );
m_textEdit = new QLineEdit(mainWidget);
formLayout->addRow(i18nc("@label", "Label:"), m_textEdit);
m_textEdit->setText(m_text);
m_textEdit->setPlaceholderText(i18n("Enter descriptive label here"));
m_urlEdit = new KUrlRequester(m_url, mainWidget);
m_urlEdit->setMode(KFile::Directory);
formLayout->addRow(i18nc("@label", "Location:"), m_urlEdit);
// Provide room for at least 40 chars (average char width is half of height)
m_urlEdit->setMinimumWidth(m_urlEdit->fontMetrics().height() * (40 / 2));
connect(m_urlEdit, &KUrlRequester::textChanged, this, &PlacesItemEditDialog::slotUrlChanged);
m_iconButton = new KIconButton(mainWidget);
formLayout->addRow(i18nc("@label", "Choose an icon:"), m_iconButton);
m_iconButton->setIconSize(IconSize(KIconLoader::Desktop));
m_iconButton->setIconType(KIconLoader::NoGroup, KIconLoader::Place);
if (m_icon.isEmpty()) {
QMimeDatabase db;
m_iconButton->setIcon(db.mimeTypeForUrl(m_url).iconName());
} else {
m_iconButton->setIcon(m_icon);
}
if (m_allowGlobal) {
const QString appName = KAboutData::applicationData().displayName();
m_appLocal = new QCheckBox( i18n("&Only show when using this application (%1)", appName ), mainWidget );
m_appLocal->setChecked(false);
vBox->addWidget(m_appLocal);
}
if (m_text.isEmpty()) {
m_urlEdit->setFocus();
} else {
m_textEdit->setFocus();
}
}
示例7: makeSaveMimetype
QString ExportManager::makeSaveMimetype(const QUrl &url)
{
QMimeDatabase mimedb;
QString type = mimedb.mimeTypeForUrl(url).preferredSuffix();
if (type.isEmpty()) {
return QStringLiteral("png");
}
return type;
}
示例8: downloadComplete
void DappLoader::downloadComplete(QNetworkReply* _reply)
{
QUrl requestUrl = _reply->request().url();
if (m_pageUrls.count(requestUrl) != 0)
{
//inject web3 js
QByteArray content = "<script>\n";
content.append(web3Content());
content.append("</script>\n");
content.append(_reply->readAll());
QString contentType = _reply->header(QNetworkRequest::ContentTypeHeader).toString();
if (contentType.isEmpty())
{
QMimeDatabase db;
contentType = db.mimeTypeForUrl(requestUrl).name();
}
pageReady(content, contentType, requestUrl);
return;
}
try
{
//try to interpret as rlp
QByteArray data = _reply->readAll();
_reply->deleteLater();
h256 expected = m_uriHashes[requestUrl];
bytes package(reinterpret_cast<unsigned char const*>(data.constData()), reinterpret_cast<unsigned char const*>(data.constData() + data.size()));
Secp256k1 dec;
dec.decrypt(expected, package);
h256 got = sha3(package);
if (got != expected)
{
//try base64
data = QByteArray::fromBase64(data);
package = bytes(reinterpret_cast<unsigned char const*>(data.constData()), reinterpret_cast<unsigned char const*>(data.constData() + data.size()));
dec.decrypt(expected, package);
got = sha3(package);
if (got != expected)
throw dev::Exception() << errinfo_comment("Dapp content hash does not match");
}
RLP rlp(package);
loadDapp(rlp);
}
catch (...)
{
qWarning() << tr("Error downloading DApp: ") << boost::current_exception_diagnostic_information().c_str();
emit dappError();
}
}
示例9: dropEvent
void KUrlNavigatorPlacesSelector::dropEvent(QDropEvent *event)
{
setDisplayHintEnabled(DraggedHint, false);
update();
QMimeDatabase db;
const QList<QUrl> urlList = KUrlMimeData::urlsFromMimeData(event->mimeData());
foreach (const QUrl &url, urlList) {
QMimeType mimetype = db.mimeTypeForUrl(url);
if (mimetype.inherits(QStringLiteral("inode/directory"))) {
m_placesModel->addPlace(url.fileName(), url);
}
}
示例10: qCDebug
MessageCore::AttachmentFromUrlBaseJob *AttachmentFromUrlUtils::createAttachmentJob(const QUrl &url, QObject *parent)
{
MessageCore::AttachmentFromUrlBaseJob *ajob = 0;
QMimeDatabase db;
if (db.mimeTypeForUrl(url).name() == QLatin1String("inode/directory")) {
qCDebug(MESSAGECORE_LOG) << "Creating attachment from folder";
ajob = new MessageCore::AttachmentFromFolderJob(url, parent);
} else {
ajob = new MessageCore::AttachmentFromUrlJob(url, parent);
qCDebug(MESSAGECORE_LOG) << "Creating attachment from file";
}
if (MessageCore::MessageCoreSettings::maximumAttachmentSize() > 0) {
ajob->setMaximumAllowedSize(MessageCore::MessageCoreSettings::maximumAttachmentSize());
}
return ajob;
}
示例11: contextMenuEvent
void ProjectView::contextMenuEvent(QContextMenuEvent *event)
{
QSignalMapper signalMapper, serviceSignalMapper;
QMenu popup;
QAction *action = Q_NULLPTR;
QTreeWidgetItem* treeWidgetItem = itemAt(event->pos());
if(!treeWidgetItem) {
return;
}
ProjectViewItem *projectViewItem = dynamic_cast<ProjectViewItem*>(treeWidgetItem);
if(!projectViewItem) {
return;
}
if(projectViewItem->type() == KileType::Folder) {
return;
}
bool insertsep = false;
bool isKilePrFile = false;
if(projectViewItem->type() != KileType::Project && projectViewItem->projectItem()
&& projectViewItem->projectItem()->project()) {
isKilePrFile = projectViewItem->projectItem()->project()->url() == projectViewItem->url();
}
if(projectViewItem->type() == KileType::ProjectExtra && !isKilePrFile) {
QMenu *servicesMenu = popup.addMenu(QIcon::fromTheme("fork"), i18n("&Open With"));
connect(&serviceSignalMapper, SIGNAL(mapped(int)), this, SLOT(slotRun(int)));
QMimeDatabase db;
m_offerList = KMimeTypeTrader::self()->query(db.mimeTypeForUrl(projectViewItem->url()).name(), "Application");
for (int i = 0; i < m_offerList.count(); ++i) {
action = new QAction(servicesMenu);
action->setIcon(QIcon::fromTheme(m_offerList[i]->icon()));
action->setText(m_offerList[i]->name());
connect(action, SIGNAL(triggered()), &serviceSignalMapper, SLOT(map()));
serviceSignalMapper.setMapping(action, i + 1);
servicesMenu->addAction(action);
}
servicesMenu->addSeparator();
action = servicesMenu->addAction(i18n("Other..."), &serviceSignalMapper, SLOT(map()));
serviceSignalMapper.setMapping(action, 0);
insertsep = true;
}
示例12: handleURL
bool DropHandler::handleURL(const QList<QUrl>& urls_) {
bool hasUnknown = false;
QList<QUrl> tc, pdf, bib, ris, ciw;
foreach(const QUrl& url, urls_) {
QMimeType ptr;
// findByURL doesn't work for http, so actually query
// the url itself
if(url.scheme() != QLatin1String("http")) {
QMimeDatabase db;
ptr = db.mimeTypeForUrl(url);
} else {
KIO::MimetypeJob* job = KIO::mimetype(url, KIO::HideProgressInfo);
KJobWidgets::setWindow(job, GUI::Proxy::widget());
job->exec();
QMimeDatabase db;
ptr = db.mimeTypeForName(job->mimetype());
}
if(ptr.inherits(QLatin1String("application/x-tellico"))) {
tc << url;
} else if(ptr.inherits(QLatin1String("application/pdf"))) {
pdf << url;
} else if(ptr.inherits(QLatin1String("text/x-bibtex")) ||
ptr.inherits(QLatin1String("application/x-bibtex")) ||
ptr.inherits(QLatin1String("application/bibtex"))) {
bib << url;
} else if(ptr.inherits(QLatin1String("application/x-research-info-systems"))) {
ris << url;
} else if(url.fileName().endsWith(QLatin1String(".bib"))) {
bib << url;
} else if(url.fileName().endsWith(QLatin1String(".ris"))) {
ris << url;
} else if(url.fileName().endsWith(QLatin1String(".ciw"))) {
ciw << url;
} else if(ptr.inherits(QLatin1String("text/plain")) && Import::BibtexImporter::maybeBibtex(url)) {
bib << url;
} else if(ptr.inherits(QLatin1String("text/plain")) && Import::RISImporter::maybeRIS(url)) {
ris << url;
} else if(ptr.inherits(QLatin1String("text/plain")) && Import::CIWImporter::maybeCIW(url)) {
ciw << url;
} else {
myDebug() << "unrecognized type: " << ptr.name() << " (" << url << ")";
hasUnknown = true;
}
}
示例13: defaultProgram
/*!
\brief Returns id of the default program that is capable to open given \a url.
*/
QString QDefaultProgram::defaultProgram(const QUrl &url)
{
QMimeDatabase db;
QMimeType mimeType = db.mimeTypeForUrl(url);
// if (!mimeType.isValid())
// return;
// QMimeType mt = mimeType;
// while (mt.isValid()) {
// qDebug() << mt.name();
// qDebug() << QDefaultProgram::defaultProgram(mt.name());
// if (mt.parentMimeTypes().isEmpty())
// break;
// mt = db.mimeTypeForName(mt.parentMimeTypes().first());
// }
return defaultProgram(mimeType.name());
}
示例14: createPostWithAttachment
void TwitterMicroBlog::createPostWithAttachment(Choqok::Account *theAccount, Choqok::Post *post,
const QString &mediumToAttach)
{
if (mediumToAttach.isEmpty()) {
TwitterApiMicroBlog::createPost(theAccount, post);
} else {
const QUrl picUrl = QUrl::fromUserInput(mediumToAttach);
KIO::StoredTransferJob *picJob = KIO::storedGet(picUrl, KIO::Reload, KIO::HideProgressInfo);
picJob->exec();
if (picJob->error()) {
qCCritical(CHOQOK) << "Job error:" << picJob->errorString();
KMessageBox::detailedError(Choqok::UI::Global::mainWindow(),
i18n("Uploading medium failed: cannot read the medium file."),
picJob->errorString());
return;
}
const QByteArray picData = picJob->data();
if (picData.count() == 0) {
qCCritical(CHOQOK) << "Cannot read the media file, please check if it exists.";
KMessageBox::error(Choqok::UI::Global::mainWindow(),
i18n("Uploading medium failed: cannot read the medium file."));
return;
}
TwitterAccount *account = qobject_cast<TwitterAccount *>(theAccount);
QUrl url = account->uploadUrl();
url.setPath(url.path() + QStringLiteral("/statuses/update_with_media.%1").arg(format));
const QMimeDatabase db;
QByteArray fileContentType = db.mimeTypeForUrl(picUrl).name().toUtf8();
QMap<QString, QByteArray> formdata;
formdata[QLatin1String("status")] = post->content.toUtf8();
if (!post->replyToPostId.isEmpty()) {
formdata[QLatin1String("in_reply_to_status_id")] = post->replyToPostId.toLatin1();
}
formdata[QLatin1String("source")] = QCoreApplication::applicationName().toLatin1();
QMap<QString, QByteArray> mediafile;
mediafile[QLatin1String("name")] = "media[]";
mediafile[QLatin1String("filename")] = picUrl.fileName().toUtf8();
mediafile[QLatin1String("mediumType")] = fileContentType;
mediafile[QLatin1String("medium")] = picData;
QList< QMap<QString, QByteArray> > listMediafiles;
listMediafiles.append(mediafile);
QByteArray data = Choqok::MediaManager::createMultipartFormData(formdata, listMediafiles);
KIO::StoredTransferJob *job = KIO::storedHttpPost(data, url, KIO::HideProgressInfo) ;
if (!job) {
qCCritical(CHOQOK) << "Cannot create a http POST request!";
return;
}
job->addMetaData(QStringLiteral("content-type"),
QStringLiteral("Content-Type: multipart/form-data; boundary=AaB03x"));
job->addMetaData(QStringLiteral("customHTTPHeader"),
QStringLiteral("Authorization: ") +
QLatin1String(authorizationHeader(account, url, QOAuth::POST)));
mCreatePostMap[ job ] = post;
mJobsAccount[job] = theAccount;
connect(job, SIGNAL(result(KJob*)),
SLOT(slotCreatePost(KJob*)));
job->start();
}
}
示例15: testDUChainBuddy
void TestBuddies::testDUChainBuddy()
{
enableBuddies();
enableOpenAfterCurrent();
QTemporaryDir dirA;
TestFile header("void myfunction();\n", "h", nullptr, dirA.path());
TestFile other("void otherfunction() {}\n", "cpp", nullptr, dirA.path());
TestFile source(
QString("#include \"%1\"\nvoid myfunction() {}\n").arg(header.url().toUrl().fileName()),
"cpp", nullptr, dirA.path()
);
header.parseAndWait();
other.parseAndWait();
source.parseAndWait();
// Test IBuddyDocumentFinder::getPotentialBuddies()
QMimeDatabase db;
IBuddyDocumentFinder* sourceBuddyFinder = IBuddyDocumentFinder::finderForMimeType(db.mimeTypeForUrl(source.url().toUrl()).name());
QVector< QUrl > sourceBuddies = sourceBuddyFinder->getPotentialBuddies(source.url().toUrl());
if (!sourceBuddies.contains(header.url().toUrl())) {
qDebug() << "got source buddies: " << sourceBuddies;
qDebug() << "expected: " << header.url().toUrl();
QFAIL("Failed to find buddy for source file");
}
QVERIFY2(!sourceBuddies.contains(other.url().toUrl()), "source buddy list contains unrelated file");
IBuddyDocumentFinder* headerBuddyFinder = IBuddyDocumentFinder::finderForMimeType(db.mimeTypeForUrl(header.url().toUrl()).name());
QVector< QUrl > headerBuddies = headerBuddyFinder->getPotentialBuddies(header.url().toUrl());
if (!headerBuddies.contains(source.url().toUrl())) {
qDebug() << "got header buddies: " << headerBuddies;
qDebug() << "expected: " << source.url().toUrl();
QFAIL("Failed to find buddy for header file");
}
QVERIFY2(!headerBuddies.contains(other.url().toUrl()), "header buddy list contains unrelated file");
// Test IBuddyDocumentFinder::areBuddies()
QVERIFY(sourceBuddyFinder->areBuddies(source.url().toUrl(), header.url().toUrl()));
}