本文整理汇总了C++中kmimetype::Ptr类的典型用法代码示例。如果您正苦于以下问题:C++ Ptr类的具体用法?C++ Ptr怎么用?C++ Ptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testAllMimeTypes
void KMimeTypeTest::testAllMimeTypes()
{
const KMimeType::List lst = KMimeType::allMimeTypes(); // does NOT include aliases
QVERIFY(!lst.isEmpty());
for (KMimeType::List::ConstIterator it = lst.begin();
it != lst.end(); ++it) {
const KMimeType::Ptr mime = (*it);
const QString name = mime->name();
//qDebug( "%s", qPrintable( name ) );
QVERIFY(!name.isEmpty());
QCOMPARE(name.count('/'), 1);
const KMimeType::Ptr lookedupMime = KMimeType::mimeType(name);
QVERIFY(lookedupMime); // not null
if (name != "application/vnd.ms-word" && name != "application/x-pkcs7-certificates"
&& name != "application/x-x509-ca-cert"
&& name != "application/x-vnd.kde.kexi" // due to /usr/share/mime/packages/kde.xml from KDE4
&& name != "application/x-kexiproject-sqlite" // due to /usr/share/mime/packages/kde.xml from KDE4
&& name != "application/vnd.sun.xml.base" // libreoffice.xml messing things up yet again
) {
QCOMPARE(lookedupMime->name(), name);
// if this fails, you have an alias defined as a real mimetype too!
//
// Note: this also happens with x-win-lnk when your kde.xml defines it as an alias, while
// /usr/share/mime/packages/kde.xml defines it as a real mimetype. This is a false positive,
// remove one of the kde.xml files.
//
// It also happens with application/x-pkcs7-certificates due to
// /usr/share/mime/packages/gcr-crypto-types.xml. Remove that file and run
// `update-mime-database /usr/share/mime`.
}
}
}
示例2: 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
}
示例3: 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;
}
示例4: testByName
void KMimeTypeTest::testByName()
{
KMimeType::Ptr s0 = KMimeType::mimeType("application/x-zerosize");
QVERIFY(s0);
QCOMPARE(s0->name(), QString::fromLatin1("application/x-zerosize"));
QCOMPARE(s0->comment(), QString::fromLatin1("empty document"));
KMimeType::Ptr s0Again = KMimeType::mimeType("application/x-zerosize");
QCOMPARE(s0Again->name(), s0->name());
QVERIFY(s0Again != s0);
KMimeType::Ptr s1 = KMimeType::mimeType("text/plain");
QVERIFY(s1);
QCOMPARE(s1->name(), QString::fromLatin1("text/plain"));
//qDebug("Comment is %s", qPrintable(s1->comment()) );
KMimeType::Ptr krita = KMimeType::mimeType("application/x-krita");
QVERIFY(krita);
// Test <comment> parsing with application/rdf+xml which has the english comment after the other ones
KMimeType::Ptr rdf = KMimeType::mimeType("application/rdf+xml");
QVERIFY(rdf);
QCOMPARE(rdf->comment(), QString::fromLatin1("RDF file"));
KMimeType::Ptr bzip2 = KMimeType::mimeType("application/x-bzip2");
QVERIFY(bzip2);
QCOMPARE(bzip2->comment(), QString::fromLatin1("Bzip archive"));
KMimeType::Ptr defaultMime = KMimeType::mimeType("application/octet-stream");
QVERIFY(defaultMime);
QVERIFY(defaultMime->isDefault());
}
示例5: setData
void BinaryWidget::setData( const QByteArray &data )
{
delete mMainWidget;
QString mimetype;
KMimeType::Ptr mime = KMimeType::findByContent( data );
if ( mime && !mime->isDefault() )
mimetype = mime->name();
if ( !mimetype.isEmpty() ) {
KParts::ReadOnlyPart *part = KParts::ComponentFactory::createPartInstanceFromQuery<KParts::ReadOnlyPart>( mimetype, QString(), this, this );
if ( part ) {
KTemporaryFile file;
file.setAutoRemove(false);
file.open();
file.write( data );
file.flush();
part->openUrl( KUrl( file.fileName() ) );
mMainWidget = part->widget();
} else {
mMainWidget = new QLabel( i18n( "No part found for visualization of mimetype %1", mimetype ), this );
}
mData = data;
mSaveButton->setEnabled( true );
} else {
mMainWidget = new QLabel( i18n( "Got data of unknown mimetype" ), this );
}
mLayout->addWidget( mMainWidget, 0, 0, 3, 1);
mMainWidget->show();
}
示例6: matchingMimeActions
void URLGrabber::matchingMimeActions(const QString& clipData)
{
KUrl url(clipData);
KConfigGroup cg(KGlobal::config(), "Actions");
if(!cg.readEntry("EnableMagicMimeActions",true)) {
//kDebug() << "skipping mime magic due to configuration";
return;
}
if(!url.isValid()) {
//kDebug() << "skipping mime magic due to invalid url";
return;
}
if(url.isRelative()) { //openinng a relative path will just not work. what path should be used?
//kDebug() << "skipping mime magic due to relative url";
return;
}
if(url.isLocalFile()) {
if ( clipData == "//") {
//kDebug() << "skipping mime magic due to C++ comment //";
return;
}
if(!QFile::exists(url.toLocalFile())) {
//kDebug() << "skipping mime magic due to nonexistent localfile";
return;
}
}
// try to figure out if clipData contains a filename
KMimeType::Ptr mimetype = KMimeType::findByUrl( url, 0,
false,
true /*fast mode*/ );
// let's see if we found some reasonable mimetype.
// If we do we'll populate menu with actions for apps
// that can handle that mimetype
// first: if clipboard contents starts with http, let's assume it's "text/html".
// That is even if we've url like "http://www.kde.org/somescript.pl", we'll
// still treat that as html page, because determining a mimetype using kio
// might take a long time, and i want this function to be quick!
if ( ( clipData.startsWith( QLatin1String("http://") ) || clipData.startsWith( QLatin1String("https://") ) )
&& mimetype->name() != "text/html" )
{
// use a fake path to create a mimetype that corresponds to "text/html"
mimetype = KMimeType::findByPath( "/tmp/klipper.html", 0, true /*fast mode*/ );
}
if ( !mimetype->isDefault() ) {
ClipAction* action = new ClipAction( QString(), mimetype->comment() );
KService::List lst = KMimeTypeTrader::self()->query( mimetype->name(), "Application" );
foreach( const KService::Ptr &service, lst ) {
QHash<QChar,QString> map;
map.insert( 'i', "--icon " + service->icon() );
map.insert( 'c', service->name() );
QString exec = service->exec();
exec = KMacroExpander::expandMacros( exec, map ).trimmed();
action->addCommand( ClipCommand( exec, service->name(), true, service->icon() ) );
}
示例7: testFromThread
void KMimeTypeTest::testFromThread()
{
// Some simple tests to test more API from testThreads without using _data()
KMimeType::Ptr mime = KMimeType::mimeType("application/pdf");
QVERIFY(mime);
QCOMPARE(mime->mainExtension(), QString::fromLatin1(".pdf"));
}
示例8: testPatterns
void KMimeTypeTest::testPatterns()
{
QFETCH(QString, mimeType);
QFETCH(QString, patterns);
QFETCH(QString, mainExtension);
KMimeType::Ptr mime = KMimeType::mimeType( mimeType );
QVERIFY(mime);
// Sort both lists; order is unreliable since shared-mime-info uses hashes internally.
QStringList expectedPatterns = patterns.split(';');
expectedPatterns.sort();
QStringList mimePatterns = mime->patterns();
if (mimeType == "application/vnd.oasis.opendocument.text" && mimePatterns.contains("*.fodt")) {
QSKIP("Skipping test which would fail due to an upstream bug, see https://bugs.freedesktop.org/show_bug.cgi?id=31242", SkipSingle);
}
if (mimeType == "application/vnd.oasis.opendocument.presentation" && mimePatterns.contains("*.fodp")) {
QSKIP("Skipping test which would fail due to an upstream bug, see https://bugs.freedesktop.org/show_bug.cgi?id=31242", SkipSingle);
}
// shared-mime-info 0.30 adds *,v to text/plain, let's add it from this test so that it works
// with older versions too.
if (mimeType == "text/plain" && !mimePatterns.contains("*,v"))
mimePatterns.append("*,v");
mimePatterns.sort();
QCOMPARE(mimePatterns.join(";"), expectedPatterns.join(";"));
QCOMPARE(mime->mainExtension(), mainExtension);
}
示例9: testFindByUrl
void KMimeTypeTest::testFindByUrl()
{
// Tests with local files are already done in testFindByPath,
// here we test for remote urls only.
KMimeType::Ptr mime;
QVERIFY( KProtocolInfo::isKnownProtocol(KUrl("http:/")) );
QVERIFY( KProtocolInfo::isKnownProtocol(KUrl("file:/")) );
mime = KMimeType::findByUrl( KUrl("http://foo/bar.png") );
QVERIFY( mime );
QCOMPARE( mime->name(), QString::fromLatin1( "application/octet-stream" ) ); // HTTP can't know before downloading
if ( !KProtocolInfo::isKnownProtocol(KUrl("man:/")) )
QSKIP( "man protocol not installed", SkipSingle );
mime = KMimeType::findByUrl( KUrl("man:/ls") );
QVERIFY( mime );
QCOMPARE( mime->name(), QString::fromLatin1("text/html") );
mime = KMimeType::findByUrl( KUrl("man:/ls/") );
QVERIFY( mime );
QCOMPARE( mime->name(), QString::fromLatin1("text/html") );
mime = KMimeType::findByUrl(KUrl("fish://host/test1")); // like fish does, to test for known extensions
QVERIFY(mime);
QCOMPARE(mime->name(), QString::fromLatin1("application/octet-stream"));
}
示例10: testPatterns
void KMimeTypeTest::testPatterns()
{
QFETCH(QString, mimeType);
QFETCH(QString, patterns);
QFETCH(QString, mainExtension);
KMimeType::Ptr mime = KMimeType::mimeType(mimeType);
QVERIFY(mime);
// Sort both lists; order is unreliable since shared-mime-info uses hashes internally.
QStringList expectedPatterns = patterns.split(';', QString::SkipEmptyParts);
expectedPatterns.sort();
QStringList mimePatterns = mime->patterns();
if (mimeType == "application/vnd.oasis.opendocument.text" && mimePatterns.contains("*.fodt")) {
QSKIP("Skipping test which would fail due to an upstream bug, see https://bugs.freedesktop.org/show_bug.cgi?id=31242");
}
if (mimeType == "application/vnd.oasis.opendocument.presentation" && mimePatterns.contains("*.fodp")) {
QSKIP("Skipping test which would fail due to an upstream bug, see https://bugs.freedesktop.org/show_bug.cgi?id=31242");
}
// shared-mime-info 0.30 adds *,v to text/plain, let's add it from this test so that it works
// with older versions too.
if (mimeType == "text/plain" && !mimePatterns.contains("*,v")) {
mimePatterns.append("*,v");
}
mimePatterns.sort();
// Not robust enough, other packages can add additional patterns, like libfm.xml adds *.inf to text/plain
//QCOMPARE(mimePatterns.join(";"), expectedPatterns.join(";"));
Q_FOREACH (const QString &expected, expectedPatterns) {
QVERIFY2(mimePatterns.contains(expected), qPrintable(mimeType + " did not have pattern " + expected));
}
示例11: 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
KMimeType::Ptr pMime = KMimeType::findByUrl(itm->url());
if(pMime->name().startsWith("text/")) {
emit(fileSelected(itm->url()));
}
else {
KRun::runUrl(itm->url(), pMime->name(), this);
}
}
}
clearSelection();
}
}
示例12: readAttachment
void readAttachment()
{
if ( mAttachment->label().isEmpty() ) {
if ( mAttachment->isUri() ) {
setText( mAttachment->uri() );
} else {
setText( i18nc( "@label attachment contains binary data", "[Binary data]" ) );
}
} else {
setText( mAttachment->label() );
}
setRenameEnabled( true );
if ( mAttachment->mimeType().isEmpty() ||
!( KMimeType::mimeType( mAttachment->mimeType() ) ) ) {
KMimeType::Ptr mimeType;
if ( mAttachment->isUri() ) {
mimeType = KMimeType::findByUrl( mAttachment->uri() );
} else {
mimeType = KMimeType::findByContent( mAttachment->decodedData() );
}
mAttachment->setMimeType( mimeType->name() );
}
setPixmap( icon() );
}
示例13: slotFixOpenWithMenu
void KateFileTree::slotFixOpenWithMenu()
{
QMenu *menu = (QMenu*)sender();
menu->clear();
KTextEditor::Document *doc = model()->data(m_indexContextMenu, KateFileTreeModel::DocumentRole).value<KTextEditor::Document *>();
if (!doc) return;
// get a list of appropriate services.
KMimeType::Ptr mime = KMimeType::mimeType(doc->mimeType());
//kDebug(13001) << "mime type: " << mime->name();
QAction *a = 0;
KService::List offers = KMimeTypeTrader::self()->query(mime->name(), "Application");
// for each one, insert a menu item...
for(KService::List::Iterator it = offers.begin(); it != offers.end(); ++it)
{
KService::Ptr service = *it;
if (service->name() == "Kate") continue;
a = menu->addAction(KIcon(service->icon()), service->name());
a->setData(service->entryPath());
}
// append "Other..." to call the KDE "open with" dialog.
a = menu->addAction(i18n("&Other..."));
a->setData(QString());
}
示例14: notifyFinished
// This can happen after openUrl returns, or directly from m_image->ref()
void KHTMLImage::notifyFinished( khtml::CachedObject *o )
{
if ( !m_image || o != m_image )
return;
//const QPixmap &pix = m_image->pixmap();
QString caption;
KMimeType::Ptr mimeType;
if ( !m_mimeType.isEmpty() )
mimeType = KMimeType::mimeType(m_mimeType, KMimeType::ResolveAliases);
if ( mimeType ) {
if ( !m_image->suggestedTitle().isEmpty() ) {
caption = i18n( "%1 (%2 - %3x%4 Pixels)", m_image->suggestedTitle(), mimeType->comment(), m_image->pixmap_size().width(), m_image->pixmap_size().height() );
} else {
caption = i18n( "%1 - %2x%3 Pixels" , mimeType->comment() ,
m_image->pixmap_size().width() , m_image->pixmap_size().height() );
}
} else {
if ( !m_image->suggestedTitle().isEmpty() ) {
caption = i18n( "%1 (%2x%3 Pixels)" , m_image->suggestedTitle(), m_image->pixmap_size().width() , m_image->pixmap_size().height() );
} else {
caption = i18n( "Image - %1x%2 Pixels" , m_image->pixmap_size().width() , m_image->pixmap_size().height() );
}
}
emit setWindowCaption( caption );
emit completed();
emit setStatusBarText(i18n("Done."));
}
示例15: setupIntro
//===========================================================
//
void ImportWizard::setupIntro()
{
m_introPage = new QWidget(this);
QVBoxLayout *vbox = new QVBoxLayout(m_introPage, KDialog::marginHint());
QLabel *lblIntro = new QLabel(m_introPage);
lblIntro->setAlignment( Qt::AlignTop | Qt::AlignLeft | Qt::WordBreak );
QString msg;
if (m_predefinedConnectionData) { //predefined import: server source
msg = i18n("<qt>Database Importing wizard is about to import \"%1\" database "
"<nobr>(connection %2)</nobr> into a Kexi database.</qt>")
.arg(m_predefinedDatabaseName).arg(m_predefinedConnectionData->serverInfoString());
}
else if (!m_predefinedDatabaseName.isEmpty()) { //predefined import: file source
//! @todo this message is currently ok for files only
KMimeType::Ptr mimeTypePtr = KMimeType::mimeType(m_predefinedMimeType);
msg = i18n("<qt>Database Importing wizard is about to import <nobr>\"%1\"</nobr> file "
"of type \"%2\" into a Kexi database.</qt>")
.arg(QDir::convertSeparators(m_predefinedDatabaseName)).arg(mimeTypePtr->comment());
}
else {
msg = i18n("Database Importing wizard allows you to import an existing database "
"into a Kexi database.");
}
lblIntro->setText(msg+"\n\n"
+i18n("Click \"Next\" button to continue or \"Cancel\" button to exit this wizard."));
vbox->addWidget( lblIntro );
addPage(m_introPage, i18n("Welcome to the Database Importing Wizard"));
}