本文整理汇总了C++中kmimetype::Ptr::is方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::is方法的具体用法?C++ Ptr::is怎么用?C++ Ptr::is使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kmimetype::Ptr
的用法示例。
在下文中一共展示了Ptr::is方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testMimeTypeParent
void KMimeTypeTest::testMimeTypeParent()
{
// All file-like mimetypes inherit from octet-stream
const KMimeType::Ptr wordperfect = KMimeType::mimeType("application/vnd.wordperfect");
QVERIFY(wordperfect);
QCOMPARE(wordperfect->parentMimeTypes().join(","), QString("application/octet-stream"));
QVERIFY(wordperfect->is("application/octet-stream"));
QVERIFY(KMimeType::mimeType("image/svg+xml-compressed")->is("application/x-gzip"));
// Check that msword derives from ole-storage [it didn't in 0.20, but we added it to kde.xml]
const KMimeType::Ptr msword = KMimeType::mimeType("application/msword");
QVERIFY(msword);
const KMimeType::Ptr olestorage = KMimeType::mimeType("application/x-ole-storage");
QVERIFY(olestorage);
QVERIFY(msword->is(olestorage->name()));
QVERIFY(msword->is("application/octet-stream"));
const KMimeType::Ptr directory = KMimeType::mimeType("inode/directory");
QVERIFY(directory);
QCOMPARE(directory->parentMimeTypes().count(), 0);
QVERIFY(!directory->is("application/octet-stream"));
// Check that text/x-patch knows that it inherits from text/plain (it says so explicitly)
const KMimeType::Ptr plain = KMimeType::mimeType("text/plain");
const KMimeType::Ptr derived = KMimeType::mimeType("text/x-patch");
QVERIFY(derived);
QCOMPARE(derived->parentMimeTypes().join(","), plain->name());
QVERIFY(derived->is("text/plain"));
QVERIFY(derived->is("application/octet-stream"));
// Check that application/x-shellscript inherits from application/x-executable
// (Otherwise KRun cannot start shellscripts...)
// This is a test for multiple inheritance...
const KMimeType::Ptr shellscript = KMimeType::mimeType("application/x-shellscript");
QVERIFY(shellscript);
QVERIFY(shellscript->is("text/plain"));
QVERIFY(shellscript->is("application/x-executable"));
const QStringList shellParents = shellscript->parentMimeTypes();
QVERIFY(shellParents.contains("text/plain"));
QVERIFY(shellParents.contains("application/x-executable"));
QCOMPARE(shellParents.count(), 2); // only the above two
const QStringList allShellParents = shellscript->allParentMimeTypes();
QVERIFY(allShellParents.contains("text/plain"));
QVERIFY(allShellParents.contains("application/x-executable"));
QVERIFY(allShellParents.contains("application/octet-stream"));
// Must be least-specific last, i.e. breadth first.
QCOMPARE(allShellParents.last(), QString("application/octet-stream"));
// Check that text/x-mrml knows that it inherits from text/plain (implicitly)
const KMimeType::Ptr mrml = KMimeType::mimeType("text/x-mrml");
if (!mrml) {
QSKIP("kdelibs not installed");
}
QVERIFY(mrml->is("text/plain"));
QVERIFY(mrml->is("application/octet-stream"));
}
示例2: return
bool Utilities::isM3u(const QString &url)
{
if (!url.isEmpty()) {
KMimeType::Ptr result = KMimeType::findByUrl(KUrl(url), 0, true);
return (result->is("audio/m3u") ||
result->is("application/vnd.apple.mpegurl") ||
result->is("audio/x-mpegurl"));
} else {
return false;
}
}
示例3: initView
void AudioPreview::initView( const QString& mimeType )
{
KUrl url = KUrl::fromPath( m_localFile );
pic->setText( QString() );
pic->setPixmap(KIO::pixmapForUrl( url ));
pic->adjustSize();
KFileMetaInfo info(m_localFile);
KMimeType::Ptr mimeptr = KMimeType::mimeType(mimeType);
QString desc;
if (info.isValid())
{
if (mimeptr->is("audio/mpeg") || mimeptr->is("application/ogg"))
{
// following 3 labels might be very long; make sure they get squeezed
KSqueezedTextLabel *sl;
sl = new KSqueezedTextLabel(this);
sl->setText(i18n("Artist: %1", info.item("Artist").value().toString()));
sl = new KSqueezedTextLabel(this);
sl->setText(i18n("Title: %1", info.item("Title").value().toString()));
sl = new KSqueezedTextLabel(this);
sl->setText(i18n("Comment: %1", info.item("Comment").value().toString()));
desc.append(i18nc("Bitrate: 160 kbits/s", "Bitrate: %1 %2\n", info.item("Bitrate").value().toString(), info.item("Bitrate").suffix() ));
}
desc.append(i18n("Sample rate: %1 %2\n", info.item("Sample Rate").value().toString(), info.item("Sample Rate").suffix() ));
desc.append(i18n("Length: "));
/* Calculate length in mm:ss format */
int length = info.item("Length").value().toInt();
if (length/60 < 10)
desc.append("0");
desc.append(QString("%1:").arg(length/60, 0, 10));
if (length%60 < 10)
desc.append("0");
desc.append(QString("%1\n").arg(length%60, 0, 10));
}
description = new QLabel(this);
description->setText( desc );
description->adjustSize();
m_player = KServiceTypeTrader::createInstanceFromQuery<KMediaPlayer::Player>( "KMediaPlayer/Player", QString(), this );
if ( m_player )
{
static_cast<KParts::ReadOnlyPart*>(m_player)->openUrl( url );
m_player->widget()->show();
}
}
示例4: dropEvent
void IconApplet::dropEvent(QGraphicsSceneDragDropEvent *event)
{
if (!KUrl::List::canDecode(event->mimeData())) {
return;
}
KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
if (urls.isEmpty()) {
return;
}
event->accept();
if (m_url.isEmpty()) {
setUrl(urls.first());
//TODO: why we don't call updateConstraints()?
constraintsEvent(Plasma::FormFactorConstraint);
return;
} else if (m_service) {
KRun::run(*m_service, urls, 0);
return;
}
KMimeType::Ptr mimetype = KMimeType::findByUrl(m_url);
if (m_url.isLocalFile() &&
((mimetype && (mimetype->is("application/x-executable") ||
mimetype->is("application/x-shellscript"))) ||
KDesktopFile::isDesktopFile(m_url.toLocalFile()))) {
if (KDesktopFile::isDesktopFile(m_url.toLocalFile())) {
//Extract the command from the Desktop file
KService service(m_url.toLocalFile());
KRun::run(service, urls, 0);
return;
}
// Just exec the local executable
QString params;
foreach (const KUrl &url, urls) {
if (url.isLocalFile()) {
params += ' ' + KShell::quoteArg(url.toLocalFile());
} else {
params += ' ' + KShell::quoteArg(url.prettyUrl());
}
}
QString commandStr = KShell::quoteArg(m_url.path());
KRun::runCommand(commandStr + ' ' + params, 0);
} else if (mimetype && mimetype->is("inode/directory")) {
示例5: updateURL
void DolphinView::updateURL()
{
KFileView* fileView = (m_iconsView != 0) ? static_cast<KFileView*>(m_iconsView) :
static_cast<KFileView*>(m_detailsView);
KFileItem* fileItem = fileView->currentFileItem();
if (fileItem == 0) {
return;
}
if (fileItem->isDir()) {
// Prefer the local path over the URL. This assures that the
// volume space information is correct. Assuming that the URL is media:/sda1,
// and the local path is /windows/C: For the URL the space info is related
// to the root partition (and hence wrong) and for the local path the space
// info is related to the windows partition (-> correct).
const QString localPath(fileItem->localPath());
if (localPath.isEmpty()) {
setURL(fileItem->url());
}
else {
setURL(KURL(localPath));
}
}
else if (fileItem->isFile()) {
// allow to browse through ZIP and tar files
KMimeType::Ptr mime = fileItem->mimeTypePtr();
if (mime->is("application/x-zip")) {
KURL url = fileItem->url();
url.setProtocol("zip");
setURL(url);
}
else if (mime->is("application/x-tar") ||
mime->is("application/x-tarz") ||
mime->is("application/x-tbz") ||
mime->is("application/x-tgz") ||
mime->is("application/x-tzo")) {
KURL url = fileItem->url();
url.setProtocol("tar");
setURL(url);
}
else {
fileItem->run();
}
}
else {
fileItem->run();
}
}
示例6: testAlias
void KMimeTypeTest::testAlias()
{
const KMimeType::Ptr canonical = KMimeType::mimeType("application/xml");
QVERIFY(canonical);
KMimeType::Ptr alias = KMimeType::mimeType("text/xml");
QVERIFY(alias);
QCOMPARE(alias->name(), QString("application/xml"));
QVERIFY(alias->is("application/xml"));
QVERIFY(canonical->is("text/xml"));
// Test for bug 197346: does nspluginscan see that audio/mp3 already exists?
bool mustWriteMimeType = !KMimeType::mimeType("audio/mp3");
QVERIFY(!mustWriteMimeType);
}
示例7: testMimeTypeInheritancePerformance
void KMimeTypeTest::testMimeTypeInheritancePerformance()
{
// Check performance of is(). In kde3 the list of mimetypes with previews had 63 items...
// We could get it with KServiceTypeTrader::self()->query("ThumbCreator") and the "MimeTypes"
// property, but this would give variable results and requires other modules installed.
QStringList mimeTypes; mimeTypes << "image/jpeg" << "image/png" << "image/tiff" << "text/plain" << "text/html";
mimeTypes += mimeTypes;
mimeTypes += mimeTypes;
mimeTypes += mimeTypes;
QCOMPARE(mimeTypes.count(), 40);
KMimeType::Ptr mime = KMimeType::mimeType("text/x-chdr");
QVERIFY(mime);
QTime dt; dt.start();
QBENCHMARK {
QString match;
foreach (const QString &mt, mimeTypes)
{
if (mime->is(mt)) {
match = mt;
// of course there would normally be a "break" here, but we're testing worse-case
// performance here
}
}
QCOMPARE(match, QString("text/plain"));
}
// Results on David's machine (April 2009):
// With the KMimeType::is() code that loaded every parent KMimeType:
// 3.5 msec / 7,000,000 ticks / 5,021,498 instr. loads per iteration
// After the QHash for parent mimetypes in ksycoca, removing the need to load full mimetypes:
// 0.57 msec / 1,115,000 ticks / 938,356 instr. loads per iteration
// After converting the QMap for aliases into a QHash too:
// 0.48 msec / 960,000 ticks / 791,404 instr. loads per iteration
// July 2010: After moving KMimeType out of ksycoca:
// 0.21 msec / 494,000 ticks / 568,345 instr. loads per iteration
}
示例8: result
bool Cb7Creator::create( const QString &path, int width, int height, QImage &img )
{
Q_UNUSED(width);
Q_UNUSED(height);
bool result( false );
// Detect mime type.
const KMimeType::Ptr mime = KMimeType::findByFileContent( path );
if ( mime->is( "application/x-cb7" ) || mime->name() == "application/x-7z-compressed" ) {
// 7Z archive.
result = Cb7Creator::extract7zImage( path );
} else {
result = false;
}
if( !m_comicCover || !result ) {
kDebug( KIO_THUMB )<<"Error creating the cb7 thumbnail.";
return false;
}
// Copy the extracted image over to KIO::ThumbCreator's img reference.
img = m_comicCover->copy();
delete m_comicCover;
return result;
}
示例9: mimeComment
QString KFileItem::mimeComment() const
{
const QString displayType = d->m_entry.stringValue( KIO::UDSEntry::UDS_DISPLAY_TYPE );
if (!displayType.isEmpty())
return displayType;
KMimeType::Ptr mType = determineMimeType();
bool isLocalUrl;
KUrl url = mostLocalUrl(isLocalUrl);
KMimeType::Ptr mime = mimeTypePtr();
// This cannot move to kio_file (with UDS_DISPLAY_TYPE) because it needs
// the mimetype to be determined, which is done here, and possibly delayed...
if (isLocalUrl && mime->is("application/x-desktop")) {
KDesktopFile cfg( url.toLocalFile() );
QString comment = cfg.desktopGroup().readEntry( "Comment" );
if (!comment.isEmpty())
return comment;
}
QString comment = mType->comment( url );
//kDebug() << "finding comment for " << url.url() << " : " << d->m_pMimeType->name();
if (!comment.isEmpty())
return comment;
else
return mType->name();
}
示例10: isWantedCollection
bool MimeTypeChecker::isWantedCollection( const Collection &collection, const QString &wantedMimeType )
{
if ( wantedMimeType.isEmpty() || !collection.isValid() )
return false;
const QStringList contentMimeTypes = collection.contentMimeTypes();
if ( contentMimeTypes.isEmpty() )
return false;
foreach ( const QString &mimeType, contentMimeTypes ) {
if ( mimeType.isEmpty() )
continue;
if ( mimeType == wantedMimeType )
return true;
KMimeType::Ptr mimeTypePtr = KMimeType::mimeType( mimeType, KMimeType::ResolveAliases );
if ( mimeTypePtr.isNull() )
continue;
if ( mimeTypePtr->is( wantedMimeType ) )
return true;
}
return false;
}
示例11: iconName
QString KFileItem::iconName() const
{
if (d->m_useIconNameCache && !d->m_iconName.isEmpty()) {
return d->m_iconName;
}
d->m_iconName = d->m_entry.stringValue( KIO::UDSEntry::UDS_ICON_NAME );
if (!d->m_iconName.isEmpty()) {
d->m_useIconNameCache = d->m_bMimeTypeKnown;
return d->m_iconName;
}
bool isLocalUrl;
KUrl url = mostLocalUrl(isLocalUrl);
KMimeType::Ptr mime = mimeTypePtr();
if (isLocalUrl && mime->is("application/x-desktop")) {
d->m_iconName = iconFromDesktopFile(url.toLocalFile());
if (!d->m_iconName.isEmpty()) {
d->m_useIconNameCache = d->m_bMimeTypeKnown;
return d->m_iconName;
}
}
// KDE5: handle .directory files here too, and get rid of
// KFolderMimeType and the url argument in KMimeType::iconName().
d->m_iconName = mime->iconName(url);
d->m_useIconNameCache = d->m_bMimeTypeKnown;
//kDebug() << "finding icon for" << url << ":" << d->m_iconName;
return d->m_iconName;
}
示例12: isFSDirectory
bool Utilities::isFSDirectory(const QString& url)
{
if (!url.isEmpty()) {
KMimeType::Ptr result = KMimeType::findByUrl(KUrl(url), 0, true);
return result->is("inode/directory");
} else {
return false;
}
}
示例13: main
int main(int argc, char **argv) {
static KCmdLineOptions options[] = {
{"show", I18N_NOOP("Show window on startup"), 0},
{"kwalletd", I18N_NOOP("For use by kwalletd only"), 0},
{"+name", I18N_NOOP("A wallet name"), 0},
KCmdLineLastOption
};
KAboutData about("kwalletmanager", I18N_NOOP("KDE Wallet Manager"), "1.1",
I18N_NOOP("KDE Wallet Management Tool"),
KAboutData::License_GPL,
I18N_NOOP("(c) 2003,2004 George Staikos"), 0,
"http://www.kde.org/");
about.addAuthor("George Staikos", I18N_NOOP("Primary author and maintainer"), "[email protected]");
about.addAuthor("Isaac Clerencia", I18N_NOOP("Developer"), "[email protected]");
KCmdLineArgs::init(argc, argv, &about);
KCmdLineArgs::addCmdLineOptions(options);
if (!KUniqueApplication::start()) {
return 0;
}
MyApp a;
KWalletManager wm;
wm.setCaption(i18n("KDE Wallet Manager"));
a.setMainWidget(&wm);
KGlobal::dirs()->addResourceType("kwallet", "share/apps/kwallet");
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
if (args->isSet("show")) {
wm.show();
}
if (args->isSet("kwalletd")) {
wm.kwalletdLaunch();
}
for (int i = 0; i < args->count(); ++i) {
QString fn = QFileInfo(args->arg(i)).absFilePath();
KMimeType::Ptr ptr;
if (QFile::exists(fn) &&
(ptr = KMimeType::findByFileContent(fn)) &&
ptr->is("application/x-kde-wallet")) {
wm.openWalletFile(fn);
} else {
wm.openWallet(args->arg(i));
}
}
args->clear();
return a.exec();
}
示例14: executeStrategy
void KNewFileMenuPrivate::executeStrategy()
{
m_tempFileToDelete = m_copyData.tempFileToDelete();
const QString src = m_copyData.sourceFileToCopy();
QString chosenFileName = expandTilde(m_copyData.chosenFileName(), true);
if (src.isEmpty())
return;
KUrl uSrc(src);
if (uSrc.isLocalFile()) {
// In case the templates/.source directory contains symlinks, resolve
// them to the target files. Fixes bug #149628.
KFileItem item(uSrc, QString(), KFileItem::Unknown);
if (item.isLink())
uSrc.setPath(item.linkDest());
if (!m_copyData.m_isSymlink) {
// If the file is not going to be detected as a desktop file, due to a
// known extension (e.g. ".pl"), append ".desktop". #224142.
QFile srcFile(uSrc.toLocalFile());
if (srcFile.open(QIODevice::ReadOnly)) {
KMimeType::Ptr wantedMime = KMimeType::findByUrl(uSrc);
KMimeType::Ptr mime = KMimeType::findByNameAndContent(m_copyData.m_chosenFileName, srcFile.read(1024));
//kDebug() << "mime=" << mime->name() << "wantedMime=" << wantedMime->name();
if (!mime->is(wantedMime->name()))
chosenFileName += wantedMime->mainExtension();
}
}
}
// The template is not a desktop file [or it's a URL one]
// Copy it.
KUrl::List::const_iterator it = m_popupFiles.constBegin();
for (; it != m_popupFiles.constEnd(); ++it)
{
KUrl dest(*it);
dest.addPath(KIO::encodeFileName(chosenFileName));
KUrl::List lstSrc;
lstSrc.append(uSrc);
KIO::Job* kjob;
if (m_copyData.m_isSymlink) {
kjob = KIO::symlink(src, dest);
// This doesn't work, FileUndoManager registers new links in copyingLinkDone,
// which KIO::symlink obviously doesn't emit... Needs code in FileUndoManager.
//KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Link, lstSrc, dest, kjob);
} else {
//kDebug(1203) << "KIO::copyAs(" << uSrc.url() << "," << dest.url() << ")";
KIO::CopyJob * job = KIO::copyAs(uSrc, dest);
job->setDefaultPermissions(true);
kjob = job;
KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Copy, lstSrc, dest, job);
}
kjob->ui()->setWindow(m_parentWidget);
QObject::connect(kjob, SIGNAL(result(KJob*)), q, SLOT(slotResult(KJob*)));
}
}
示例15: isPls
bool Utilities::isPls(const QString &url)
{
if (!url.isEmpty()) {
KMimeType::Ptr result = KMimeType::findByUrl(KUrl(url), 0, true);
return result->is("audio/x-scpls");
} else {
return false;
}
}