Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b45b0845 authored by Marco Nelissen's avatar Marco Nelissen
Browse files

Do autodetection even if no locale was specified, and use the

detected encoding if it is unambiguous.
parent bfcb22a2
Loading
Loading
Loading
Loading
+39 −35
Original line number Diff line number Diff line
@@ -64,7 +64,6 @@ void MediaScannerClient::beginFile()

bool MediaScannerClient::addStringTag(const char* name, const char* value)
{
    if (mLocaleEncoding != kEncodingNone) {
    // don't bother caching strings that are all ASCII.
    // call handleStringTag directly instead.
    // check to see if value (which should be utf8) has any non-ASCII characters
@@ -85,7 +84,6 @@ bool MediaScannerClient::addStringTag(const char* name, const char* value)
        return true;
    }
    // else fall through
    }

    // autodetection is not necessary, so no need to cache the values
    // pass directly to the client instead
@@ -198,7 +196,6 @@ void MediaScannerClient::convertValues(uint32_t encoding)

void MediaScannerClient::endFile()
{
    if (mLocaleEncoding != kEncodingNone) {
    int size = mNames->size();
    uint32_t encoding = kEncodingAll;

@@ -206,16 +203,23 @@ void MediaScannerClient::endFile()
    for (int i = 0; i < mNames->size(); i++)
        encoding &= possibleEncodings(mValues->getEntry(i));

        // if the locale encoding matches, then assume we have a native encoding.
    // If one of the possible encodings matches the locale encoding, use that.
    // Otherwise, if there is only one possible encoding, use that.
    if (encoding & mLocaleEncoding)
        convertValues(mLocaleEncoding);
    else if ((encoding & (encoding - 1)) == 0)
        convertValues(encoding);
    else {
        // TODO: try harder to disambiguate the encoding, perhaps by looking at
        // other files by same artist, or even the user's entire collection.
        // For now, fall through and insert the strings as they are.
    }

    // finally, push all name/value pairs to the client
    for (int i = 0; i < mNames->size(); i++) {
        if (!handleStringTag(mNames->getEntry(i), mValues->getEntry(i)))
            break;
    }
    }
    // else addStringTag() has done all the work so we have nothing to do

    delete mNames;