davidmhewitt / torrential

A simple torrent client for elementary OS
GNU General Public License v2.0
143 stars 30 forks source link

Play video from folder #122

Open peteruithoven opened 5 years ago

peteruithoven commented 5 years ago

It's quite common that video torrents are folders with the video file. I'm trying to make it easier to play that video from Torrential without having to deal with files. Fixes: #107

An alternative approach might be to have an easier / quicker way to open a specific file in a folder, for example by showing the file tree in a menu somewhere.

ToDo:

peteruithoven commented 5 years ago

Looking through the AppInfo API I noticed there is a launch_default_for_uri function which seems like a much easier way to do things. It removes the need for the content type guess and the need to create a uri list for example.

Before

private bool open_file (string file_path) {
    bool certain = false;
    var content_type = ContentType.guess (file_path, null, out certain);
    var appinfo = AppInfo.get_default_for_type (content_type, true);
    if (appinfo != null) {
        var file = File.new_for_path (file_path);
        if (file.query_exists ()) {
            var file_list = new List<string> ();
            file_list.append (file.get_uri ());
            try {
                appinfo.launch_uris (file_list, null);
                return true;
            } catch (Error e) {
                warning ("Unable to launch default handler for %s", content_type);
            }
        }
    }
    return false;
}

After

private bool open_file (string file_path) {
    var file = File.new_for_path (file_path);
    if (file.query_exists ()) {
        try {
            AppInfo.launch_default_for_uri (file.get_uri (), null);
            return true;
        } catch (Error e) {
            warning ("Unable to launch default handler for %s", file_path);
        }
    }
    return false;
}

Should I simplify the open_file method or am I missing something that the current approach handles better?