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; }
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; }
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(); } }
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}; }
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 }
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())); }
// 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(); } }
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); } }
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; }
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; }
void CameraItemPropertiesTab::setCurrentItem(const CamItemInfo& itemInfo, const DMetadata& meta) { if (itemInfo.isNull()) { d->labelFile->setAdjustedText(QString()); d->labelFolder->setAdjustedText(QString()); d->labelFileIsReadable->setAdjustedText(QString()); d->labelFileIsWritable->setAdjustedText(QString()); d->labelFileDate->setAdjustedText(QString()); d->labelFileSize->setAdjustedText(QString()); d->labelImageMime->setAdjustedText(QString()); d->labelImageDimensions->setAdjustedText(QString()); d->labelImageRatio->setAdjustedText(QString()); d->labelNewFileName->setAdjustedText(QString()); d->labelAlreadyDownloaded->setAdjustedText(QString()); d->labelPhotoMake->setAdjustedText(QString()); d->labelPhotoModel->setAdjustedText(QString()); d->labelPhotoDateTime->setAdjustedText(QString()); d->labelPhotoLens->setAdjustedText(QString()); d->labelPhotoAperture->setAdjustedText(QString()); d->labelPhotoFocalLength->setAdjustedText(QString()); d->labelPhotoExposureTime->setAdjustedText(QString()); d->labelPhotoSensitivity->setAdjustedText(QString()); d->labelPhotoExposureMode->setAdjustedText(QString()); d->labelPhotoFlash->setAdjustedText(QString()); d->labelPhotoWhiteBalance->setAdjustedText(QString()); d->labelVideoAspectRatio->setAdjustedText(QString()); d->labelVideoAudioBitRate->setAdjustedText(QString()); d->labelVideoAudioChannelType->setAdjustedText(QString()); d->labelVideoAudioCompressor->setAdjustedText(QString()); d->labelVideoDuration->setAdjustedText(QString()); d->labelVideoFrameRate->setAdjustedText(QString()); d->labelVideoVideoCodec->setAdjustedText(QString()); setEnabled(false); return; } setEnabled(true); QString str; QString unknown(i18n("<i>unknown</i>")); // -- Camera file system information ------------------------------------------ d->labelFile->setAdjustedText(itemInfo.name); d->labelFolder->setAdjustedText(itemInfo.folder); if (itemInfo.readPermissions < 0) { str = unknown; } else if (itemInfo.readPermissions == 0) { str = i18n("No"); } else { str = i18n("Yes"); } d->labelFileIsReadable->setAdjustedText(str); if (itemInfo.writePermissions < 0) { str = unknown; } else if (itemInfo.writePermissions == 0) { 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); if (!dims.isValid()) str = unknown; else ImagePropertiesTab::aspectRatioToString(dims.width(), dims.height(), str); d->labelImageRatio->setAdjustedText(str); // -- Download information ------------------------------------------ d->labelNewFileName->setAdjustedText(itemInfo.downloadName.isEmpty() ? i18n("<i>unchanged</i>") : itemInfo.downloadName); if (itemInfo.downloaded == CamItemInfo::DownloadUnknown) { str = unknown; } else if (itemInfo.downloaded == CamItemInfo::DownloadedYes) { str = i18n("Yes"); } else { str = i18n("No"); } d->labelAlreadyDownloaded->setAdjustedText(str); // -- Photograph information ------------------------------------------ // Note: If something is changed here, please updated albumfiletip section too. QString unavailable(i18n("<i>unavailable</i>")); PhotoInfoContainer photoInfo = meta.getPhotographInformation(); if (photoInfo.isEmpty()) { widget(1)->hide(); } else { widget(1)->show(); } ImagePropertiesTab::shortenedMakeInfo(photoInfo.make); ImagePropertiesTab::shortenedModelInfo(photoInfo.model); d->labelPhotoMake->setAdjustedText(photoInfo.make.isEmpty() ? unavailable : photoInfo.make); d->labelPhotoModel->setAdjustedText(photoInfo.model.isEmpty() ? unavailable : photoInfo.model); if (photoInfo.dateTime.isValid()) { str = QLocale().toString(photoInfo.dateTime, QLocale::ShortFormat); d->labelPhotoDateTime->setAdjustedText(str); } else { d->labelPhotoDateTime->setAdjustedText(unavailable); } d->labelPhotoLens->setAdjustedText(photoInfo.lens.isEmpty() ? unavailable : photoInfo.lens); d->labelPhotoAperture->setAdjustedText(photoInfo.aperture.isEmpty() ? unavailable : photoInfo.aperture); if (photoInfo.focalLength35mm.isEmpty()) { d->labelPhotoFocalLength->setAdjustedText(photoInfo.focalLength.isEmpty() ? unavailable : photoInfo.focalLength); } else { str = i18n("%1 (%2)", photoInfo.focalLength, photoInfo.focalLength35mm); d->labelPhotoFocalLength->setAdjustedText(str); } d->labelPhotoExposureTime->setAdjustedText(photoInfo.exposureTime.isEmpty() ? unavailable : photoInfo.exposureTime); d->labelPhotoSensitivity->setAdjustedText(photoInfo.sensitivity.isEmpty() ? unavailable : i18n("%1 ISO", photoInfo.sensitivity)); if (photoInfo.exposureMode.isEmpty() && photoInfo.exposureProgram.isEmpty()) { d->labelPhotoExposureMode->setAdjustedText(unavailable); } else if (!photoInfo.exposureMode.isEmpty() && photoInfo.exposureProgram.isEmpty()) { d->labelPhotoExposureMode->setAdjustedText(photoInfo.exposureMode); } else if (photoInfo.exposureMode.isEmpty() && !photoInfo.exposureProgram.isEmpty()) { d->labelPhotoExposureMode->setAdjustedText(photoInfo.exposureProgram); } else { str = QString::fromUtf8("%1 / %2").arg(photoInfo.exposureMode).arg(photoInfo.exposureProgram); d->labelPhotoExposureMode->setAdjustedText(str); } d->labelPhotoFlash->setAdjustedText(photoInfo.flash.isEmpty() ? unavailable : photoInfo.flash); d->labelPhotoWhiteBalance->setAdjustedText(photoInfo.whiteBalance.isEmpty() ? unavailable : photoInfo.whiteBalance); // -- Video information ------------------------------------------ VideoInfoContainer videoInfo = meta.getVideoInformation(); if (videoInfo.isEmpty()) { widget(2)->hide(); } else { widget(2)->show(); } d->labelVideoAspectRatio->setAdjustedText(videoInfo.aspectRatio.isEmpty() ? unavailable : videoInfo.aspectRatio); d->labelVideoAudioBitRate->setAdjustedText(videoInfo.audioBitRate.isEmpty() ? unavailable : videoInfo.audioBitRate); d->labelVideoAudioChannelType->setAdjustedText(videoInfo.audioChannelType.isEmpty() ? unavailable : videoInfo.audioChannelType); d->labelVideoAudioCompressor->setAdjustedText(videoInfo.audioCompressor.isEmpty() ? unavailable : videoInfo.audioCompressor); d->labelVideoDuration->setAdjustedText(videoInfo.duration.isEmpty() ? unavailable : videoInfo.duration); d->labelVideoFrameRate->setAdjustedText(videoInfo.frameRate.isEmpty() ? unavailable : videoInfo.frameRate); d->labelVideoVideoCodec->setAdjustedText(videoInfo.videoCodec.isEmpty() ? unavailable : videoInfo.videoCodec); }
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())); }
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; } default: break; } return QVariant(); } case Qt::TextAlignmentRole: { switch (index.column()) { case KrViewProperties::Size: return QVariant(Qt::AlignRight | Qt::AlignVCenter); default: return QVariant(Qt::AlignLeft | Qt::AlignVCenter); } return QVariant(); } case Qt::BackgroundRole: case Qt::ForegroundRole: { KrColorItemType colorItemType; colorItemType.m_activePanel = _view->isFocused(); int actRow = index.row(); if (_alternatingTable) { int itemNum = _view->itemsPerPage(); if (itemNum == 0) itemNum++; if ((itemNum & 1) == 0) actRow += (actRow / itemNum); } colorItemType.m_alternateBackgroundColor = (actRow & 1); colorItemType.m_currentItem = _view->getCurrentIndex().row() == index.row(); colorItemType.m_selectedItem = _view->isSelected(index); if (vf->vfile_isSymLink()) { if (vf->vfile_isBrokenLink()) colorItemType.m_fileType = KrColorItemType::InvalidSymlink; else colorItemType.m_fileType = KrColorItemType::Symlink; } else if (vf->vfile_isDir()) colorItemType.m_fileType = KrColorItemType::Directory; else if (vf->vfile_isExecutable()) colorItemType.m_fileType = KrColorItemType::Executable; else colorItemType.m_fileType = KrColorItemType::File; KrColorGroup cols; KrColorCache::getColorCache().getColors(cols, colorItemType); if (colorItemType.m_selectedItem) { if (role == Qt::ForegroundRole) return cols.highlightedText(); else return cols.highlight(); } if (role == Qt::ForegroundRole) return cols.text(); else return cols.background(); } default: return QVariant(); } }