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`. } } }
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 }
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; }
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()); }
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(); }
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() ) ); }
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")); }
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); }
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")); }
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)); }
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(); } }
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() ); }
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()); }
// 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.")); }
//=========================================================== // 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")); }
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(); }
QString saveFile(KoDocument *document, const QString &filename, const QString &outname) { QString saveAs = outname; // use the name and add -roundtrip if (outname.isEmpty()) { saveAs = filename; int dotPos = saveAs.lastIndexOf('.'); if (dotPos != -1) { saveAs.truncate(dotPos); } saveAs += "-roundtrip"; } QByteArray mimetype = document->nativeFormatMimeType(); KMimeType::Ptr mime = KMimeType::mimeType(mimetype); Q_ASSERT(mime); QString extension = mime->mainExtension(); saveAs += extension; KUrl url; url.setPath(saveAs); document->setOutputMimeType(mimetype, 0); document->saveAs(url); kDebug(31000) << "save done"; return saveAs; }
bool MPForm::addFile(const QString& name, const QString& path) { KMimeType::Ptr ptr = KMimeType::findByUrl(path); QString mime = ptr->name(); if (mime.isEmpty()) return false; QFile imageFile(path); if (!imageFile.open(QIODevice::ReadOnly)) return false; QByteArray imageData = imageFile.readAll(); //QString file_size = QString::number(imageFile.size()); imageFile.close(); QByteArray str; str += "--"; str += m_boundary; str += "\r\n"; str += "Content-Disposition: form-data; filename=\""; str += QFile::encodeName(name); str += "\"\r\n"; //str += "Content-Length: "; //str += file_size.toAscii(); //str += "\r\n"; str += "Content-Type: "; str += mime.toAscii(); str += "\r\n\r\n"; m_buffer.append(str); m_buffer.append(imageData); m_buffer.append("\r\n"); return true; }
// at first, tries to find the iconname in the cache // if not available, tries to find the pixmap for the mimetype of url // if that fails, gets the icon for the protocol // finally, inserts the url/icon pair into the cache QString KonqPixmapProvider::iconNameFor( const KUrl& url ) { QMap<KUrl,QString>::iterator it = iconMap.find( url ); QString icon; if ( it != iconMap.end() ) { icon = it.value(); if ( !icon.isEmpty() ) return icon; } if ( url.url().isEmpty() ) { // Use the folder icon for the empty URL const KMimeType::Ptr directoryType = KMimeType::mimeType( "inode/directory" ); if( directoryType.isNull() ) // no mimetypes installed! return QString(); icon = directoryType->iconName(); Q_ASSERT( !icon.isEmpty() ); } else { icon = KMimeType::iconNameForUrl( url ); Q_ASSERT( !icon.isEmpty() ); } // cache the icon found for url iconMap.insert( url, icon ); return icon; }
bool Script::execute() { if (!bt::Exists(file) || action) return false; KMimeType::Ptr mt = KMimeType::findByPath(file); QString name = QFileInfo(file).fileName(); action = new Kross::Action(this,name); action->setText(name); action->setDescription(name); action->setFile(file); action->setIconName(mt->iconName()); QString interpreter = Kross::Manager::self().interpreternameForFile(file); if (interpreter.isNull()) { delete action; action = 0; return false; } else { action->setInterpreter(interpreter); Kross::Manager::self().actionCollection()->addAction(file,action); action->trigger(); executing = true; return true; } }
QString KoOdfCollectionLoader::findMimeTypeByUrl(const KUrl& url) { // // The following code was copied from KoDocument::openFile() // QString typeName = KMimeType::findByUrl(url, 0, true)->name(); // Allow to open backup files, don't keep the mimetype application/x-trash. if (typeName == "application/x-trash") { QString path = url.path(); KMimeType::Ptr mime = KMimeType::mimeType(typeName); QStringList patterns = mime ? mime->patterns() : QStringList(); // Find the extension that makes it a backup file, and remove it for(QStringList::Iterator it = patterns.begin(); it != patterns.end(); ++it) { QString ext = *it; if (!ext.isEmpty() && ext[0] == '*') { ext.remove(0, 1); if (path.endsWith(ext)) { path.truncate(path.length() - ext.length()); break; } } } typeName = KMimeType::findByPath(path, 0, true)->name(); } return typeName; }
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; }
void DownloadAndConvertJob::downloadFileFinished(KJob* j) { active_job = 0; if (j->error()) { Out(SYS_IPF|LOG_NOTICE) << "IP filter update failed: " << j->errorString() << endl; if (mode == Verbose) { ((KIO::Job*)j)->ui()->showErrorMessage(); } else { QString msg = i18n("Automatic update of IP filter failed: %1", j->errorString()); notification(msg); } setError(DOWNLOAD_FAILED); emitResult(); return; } QString temp = kt::DataDir() + "tmp-" + url.fileName(); //now determine if it's ZIP or TXT file KMimeType::Ptr ptr = KMimeType::findByPath(temp); if (ptr->name() == "application/zip") { active_job = KIO::file_move(temp,QString(kt::DataDir() + QLatin1String("level1.zip")),-1,KIO::HideProgressInfo|KIO::Overwrite); connect(active_job,SIGNAL(result(KJob*)),this,SLOT(extract(KJob*))); }
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; }
static KMimeType::Ptr fixupMimeType (const QString& mimeType, const QString& fileName) { KMimeType::Ptr mime = KMimeType::mimeType(mimeType, KMimeType::ResolveAliases); if ((!mime || mime->isDefault()) && !fileName.isEmpty()) { mime = KMimeType::findByUrl(fileName, 0, false, true); } return mime; }
STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi) { TCHAR szFileUserClickedOn[MAX_PATH]; TCHAR dllPath[MAX_PATH]; QString command; FORMATETC fmte = { CF_HDROP, (DVTARGETDEVICE FAR *)NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; GetModuleFileName(_hModule, dllPath, MAX_PATH); QString module = lptstr2QString(dllPath); command += module.left(module.lastIndexOf('\\')); command += '\\'; for (unsigned i = 0; i < m_cbFiles; i++) { DragQueryFile((HDROP)m_stgMedium.hGlobal, i, szFileUserClickedOn, MAX_PATH); QString path = lptstr2QString(szFileUserClickedOn); if(0 == i) { KMimeType::Ptr ptr = KMimeType::findByPath(path); KService::List lst = KMimeTypeTrader::self()->query(ptr->name(), "Application"); if(lst.size() > 0) { QString exec = lst.at(0)->exec(); if( -1 != exec.indexOf("%u", 0, Qt::CaseInsensitive) ) { exec = exec.left(exec.indexOf("%u", 0, Qt::CaseInsensitive)); } command += exec; } }; command += "\"" + path + "\""; } STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_RESTORE; if (!CreateProcess(NULL, (LPTSTR)command.utf16(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { MessageBox(lpcmi->hwnd, TEXT("Error creating process: kdecm.dll needs to be in the same directory as the executable"), TEXT("KDE Extension"), MB_OK); } return NOERROR; }
void DocumentPreviewTab::setResource(Nepomuk2::Resource & resource) { m_resource = resource; ui->urlSelector->clear(); if(m_part) { m_part->closeUrl(); } QString specificUrl; if(resource.isValid()) { specificUrl = resource.property(Nepomuk2::Vocabulary::NIE::url()).toString(); if(!specificUrl.isEmpty()) { resource = resource.property(Nepomuk2::Vocabulary::NBIB::publishedAs()).toResource(); m_resource = resource; } QList<Nepomuk2::Resource> fileList; if(resource.hasType(Nepomuk2::Vocabulary::NBIB::Reference())) { Nepomuk2::Resource publication = resource.property(Nepomuk2::Vocabulary::NBIB::publication()).toResource(); fileList = publication.property(Nepomuk2::Vocabulary::NBIB::isPublicationOf()).toResourceList(); fileList.append( publication.property(Nepomuk2::Vocabulary::NIE::links()).toResourceList() ); } else if(resource.hasType(Nepomuk2::Vocabulary::NBIB::Publication())) { fileList = resource.property(Nepomuk2::Vocabulary::NBIB::isPublicationOf()).toResourceList(); fileList.append( resource.property(Nepomuk2::Vocabulary::NIE::links()).toResourceList() ); } else { fileList.append(resource); } // add all DataObjects to the preview foreach(const Nepomuk2::Resource & r, fileList) { KUrl url = KUrl(r.property(Nepomuk2::Vocabulary::NIE::url()).toString()); KIcon icon; QString mimetype; if( r.hasType(Nepomuk2::Vocabulary::NFO::Website())// || r.hasType(Nepomuk2::Vocabulary::NFO::WebDataObject()) || url.scheme() == QLatin1String("http")) { QString favIcon = KMimeType::favIconForUrl(url); if(favIcon.isEmpty()) { favIcon = QLatin1String("text-html"); } icon = KIcon(favIcon); mimetype = QLatin1String("text/html"); } else { KMimeType::Ptr mimeTypePtr = KMimeType::findByUrl(url); icon = KIcon(mimeTypePtr->iconName()); mimetype = mimeTypePtr->name(); } ui->urlSelector->addItem(icon,url.url(),QVariant(mimetype)); }
bool GalleryMPForm::addFile(const QString& path, const QString& displayFilename) { QString filename = "userfile_name"; if (GalleryTalker::isGallery2()) filename = "g2_userfile_name"; if (!addPairRaw(filename, displayFilename)) { return false; } KMimeType::Ptr ptr = KMimeType::findByUrl(path); QString mime = ptr->name(); if (mime.isEmpty()) { // if we ourselves can't determine the mime of the local file, // very unlikely the remote gallery will be able to identify it return false; } QFile imageFile(path); if (!imageFile.open(QIODevice::ReadOnly)) return false; QByteArray imageData = imageFile.readAll(); imageFile.close(); QString str; str += "--"; str += m_boundary; str += "\r\n"; str += "Content-Disposition: form-data; name=\""; if (GalleryTalker::isGallery2()) str += "g2_userfile"; else str += "userfile"; str += "\"; "; str += "filename=\""; str += QFile::encodeName(KUrl(path).fileName()); str += "\""; str += "\r\n"; str += "Content-Type: "; str += mime.toAscii(); str += "\r\n\r\n"; m_buffer.append(str.toUtf8()); int oldSize = m_buffer.size(); m_buffer.resize(oldSize + imageData.size() + 2); memcpy(m_buffer.data() + oldSize, imageData.data(), imageData.size()); m_buffer[m_buffer.size()-2] = '\r'; m_buffer[m_buffer.size()-1] = '\n'; return true; }
KIcon iconForContent( KMime::Content *content ) { if ( !content->contentType( false ) ) return KIcon(); KMimeType::Ptr mimeType = KMimeType::mimeType( QString::fromLatin1( content->contentType()->mimeType() ) ); if ( mimeType.isNull() || mimeType->iconName().isEmpty() ) return KIcon(); return KIcon( mimeType->iconName() ); }
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*))); } }