本文整理汇总了C++中QMimeType::comment方法的典型用法代码示例。如果您正苦于以下问题:C++ QMimeType::comment方法的具体用法?C++ QMimeType::comment怎么用?C++ QMimeType::comment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMimeType
的用法示例。
在下文中一共展示了QMimeType::comment方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: chooseFormatAndUrl
static QByteArray chooseFormatAndUrl(const QUrl &u, const QMimeData *mimeData,
const QStringList &formats,
const QString &text,
const QString &suggestedFileName,
QWidget *widget,
bool clipboard,
QUrl *newUrl)
{
QMimeDatabase db;
QStringList formatLabels;
for (int i = 0; i < formats.size(); ++i) {
const QString &fmt = formats[i];
QMimeType mime = db.mimeTypeForName(fmt);
if (mime.isValid()) {
formatLabels.append(i18n("%1 (%2)", mime.comment(), fmt));
} else {
formatLabels.append(fmt);
}
}
QString dialogText(text);
if (dialogText.isEmpty()) {
dialogText = i18n("Filename for clipboard content:");
}
//using QString() instead of QString::null didn't compile (with gcc 3.2.3), because the ctor was mistaken as a function declaration, Alex //krazy:exclude=nullstrassign
KIO::PasteDialog dlg(QString::null, dialogText, suggestedFileName, formatLabels, widget, clipboard); //krazy:exclude=nullstrassign
if (dlg.exec() != QDialog::Accepted) {
return QByteArray();
}
if (clipboard && dlg.clipboardChanged()) {
KMessageBox::sorry(widget,
i18n("The clipboard has changed since you used 'paste': "
"the chosen data format is no longer applicable. "
"Please copy again what you wanted to paste."));
return QByteArray();
}
const QString result = dlg.lineEditText();
const QString chosenFormat = formats[ dlg.comboItem() ];
//qDebug() << " result=" << result << " chosenFormat=" << chosenFormat;
*newUrl = u;
newUrl->setPath(newUrl->path() + '/' + result);
// In Qt3, the result of clipboard()->mimeData() only existed until the next
// event loop run (see dlg.exec() above), so we re-fetched it.
// TODO: This should not be necessary with Qt5; remove this conditional
// and test that it still works.
if (clipboard) {
mimeData = QApplication::clipboard()->mimeData();
}
const QByteArray ba = mimeData->data(chosenFormat);
return ba;
}
示例2: writeMimeInfo
bool Helper::writeMimeInfo( QMimeType mime )
{
KService::Ptr service = KMimeTypeTrader::self()->preferredService( mime.name());
if( service )
{
outputLine( mime.name());
outputLine( mime.comment());
outputLine( service->name());
return true;
}
return false;
}
示例3: showMetaDataFor
void InfoPanel::showMetaDataFor(const QModelIndex &index)
{
showMetaData();
const Archive::Entry *entry = m_model->entryForIndex(index);
QMimeDatabase db;
QMimeType mimeType;
if (entry->isDir()) {
mimeType = db.mimeTypeForName(QStringLiteral("inode/directory"));
} else {
mimeType = db.mimeTypeForFile(entry->fullPath(), QMimeDatabase::MatchExtension);
}
m_typeValueLabel->setText(mimeType.comment());
if (!entry->property("owner").toString().isEmpty()) {
m_ownerLabel->show();
m_ownerValueLabel->show();
m_ownerValueLabel->setText(entry->property("owner").toString());
} else {
m_ownerLabel->hide();
m_ownerValueLabel->hide();
}
if (!entry->property("group").toString().isEmpty()) {
m_groupLabel->show();
m_groupValueLabel->show();
m_groupValueLabel->setText(entry->property("group").toString());
} else {
m_groupLabel->hide();
m_groupValueLabel->hide();
}
if (!entry->property("link").toString().isEmpty()) {
m_targetLabel->show();
m_targetValueLabel->show();
m_targetValueLabel->setText(entry->property("link").toString());
} else {
m_targetLabel->hide();
m_targetValueLabel->hide();
}
if (entry->property("isPasswordProtected").toBool()) {
m_passwordLabel->show();
m_passwordValueLabel->show();
} else {
m_passwordLabel->hide();
m_passwordValueLabel->hide();
}
}
示例4: createRow
QT_END_NAMESPACE
static StandardItemList createRow(const QMimeType &t)
{
const QVariant v = QVariant::fromValue(t);
QStandardItem *nameItem = new QStandardItem(t.name());
const Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
nameItem->setData(v, mimeTypeRole);
nameItem->setData(QVariant(false), iconQueriedRole);
nameItem->setFlags(flags);
nameItem->setToolTip(t.comment());
return StandardItemList{nameItem};
}
示例5: mimeTypeForName
void tst_QMimeDatabase::mimeTypeForName()
{
QMimeDatabase db;
QMimeType s0 = db.mimeTypeForName(QString::fromLatin1("application/x-zerosize"));
QVERIFY(s0.isValid());
QCOMPARE(s0.name(), QString::fromLatin1("application/x-zerosize"));
QCOMPARE(s0.comment(), QString::fromLatin1("empty document"));
QMimeType s0Again = db.mimeTypeForName(QString::fromLatin1("application/x-zerosize"));
QCOMPARE(s0Again.name(), s0.name());
QMimeType s1 = db.mimeTypeForName(QString::fromLatin1("text/plain"));
QVERIFY(s1.isValid());
QCOMPARE(s1.name(), QString::fromLatin1("text/plain"));
//qDebug("Comment is %s", qPrintable(s1.comment()));
QMimeType krita = db.mimeTypeForName(QString::fromLatin1("application/x-krita"));
QVERIFY(krita.isValid());
// Test <comment> parsing with application/rdf+xml which has the english comment after the other ones
QMimeType rdf = db.mimeTypeForName(QString::fromLatin1("application/rdf+xml"));
QVERIFY(rdf.isValid());
QCOMPARE(rdf.comment(), QString::fromLatin1("RDF file"));
QMimeType bzip2 = db.mimeTypeForName(QString::fromLatin1("application/x-bzip2"));
QVERIFY(bzip2.isValid());
QCOMPARE(bzip2.comment(), QString::fromLatin1("Bzip archive"));
QMimeType defaultMime = db.mimeTypeForName(QString::fromLatin1("application/octet-stream"));
QVERIFY(defaultMime.isValid());
QVERIFY(defaultMime.isDefault());
QMimeType doesNotExist = db.mimeTypeForName(QString::fromLatin1("foobar/x-doesnot-exist"));
QVERIFY(!doesNotExist.isValid());
// TODO move to findByFile
#ifdef Q_OS_LINUX
QString exePath = QStandardPaths::findExecutable(QLatin1String("ls"));
if (exePath.isEmpty())
qWarning() << "ls not found";
else {
const QString executableType = QString::fromLatin1("application/x-executable");
//QTest::newRow("executable") << exePath << executableType;
QCOMPARE(db.mimeTypeForFile(exePath).name(), executableType);
}
#endif
}
示例6: KoDialog
KisFilterChooser::KisFilterChooser(QWidget *parent, const QStringList &mimeTypes, const QString &/*nativeFormat*/, const QUrl &url)
: KoDialog(parent),
m_mimeTypes(mimeTypes)
{
setObjectName("kofilterchooser");
setInitialSize(QSize(300, 350));
setButtons(KoDialog::Ok|KoDialog::Cancel);
setDefaultButton(KoDialog::Ok);
setCaption(i18n("Choose Filter"));
setModal(true);
QWidget *page = new QWidget(this);
setMainWidget(page);
QVBoxLayout *layout = new QVBoxLayout(page);
if (url.isValid()) {
KSqueezedTextLabel *l = new KSqueezedTextLabel(url.path(), page);
layout->addWidget(l);
}
m_filterList = new QListWidget(page);
layout->addWidget(m_filterList);
page->setLayout(layout);
Q_ASSERT(!m_mimeTypes.isEmpty());
for (QStringList::ConstIterator it = m_mimeTypes.constBegin();
it != m_mimeTypes.constEnd();
++it) {
QMimeDatabase db;
QMimeType mime = db.mimeTypeForName(*it);
const QString name = mime.isValid() ? mime.comment() : *it;
if (! name.isEmpty()) {
QListWidgetItem *item = new QListWidgetItem(name, m_filterList);
item->setData(32, *it);
}
}
m_filterList->sortItems();
if (m_filterList->currentRow() == -1)
m_filterList->setCurrentRow(0);
m_filterList->setFocus();
connect(m_filterList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(accept()));
resize(QSize(520, 400));//.expandedTo(minimumSizeHint()));
}
示例7: mimeComment
// KDE5 TODO: merge with comment()? Need to see what lxr says about the usage of both.
QString KFileItem::mimeComment() const
{
if (!d) {
return QString();
}
const QString displayType = d->m_entry.stringValue(KIO::UDSEntry::UDS_DISPLAY_TYPE);
if (!displayType.isEmpty()) {
return displayType;
}
bool isLocalUrl;
QUrl url = mostLocalUrl(&isLocalUrl);
QMimeType mime = currentMimeType();
// 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 && !d->isSlow() && mime.inherits(QStringLiteral("application/x-desktop"))) {
KDesktopFile cfg(url.toLocalFile());
QString comment = cfg.desktopGroup().readEntry("Comment");
if (!comment.isEmpty()) {
return comment;
}
}
// Support for .directory file in directories
if (isLocalUrl && isDir() && isDirectoryMounted(url)) {
QUrl u(url);
u.setPath(u.path() + QLatin1String("/.directory"));
const KDesktopFile cfg(u.toLocalFile());
const QString comment = cfg.readComment();
if (!comment.isEmpty()) {
return comment;
}
}
const QString comment = mime.comment();
//qDebug() << "finding comment for " << url.url() << " : " << d->m_mimeType->name();
if (!comment.isEmpty()) {
return comment;
} else {
return mime.name();
}
}
示例8: slotImagesplit
void Imagesplit::slotImagesplit()
{
// Taking the title - url from caption function and removing file extension
QStringList strList = ((m_view->document())->caption()).split('.');
QString suffix = strList.at(0);
// Getting all mime types and converting them into names which are displayed at combo box
QStringList listMimeFilter = KisImportExportManager::mimeFilter("application/x-krita", KisImportExportManager::Export);
QStringList filteredMimeTypes;
QStringList listFileType;
foreach(const QString & tempStr, listMimeFilter) {
QMimeDatabase db;
QMimeType type = db.mimeTypeForName(tempStr);
dbgKrita << tempStr << type;
if (type.isValid()) {
listFileType.append(type.comment());
filteredMimeTypes.append(tempStr);
}
}
示例9: formatMimeTypeInfo
QString MimetypeModel::formatMimeTypeInfo(const QMimeType &t)
{
QString result;
QTextStream str(&result);
str << "<html><head/><body><h3><center>" << t.name() << "</center></h3><br><table>";
const QStringList &aliases = t.aliases();
if (!aliases.isEmpty())
str << "<tr><td>Aliases:</td><td>" << " (" << aliases << ')';
str << "</td></tr>"
<< "<tr><td>Comment:</td><td>" << t.comment() << "</td></tr>"
<< "<tr><td>Icon name:</td><td>" << t.iconName() << "</td></tr>"
<< "<tr><td>Generic icon name</td><td>" << t.genericIconName() << "</td></tr>";
const QString &filter = t.filterString();
if (!filter.isEmpty())
str << "<tr><td>Filter:</td><td>" << t.filterString() << "</td></tr>";
const QStringList &patterns = t.globPatterns();
if (!patterns.isEmpty())
str << "<tr><td>Glob patterns:</td><td>" << patterns << "</td></tr>";
const QStringList &parentMimeTypes = t.parentMimeTypes();
if (!parentMimeTypes.isEmpty())
str << "<tr><td>Parent types:</td><td>" << t.parentMimeTypes() << "</td></tr>";
QStringList suffixes = t.suffixes();
if (!suffixes.isEmpty()) {
str << "<tr><td>Suffixes:</td><td>";
const QString &preferredSuffix = t.preferredSuffix();
if (!preferredSuffix.isEmpty()) {
suffixes.removeOne(preferredSuffix);
str << "<b>" << preferredSuffix << "</b> ";
}
str << suffixes << "</td></tr>";
}
str << "</table></body></html>";
return result;
}
示例10: viewInInternalViewer
bool ArkViewer::viewInInternalViewer(const QString& fileName, const QMimeType &mimeType)
{
setWindowFilePath(fileName);
// Set icon and comment for the mimetype.
m_iconLabel->setPixmap(QIcon::fromTheme(mimeType.iconName()).pixmap(IconSize(KIconLoader::Small), IconSize(KIconLoader::Small)));
m_commentLabel->setText(mimeType.comment());
// Create the ReadOnlyPart instance.
m_part = KMimeTypeTrader::self()->createPartInstanceFromQuery<KParts::ReadOnlyPart>(mimeType.name(), this, this);
// Drop the KHTMLPart, if necessary.
const KService::Ptr service = KMimeTypeTrader::self()->preferredService(mimeType.name(), QStringLiteral("KParts/ReadOnlyPart"));
qCDebug(ARK) << "Preferred service for mimetype" << mimeType.name() << "is" << service->library();
if (service.constData()->desktopEntryName() == QLatin1String("khtml")) {
KService::List offers = KMimeTypeTrader::self()->query(mimeType.name(), QStringLiteral("KParts/ReadOnlyPart"));
offers.removeFirst();
qCDebug(ARK) << "Removed KHTMLPart from the offers for mimetype" << mimeType.name()
<< ". Using" << offers.first().constData()->desktopEntryName() << "instead.";
m_part = offers.first().constData()->createInstance<KParts::ReadOnlyPart>(this, this);
}
if (!m_part.data()) {
return false;
}
// Insert the KPart into its placeholder.
centralWidget()->layout()->replaceWidget(m_partPlaceholder, m_part.data()->widget());
createGUI(m_part.data());
setAutoSaveSettings(QStringLiteral("Viewer"), true);
m_part.data()->openUrl(QUrl::fromLocalFile(fileName));
m_part.data()->widget()->setFocus();
m_fileName = fileName;
return true;
}
示例11: setCurrentItem
//.........这里部分代码省略.........
str = i18n("No");
}
else
{
str = i18n("Yes");
}
d->labelFileIsWritable->setAdjustedText(str);
if (itemInfo.ctime.isValid())
{
d->labelFileDate->setAdjustedText(QLocale().toString(itemInfo.ctime, QLocale::ShortFormat));
}
else
{
d->labelFileDate->setAdjustedText(unknown);
}
str = i18n("%1 (%2)", ImagePropertiesTab::humanReadableBytesCount(itemInfo.size), QLocale().toString(itemInfo.size));
d->labelFileSize->setAdjustedText(str);
// -- Image Properties --------------------------------------------------
if (itemInfo.mime == QLatin1String("image/x-raw"))
{
d->labelImageMime->setAdjustedText(i18n("RAW Image"));
}
else
{
QMimeType mimeType = QMimeDatabase().mimeTypeForName(itemInfo.mime);
if (mimeType.isValid())
{
d->labelImageMime->setAdjustedText(mimeType.comment());
}
else
{
d->labelImageMime->setAdjustedText(itemInfo.mime); // last fallback
}
}
QString mpixels;
QSize dims;
if (itemInfo.width == -1 && itemInfo.height == -1)
{
// delayed loading to list faster from UMSCamera
if (itemInfo.mime == QLatin1String("image/x-raw"))
{
dims = meta.getImageDimensions();
}
else
{
dims = meta.getPixelSize();
}
}
else
{
// if available (GPCamera), take dimensions directly from itemInfo
dims = QSize(itemInfo.width, itemInfo.height);
}
mpixels.setNum(dims.width()*dims.height()/1000000.0, 'f', 2);
str = (!dims.isValid()) ? unknown : i18n("%1x%2 (%3Mpx)",
dims.width(), dims.height(), mpixels);
d->labelImageDimensions->setAdjustedText(str);
示例12: file
LocalListingNetworkReply::LocalListingNetworkReply(QObject *parent, const QNetworkRequest &request) : QNetworkReply(parent),
m_offset(0)
{
setRequest(request);
open(QIODevice::ReadOnly | QIODevice::Unbuffered);
QFile file(QLatin1String(":/files/listing.html"));
file.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream stream(&file);
stream.setCodec("UTF-8");
QDir directory(request.url().toLocalFile());
const QFileInfoList entries = directory.entryInfoList((QDir::AllEntries | QDir::Hidden), (QDir::Name | QDir::DirsFirst));
const QRegularExpression expression(QLatin1String("^/+"));
QStringList navigation;
do
{
navigation.prepend(QStringLiteral("<a href=\"file:///%1\">%2</a>%3").arg(directory.canonicalPath().remove(expression)).arg(directory.dirName().isEmpty() ? QString('/') : directory.dirName()).arg(directory.dirName().isEmpty() ? QString() : QString('/')));
}
while (directory.cdUp());
QHash<QString, QString> variables;
variables[QLatin1String("title")] = QFileInfo(request.url().toLocalFile()).canonicalFilePath();
variables[QLatin1String("description")] = tr("Directory Contents");
variables[QLatin1String("dir")] = (QGuiApplication::isLeftToRight() ? QLatin1String("ltr") : QLatin1String("rtl"));
variables[QLatin1String("navigation")] = navigation.join(QString());
variables[QLatin1String("header_name")] = tr("Name");
variables[QLatin1String("header_type")] = tr("Type");
variables[QLatin1String("header_size")] = tr("Size");
variables[QLatin1String("header_date")] = tr("Date");
variables[QLatin1String("body")] = QString();
const QMimeDatabase database;
for (int i = 0; i < entries.count(); ++i)
{
const QMimeType mimeType = database.mimeTypeForFile(entries.at(i).canonicalFilePath());
QByteArray byteArray;
QBuffer buffer(&byteArray);
QIcon::fromTheme(mimeType.iconName(), Utils::getIcon(entries.at(i).isDir() ? QLatin1String("inode-directory") : QLatin1String("unknown"))).pixmap(16, 16).save(&buffer, "PNG");
variables[QLatin1String("body")].append(QStringLiteral("<tr>\n<td><a href=\"file:///%1\"><img src=\"data:image/png;base64,%2\" alt=\"\"> %3</a></td>\n<td>%4</td>\n<td>%5</td>\n<td>%6</td>\n</tr>\n").arg(entries.at(i).filePath().remove(expression)).arg(QString(byteArray.toBase64())).arg(entries.at(i).fileName()).arg(mimeType.comment()).arg(entries.at(i).isDir() ? QString() : Utils::formatUnit(entries.at(i).size(), false, 2)).arg(QLocale().toString(entries.at(i).lastModified())));
}
QString html = stream.readAll();
QHash<QString, QString>::iterator iterator;
for (iterator = variables.begin(); iterator != variables.end(); ++iterator)
{
html.replace(QStringLiteral("{%1}").arg(iterator.key()), iterator.value());
}
m_content = html.toUtf8();
setHeader(QNetworkRequest::ContentTypeHeader, QVariant("text/html; charset=UTF-8"));
setHeader(QNetworkRequest::ContentLengthHeader, QVariant(m_content.size()));
QTimer::singleShot(0, this, SIGNAL(readyRead()));
QTimer::singleShot(0, this, SIGNAL(finished()));
}
示例13: data
QVariant KrVfsModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid() || index.row() >= rowCount())
return QVariant();
vfile *vf = _vfiles.at(index.row());
if (vf == 0)
return QVariant();
switch (role) {
case Qt::FontRole:
return _defaultFont;
case Qt::EditRole: {
if (index.column() == 0) {
return vf->vfile_getName();
}
return QVariant();
}
case Qt::UserRole: {
if (index.column() == 0) {
return nameWithoutExtension(vf, false);
}
return QVariant();
}
case Qt::ToolTipRole:
case Qt::DisplayRole: {
switch (index.column()) {
case KrViewProperties::Name: {
return nameWithoutExtension(vf);
}
case KrViewProperties::Ext: {
QString nameOnly = nameWithoutExtension(vf);
const QString& vfName = vf->vfile_getName();
return vfName.mid(nameOnly.length() + 1);
}
case KrViewProperties::Size: {
if (vf->vfile_isDir() && vf->vfile_getSize() <= 0) {
//HACK add <> brackets AFTER translating - otherwise KUIT thinks it's a tag
static QString label = QString("<") +
i18nc("Show the string 'DIR' instead of file size in detailed view (for folders)", "DIR") + ">";
return label;
} else
return (properties()->humanReadableSize) ?
KIO::convertSize(vf->vfile_getSize()) + " " :
KRpermHandler::parseSize(vf->vfile_getSize()) + ' ';
}
case KrViewProperties::Type: {
if (vf == _dummyVfile)
return QVariant();
QMimeDatabase db;
QMimeType mt = db.mimeTypeForName(vf->vfile_getMime());
if (mt.isValid())
return mt.comment();
return QVariant();
}
case KrViewProperties::Modified: {
if (vf == _dummyVfile)
return QVariant();
time_t time = vf->vfile_getTime_t();
struct tm* t = localtime((time_t *) & time);
QDateTime tmp(QDate(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday), QTime(t->tm_hour, t->tm_min));
return QLocale().toString(tmp, QLocale::ShortFormat);
}
case KrViewProperties::Permissions: {
if (vf == _dummyVfile)
return QVariant();
if (properties()->numericPermissions) {
QString perm;
return perm.sprintf("%.4o", vf->vfile_getMode() & PERM_BITMASK);
}
return vf->vfile_getPerm();
}
case KrViewProperties::KrPermissions: {
if (vf == _dummyVfile)
return QVariant();
return KrView::krPermissionString(vf);
}
case KrViewProperties::Owner: {
if (vf == _dummyVfile)
return QVariant();
return vf->vfile_getOwner();
}
case KrViewProperties::Group: {
if (vf == _dummyVfile)
return QVariant();
return vf->vfile_getGroup();
}
default: return QString();
}
return QVariant();
}
case Qt::DecorationRole: {
switch (index.column()) {
case KrViewProperties::Name: {
if (properties()->displayIcons) {
if (_justForSizeHint)
return QPixmap(_view->fileIconSize(), _view->fileIconSize());
return _view->getIcon(vf);
}
break;
//.........这里部分代码省略.........