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; }
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(); }
KoDocumentInfoDlg::KoDocumentInfoDlg(QWidget* parent, KoDocumentInfo* docInfo) : KPageDialog(parent) , d(new KoDocumentInfoDlgPrivate) { d->info = docInfo; setWindowTitle(i18n("Document Information")); // setInitialSize(QSize(500, 500)); setFaceType(KPageDialog::List); setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); button(QDialogButtonBox::Ok)->setDefault(true); d->aboutUi = new Ui::KoDocumentInfoAboutWidget(); QWidget *infodlg = new QWidget(); d->aboutUi->setupUi(infodlg); d->aboutUi->cbLanguage->addItems(KoGlobal::listOfLanguages()); d->aboutUi->cbLanguage->setCurrentIndex(-1); KPageWidgetItem *page = new KPageWidgetItem(infodlg, i18n("General")); page->setHeader(i18n("General")); // Ugly hack, the mimetype should be a parameter, instead KoDocumentBase* doc = dynamic_cast< KoDocumentBase* >(d->info->parent()); if (doc) { QMimeDatabase db; QMimeType mime = db.mimeTypeForName(doc->mimeType()); if (mime.isValid()) { page->setIcon(KisIconUtils::loadIcon(mime.iconName())); } } else { // hide all entries not used in pages for KoDocumentInfoPropsPage d->aboutUi->filePathInfoLabel->setVisible(false); d->aboutUi->filePathLabel->setVisible(false); d->aboutUi->filePathSeparatorLine->setVisible(false); d->aboutUi->lblTypeDesc->setVisible(false); d->aboutUi->lblType->setVisible(false); } addPage(page); d->pages.append(page); initAboutTab(); d->authorUi = new Ui::KoDocumentInfoAuthorWidget(); QWidget *authordlg = new QWidget(); d->authorUi->setupUi(authordlg); page = new KPageWidgetItem(authordlg, i18n("Author")); page->setHeader(i18n("Last saved by")); page->setIcon(koIcon("user-identity")); addPage(page); d->pages.append(page); initAuthorTab(); }
QString vfile::vfile_getIcon() { if (vfile_icon.isEmpty()) { QString mime = vfile_getMime(); if (vfile_isBrokenLink()) vfile_icon = "file-broken"; else if (vfile_icon.isEmpty()) { QMimeDatabase db; QMimeType mt = db.mimeTypeForName(mime); vfile_icon = mt.isValid() ? mt.iconName() : "file-broken"; } } return vfile_icon; }
QIcon CTTask::commandIcon() const { QUrl commandPath = QUrl::fromLocalFile(completeCommandPath()); QMimeType mimeType = QMimeDatabase().mimeTypeForUrl(commandPath); //logDebug() << mimeType->name() << endl; if (mimeType.name() == QLatin1String( "application/x-executable" ) || mimeType.name() == QLatin1String( "application/octet-stream" )) { //The next line is identical as SmallIcon(commandPath.fileName()), but is able to return a isNull() QPixmap QPixmap pixmap = KIconLoader::global()->loadIcon(commandPath.fileName(), KIconLoader::Small, 0, KIconLoader::DefaultState, QStringList(), 0L, true); if (pixmap.isNull()) { return QIcon::fromTheme(QLatin1String("system-run")); } return QIcon(pixmap); } return QIcon::fromTheme(mimeType.iconName()); }
void InfoPanel::setIndex(const QModelIndex& index) { if (!index.isValid()) { updateWithDefaults(); } else { const Archive::Entry *entry = m_model->entryForIndex(index); if (!entry) { return; } QMimeDatabase db; QMimeType mimeType; if (entry->isDir()) { mimeType = db.mimeTypeForName(QStringLiteral("inode/directory")); } else { mimeType = db.mimeTypeForFile(entry->fullPath(), QMimeDatabase::MatchExtension); } iconLabel->setPixmap(getDesktopIconForName(mimeType.iconName())); if (entry->isDir()) { uint dirs; uint files; entry->countChildren(dirs, files); additionalInfo->setText(KIO::itemsSummaryString(dirs + files, files, dirs, 0, false)); } else if (!entry->property("link").toString().isEmpty()) { additionalInfo->setText(i18n("Symbolic Link")); } else { if (entry->property("size") != 0) { additionalInfo->setText(KIO::convertSize(entry->property("size").toULongLong())); } else { additionalInfo->setText(i18n("Unknown size")); } } const QStringList nameParts = entry->fullPath().split(QLatin1Char( '/' ), QString::SkipEmptyParts); const QString name = (nameParts.count() > 0) ? nameParts.last() : entry->fullPath(); fileName->setText(name); showMetaDataFor(index); } }
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; }
QVariant DirModel::data(const QModelIndex &index, int role) const { //its not for QML #if defined(REGRESSION_TEST_FOLDERLISTMODEL) if (!index.isValid() || (role != Qt::DisplayRole && role != Qt::DecorationRole && role != Qt::BackgroundRole) ) { return QVariant(); } if (role == Qt::DecorationRole && index.column() == 0) { QIcon icon; QMimeType mime = mDirectoryContents.at(index.row()).mimeType(); if (mime.isValid()) { if (QIcon::hasThemeIcon(mime.iconName()) ) { icon = QIcon::fromTheme(mime.iconName()); } else if (QIcon::hasThemeIcon(mime.genericIconName())) { icon = QIcon::fromTheme(mime.genericIconName()); } } if (icon.isNull()) { if (mDirectoryContents.at(index.row()).isLocal()) { icon = QFileIconProvider().icon(mDirectoryContents.at(index.row()).diskFileInfo()); } else if (mDirectoryContents.at(index.row()).isDir()) { icon = QFileIconProvider().icon(QFileIconProvider::Folder); } else { icon = QFileIconProvider().icon(QFileIconProvider::File); } } return icon; } if (role == Qt::BackgroundRole && index.column() == 0) { if (mDirectoryContents.at(index.row()).isSelected()) { //TODO it'd better to get some style or other default // background color return QBrush(Qt::lightGray); } return QVariant(); } role = FileNameRole + index.column(); #else if (role < FileNameRole || role > TrackCoverRole) { qWarning() << Q_FUNC_INFO << this << "Got an out of range role: " << role; return QVariant(); } if (index.row() < 0 || index.row() >= mDirectoryContents.count()) { qWarning() << "Attempted to access out of range row: " << index.row(); return QVariant(); } if (index.column() != 0) return QVariant(); #endif const DirItemInfo &fi = mDirectoryContents.at(index.row()); switch (role) { case FileNameRole: return fi.fileName(); case AccessedDateRole: return fi.lastRead(); case CreationDateRole: return fi.created(); case ModifiedDateRole: return fi.lastModified(); case FileSizeRole: { if (fi.isDir() && fi.isLocal()) { return dirItems(fi.diskFileInfo()); } return fileSize(fi.size()); } case IconSourceRole: { const QString &fileName = fi.fileName(); if (fi.isDir()) return QLatin1String("image://theme/icon-m-common-directory"); if (fileName.endsWith(QLatin1String(".jpg"), Qt::CaseInsensitive) || fileName.endsWith(QLatin1String(".png"), Qt::CaseInsensitive)) { return QLatin1String("image://nemoThumbnail/") + fi.filePath(); } return "image://theme/icon-m-content-document"; } case FilePathRole: return fi.filePath(); case MimeTypeRole: return fi.mimeType().name(); case MimeTypeDescriptionRole: return fi.mimeType().comment(); case IsDirRole: return fi.isDir(); case IsFileRole: return !fi.isDir(); case IsReadableRole: return fi.isReadable(); case IsWritableRole: return fi.isWritable(); case IsExecutableRole: return fi.isExecutable(); case IsSelectedRole: return fi.isSelected(); #ifndef DO_NOT_USE_TAG_LIB case TrackTitleRole: case TrackArtistRole: case TrackAlbumRole: case TrackYearRole: case TrackNumberRole: case TrackGenreRole: case TrackLengthRole: case TrackCoverRole: if (mReadsMediaMetadata && fi.isLocal()) { return getAudioMetaData(fi.diskFileInfo(), role); } break; #endif default: #if !defined(REGRESSION_TEST_FOLDERLISTMODEL) // this should not happen, ever Q_ASSERT(false); qWarning() << Q_FUNC_INFO << this << "Got an unknown role: " << role; #endif break; } return QVariant(); }
void AddressCompletionModel::timerEvent(QTimerEvent *event) { if (event->timerId() == m_updateTimer) { killTimer(m_updateTimer); m_updateTimer = 0; if (m_filter.isEmpty()) { return; } QList<CompletionEntry> completions; if (m_types.testFlag(SearchSuggestionsCompletionType)) { const QString keyword(m_filter.section(QLatin1Char(' '), 0, 0)); const SearchEnginesManager::SearchEngineDefinition searchEngine(SearchEnginesManager::getSearchEngine(keyword, true)); QString title(m_defaultSearchEngine.title); QString text(m_filter); QIcon icon(m_defaultSearchEngine.icon); if (!searchEngine.identifier.isEmpty()) { title = searchEngine.title; text = m_filter.section(QLatin1Char(' '), 1, -1); icon = searchEngine.icon; } else if (keyword == QLatin1String("?")) { text = m_filter.section(QLatin1Char(' '), 1, -1); } if (icon.isNull()) { icon = ThemesManager::getIcon(QLatin1String("edit-find")); } if (m_showCompletionCategories) { completions.append(CompletionEntry(QUrl(), tr("Search with %1").arg(title), QString(), QIcon(), HeaderType)); title = QString(); } CompletionEntry completionEntry(QUrl(), title, QString(), icon, SearchSuggestionType); completionEntry.text = text; completions.append(completionEntry); } if (m_types.testFlag(BookmarksCompletionType)) { const QList<BookmarksModel::BookmarkMatch> bookmarks(BookmarksManager::findBookmarks(m_filter)); if (m_showCompletionCategories && !bookmarks.isEmpty()) { completions.append(CompletionEntry(QUrl(), tr("Bookmarks"), QString(), QIcon(), HeaderType)); } for (int i = 0; i < bookmarks.count(); ++i) { CompletionEntry completionEntry(bookmarks.at(i).bookmark->data(BookmarksModel::UrlRole).toUrl(), bookmarks.at(i).bookmark->data(BookmarksModel::TitleRole).toString(), bookmarks.at(i).match, bookmarks.at(i).bookmark->data(Qt::DecorationRole).value<QIcon>(), BookmarkType); completionEntry.keyword = bookmarks.at(i).bookmark->data(BookmarksModel::KeywordRole).toString(); if (completionEntry.keyword.startsWith(m_filter)) { completionEntry.match = completionEntry.keyword; } completions.append(completionEntry); } } if (m_types.testFlag(LocalPathSuggestionsCompletionType) && m_filter.contains(QDir::separator())) { const QString directory(m_filter.section(QDir::separator(), 0, -2) + QDir::separator()); const QString prefix(m_filter.section(QDir::separator(), -1, -1)); const QList<QFileInfo> entries(QDir(Utils::normalizePath(directory)).entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot)); const QFileIconProvider iconProvider; bool wasAdded(!m_showCompletionCategories); for (int i = 0; i < entries.count(); ++i) { if (entries.at(i).fileName().startsWith(prefix, Qt::CaseInsensitive)) { const QString path(directory + entries.at(i).fileName()); const QMimeType type(QMimeDatabase().mimeTypeForFile(entries.at(i), QMimeDatabase::MatchExtension)); if (!wasAdded) { completions.append(CompletionEntry(QUrl(), tr("Local files"), QString(), QIcon(), HeaderType)); wasAdded = true; } completions.append(CompletionEntry(path, path, QString(), QIcon::fromTheme(type.iconName(), iconProvider.icon(entries.at(i))), LocalPathType)); } } } if (m_types.testFlag(HistoryCompletionType)) { const QList<HistoryModel::HistoryEntryMatch> entries(HistoryManager::findEntries(m_filter)); if (m_showCompletionCategories && !entries.isEmpty()) { completions.append(CompletionEntry(QUrl(), tr("History"), QString(), QIcon(), HeaderType)); } for (int i = 0; i < entries.count(); ++i) { completions.append(CompletionEntry(entries.at(i).entry->data(HistoryModel::UrlRole).toUrl(), entries.at(i).entry->data(HistoryModel::TitleRole).toString(), entries.at(i).match, entries.at(i).entry->data(Qt::DecorationRole).value<QIcon>(), (entries.at(i).isTypedIn ? TypedInHistoryType : HistoryType))); } } if (m_types.testFlag(SpecialPagesCompletionType)) { const QStringList specialPages(AddonsManager::getSpecialPages()); bool wasAdded(!m_showCompletionCategories); for (int i = 0; i < specialPages.count(); ++i) { const AddonsManager::SpecialPageInformation information(AddonsManager::getSpecialPage(specialPages.at(i))); if (information.url.toString().startsWith(m_filter)) { if (!wasAdded) { completions.append(CompletionEntry(QUrl(), tr("Special pages"), QString(), QIcon(), HeaderType)); wasAdded = true; } completions.append(CompletionEntry(information.url, information.getTitle(), QString(), information.icon, SpecialPageType)); } } } beginResetModel(); m_completions = completions; endResetModel(); emit completionReady(m_filter); } }
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())); }