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

Commit 6e039982 authored by Matt Garnes's avatar Matt Garnes
Browse files

Support ambigous file extension mimetypes.

Previously, CMFileManager operated under the assumption that file
extensions map to exactly one mimetype. This is not true in some cases,
such as .3gp files, which can have an audio or video mimetype.

Add support so that in mime_types.properties we can specify a comma
separated list of mimetype info that are matched with a given extension.
If an AmbiguousExtensionHelper subclass implementation is provided for one of these
extensions, this is used to determine the correct mimetype for the file.

Change-Id: Ie73d6ad646692dfeac112ac50c1c6436e6b5559b
parent 1288edb9
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -274,10 +274,6 @@ qcp = AUDIO | audio/qcelp | fso_type_audio_drawable
xmf   = AUDIO    | audio/xmf                        | fso_type_audio_drawable

# Video
3gp   = VIDEO    | video/3gpp                       | fso_type_video_drawable
3gpp  = VIDEO    | video/3gpp                       | fso_type_video_drawable
3g2   = VIDEO    | video/3gpp2                      | fso_type_video_drawable
3gpp2 = VIDEO    | video/3gpp2                      | fso_type_video_drawable
h261  = VIDEO    | video/h261                       | fso_type_video_drawable
h263  = VIDEO    | video/h263                       | fso_type_video_drawable
h264  = VIDEO    | video/h264                       | fso_type_video_drawable
@@ -322,6 +318,16 @@ m4v = VIDEO | video/x-m4v | fso_type_video_drawable
divx  = VIDEO    | video/divx                       | fso_type_video_drawable
ts    = VIDEO    | video/MP2T                       | fso_type_video_drawable

# Audio and Video
3gp   = VIDEO    | video/3gpp                       | fso_type_video_drawable,\
        AUDIO    | audio/3gpp                       | fso_type_audio_drawable
3gpp  = VIDEO    | video/3gpp                       | fso_type_video_drawable,\
        AUDIO    | audio/3gpp                       | fso_type_audio_drawable
3g2   = VIDEO    | video/3gpp2                      | fso_type_video_drawable,\
        AUDIO    | audio/3gpp2                      | fso_type_audio_drawable
3gpp2 = VIDEO    | video/3gpp2                      | fso_type_video_drawable,\
        AUDIO    | audio/3gpp2                      | fso_type_audio_drawable

# Security
asc   = SECURITY | application/pgp-signature        | fso_type_security_drawable
cer   = SECURITY | application/pkix-cert            | fso_type_security_drawable
+4 −3
Original line number Diff line number Diff line
@@ -1025,7 +1025,7 @@ public class SearchActivity extends Activity
            // all of the video files in the current search will also be sent as an extra in the
            // intent along with the item that was clicked
            MimeTypeCategory fileCategory = MimeTypeHelper.getCategoryFromExt(this,
                    FileHelper.getExtension(fso));
                    FileHelper.getExtension(fso), fso.getFullPath());
            if (fileCategory == MimeTypeCategory.VIDEO) {

                ArrayList<FileSystemObject> filteredList = filterSearchResults(fileCategory);
@@ -1075,8 +1075,9 @@ public class SearchActivity extends Activity
        if (mAdapter.getCount() < 1) return filteredList;

        for (FileSystemObject fso : mAdapter.getFiles()) {
            if (MimeTypeHelper.getCategoryFromExt(this, FileHelper.getExtension(fso))
                    == category) {
            if (MimeTypeHelper.getCategoryFromExt(this,
                                                  FileHelper.getExtension(fso),
                                                  fso.getFullPath()) == category) {
                filteredList.add(fso);
            }
        }
+6 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import com.cyanogenmod.filemanager.console.ExecutionException;
import com.cyanogenmod.filemanager.console.InsufficientPermissionsException;
import com.cyanogenmod.filemanager.console.NoSuchFileOrDirectory;
import com.cyanogenmod.filemanager.model.FolderUsage;
import com.cyanogenmod.filemanager.util.FileHelper;
import com.cyanogenmod.filemanager.util.MimeTypeHelper;
import com.cyanogenmod.filemanager.util.MimeTypeHelper.MimeTypeCategory;

@@ -149,8 +150,12 @@ public class FolderUsageCommand extends Program implements FolderUsageExecutable
                    } else {
                        this.mFolderUsage.addFile();
                        // Compute statistics and size
                        File file = files[i];
                        String ext = FileHelper.getExtension(file.getName());
                        MimeTypeCategory category =
                                MimeTypeHelper.getCategory(null, files[i]);
                                MimeTypeHelper.getCategoryFromExt(null,
                                                                  ext,
                                                                  file.getAbsolutePath());
                        this.mFolderUsage.addFileToCategory(category);
                        this.mFolderUsage.addSize(files[i].length());
                    }
+8 −1
Original line number Diff line number Diff line
@@ -24,11 +24,14 @@ import com.cyanogenmod.filemanager.console.ExecutionException;
import com.cyanogenmod.filemanager.console.NoSuchFileOrDirectory;
import com.cyanogenmod.filemanager.console.secure.SecureConsole;
import com.cyanogenmod.filemanager.model.FolderUsage;
import com.cyanogenmod.filemanager.util.FileHelper;
import com.cyanogenmod.filemanager.util.MimeTypeHelper;
import com.cyanogenmod.filemanager.util.MimeTypeHelper.MimeTypeCategory;

import de.schlichtherle.truezip.file.TFile;

import java.io.File;

/**
 * A class for retrieve the disk usage of a folder.
 */
@@ -149,8 +152,12 @@ public class FolderUsageCommand extends Program implements FolderUsageExecutable
                    } else {
                        this.mFolderUsage.addFile();
                        // Compute statistics and size
                        File file = files[i];
                        String ext = FileHelper.getExtension(file.getName());
                        MimeTypeCategory category =
                                MimeTypeHelper.getCategory(null, files[i]);
                                MimeTypeHelper.getCategoryFromExt(null,
                                                                  ext,
                                                                  file.getAbsolutePath());
                        this.mFolderUsage.addFileToCategory(category);
                        this.mFolderUsage.addSize(files[i].length());
                    }
+5 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.cyanogenmod.filemanager.util.MimeTypeHelper;
import com.cyanogenmod.filemanager.util.MimeTypeHelper.MimeTypeCategory;

import java.io.BufferedReader;
import java.io.File;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
@@ -174,8 +175,11 @@ public class FolderUsageCommand extends AsyncResultProgram implements FolderUsag
                                long size = Long.parseLong(fields[4]);
                                String name = fields[fields.length-1];// We only need the extension
                                String ext = FileHelper.getExtension(name);
                                File file = new File(mDirectory, name);
                                MimeTypeCategory category =
                                        MimeTypeHelper.getCategoryFromExt(null, ext);
                                        MimeTypeHelper.getCategoryFromExt(null,
                                                                          ext,
                                                                          file.getAbsolutePath());
                                this.mFolderUsage.addFile();
                                this.mFolderUsage.addFileToCategory(category);
                                this.mFolderUsage.addSize(size);
Loading