void MimetypeViewer::currentMimetypeChanged() { widget.iconLabel->hide(); widget.descriptionLabel->setText(tr("None")); widget.mimetypeGroupBox->setEnabled(false); widget.patternsLabel->clear(); widget.patternsGroupBox->setEnabled(false); widget.appIcon->hide(); widget.applicationLabel->clear(); widget.applicationsGroupBox->setEnabled(false); QTreeWidgetItem *sel = widget.mimetypeTreeWidget->currentItem(); if (!sel || sel->type() == GroupType) { return; } MimeTypeData mimeData = sel->data(0, Qt::UserRole).value<MimeTypeData>(); QMimeDatabase db; XdgMimeType mt = db.mimeTypeForName(mimeData.name()); if (mt.name().isEmpty()) return; m_CurrentMime = mt; widget.descriptionLabel->setText(mimeData.comment()); QIcon icon = m_CurrentMime.icon(); if (! icon.isNull()) { widget.iconLabel->setPixmap(icon.pixmap(widget.iconLabel->size())); widget.iconLabel->show(); } widget.mimetypeGroupBox->setEnabled(true); widget.patternsLabel->setText(mimeData.patterns()); widget.patternsGroupBox->setEnabled(true); XdgDesktopFile* defaultApp = XdgDesktopFileCache::getDefaultApp(m_CurrentMime.name()); if (defaultApp && defaultApp->isValid()) { QString nonLocalizedName = defaultApp->value("Name").toString(); QString localizedName = defaultApp->localizedValue("Name", nonLocalizedName).toString(); QIcon appIcon = defaultApp->icon(); widget.appIcon->setPixmap(appIcon.pixmap(widget.iconLabel->size())); widget.appIcon->show(); widget.applicationLabel->setText(localizedName); widget.chooseApplicationsButton->setText(tr("&Change...")); } else { widget.applicationLabel->setText(tr("None")); widget.chooseApplicationsButton->setText(tr("&Choose...")); } widget.applicationsGroupBox->setEnabled(true); }
MimeTypeData::MimeTypeData(const XdgMimeType& mime) { mName = mime.name(); mPatterns = mime.globPatterns().join(" "); mComment = mime.comment(); }