Skip to content

Commit

Permalink
Merge x-scheme-handler to master
Browse files Browse the repository at this point in the history
  • Loading branch information
magnus-ISU committed Jan 3, 2022
2 parents 54ef9cb + 62114bb commit fd5ce7a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
35 changes: 29 additions & 6 deletions selectdefaultapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ void SelectDefaultApplication::onApplicationSelectedLogic(bool allowEnabled)
}
void SelectDefaultApplication::addToMimetypeList(QListWidget *list, const QString &mimetypeName, const bool selected)
{
QString name = mimetypeName;
QListWidgetItem *item = new QListWidgetItem(name);
QString description = mimetypeDescription(mimetypeName);
QListWidgetItem *item = new QListWidgetItem(description);
item->setData(Qt::UserRole, mimetypeName);
item->setIcon(m_mimeTypeIcons[mimetypeName]);
list->addItem(item);
Expand Down Expand Up @@ -638,19 +638,42 @@ bool SelectDefaultApplication::applicationHasAnyCorrectMimetype(const QString &a
return false;
}

const char *X_SCHEME_HANDLER = "x-scheme-handler/";
// Returns the value of m_mimeDb.mimeTypeForName(name) but
// mimeTypeForName(application/x-pkcs12) always returns application/x-pkcs12 instead of application/pkcs12
// If
// If starts with x-scheme-handler, instead just returns the argument
const QString SelectDefaultApplication::wrapperMimeTypeForName(const QString &name) {
if (name.startsWith(X_SCHEME_HANDLER)) {
// x-scheme-handler is not a valid mimetype for a file, but we do want to be able to set applications as the default handlers for it.
// Assumes all x-scheme-handler/* is valid
return name;
}
const QMimeType mimetype = m_mimeDb.mimeTypeForName(name);
QString mimetypeName = mimetype.name();
// There appears to be a bug in Qt https://bugreports.qt.io/browse/QTBUG-99509, hack around it
if (mimetypeName == "application/pkcs12") {
mimetypeName = "application/x-pkcs12";
} else if (name.startsWith("x-scheme-handler/")) {
}
return mimetypeName;
}

const QString SelectDefaultApplication::mimetypeDescription(QString name) {
if (name.startsWith(X_SCHEME_HANDLER)) {
// x-scheme-handler is not a valid mimetype for a file, but we do want to be able to set applications as the default handlers for it.
// Assumes all x-scheme-handler/* is valid
mimetypeName = name;
return "Handles " + name.mid(strlen(X_SCHEME_HANDLER)) + ":// URIs\n" + name;
}
return mimetypeName;
// There appears to be a bug in Qt https://bugreports.qt.io/browse/QTBUG-99509, hack around it
if (name == "application/pkcs12") {
name = "application/x-pkcs12";
}
const QMimeType mimetype = m_mimeDb.mimeTypeForName(name);
QString desc = mimetype.filterString().trimmed();
if (desc.isEmpty()) {
desc = mimetype.comment().trimmed();
}
if (!desc.isEmpty()) {
desc += '\n';
}
return desc + name;
}
1 change: 1 addition & 0 deletions selectdefaultapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ private slots:
void onApplicationSelectedLogic(bool allowEnable);
const QString wrapperMimeTypeForName(const QString &name);
overwriteConfirm getOverwriteConfirmation(const QHash<QString, QString> &warnings);
const QString mimetypeDescription(QString name);

// Hashtable of application names to hashtables of mimetypes to .desktop file entries
QHash<QString, QHash<QString, QString> > m_apps;
Expand Down

0 comments on commit fd5ce7a

Please sign in to comment.