Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-29702

QMimeDatabase::mimeTypeForFile(QString, MatchMode) doesn't work properly for mode == MatchContent

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Not Evaluated
    • None
    • 5.0.0, 5.0.1
    • Core: Other
    • None
    • f2e8a81227b3ee09afe1bf8a5d292e8c5f2ee67f

    Description

      QMimeType QMimeDatabase::mimeTypeForFile(const QString & fileName, MatchMode mode = MatchDefault) const
      does not work properly for QMimeDatabase::MatchContent. It will use MatchDefault instead.

      You can see in the following code that if mode is not MatchExtension, it passes through to the mimeTypeForFile( const QFileInfo & fileInfo, MatchMode mode = MatchDefault) version but it doesn't pass along the mode argument which defaults to MatchDefault. Passing the mode argument to the QFileInfo version should fix the problem.

      QMimeType QMimeDatabase::mimeTypeForFile(const QString &fileName, MatchMode mode) const
      {
      if (mode == MatchExtension) {
      QMutexLocker locker(&d->mutex);
      QStringList matches = d->mimeTypeForFileName(fileName);
      const int matchCount = matches.count();
      if (matchCount == 0)

      { return d->mimeTypeForName(d->defaultMimeType()); }

      else if (matchCount == 1)

      { return d->mimeTypeForName(matches.first()); }

      else

      { // We have to pick one. matches.sort(); // Make it deterministic return d->mimeTypeForName(matches.first()); }

      } else

      { // Implemented as a wrapper around mimeTypeForFile(QFileInfo), so no mutex. QFileInfo fileInfo(fileName); return mimeTypeForFile(fileInfo); }

      }

      Attachments

        For Gerrit Dashboard: QTBUG-29702
        # Subject Branch Project Status CR V

        Activity

          People

            dfaure David Faure (Private)
            davegrossman-ics Dave Grossman
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes