Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Marco Nelissen | 544ad2b | 2013-11-13 14:18:21 -0800 | [diff] [blame^] | 17 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "MediaScannerClient" |
| 19 | #include <utils/Log.h> |
| 20 | |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 21 | #include <media/mediascanner.h> |
| 22 | |
Marco Nelissen | 544ad2b | 2013-11-13 14:18:21 -0800 | [diff] [blame^] | 23 | #include "CharacterEncodingDetector.h" |
Mathias Agopian | 1f7d356 | 2013-05-06 20:20:16 -0700 | [diff] [blame] | 24 | #include "StringArray.h" |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 25 | |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 26 | namespace android { |
| 27 | |
| 28 | MediaScannerClient::MediaScannerClient() |
Marco Nelissen | 544ad2b | 2013-11-13 14:18:21 -0800 | [diff] [blame^] | 29 | : mEncodingDetector(NULL) |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 30 | { |
| 31 | } |
| 32 | |
| 33 | MediaScannerClient::~MediaScannerClient() |
| 34 | { |
Marco Nelissen | 544ad2b | 2013-11-13 14:18:21 -0800 | [diff] [blame^] | 35 | delete mEncodingDetector; |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | void MediaScannerClient::setLocale(const char* locale) |
| 39 | { |
Marco Nelissen | 544ad2b | 2013-11-13 14:18:21 -0800 | [diff] [blame^] | 40 | mLocale = locale; // not currently used |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void MediaScannerClient::beginFile() |
| 44 | { |
Marco Nelissen | 544ad2b | 2013-11-13 14:18:21 -0800 | [diff] [blame^] | 45 | delete mEncodingDetector; |
| 46 | mEncodingDetector = new CharacterEncodingDetector(); |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Jeff Brown | 7188e55 | 2011-07-20 16:38:43 -0700 | [diff] [blame] | 49 | status_t MediaScannerClient::addStringTag(const char* name, const char* value) |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 50 | { |
Marco Nelissen | 544ad2b | 2013-11-13 14:18:21 -0800 | [diff] [blame^] | 51 | mEncodingDetector->addTag(name, value); |
| 52 | return OK; |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void MediaScannerClient::endFile() |
| 56 | { |
Marco Nelissen | 544ad2b | 2013-11-13 14:18:21 -0800 | [diff] [blame^] | 57 | mEncodingDetector->detectAndConvert(); |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 58 | |
Marco Nelissen | 544ad2b | 2013-11-13 14:18:21 -0800 | [diff] [blame^] | 59 | int size = mEncodingDetector->size(); |
| 60 | if (size) { |
| 61 | for (int i = 0; i < size; i++) { |
| 62 | const char *name; |
| 63 | const char *value; |
| 64 | mEncodingDetector->getTag(i, &name, &value); |
| 65 | handleStringTag(name, value); |
Marco Nelissen | b5c3107 | 2010-03-11 13:37:46 -0800 | [diff] [blame] | 66 | } |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 67 | } |
Andreas Huber | 413f523 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | } // namespace android |