本文整理汇总了C++中QMimeType类的典型用法代码示例。如果您正苦于以下问题:C++ QMimeType类的具体用法?C++ QMimeType怎么用?C++ QMimeType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QMimeType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: foreach
void FolderListModel::readDirectory()
{
this->beginResetModel();
QFileInfoList fileinfolist = this->_directory.entryInfoList(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks, QDir::DirsFirst);
if(!this->_mimefilter.isEmpty())
{
QMimeDatabase mimedb;
QStringList mimefilter = this->_mimefilter.split("/");
this->_files.clear();
foreach(const QFileInfo& fi, fileinfolist)
{
if(fi.isDir())
{
this->_files.append(fi);
continue;
}
QMimeType mime = mimedb.mimeTypeForFile(fi.filePath());
QStringList mimestring = mime.name().split("/");
if(mimefilter[0] != mimestring[0])
continue;
if((mimefilter.length() > 1) && mimefilter[1] != mimestring[1])
continue;
this->_files.append(fi);
}
}
示例2: QVariant
QVariant MessageComposer::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.column() != 0 || index.row() < 0 || index.row() >= m_attachments.size())
return QVariant();
switch (role) {
case Qt::DisplayRole:
return m_attachments[index.row()]->caption();
case Qt::ToolTipRole:
return m_attachments[index.row()]->tooltip();
case Qt::DecorationRole:
{
// This is more or less copy-pasted from Gui/AttachmentView.cpp. Unfortunately, sharing the implementation
// is not trivial due to the way how the static libraries are currently built.
QMimeType mimeType = QMimeDatabase().mimeTypeForName(QString::fromUtf8(m_attachments[index.row()]->mimeType()));
if (mimeType.isValid() && !mimeType.isDefault()) {
return QIcon::fromTheme(mimeType.iconName(), UiUtils::loadIcon(QStringLiteral("mail-attachment")));
} else {
return UiUtils::loadIcon(QStringLiteral("mail-attachment"));
}
}
case Imap::Mailbox::RoleAttachmentContentDispositionMode:
return static_cast<int>(m_attachments[index.row()]->contentDispositionMode());
}
return QVariant();
}
示例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: QLatin1String
void tst_QMimeDatabase::inheritsPerformance()
{
// Check performance of inherits().
// This benchmark (which started in 2009 in kmimetypetest.cpp) uses 40 mimetypes.
QStringList mimeTypes;
mimeTypes << QLatin1String("image/jpeg") << QLatin1String("image/png") << QLatin1String("image/tiff") << QLatin1String("text/plain") << QLatin1String("text/html");
mimeTypes += mimeTypes;
mimeTypes += mimeTypes;
mimeTypes += mimeTypes;
QCOMPARE(mimeTypes.count(), 40);
QMimeDatabase db;
QMimeType mime = db.mimeTypeForName(QString::fromLatin1("text/x-chdr"));
QVERIFY(mime.isValid());
QBENCHMARK {
QString match;
foreach (const QString &mt, mimeTypes) {
if (mime.inherits(mt)) {
match = mt;
// of course there would normally be a "break" here, but we're testing worse-case
// performance here
}
}
QCOMPARE(match, QString::fromLatin1("text/plain"));
}
// Numbers from 2011, in release mode:
// KDE 4.7 numbers: 0.21 msec / 494,000 ticks / 568,345 instr. loads per iteration
// QMimeBinaryProvider (with Qt 5): 0.16 msec / NA / 416,049 instr. reads per iteration
// QMimeXmlProvider (with Qt 5): 0.062 msec / NA / 172,889 instr. reads per iteration
// (but the startup time is way higher)
// And memory usage is flat at 200K with QMimeBinaryProvider, while it peaks at 6 MB when
// parsing XML, and then keeps being around 4.5 MB for all the in-memory hashes.
}
示例5: currentItem
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();
}
}
示例6: setEndPoint
QNetworkReply* Parse::uploadFileData(QByteArray data, QString name)
{
if (!isReady() || data.isEmpty()) return NULL;
if (name.isEmpty()) {
// compute name from content
}
setEndPoint( "files/"+name);
QMimeDatabase db;
QMimeType mime = db.mimeTypeForData(data);
initHeaders();
setHeader(QNetworkRequest::ContentTypeHeader, mime.name().toUtf8());
m_conn = connect(this, &BaaS::replyFinished, [=]( QJsonDocument json){
disconnect(m_conn);
if ( getHttpCode() == 201 ){
currentObject = json.object();
// Create fileLit object
QString mainObj = "{\"url\": \""+currentObject.value("url").toString()+
"\",\"file\": {\"name\": \""+currentObject.value("name").toString()+
",\"__type\": \"File\"}}";
setEndPoint("classes/FilesList");
create( mainObj);
emit fileUploaded( currentObject);
}
} );
return request( BaaS::POST, data );
}
示例7: documentType
int Global::documentType(const QUrl& document)
{
QMimeType mime = QMimeDatabase{}.mimeTypeForUrl(document);
QList<QPluginLoader*> plugins = KoJsonTrader::self()->query("Calligra/Part", mime.name());
for (int i = 0; i < plugins.count(); i++) {
QPluginLoader* loader = plugins.at(i);
if(loader->fileName().contains("words")) {
return DocumentType::TextDocument;
} else if(loader->fileName().contains("sheets")) {
return DocumentType::Spreadsheet;
} else if(loader->fileName().contains("stage")) {
return DocumentType::Presentation;
}
}
// Since we don't actually have a Calligra plugin that handles these...
if(staticTextTypes.contains(mime.name())) {
return DocumentType::StaticTextDocument;
}
return DocumentType::Unknown;
}
示例8: foreach
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;
}
QMimeDatabase db;
const QMimeType mt = db.mimeTypeForName(mimeType);
if (!mt.isValid()) {
continue;
}
if (mt.inherits(wantedMimeType)) {
return true;
}
}
return false;
}
示例9: mimeType
QString AnimationResult::mimeType()
{
QMimeDatabase db;
QMimeType type = db.mimeTypeForUrl(d->url);
return type.name();
}
示例10: loadMedia
void MainWindow::loadMedia(){
// mime database to detect file type
QMimeDatabase db;
// the mime type (to test if it is an audio file
QMimeType type;
// file list to be inserted into playlist
QStringList filelist;
// audio file to be opened
QFileDialog d;
filelist = d.getOpenFileNames(this,tr("Open File"),
"/home",
tr("Audio (*.wav *.mp3 *.ogg *.flac)"));
// retrieve mime type
for(QList<QString>::const_iterator it=filelist.begin(); it!= filelist.end(); it++){
type = db.mimeTypeForFile(*it);
// test if the file is an audio file
// if yes, send it to the playlist
if(type.name().startsWith("audio")){
playlist->addMedia(QUrl::fromLocalFile(*it));
}
}
}
示例11: QObject
EditWithMenu::EditWithMenu(const QUrl& url, QWidget* parent)
: QObject(parent)
, m_menu(0)
, m_url(url)
{
QMimeDatabase db;
QMimeType type = db.mimeTypeForFile(url.path(), QMimeDatabase::MatchExtension);
if ( !type.isValid() )
{
qCDebug(log_cervisia) << "Couldn't find mime type!";
return;
}
m_offers = KMimeTypeTrader::self()->query(type.name());
if( !m_offers.isEmpty() )
{
m_menu = new QMenu(i18n("Edit With"));
KService::List::ConstIterator it = m_offers.constBegin();
for( int i = 0 ; it != m_offers.constEnd(); ++it, ++i )
{
QAction* pAction = m_menu->addAction(QIcon::fromTheme((*it)->icon()), (*it)->name());
pAction->setData(i);
}
connect(m_menu, SIGNAL(triggered(QAction*)),
this, SLOT(actionTriggered(QAction*)));
}
示例12: QMimeDatabase
Vector<String> MIMETypeRegistry::getExtensionsForMIMEType(const String& mimeTypeName)
{
Vector<String> extensions;
QMimeType mimeType = QMimeDatabase().mimeTypeForName(mimeTypeName);
if (mimeType.isValid() && !mimeType.isDefault()) {
Q_FOREACH(const QString& suffix, mimeType.suffixes()) {
extensions.append(suffix);
}
}
示例13: magicSetType
void NodeHelper::magicSetType(KMime::Content *node, bool aAutoDecode)
{
const QByteArray body = (aAutoDecode) ? node->decodedContent() : node->body();
QMimeDatabase db;
QMimeType mime = db.mimeTypeForData(body);
QString mimetype = mime.name();
node->contentType()->setMimeType(mimetype.toLatin1());
}
示例14: openUrl
void openUrl() {
if (urlToOpen.isValid()) {
/// Guess mime type for url to open
QMimeType mimeType = FileInfo::mimeTypeForUrl(urlToOpen);
const QString mimeTypeName = mimeType.name();
/// Ask KDE subsystem to open url in viewer matching mime type
KRun::runUrl(urlToOpen, mimeTypeName, parent, false, false);
}
}
示例15: mimeTypeForFileName
QMimeType QMimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileName, QIODevice *device, int *accuracyPtr)
{
// First, glob patterns are evaluated. If there is a match with max weight,
// this one is selected and we are done. Otherwise, the file contents are
// evaluated and the match with the highest value (either a magic priority or
// a glob pattern weight) is selected. Matching starts from max level (most
// specific) in both cases, even when there is already a suffix matching candidate.
*accuracyPtr = 0;
// Pass 1) Try to match on the file name
QStringList candidatesByName = mimeTypeForFileName(fileName);
if (candidatesByName.count() == 1) {
*accuracyPtr = 100;
const QMimeType mime = mimeTypeForName(candidatesByName.at(0));
if (mime.isValid())
return mime;
candidatesByName.clear();
}
// Extension is unknown, or matches multiple mimetypes.
// Pass 2) Match on content, if we can read the data
if (device->isOpen()) {
// Read 16K in one go (QIODEVICE_BUFFERSIZE in qiodevice_p.h).
// This is much faster than seeking back and forth into QIODevice.
const QByteArray data = device->peek(16384);
int magicAccuracy = 0;
QMimeType candidateByData(findByData(data, &magicAccuracy));
// Disambiguate conflicting extensions (if magic matching found something)
if (candidateByData.isValid() && magicAccuracy > 0) {
// "for glob_match in glob_matches:"
// "if glob_match is subclass or equal to sniffed_type, use glob_match"
const QString sniffedMime = candidateByData.name();
foreach (const QString &m, candidatesByName) {
if (inherits(m, sniffedMime)) {
// We have magic + pattern pointing to this, so it's a pretty good match
*accuracyPtr = 100;
return mimeTypeForName(m);
}
}
*accuracyPtr = magicAccuracy;
return candidateByData;
}
}
if (candidatesByName.count() > 1) {
*accuracyPtr = 20;
candidatesByName.sort(); // to make it deterministic
const QMimeType mime = mimeTypeForName(candidatesByName.at(0));
if (mime.isValid())
return mime;
}
return mimeTypeForName(defaultMimeType());
}