diff --git a/po/fr.po b/po/fr.po index b6ff176..8f1d9ea 100644 --- a/po/fr.po +++ b/po/fr.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-12-06 14:38+0100\n" +"POT-Creation-Date: 2017-12-10 17:06+0100\n" "Content-Type: text/plain; charset=UTF-8\n" #: data/appdata/com.github.birros.WebArchives.appdata.xml.in:7 @@ -426,50 +426,58 @@ msgstr "il y a %llum" msgid "%llus ago" msgstr "il y a %llus" -#: src/app/ui/content/home-view.vala:23 +#: src/app/ui/content/home-view.vala:25 msgid "Cannot open the archive file" msgstr "Impossible d'ouvrir l'archive" #. RECENTS -#: src/app/ui/content/home-view.vala:56 +#: src/app/ui/content/home-view.vala:58 msgid "Recents" msgstr "Récents" -#: src/app/ui/content/home-view.vala:82 +#: src/app/ui/content/home-view.vala:84 msgid "No archive recently opened." msgstr "Aucune archive récemment ouverte." -#: src/app/ui/content/home-view.vala:104 +#: src/app/ui/content/home-view.vala:106 msgid "Local" msgstr "" -#: src/app/ui/content/home-view.vala:122 src/app/ui/content/home-view.vala:198 +#: src/app/ui/content/home-view.vala:124 src/app/ui/content/home-view.vala:200 msgid "Refresh" msgstr "Actualiser" -#: src/app/ui/content/home-view.vala:140 +#: src/app/ui/content/home-view.vala:142 msgid "No archive automaticly detected on your system." msgstr "Aucune archive automatiquement détectée sur votre système." -#: src/app/ui/content/home-view.vala:162 +#: src/app/ui/content/home-view.vala:164 msgid "Remote" msgstr "Distant" -#: src/app/ui/content/home-view.vala:193 +#: src/app/ui/content/home-view.vala:195 msgid "Downloading" msgstr "Téléchargement" -#: src/app/ui/content/home-view.vala:216 +#: src/app/ui/content/home-view.vala:218 msgid "No archive available for download." msgstr "Aucune archive disponible en téléchargement." -#: src/app/ui/content/home-view.vala:405 -msgid "Are you sure to download %s ?" -msgstr "Êtes-vous sûr de vouloir télécharger %s ?" +#: src/app/ui/content/home-view.vala:407 +msgid "How would you like to download %s ?" +msgstr "Comment souhaitez-vous télécharger %s ?" -#: src/app/ui/content/home-view.vala:409 -msgid "This will open a link in your web browser." -msgstr "Ceci ouvrira un lien dans votre navigateur web." +#: src/app/ui/content/home-view.vala:411 +msgid "This will open a third-party application to download the archive." +msgstr "Ceci ouvrira une application tierce pour télécharger l'archive." + +#: src/app/ui/content/home-view.vala:413 +msgid "From a server" +msgstr "Depuis un serveur" + +#: src/app/ui/content/home-view.vala:414 +msgid "Peer-to-peer network" +msgstr "Réseau pair à pair" #: src/app/ui/gtk/notebook/notebook-popup-menu.vala:13 msgid "Detach to a new window" diff --git a/src/app/meson.build b/src/app/meson.build index 088de61..f9f2c4e 100644 --- a/src/app/meson.build +++ b/src/app/meson.build @@ -88,11 +88,9 @@ web_archives_sources = [ 'models/history-store.vala', 'models/history-model.vala', 'models/history-item.vala', - 'models/metalink.vala', 'utils/file-downloader.vala', 'utils/archive-downloader.vala', 'utils/library-parser.vala', - 'utils/metalink-parser.vala', 'utils/language-formater.vala', 'utils/tag-formater.vala', 'utils/tag-parser.vala', diff --git a/src/app/models/metalink.vala b/src/app/models/metalink.vala deleted file mode 100644 index 4dc27df..0000000 --- a/src/app/models/metalink.vala +++ /dev/null @@ -1,7 +0,0 @@ -public class WebArchives.Metalink : Object { - public SList urls; - - public Metalink () { - urls = new SList (); - } -} diff --git a/src/app/ui/content/home-view.vala b/src/app/ui/content/home-view.vala index 1c823ef..09e81f7 100644 --- a/src/app/ui/content/home-view.vala +++ b/src/app/ui/content/home-view.vala @@ -7,6 +7,8 @@ public class WebArchives.HomeView : Gtk.Overlay { private ArchiveModel remote_model; private ArchiveModel local_model; private ulong remote_model_callback; + private const int DIRECT_DOWNLOAD = 14; + private const int TORRENT_DOWNLOAD = 15; public HomeView (Context context) { this.context = context; @@ -400,26 +402,34 @@ public class WebArchives.HomeView : Gtk.Overlay { win, Gtk.DialogFlags.MODAL, Gtk.MessageType.QUESTION, - Gtk.ButtonsType.OK_CANCEL, + Gtk.ButtonsType.CANCEL, """%s""", - _("Are you sure to download %s ?").printf (espaced_title) + _("How would you like to download %s ?").printf (espaced_title) ); message_dialog.use_markup = true; message_dialog.secondary_text = - _("This will open a link in your web browser."); + _("This will open a third-party application to download the archive."); - Gtk.Widget ok_button = - message_dialog.get_widget_for_response (Gtk.ResponseType.OK); - ok_button.get_style_context().add_class ("suggested-action"); + message_dialog.add_button (_("From a server"), DIRECT_DOWNLOAD); + message_dialog.add_button (_("Peer-to-peer network"), TORRENT_DOWNLOAD); + Gtk.Widget torrent_button = + message_dialog.get_widget_for_response (TORRENT_DOWNLOAD); + torrent_button.get_style_context().add_class ("suggested-action"); message_dialog.response.connect ((response_type) => { switch (response_type) { - case Gtk.ResponseType.OK: + case DIRECT_DOWNLOAD: { - string metalink_url = archive.url.replace ( - "http://", "https://" + ArchiveDownloader.download ( + archive.url, ArchiveDownloader.Type.DIRECT + ); + break; + } + case TORRENT_DOWNLOAD: + { + ArchiveDownloader.download ( + archive.url, ArchiveDownloader.Type.TORRENT ); - ArchiveDownloader.download (metalink_url); break; } } diff --git a/src/app/utils/archive-downloader.vala b/src/app/utils/archive-downloader.vala index 5e89813..7186dde 100644 --- a/src/app/utils/archive-downloader.vala +++ b/src/app/utils/archive-downloader.vala @@ -1,53 +1,71 @@ public class WebArchives.ArchiveDownloader : Object { - public static void download (string url) { - string[] url_parts = url.split ("."); + public enum Type { + DIRECT, + TORRENT + } + + public static void download (string url, Type type) { + // ensure that https is used + string archive_url = url.replace ("http://", "https://"); + + string[] url_parts = archive_url.split ("."); string extension = url_parts [url_parts.length - 1]; + // remove meta4 file extension if exists if (extension == "meta4") { - download_metalink (url); + int limit = archive_url.length - "meta4".length - 1; + archive_url = archive_url.substring (0, limit); + } + + switch (type) { + case Type.DIRECT: + { + try { + AppInfo.launch_default_for_uri (archive_url, null); + } catch (Error e) { + warning (e.message); + } + break; + } + case Type.TORRENT: + { + /** + * The Kiwix download server is a MirrorBrain server, so a + * torrent file exists for all the files it serves. + * Just add a torrent file extension to the url to get it. + */ + download_torrent (archive_url + ".torrent"); + break; + } } } - private static void download_metalink (string metalink_url) { - string[] url_parts = metalink_url.split ("/"); - string metalink_filename = url_parts [url_parts.length - 1]; + private static void download_torrent (string url) { + string[] url_parts = url.split ("/"); + string filename = url_parts [url_parts.length - 1]; - // build metalink path + // build torrent path string cache_dir = Environment.get_user_cache_dir (); string files_folder = Path.build_filename ( cache_dir, "web-archives", "files" ); - string metalink_path = Path.build_filename( - files_folder, metalink_filename + string torrent_path = Path.build_filename( + files_folder, filename ); - FileDownloader metalink_downloader = new FileDownloader (); - metalink_downloader.download_file (metalink_url, metalink_path); - metalink_downloader.complete.connect (() => { - info ("COMPLETE"); - - // parse metalink - MetalinkParser metalink_parser = new MetalinkParser (); - Metalink metalink = metalink_parser.parse_file (metalink_path); - - // download first https - unowned SList urls = metalink.urls; - while (urls != null) { - if (urls.data.has_prefix ("https://")) { - info ("download: %s", urls.data); - try { - AppInfo.launch_default_for_uri (urls.data, null); - } catch (Error e) { - warning (e.message); - } - return; - } - urls = urls.next; + FileDownloader downloader = new FileDownloader (); + downloader.download_file (url, torrent_path); + downloader.complete.connect (() => { + try { + string torrent_file_uri = Filename.to_uri (torrent_path); + AppInfo.launch_default_for_uri (torrent_file_uri, null); + } catch (Error e) { + warning (e.message); } }); - metalink_downloader.notify["progress"].connect (() => { + downloader.notify["progress"].connect (() => { uint8 progress_percent = (uint8) ( - metalink_downloader.progress * 100 + downloader.progress * 100 ); info ("%u %%", progress_percent); }); diff --git a/src/app/utils/metalink-parser.vala b/src/app/utils/metalink-parser.vala deleted file mode 100644 index 6baa379..0000000 --- a/src/app/utils/metalink-parser.vala +++ /dev/null @@ -1,62 +0,0 @@ -public class WebArchives.MetalinkParser : Object { - private Metalink metalink; - - public Metalink? parse_file (string filepath) { - metalink = new Metalink (); - - Xml.Parser.init (); - - Xml.Doc* doc = Xml.Parser.parse_file (filepath); - if (doc == null) { - warning ("File %s not found or permissions missing", filepath); - return null; - } - - Xml.Node* root = doc->get_root_element (); - if (root == null) { - delete doc; - warning ("The xml file '%s' is empty", filepath); - return null; - } - - if (root->name == "metalink") { - parse_metalink (root); - } - - delete doc; - - Xml.Parser.cleanup (); - - return metalink; - } - - private void parse_metalink (Xml.Node* node) { - for (Xml.Node* iter = node->children; iter != null; iter = iter->next) { - // Spaces between tags are also nodes, discard them - if (iter->type != Xml.ElementType.ELEMENT_NODE) { - continue; - } - - string node_name = iter->name; - if (node_name == "file") { - parse_file_node (iter); - return; - } - } - } - - private void parse_file_node (Xml.Node* node) { - for (Xml.Node* iter = node->children; iter != null; iter = iter->next) { - // Spaces between tags are also nodes, discard them - if (iter->type != Xml.ElementType.ELEMENT_NODE) { - continue; - } - - string node_name = iter->name; - string node_content = iter->get_content (); - if (node_name == "url") { - metalink.urls.append (node_content); - } - } - } -}