From a22ee46bbbcb81eb7f33dcd71b41203b50d358ce Mon Sep 17 00:00:00 2001 From: ItsMicin Date: Thu, 30 Dec 2021 20:18:39 +0700 Subject: [PATCH] New feature --- .../com.github.gabutakut.gabutdm.seed.svg | 813 ++++++++++++++++++ data/meson.build | 3 +- src/AddUrl.vala | 260 ++++-- src/Application.vala | 1 + src/DownloadRow.vala | 41 +- src/Downloader.vala | 3 +- src/GabutWindow.vala | 41 +- src/PieceSelector.vala | 48 ++ src/Preferences.vala | 127 ++- src/ServerUpload.vala | 8 +- src/UriSelector.vala | 48 ++ src/Utils.vala | 369 ++++++-- src/meson.build | 4 +- 13 files changed, 1539 insertions(+), 227 deletions(-) create mode 100644 data/icons/actions/com.github.gabutakut.gabutdm.seed.svg create mode 100755 src/PieceSelector.vala create mode 100755 src/UriSelector.vala diff --git a/data/icons/actions/com.github.gabutakut.gabutdm.seed.svg b/data/icons/actions/com.github.gabutakut.gabutdm.seed.svg new file mode 100644 index 0000000..710bb38 --- /dev/null +++ b/data/icons/actions/com.github.gabutakut.gabutdm.seed.svg @@ -0,0 +1,813 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/data/meson.build b/data/meson.build index 69dedb0..6f97fcf 100644 --- a/data/meson.build +++ b/data/meson.build @@ -19,7 +19,8 @@ actions = [ '.pause.svg', '.magnet.svg', '.waiting.svg', - '.auto-symbolic.svg' + '.auto-symbolic.svg', + '.seed.svg' ] foreach m : actions diff --git a/src/AddUrl.vala b/src/AddUrl.vala index 131e3a9..e0cdb90 100644 --- a/src/AddUrl.vala +++ b/src/AddUrl.vala @@ -26,7 +26,7 @@ namespace Gabut { PROPERTY } public signal void downloadfile (string url, Gee.HashMap options, bool later, int linkmode); - public signal void saveproperty (Gee.HashMap options); + public Gtk.Button save_button; private Gtk.Image status_image; private Gtk.Label sizelabel; private MediaEntry link_entry; @@ -52,6 +52,8 @@ namespace Gabut { private Gtk.CheckButton usecookie; private Gtk.CheckButton usefolder; private Gtk.CheckButton encrypt; + private Gtk.CheckButton integrity; + private Gtk.CheckButton unverified; private Gtk.FileChooserButton folder_location; private Gtk.FileChooserButton cookie_location; public DialogType dialogtype { get; construct; } @@ -132,7 +134,7 @@ namespace Gabut { view_mode.append_text (_("Option")); view_mode.append_text (_("Folder")); view_mode.append_text (_("Checksum")); - view_mode.append_text (_("Encrypt")); + view_mode.append_text (_("Torrent")); view_mode.selected = 0; var header = get_header_bar (); @@ -186,7 +188,8 @@ namespace Gabut { var alllink = new Gtk.Grid () { expand = true, height_request = 130, - halign = Gtk.Align.START + halign = Gtk.Align.CENTER, + valign = Gtk.Align.CENTER }; alllink.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); alllink.attach (overlay, 0, 0, 1, 5); @@ -302,7 +305,8 @@ namespace Gabut { var logingrid = new Gtk.Grid () { expand = true, height_request = 130, - halign = Gtk.Align.CENTER + halign = Gtk.Align.CENTER, + valign = Gtk.Align.CENTER }; logingrid.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); logingrid.attach (login_button, 1, 0, 1, 1); @@ -324,7 +328,8 @@ namespace Gabut { var moregrid = new Gtk.Grid () { expand = true, height_request = 130, - halign = Gtk.Align.CENTER + halign = Gtk.Align.CENTER, + valign = Gtk.Align.CENTER }; moregrid.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); moregrid.attach (new HeaderLabel (_("User Agent:"), 300), 1, 0, 1, 1); @@ -377,7 +382,8 @@ namespace Gabut { var foldergrid = new Gtk.Grid () { expand = true, height_request = 130, - halign = Gtk.Align.CENTER + halign = Gtk.Align.CENTER, + valign = Gtk.Align.CENTER }; foldergrid.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); foldergrid.attach (usecookie, 1, 0, 1, 1); @@ -421,7 +427,8 @@ namespace Gabut { var checksumgrid = new Gtk.Grid () { expand = true, height_request = 130, - halign = Gtk.Align.CENTER + halign = Gtk.Align.CENTER, + valign = Gtk.Align.CENTER }; checksumgrid.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); checksumgrid.attach (new HeaderLabel (_("Type:"), 300), 1, 0, 1, 1); @@ -429,6 +436,24 @@ namespace Gabut { checksumgrid.attach (new HeaderLabel (_("Hash:"), 300), 1, 2, 1, 1); checksumgrid.attach (checksum_entry, 1, 3, 1, 1); + var integimg = new Gtk.Grid (); + integimg.add (new Gtk.Image.from_icon_name ("com.github.gabutakut.gabutdm.seed", Gtk.IconSize.SMALL_TOOLBAR)); + integimg.add (new Gtk.Label (_("BT Seed"))); + + integrity = new Gtk.CheckButton () { + width_request = 300, + margin_bottom = 5 + }; + integrity.add (integimg); + + var unveimg = new Gtk.Grid (); + unveimg.add (new Gtk.Image.from_icon_name ("com.github.gabutakut.gabutdm.seed", Gtk.IconSize.SMALL_TOOLBAR)); + unveimg.add (new Gtk.Label (_("BT Seed Unverified"))); + unverified = new Gtk.CheckButton () { + width_request = 300 + }; + unverified.add (unveimg); + encrypt_button = new Gtk.MenuButton (); encrypt_flow = new Gtk.FlowBox () { orientation = Gtk.Orientation.HORIZONTAL, @@ -475,12 +500,16 @@ namespace Gabut { var encryptgrid = new Gtk.Grid () { expand = true, height_request = 130, - halign = Gtk.Align.CENTER + halign = Gtk.Align.CENTER, + valign = Gtk.Align.CENTER }; encryptgrid.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); - encryptgrid.attach (new HeaderLabel (_("BitTorrent Encryption:"), 300), 1, 0, 1, 1); - encryptgrid.attach (encrypt, 1, 1, 1, 1); - encryptgrid.attach (encrypt_button, 1, 2, 1, 1); + encryptgrid.attach (new HeaderLabel (_("BitTorrent Seed:"), 300), 1, 0, 1, 1); + encryptgrid.attach (integrity, 1, 1, 1, 1); + encryptgrid.attach (unverified, 1, 2, 1, 1); + encryptgrid.attach (new HeaderLabel (_("BitTorrent Encryption:"), 300), 1, 3, 1, 1); + encryptgrid.attach (encrypt, 1, 4, 1, 1); + encryptgrid.attach (encrypt_button, 1, 5, 1, 1); var stack = new Gtk.Stack () { transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT, @@ -524,14 +553,13 @@ namespace Gabut { destroy (); }); - var save_button = new Gtk.Button.with_label (_("Save")) { + save_button = new Gtk.Button.with_label (_("Save")) { width_request = 120, height_request = 25 }; save_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION); save_button.clicked.connect (()=> { set_option (true); - saveproperty (hashoptions); destroy (); }); var box_action = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 5) { @@ -622,18 +650,35 @@ namespace Gabut { hashoptions.unset (AriaOptions.PROXYPASSWORD.get_name ()); } } - if (loguser_entry.text.strip () != "") { - hashoptions[AriaOptions.USERNAME.get_name ()] = loguser_entry.text.strip (); - } else { - if (hashoptions.has_key (AriaOptions.USERNAME.get_name ())) { - hashoptions.unset (AriaOptions.USERNAME.get_name ()); + if (loginuser.loginuser.get_name ().down () == "http") { + if (loguser_entry.text.strip () != "") { + hashoptions[AriaOptions.HTTP_USER.get_name ()] = loguser_entry.text.strip (); + } else { + if (hashoptions.has_key (AriaOptions.HTTP_USER.get_name ())) { + hashoptions.unset (AriaOptions.HTTP_USER.get_name ()); + } + } + if (logpass_entry.text.strip () != "") { + hashoptions[AriaOptions.HTTP_PASSWD.get_name ()] = logpass_entry.text.strip (); + } else { + if (hashoptions.has_key (AriaOptions.HTTP_PASSWD.get_name ())) { + hashoptions.unset (AriaOptions.HTTP_PASSWD.get_name ()); + } } - } - if (logpass_entry.text.strip () != "") { - hashoptions[AriaOptions.PASSWORD.get_name ()] = logpass_entry.text.strip (); } else { - if (hashoptions.has_key (AriaOptions.PASSWORD.get_name ())) { - hashoptions.unset (AriaOptions.PASSWORD.get_name ()); + if (loguser_entry.text.strip () != "") { + hashoptions[AriaOptions.FTP_USER.get_name ()] = loguser_entry.text.strip (); + } else { + if (hashoptions.has_key (AriaOptions.FTP_USER.get_name ())) { + hashoptions.unset (AriaOptions.FTP_USER.get_name ()); + } + } + if (logpass_entry.text.strip () != "") { + hashoptions[AriaOptions.FTP_PASSWD.get_name ()] = logpass_entry.text.strip (); + } else { + if (hashoptions.has_key (AriaOptions.FTP_PASSWD.get_name ())) { + hashoptions.unset (AriaOptions.FTP_PASSWD.get_name ()); + } } } if (usefolder.active) { @@ -680,34 +725,80 @@ namespace Gabut { hashoptions.unset (AriaOptions.CHECKSUM.get_name ()); } } + hashoptions[AriaOptions.BT_SEED_UNVERIFIED.get_name ()] = unverified.active.to_string (); + hashoptions[AriaOptions.CHECK_INTEGRITY.get_name ()] = integrity.active.to_string (); hashoptions[AriaOptions.BT_SAVE_METADATA.get_name ()] = save_meta.active.to_string (); hashoptions[AriaOptions.RPC_SAVE_UPLOAD_METADATA.get_name ()] = save_meta.active.to_string (); hashoptions[AriaOptions.PROXY_METHOD.get_name ()] = proxymethod.method.get_name ().down (); hashoptions[AriaOptions.BT_REQUIRE_CRYPTO.get_name ()] = encrypt.active.to_string (); hashoptions[AriaOptions.BT_MIN_CRYPTO_LEVEL.get_name ()] = btencrypt.btencrypt.get_name ().down (); + if (!integrity.active && !unverified.active) { + hashoptions[AriaOptions.SEED_TIME.get_name ()] = "0"; + } else { + hashoptions[AriaOptions.SEED_TIME.get_name ()] = get_dbsetting (DBSettings.SEEDTIME); + } if (save) { - if (checksumtype.checksums.get_name ().down () != "none") { - aria_set_option (row.ariagid, AriaOptions.CHECKSUM, checksumtype.checksums.get_name () + checksum_entry.text.strip ()); - } else { - aria_set_option (row.ariagid, AriaOptions.CHECKSUM, ""); - } - aria_set_option (row.ariagid, AriaOptions.PROXYUSERNAME, user_entry.text); - aria_set_option (row.ariagid, AriaOptions.PROXYPASSWORD, pass_entry.text); - aria_set_option (row.ariagid, AriaOptions.USERNAME, loguser_entry.text); - aria_set_option (row.ariagid, AriaOptions.PASSWORD, logpass_entry.text); aria_set_option (row.ariagid, AriaOptions.COOKIE, usecookie.active? cookie_location.get_file ().get_path ().replace ("/", "\\/") : ""); aria_set_option (row.ariagid, AriaOptions.DIR, usefolder.active? folder_location.get_file ().get_path ().replace ("/", "\\/") : get_dbsetting (DBSettings.DIR)); aria_set_option (row.ariagid, AriaOptions.REFERER, refer_entry.text); if (name_entry.text.strip () != "") { aria_set_option (row.ariagid, AriaOptions.OUT, name_entry.text); } - aria_set_option (row.ariagid, AriaOptions.USER_AGENT, useragent_entry.text.strip ()); - aria_set_option (row.ariagid, AriaOptions.PROXY, proxy_entry.text.strip () != ""? @"$(proxy_entry.text):$(port_entry.value))" : ""); - aria_set_option (row.ariagid, AriaOptions.BT_SAVE_METADATA, save_meta.active.to_string ()); - aria_set_option (row.ariagid, AriaOptions.RPC_SAVE_UPLOAD_METADATA, save_meta.active.to_string ()); aria_set_option (row.ariagid, AriaOptions.PROXY_METHOD, proxymethod.method.get_name ().down ()); - aria_set_option (row.ariagid, AriaOptions.BT_REQUIRE_CRYPTO, encrypt.active.to_string ()); - aria_set_option (row.ariagid, AriaOptions.BT_MIN_CRYPTO_LEVEL, btencrypt.btencrypt.get_name ().down ()); + aria_set_option (row.ariagid, AriaOptions.BT_SEED_UNVERIFIED, unverified.active.to_string ()); + aria_set_option (row.ariagid, AriaOptions.CHECK_INTEGRITY, integrity.active.to_string ()); + if (row.status == StatusMode.ACTIVE) { + aria_pause (row.ariagid); + set_options (); + aria_unpause (row.ariagid); + } else { + set_options (); + } + if (checksumtype.checksums.get_name () + checksum_entry.text.strip () != aria_get_option (row.ariagid, AriaOptions.CHECKSUM) + || save_meta.active != bool.parse (aria_get_option (row.ariagid, AriaOptions.BT_SAVE_METADATA))) { + aria_remove (row.ariagid); + if (row.linkmode == LinkMode.TORRENT) { + if (row.url.has_prefix ("magnet:?")) { + row.linkmode = LinkMode.MAGNETLINK; + row.ariagid = aria_url (row.url, hashoptions); + } else { + row.ariagid = aria_torrent (row.url, hashoptions); + } + } else if (row.linkmode == LinkMode.METALINK) { + row.ariagid = aria_metalink (row.url, hashoptions); + } else if (row.linkmode == LinkMode.URL) { + if (row.url.has_prefix ("magnet:?")) { + row.linkmode = LinkMode.MAGNETLINK; + row.ariagid = aria_url (row.url, hashoptions); + } else { + row.linkmode = LinkMode.URL; + row.ariagid = aria_url (row.url, hashoptions); + } + } + } + row.status = row.status_aria (aria_tell_status (row.ariagid, TellStatus.STATUS)); + row.filepath = aria_str_files (AriaGetfiles.PATH, row.ariagid); + if (!integrity.active && !unverified.active) { + aria_set_option (row.ariagid, AriaOptions.SEED_TIME, "0"); + } else { + aria_set_option (row.ariagid, AriaOptions.SEED_TIME, get_dbsetting (DBSettings.SEEDTIME)); + } + } + } + + private void set_options () { + aria_set_option (row.ariagid, AriaOptions.PROXY, proxy_entry.text.strip () != ""? @"$(proxy_entry.text):$(port_entry.value))" : ""); + aria_set_option (row.ariagid, AriaOptions.PROXYUSERNAME, user_entry.text); + aria_set_option (row.ariagid, AriaOptions.PROXYPASSWORD, pass_entry.text); + aria_set_option (row.ariagid, AriaOptions.BT_REQUIRE_CRYPTO, encrypt.active.to_string ()); + aria_set_option (row.ariagid, AriaOptions.USER_AGENT, useragent_entry.text.strip ()); + aria_set_option (row.ariagid, AriaOptions.BT_MIN_CRYPTO_LEVEL, btencrypt.btencrypt.get_name ().down ()); + if (loginuser.loginuser.get_name ().down () == "http") { + aria_set_option (row.ariagid, AriaOptions.HTTP_USER, loguser_entry.text); + aria_set_option (row.ariagid, AriaOptions.HTTP_PASSWD, logpass_entry.text); + } else { + aria_set_option (row.ariagid, AriaOptions.FTP_USER, loguser_entry.text); + aria_set_option (row.ariagid, AriaOptions.FTP_PASSWD, logpass_entry.text); } } @@ -755,23 +846,26 @@ namespace Gabut { this.hashoptions = row.hashoption; status_image.gicon = row.imagefile.gicon; sizelabel.label = GLib.format_size (row.totalsize); - if (hashoptions.has_key (AriaOptions.PROXY.get_name ())) { - proxy_entry.text = hashoptions.@get (AriaOptions.PROXY.get_name ().replace (@":$(hashoptions.@get (AriaOptions.PROXYPORT.get_name ()))", "")); - } - if (hashoptions.has_key (AriaOptions.PROXYPORT.get_name ())) { - port_entry.value = double.parse (hashoptions.@get (AriaOptions.PROXYPORT.get_name ())); - } - if (hashoptions.has_key (AriaOptions.PROXYUSERNAME.get_name ())) { - user_entry.text = hashoptions.@get (AriaOptions.PROXYUSERNAME.get_name ()); - } - if (hashoptions.has_key (AriaOptions.PROXYPASSWORD.get_name ())) { - pass_entry.text = hashoptions.@get (AriaOptions.PROXYPASSWORD.get_name ()); - } - if (hashoptions.has_key (AriaOptions.USERNAME.get_name ())) { - loguser_entry.text = hashoptions.@get (AriaOptions.USERNAME.get_name ()); - } - if (hashoptions.has_key (AriaOptions.PASSWORD.get_name ())) { - logpass_entry.text = hashoptions.@get (AriaOptions.PASSWORD.get_name ()); + string myproxy = aria_get_option (row.ariagid, AriaOptions.PROXY); + if (myproxy != "") { + int lastprox = myproxy.last_index_of (":"); + string proxytext = myproxy.slice (0, lastprox); + proxy_entry.text = proxytext.contains ("\\/")? proxytext.replace ("\\/", "/") : proxytext; + port_entry.value = double.parse (myproxy.slice (lastprox + 1, myproxy.length - 1)); + } + user_entry.text = aria_get_option (row.ariagid, AriaOptions.PROXYUSERNAME); + pass_entry.text = aria_get_option (row.ariagid, AriaOptions.PROXYPASSWORD); + string httpusr = aria_get_option (row.ariagid, AriaOptions.HTTP_USER); + if (httpusr != "") { + loginuser = login_flow.get_children ().nth_data (0) as LoginUser; + loguser_entry.text = aria_get_option (row.ariagid, AriaOptions.HTTP_USER); + logpass_entry.text = aria_get_option (row.ariagid, AriaOptions.HTTP_PASSWD); + } + string ftpusr = aria_get_option (row.ariagid, AriaOptions.FTP_USER); + if (ftpusr != "") { + loginuser = login_flow.get_children ().nth_data (1) as LoginUser; + loguser_entry.text = aria_get_option (row.ariagid, AriaOptions.FTP_USER); + logpass_entry.text = aria_get_option (row.ariagid, AriaOptions.FTP_PASSWD); } usefolder.active = hashoptions.has_key (AriaOptions.DIR.get_name ()); if (usefolder.active) { @@ -781,41 +875,37 @@ namespace Gabut { if (usecookie.active) { cookie_location.set_uri (File.new_for_path (hashoptions.@get (AriaOptions.COOKIE.get_name ()).replace ("\\/", "/")).get_uri ()); } - if (hashoptions.has_key (AriaOptions.REFERER.get_name ())) { - refer_entry.text = hashoptions.@get (AriaOptions.REFERER.get_name ()); - } - if (hashoptions.has_key (AriaOptions.USER_AGENT.get_name ())) { - useragent_entry.text = hashoptions.@get (AriaOptions.USER_AGENT.get_name ()); - } - if (hashoptions.has_key (AriaOptions.OUT.get_name ())) { - name_entry.text = hashoptions.@get (AriaOptions.OUT.get_name ()); - } - if (hashoptions.has_key (AriaOptions.BT_REQUIRE_CRYPTO.get_name ())) { - encrypt.active = bool.parse (hashoptions.@get (AriaOptions.BT_REQUIRE_CRYPTO.get_name ())); - } - if (hashoptions.has_key (AriaOptions.PROXY_METHOD.get_name ())) { - foreach (var method in method_flow.get_children ()) { - if (((ProxyMethod) method).method.get_name ().down () == hashoptions.@get (AriaOptions.PROXY_METHOD.get_name ())) { - proxymethod = method as ProxyMethod; - } - }; - } - if (hashoptions.has_key (AriaOptions.CHECKSUM.get_name ())) { - foreach (var checksum in checksums_flow.get_children ()) { - if (hashoptions.@get (AriaOptions.CHECKSUM.get_name ()).contains (((ChecksumType) checksum).checksums.get_name ())) { - checksumtype = checksum as ChecksumType; - checksum_entry.text = hashoptions.@get (AriaOptions.CHECKSUM.get_name ()).split ("=")[1]; - } - }; - } - if (hashoptions.has_key (AriaOptions.BT_MIN_CRYPTO_LEVEL.get_name ())) { + string reffer = aria_get_option (row.ariagid, AriaOptions.REFERER); + if (reffer != "") { + refer_entry.text = reffer.contains ("\\/")? reffer.replace ("\\/", "/") : reffer; + } + string agntusr = aria_get_option (row.ariagid, AriaOptions.USER_AGENT); + if (agntusr != "") { + useragent_entry.text = agntusr.contains ("\\/")? agntusr.replace ("\\/", "/") : agntusr; + } + name_entry.text = aria_get_option (row.ariagid, AriaOptions.OUT); + encrypt.active = bool.parse (aria_get_option (row.ariagid, AriaOptions.BT_REQUIRE_CRYPTO)); + integrity.active = bool.parse (aria_get_option (row.ariagid, AriaOptions.CHECK_INTEGRITY)); + unverified.active = bool.parse (aria_get_option (row.ariagid, AriaOptions.BT_SEED_UNVERIFIED)); + foreach (var method in method_flow.get_children ()) { + if (((ProxyMethod) method).method.get_name ().down () == aria_get_option (row.ariagid, AriaOptions.PROXY_METHOD).down ()) { + proxymethod = method as ProxyMethod; + } + }; + foreach (var checksum in checksums_flow.get_children ()) { + if (aria_get_option (row.ariagid, AriaOptions.CHECKSUM).contains (((ChecksumType) checksum).checksums.get_name ())) { + checksumtype = checksum as ChecksumType; + checksum_entry.text = aria_get_option (row.ariagid, AriaOptions.CHECKSUM).split ("=")[1]; + } + }; + if (encrypt.active) { foreach (var encrp in encrypt_flow.get_children ()) { - if (hashoptions.@get (AriaOptions.BT_MIN_CRYPTO_LEVEL.get_name ()).contains (((BTEncrypt) encrp).btencrypt.get_name ().down ())) { + if (aria_get_option (row.ariagid, AriaOptions.BT_MIN_CRYPTO_LEVEL).contains (((BTEncrypt) encrp).btencrypt.get_name ().down ())) { btencrypt = encrp as BTEncrypt; } }; } - save_meta.active = bool.parse (hashoptions.get (AriaOptions.RPC_SAVE_UPLOAD_METADATA.get_name ())) | bool.parse (hashoptions.get (AriaOptions.RPC_SAVE_UPLOAD_METADATA.get_name ())); + save_meta.active = bool.parse (aria_get_option (row.ariagid, AriaOptions.RPC_SAVE_UPLOAD_METADATA)) | bool.parse (aria_get_option (row.ariagid, AriaOptions.RPC_SAVE_UPLOAD_METADATA)); } } } diff --git a/src/Application.vala b/src/Application.vala index 5ef8c68..1ad685c 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -153,6 +153,7 @@ namespace Gabut { perform_key_event ("v", false, 0); pantheon_theme.begin (); gabutwindow.load_dowanload (); + check_optdown (); } else { if (startingup) { gabutwindow.show_all (); diff --git a/src/DownloadRow.vala b/src/DownloadRow.vala index 4eeb99a..15e8f5f 100644 --- a/src/DownloadRow.vala +++ b/src/DownloadRow.vala @@ -29,7 +29,6 @@ namespace Gabut { public Gtk.Image imagefile; public Gtk.Image badge_img; private bool stoptimer; - private uint completedl = 0U; public Gee.HashMap hashoption = new Gee.HashMap (); private int _linkmode; @@ -88,28 +87,26 @@ namespace Gabut { remove_timeout (); break; case StatusMode.COMPLETE: - ((Gtk.Image) start_button.image).icon_name = "process-completed"; - start_button.tooltip_text = _("Complete"); + if (ariagid != null) { + if (aria_tell_status (ariagid, TellStatus.SEEDER) == "true") { + ((Gtk.Image) start_button.image).icon_name = "com.github.gabutakut.gabutdm.seed"; + start_button.tooltip_text = _("Seeding"); + return; + } else { + ((Gtk.Image) start_button.image).icon_name = "process-completed"; + start_button.tooltip_text = _("Complete"); + } + } if (linkmode != LinkMode.MAGNETLINK) { if (filename != null) { - if (completedl != 0) { - Source.remove (completedl); - completedl = 0; + GabutApp.gabutwindow.application.activate_action ("destroy", new Variant.string (ariagid)); + notify_app (_("Download Complete"), filename, imagefile.gicon); + if (bool.parse (get_dbsetting (DBSettings.DIALOGNOTIF))) { + send_dialog (); + } + if (db_download_exist (url)) { + update_download (this); } - completedl = Timeout.add (50, ()=> { - if (timeout_id == 0) { - GabutApp.gabutwindow.application.activate_action ("destroy", new Variant.string (ariagid)); - notify_app (_("Download Complete"), filename, imagefile.gicon); - if (bool.parse (get_dbsetting (DBSettings.DIALOGNOTIF))) { - send_dialog (); - } - } - if (db_download_exist (url)) { - update_download (this); - } - completedl = 0; - return false; - }); } } else { bool foundgid = false; @@ -276,8 +273,8 @@ namespace Gabut { public DownloadRow (Sqlite.Statement stmt) { linkmode = stmt.column_int (DBDownload.LINKMODE); - status = stmt.column_int (DBDownload.STATUS); ariagid = stmt.column_text (DBDownload.ARIAGID); + status = stmt.column_int (DBDownload.STATUS); transferrate = stmt.column_int (DBDownload.TRANSFERRATE); totalsize = stmt.column_int64 (DBDownload.TOTALSIZE); transferred = stmt.column_int64 (DBDownload.TRANSFERRED); @@ -520,7 +517,7 @@ namespace Gabut { return stoptimer; } - private int status_aria (string input) { + public int status_aria (string input) { switch (input) { case "paused": return StatusMode.PAUSED; diff --git a/src/Downloader.vala b/src/Downloader.vala index 3cbfff7..70e9b77 100644 --- a/src/Downloader.vala +++ b/src/Downloader.vala @@ -605,7 +605,8 @@ namespace Gabut { infostore.set (iters, 0, announce); } } - commenttext.buffer.text = aria_tell_bittorent (ariagid, TellBittorrent.COMMENT); + var commenttorrent = aria_tell_bittorent (ariagid, TellBittorrent.COMMENT); + commenttext.buffer.text = commenttorrent.contains ("\\/")? Soup.URI.decode (commenttorrent.replace ("\\/", "/")) : commenttorrent; } private uint timeout_id = 0; diff --git a/src/GabutWindow.vala b/src/GabutWindow.vala index 59289b2..9c2f3b3 100644 --- a/src/GabutWindow.vala +++ b/src/GabutWindow.vala @@ -33,7 +33,6 @@ namespace Gabut { private Gtk.SearchEntry search_entry; private ModeButton view_mode; private AlertView nodown_alert; - private int64 statusactive = 0; private GLib.List properties; public GabutWindow (Gtk.Application application) { @@ -91,7 +90,7 @@ namespace Gabut { }); Timeout.add (500, ()=> { - bool statact = statusactive > 0; + bool statact = int.parse (aria_globalstat (GlobalStat.NUMACTIVE)) > 0; set_progress_visible.begin (!is_active && statact); set_badge_visible.begin (!is_active && statact); return true; @@ -181,8 +180,8 @@ namespace Gabut { property.show_all (); properties.append (property); property.property (row); - property.saveproperty.connect ((hashoption)=> { - row.hashoption = hashoption; + property.save_button.clicked.connect (()=> { + row = property.row; }); property.destroy.connect (()=> { properties.foreach ((proper)=> { @@ -252,7 +251,6 @@ namespace Gabut { public override void destroy () { base.destroy (); - check_optdown (); var downloads = new GLib.List (); foreach (var row in list_box.get_children ()) { if (((DownloadRow) row).url == "") { @@ -297,7 +295,7 @@ namespace Gabut { } } }); - get_active (); + set_badge.begin (int.parse (aria_globalstat (GlobalStat.NUMACTIVE))); } private Hdy.HeaderBar mode_headerbar () { @@ -353,7 +351,7 @@ namespace Gabut { ((DownloadRow) row).add_timeout (); } } - get_active (); + set_badge.begin (int.parse (aria_globalstat (GlobalStat.NUMACTIVE))); } public void fast_respond (string ariagid) { @@ -362,19 +360,7 @@ namespace Gabut { ((DownloadRow) row).update_progress (); } } - get_active (); - } - - private bool get_active () { - statusactive = 0; - foreach (var row in list_box.get_children ()) { - if (((DownloadRow) row).status == StatusMode.ACTIVE) { - statusactive++; - } - } - set_badge.begin (statusactive); - remove_time = 0; - return false; + set_badge.begin (int.parse (aria_globalstat (GlobalStat.NUMACTIVE))); } public void remove_all () { @@ -405,7 +391,7 @@ namespace Gabut { } if (!later) { row.download (); - get_active (); + set_badge.begin (int.parse (aria_globalstat (GlobalStat.NUMACTIVE))); } } @@ -419,7 +405,6 @@ namespace Gabut { return linkexist; } - private uint remove_time = 0U; private void start_all () { foreach (var row in list_box.get_children ()) { if (((DownloadRow) row).status != StatusMode.COMPLETE) { @@ -428,11 +413,7 @@ namespace Gabut { } } view_status (); - if (remove_time > 0) { - Source.remove (remove_time); - } - remove_time = 0; - remove_time = Timeout.add (50, get_active); + set_badge.begin (int.parse (aria_globalstat (GlobalStat.NUMACTIVE))); } private void stop_all () { @@ -444,11 +425,7 @@ namespace Gabut { } } view_status (); - if (remove_time > 0) { - Source.remove (remove_time); - } - remove_time = 0; - remove_time = Timeout.add (50, get_active); + set_badge.begin (int.parse (aria_globalstat (GlobalStat.NUMACTIVE))); } public string set_selected (string ariagid, string selected) { diff --git a/src/PieceSelector.vala b/src/PieceSelector.vala new file mode 100755 index 0000000..28f7b57 --- /dev/null +++ b/src/PieceSelector.vala @@ -0,0 +1,48 @@ +/* +* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +* Authored by: torikulhabib +*/ + +namespace Gabut { + public class PieceSelector : Gtk.FlowBoxChild { + private Gtk.Grid content; + public PieceSelectors selector { get; private set; } + + construct { + content = new Gtk.Grid () { + row_spacing = 12, + halign = Gtk.Align.CENTER + }; + add (content); + } + + public PieceSelector (PieceSelectors selector) { + this.selector = selector; + var title = new Gtk.Label (selector.get_name ()) { + halign = Gtk.Align.CENTER, + margin_top = 6, + margin_bottom = 6, + margin_start = 12, + margin_end = 12 + }; + content.add (title); + show_all (); + } + } +} diff --git a/src/Preferences.vala b/src/Preferences.vala index 3d99db7..3fd8cfc 100644 --- a/src/Preferences.vala +++ b/src/Preferences.vala @@ -24,6 +24,8 @@ namespace Gabut { public signal void restart_server (); public signal void max_active (); private Gtk.MenuButton allocate_button; + private Gtk.MenuButton piecesel_button; + private Gtk.MenuButton urisel_button; FileAllocation _fileallocation = null; FileAllocation fileallocation { @@ -36,6 +38,28 @@ namespace Gabut { } } + PieceSelector _PieceSelector = null; + PieceSelector pieceselector { + get { + return _PieceSelector; + } + set { + _PieceSelector = value; + piecesel_button.label = _PieceSelector.selector.get_name (); + } + } + + UriSelector _uriselector = null; + UriSelector uriselector { + get { + return _uriselector; + } + set { + _uriselector = value; + urisel_button.label = _uriselector.selector.get_name (); + } + } + public Preferences (Gtk.Application application) { Object (application: application, resizable: false, @@ -76,7 +100,7 @@ namespace Gabut { value = double.parse (aria_get_globalops (AriaOptions.MAX_CONNECTION_PER_SERVER)) }; - var maxcurrent = new Gtk.SpinButton.with_range (1, 20, 1) { + var maxcurrent = new Gtk.SpinButton.with_range (1, 50, 1) { width_request = 220, hexpand = true, primary_icon_name = "media-playback-start", @@ -97,13 +121,92 @@ namespace Gabut { value = double.parse (aria_get_globalops (AriaOptions.RETRY_WAIT)) }; - var split = new Gtk.SpinButton.with_range (0, 100, 1) { + var split = new Gtk.SpinButton.with_range (0, 200, 1) { width_request = 220, hexpand = true, primary_icon_name = "edit-cut", value = double.parse (aria_get_globalops (AriaOptions.SPLIT)) }; + var splitsize = new Gtk.SpinButton.with_range (0, 9999999, 1) { + width_request = 220, + hexpand = true, + primary_icon_name = "drive-harddisk", + value = double.parse (aria_get_globalops (AriaOptions.MIN_SPLIT_SIZE)) / 1024 + }; + + var lowestspd = new Gtk.SpinButton.with_range (0, 9999999, 1) { + width_request = 220, + hexpand = true, + primary_icon_name = "go-down", + primary_icon_tooltip_text = _("0 Means Unrestricted"), + value = double.parse (aria_get_globalops (AriaOptions.LOWEST_SPEED_LIMIT)) / 1024 + }; + + piecesel_button = new Gtk.MenuButton (); + var stream_flow = new Gtk.FlowBox () { + orientation = Gtk.Orientation.HORIZONTAL, + width_request = 70, + margin = 10 + }; + var stream_popover = new Gtk.Popover (piecesel_button) { + position = Gtk.PositionType.TOP, + width_request = 70 + }; + stream_popover.add (stream_flow); + stream_popover.show.connect (() => { + if (pieceselector != null) { + stream_flow.select_child (pieceselector); + pieceselector.grab_focus (); + } + }); + piecesel_button.popover = stream_popover; + foreach (var piecesel in PieceSelectors.get_all ()) { + stream_flow.add (new PieceSelector (piecesel)); + } + stream_flow.show_all (); + stream_flow.child_activated.connect ((piecesel)=> { + pieceselector = piecesel as PieceSelector; + stream_popover.hide (); + }); + foreach (var piecesel in stream_flow.get_children ()) { + if (((PieceSelector) piecesel).selector.get_name ().down () == aria_get_globalops (AriaOptions.STREAM_PIECE_SELECTOR)) { + pieceselector = piecesel as PieceSelector; + } + }; + + urisel_button = new Gtk.MenuButton (); + var urisel_flow = new Gtk.FlowBox () { + orientation = Gtk.Orientation.HORIZONTAL, + width_request = 70, + margin = 10 + }; + var urisel_popover = new Gtk.Popover (urisel_button) { + position = Gtk.PositionType.TOP, + width_request = 70 + }; + urisel_popover.add (urisel_flow); + urisel_popover.show.connect (() => { + if (uriselector != null) { + urisel_flow.select_child (uriselector); + uriselector.grab_focus (); + } + }); + urisel_button.popover = urisel_popover; + foreach (var urisel in UriSelectors.get_all ()) { + urisel_flow.add (new UriSelector (urisel)); + } + urisel_flow.show_all (); + urisel_flow.child_activated.connect ((urisel)=> { + uriselector = urisel as UriSelector; + urisel_popover.hide (); + }); + foreach (var urisel in urisel_flow.get_children ()) { + if (((UriSelector) urisel).selector.get_name ().down () == aria_get_globalops (AriaOptions.URI_SELECTOR)) { + uriselector = urisel as UriSelector; + } + }; + var settings = new Gtk.Grid () { expand = true, column_homogeneous = true, @@ -125,6 +228,14 @@ namespace Gabut { settings.attach (retry, 1, 5, 1, 1); settings.attach (new HeaderLabel (_("Split:"), 220), 0, 4, 1, 1); settings.attach (split, 0, 5, 1, 1); + settings.attach (new HeaderLabel (_("Lowest Speed (in Kb):"), 220), 1, 6, 1, 1); + settings.attach (lowestspd, 1, 7, 1, 1); + settings.attach (new HeaderLabel (_("Split Size (in Kb):"), 220), 0, 6, 1, 1); + settings.attach (splitsize, 0, 7, 1, 1); + settings.attach (new HeaderLabel (_("Piece Selector:"), 220), 1, 8, 1, 1); + settings.attach (piecesel_button, 1, 9, 1, 1); + settings.attach (new HeaderLabel (_("Uri Selector:"), 220), 0, 8, 1, 1); + settings.attach (urisel_button, 0, 9, 1, 1); var maxopfile = new Gtk.SpinButton.with_range (0, 200, 1) { width_request = 220, @@ -245,7 +356,7 @@ namespace Gabut { halign = Gtk.Align.START }; folderopt.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); - folderopt.attach (new HeaderLabel (_("Folder:"), 450), 1, 0, 1, 1); + folderopt.attach (new HeaderLabel (_("Save to Folder:"), 450), 1, 0, 1, 1); folderopt.attach (folder_location, 1, 1, 1, 1); var rpc_port = new Gtk.SpinButton.with_range (0, 9999, 1) { @@ -316,7 +427,7 @@ namespace Gabut { allocate_popover.hide (); }); foreach (var allocate in allocate_flow.get_children ()) { - if (((FileAllocation) allocate).fileallocation.get_name () == get_dbsetting (DBSettings.FILEALLOCATION)) { + if (((FileAllocation) allocate).fileallocation.get_name ().down () == aria_get_globalops (AriaOptions.FILE_ALLOCATION)) { fileallocation = allocate as FileAllocation; } }; @@ -473,6 +584,10 @@ namespace Gabut { aria_set_globalops (AriaOptions.MAX_OVERALL_DOWNLOAD_LIMIT, set_dbsetting (DBSettings.DOWNLOADLIMIT, (bt_download.value * 1024).to_string ())); aria_set_globalops (AriaOptions.BT_TRACKER, set_dbsetting (DBSettings.BTTRACKER, bttrackertext.buffer.text.replace ("/", "\\/"))); aria_set_globalops (AriaOptions.BT_EXCLUDE_TRACKER, set_dbsetting (DBSettings.BTTRACKEREXC, bttrackertextext.buffer.text.replace ("/", "\\/"))); + aria_set_globalops (AriaOptions.MIN_SPLIT_SIZE, set_dbsetting (DBSettings.SPLITSIZE, (splitsize.value * 1024).to_string ())); + aria_set_globalops (AriaOptions.LOWEST_SPEED_LIMIT, set_dbsetting (DBSettings.LOWESTSPEED, (lowestspd.value * 1024).to_string ())); + aria_set_globalops (AriaOptions.URI_SELECTOR, set_dbsetting (DBSettings.URISELECTOR, uriselector.selector.get_name ().down ())); + aria_set_globalops (AriaOptions.STREAM_PIECE_SELECTOR, set_dbsetting (DBSettings.PIECESELECTOR, pieceselector.selector.get_name ().down ())); set_dbsetting (DBSettings.DIALOGNOTIF, dialognotify.active.to_string ()); set_dbsetting (DBSettings.SYSTEMNOTIF, systemnotif.active.to_string ()); set_dbsetting (DBSettings.ONBACKGROUND, retonhide.active.to_string ()); @@ -482,6 +597,7 @@ namespace Gabut { set_dbsetting (DBSettings.DISKCACHE, diskcache.value.to_string ()); set_dbsetting (DBSettings.BTLISTENPORT, bt_listenport.value.to_string ()); set_dbsetting (DBSettings.DHTLISTENPORT, dht_listenport.value.to_string ()); + set_dbsetting (DBSettings.FILEALLOCATION, fileallocation.fileallocation.get_name ()); if (maxcurrent.value != double.parse (aria_get_globalops (AriaOptions.MAX_CONCURRENT_DOWNLOADS))) { aria_set_globalops (AriaOptions.MAX_CONCURRENT_DOWNLOADS, set_dbsetting (DBSettings.MAXACTIVE, maxcurrent.value.to_string ())); max_active (); @@ -491,8 +607,7 @@ namespace Gabut { || rpc_port.value != double.parse (aria_get_globalops (AriaOptions.RPC_LISTEN_PORT)) || bt_listenport.value != double.parse (aria_get_globalops (AriaOptions.LISTEN_PORT)) || dht_listenport.value != double.parse (aria_get_globalops (AriaOptions.DHT_LISTEN_PORT)) - || get_dbsetting (DBSettings.FILEALLOCATION) != fileallocation.fileallocation.get_name ()) { - set_dbsetting (DBSettings.FILEALLOCATION, fileallocation.fileallocation.get_name ()); + || fileallocation.fileallocation.get_name ().down () != aria_get_globalops (AriaOptions.FILE_ALLOCATION)) { aria_shutdown (); do { } while (aria_getverion ()); diff --git a/src/ServerUpload.vala b/src/ServerUpload.vala index 6dd175c..d96909b 100644 --- a/src/ServerUpload.vala +++ b/src/ServerUpload.vala @@ -58,7 +58,7 @@ namespace Gabut {

Send Multiple File

-
+
@@ -102,6 +102,12 @@ namespace Gabut { +