diff --git a/data/com.github.gabutakut.gabutdm.appdata.xml.in b/data/com.github.gabutakut.gabutdm.appdata.xml.in index 9ee0489..9851a84 100644 --- a/data/com.github.gabutakut.gabutdm.appdata.xml.in +++ b/data/com.github.gabutakut.gabutdm.appdata.xml.in @@ -31,6 +31,13 @@ com.github.gabutakut.gabutdm + + +

Replace Treeview to Listbox

+

Remove and replace Deprecated library

+

Adwaita style

+
+

Feature TrayIcon

diff --git a/data/icons/actions/com.github.gabutakut.gabutdm.client.svg b/data/icons/actions/com.github.gabutakut.gabutdm.client.svg new file mode 100644 index 0000000..8a968f6 --- /dev/null +++ b/data/icons/actions/com.github.gabutakut.gabutdm.client.svg @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/data/icons/actions/com.github.gabutakut.gabutdm.cookie.svg b/data/icons/actions/com.github.gabutakut.gabutdm.cookie.svg new file mode 100644 index 0000000..7c07e49 --- /dev/null +++ b/data/icons/actions/com.github.gabutakut.gabutdm.cookie.svg @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/icons/actions/com.github.gabutakut.gabutdm.date.svg b/data/icons/actions/com.github.gabutakut.gabutdm.date.svg new file mode 100644 index 0000000..4a423c2 --- /dev/null +++ b/data/icons/actions/com.github.gabutakut.gabutdm.date.svg @@ -0,0 +1,315 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/icons/actions/com.github.gabutakut.gabutdm.down.svg b/data/icons/actions/com.github.gabutakut.gabutdm.down.svg new file mode 100644 index 0000000..b670607 --- /dev/null +++ b/data/icons/actions/com.github.gabutakut.gabutdm.down.svg @@ -0,0 +1,150 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/icons/actions/com.github.gabutakut.gabutdm.hdd.svg b/data/icons/actions/com.github.gabutakut.gabutdm.hdd.svg new file mode 100644 index 0000000..0d075aa --- /dev/null +++ b/data/icons/actions/com.github.gabutakut.gabutdm.hdd.svg @@ -0,0 +1,446 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/icons/actions/com.github.gabutakut.gabutdm.menu.svg b/data/icons/actions/com.github.gabutakut.gabutdm.menu.svg new file mode 100644 index 0000000..7dfd80e --- /dev/null +++ b/data/icons/actions/com.github.gabutakut.gabutdm.menu.svg @@ -0,0 +1,100 @@ + + + + + + + + + + + + diff --git a/data/icons/actions/com.github.gabutakut.gabutdm.opt.svg b/data/icons/actions/com.github.gabutakut.gabutdm.opt.svg new file mode 100644 index 0000000..9aadb70 --- /dev/null +++ b/data/icons/actions/com.github.gabutakut.gabutdm.opt.svg @@ -0,0 +1,110 @@ + + + + + + + + + + + + + diff --git a/data/icons/actions/com.github.gabutakut.gabutdm.svdrv.svg b/data/icons/actions/com.github.gabutakut.gabutdm.svdrv.svg new file mode 100644 index 0000000..050b19f --- /dev/null +++ b/data/icons/actions/com.github.gabutakut.gabutdm.svdrv.svg @@ -0,0 +1,287 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/icons/actions/com.github.gabutakut.gabutdm.up.svg b/data/icons/actions/com.github.gabutakut.gabutdm.up.svg new file mode 100644 index 0000000..7419c07 --- /dev/null +++ b/data/icons/actions/com.github.gabutakut.gabutdm.up.svg @@ -0,0 +1,137 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/icons/actions/com.github.gabutakut.gabutdm.uri.svg b/data/icons/actions/com.github.gabutakut.gabutdm.uri.svg new file mode 100644 index 0000000..435fc36 --- /dev/null +++ b/data/icons/actions/com.github.gabutakut.gabutdm.uri.svg @@ -0,0 +1,277 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/data/icons/actions/com.github.gabutakut.gabutdm.waiting.svg b/data/icons/actions/com.github.gabutakut.gabutdm.waiting.svg index 8edbe12..1207722 100644 --- a/data/icons/actions/com.github.gabutakut.gabutdm.waiting.svg +++ b/data/icons/actions/com.github.gabutakut.gabutdm.waiting.svg @@ -4,8 +4,8 @@ width="64" height="64" id="svg3489" - inkscape:version="1.1.1 (1:1.1+202109281949+c3084ef5ed)" - sodipodi:docname="com.github.torikulhabib.oni.waiting.svg" + inkscape:version="1.2.2 (b0a8486541, 2022-12-01)" + sodipodi:docname="com.github.gabutakut.gabutdm.waiting.svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:xlink="http://www.w3.org/1999/xlink" @@ -24,18 +24,20 @@ inkscape:pageopacity="0" inkscape:pageshadow="2" inkscape:window-width="1366" - inkscape:window-height="707" + inkscape:window-height="705" id="namedview48" showgrid="false" - inkscape:zoom="4" - inkscape:cx="41.25" - inkscape:cy="29.625" + inkscape:zoom="8" + inkscape:cx="41.3125" + inkscape:cy="20.5625" inkscape:window-x="0" - inkscape:window-y="30" + inkscape:window-y="0" inkscape:window-maximized="1" inkscape:current-layer="svg3489" inkscape:object-nodes="true" - inkscape:pagecheckerboard="0"> + inkscape:pagecheckerboard="0" + inkscape:showpageshadow="2" + inkscape:deskcolor="#d1d1d1"> @@ -313,21 +315,21 @@ sodipodi:nodetypes="sssss" /> (); var view_mode = new ModeButton () { hexpand = true, + homogeneous = true, halign = Gtk.Align.CENTER, valign = Gtk.Align.CENTER }; @@ -184,10 +185,17 @@ namespace Gabut { folder_location = new Gtk.Button (); folder_location.clicked.connect (()=> { - var file = run_open_fd (this, OpenFiles.OPENPERDONLOADFOLDER); - if (file != null) { - selectfd = file; - } + run_open_fd.begin (this, OpenFiles.OPENPERDONLOADFOLDER, (obj, res)=> { + try { + GLib.File file; + run_open_fd.end (res, out file); + if (file != null) { + selectfd = file; + } + } catch (GLib.Error e) { + critical (e.message); + } + }); }); selectfd = File.new_for_path (get_dbsetting (DBSettings.DIR).replace ("\\/", "/")); @@ -197,13 +205,21 @@ namespace Gabut { usefolder.toggled.connect (()=> { folder_location.sensitive = usefolder.active; }); + ((Gtk.Label) usefolder.get_last_child ()).attributes = set_attribute (Pango.Weight.SEMIBOLD); folder_location.sensitive = usefolder.active; cookie_location = new Gtk.Button (); cookie_location.clicked.connect (()=> { - var file = run_open_all (this, OpenFiles.OPENCOOKIES); - if (file != null) { - selectcook = file; - } + run_open_all.begin (this, OpenFiles.OPENCOOKIES, (obj, res)=> { + try { + GLib.File file; + run_open_all.end (res, out file); + if (file != null) { + selectcook = file; + } + } catch (GLib.Error e) { + critical (e.message); + } + }); }); selectcook = null; usecookie = new Gtk.CheckButton.with_label (_("Cookie")) { @@ -212,6 +228,7 @@ namespace Gabut { usecookie.toggled.connect (()=> { cookie_location.sensitive = usecookie.active; }); + ((Gtk.Label) usecookie.get_last_child ()).attributes = set_attribute (Pango.Weight.SEMIBOLD); cookie_location.sensitive = usecookie.active; var foldergrid = new Gtk.Grid () { margin_top = 10, @@ -261,12 +278,13 @@ namespace Gabut { var save_image = new Gtk.Image () { valign = Gtk.Align.CENTER, pixel_size = 64, - gicon = new ThemedIcon ("document-save") + gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.svdrv") }; save_meta = new Gtk.CheckButton.with_label ("Backup") { valign = Gtk.Align.END, - halign = Gtk.Align.CENTER + halign = Gtk.Align.CENTER, + tooltip_text = _("Backup Torrent File") }; ((Gtk.Label) save_meta.get_last_child ()).attributes = set_attribute (Pango.Weight.SEMIBOLD); ((Gtk.Label) save_meta.get_last_child ()).ellipsize = Pango.EllipsizeMode.END; @@ -468,7 +486,6 @@ namespace Gabut { child = checksums_flow }; checksums_popover.show.connect (() => { - checksums_popover.width_request = checksum_button.get_allocated_width (); if (checksumtype != null) { checksums_flow.select_child (checksumtype); checksumtype.grab_focus (); diff --git a/src/Application.vala b/src/Application.vala index 1cf45d2..d8aadac 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 @@ -30,14 +30,9 @@ namespace Gabut { private bool dontopen = false; private string lastclipboard; - public GabutApp () { - Object ( - application_id: "com.github.gabutakut.gabutdm", - flags: GLib.ApplicationFlags.HANDLES_COMMAND_LINE - ); - } - construct { + application_id = "com.github.gabutakut.gabutdm"; + flags = GLib.ApplicationFlags.HANDLES_COMMAND_LINE; GLib.OptionEntry [] options = new GLib.OptionEntry [3]; options [0] = { "startingup", 's', GLib.OptionFlags.NONE, GLib.OptionArg.NONE, null, "Starup", "Run App on Startup" }; options [1] = { GLib.OPTION_REMAINING, 0, GLib.OptionFlags.NONE, GLib.OptionArg.STRING_ARRAY, null, "Array file", "Open File or URIs" }; @@ -72,8 +67,8 @@ namespace Gabut { protected override void activate () { if (gabutwindow == null) { if (open_database (out gabutdb) != Sqlite.OK) { - notify_app (_("Database Error"), - _("Can't open database: %s\n").printf (gabutdb.errmsg ()), new ThemedIcon ("office-database")); + notify_app (_("Database Error"), _("Can't open database: %s\n").printf (gabutdb.errmsg ()), new ThemedIcon ("office-database")); + play_sound ("dialog-error"); } settings_table (); if (!bool.parse (get_dbsetting (DBSettings.STARTUP)) && startingup) { @@ -169,13 +164,8 @@ namespace Gabut { gabutserver.delete_row.connect ((status)=> { gabutwindow.remove_item (status); }); - var gtkset = Gtk.Settings.get_default ().gtk_theme_name; - if (gtkset.down ().contains ("-dark")){ - set_dbsetting (Gabut.DBSettings.THEMESYSTEM, gtkset.replace ("-dark", "")); - } else { - set_dbsetting (Gabut.DBSettings.THEMESYSTEM, gtkset); - } - pantheon_theme.begin (); + gdm_theme.begin (); + set_dbsetting (Gabut.DBSettings.THEMESYSTEM, Gtk.Settings.get_default ().gtk_theme_name); gabutwindow.load_dowanload (); download_table (); if (!startingup && !dontopen) { @@ -432,7 +422,7 @@ namespace Gabut { return Gdk.EVENT_PROPAGATE; } - private async void drag_value (Gdk.Drop drop, out Value? valu) throws Error { + private async void drag_value (Gdk.Drop drop, out GLib.Value? valu) throws Error { valu = yield drop.read_value_async (GLib.Type.STRING, GLib.Priority.DEFAULT, null); } diff --git a/src/BTEncrypt.vala b/src/BTEncrypt.vala index bf64467..b18c973 100755 --- a/src/BTEncrypt.vala +++ b/src/BTEncrypt.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/CanonicalDbusmenu.vala b/src/CanonicalDbusmenu.vala index fad7bb4..07f3423 100644 --- a/src/CanonicalDbusmenu.vala +++ b/src/CanonicalDbusmenu.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/ChecksumType.vala b/src/ChecksumType.vala index a385109..91eb4f3 100755 --- a/src/ChecksumType.vala +++ b/src/ChecksumType.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/DbusIndicator.vala b/src/DbusIndicator.vala index 5a289ce..d069be2 100644 --- a/src/DbusIndicator.vala +++ b/src/DbusIndicator.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/DbusmenuItem.vala b/src/DbusmenuItem.vala index 196bddd..0616098 100644 --- a/src/DbusmenuItem.vala +++ b/src/DbusmenuItem.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/DeAscending.vala b/src/DeAscending.vala index a13e72c..0c7e81c 100755 --- a/src/DeAscending.vala +++ b/src/DeAscending.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 @@ -46,16 +46,22 @@ namespace Gabut { margin_bottom = 6, margin_start = 12, margin_end = 12, - width_request = 100 + width_request = 80 }; cheked = new Gtk.CheckButton () { halign = Gtk.Align.CENTER, margin_start = 6, - active = false + active = false, + sensitive = false + }; + var dateimg = new Gtk.Image () { + valign = Gtk.Align.CENTER, + gicon = new ThemedIcon (deascend.to_icon ()) }; var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); box.append (cheked); box.append (title); + box.append (dateimg); child = box; show (); } diff --git a/src/DownloadRow.vala b/src/DownloadRow.vala index e8da5b7..9960621 100644 --- a/src/DownloadRow.vala +++ b/src/DownloadRow.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 @@ -23,7 +23,7 @@ namespace Gabut { public class DownloadRow : Gtk.ListBoxRow { public signal int activedm (); public signal void update_agid (string ariagid, string newgid); - public signal void myproperty (); + public signal void gsmproperties (); private Gtk.Button start_button; private Gtk.Label transfer_rate; private Gtk.ProgressBar progressbar; @@ -90,7 +90,7 @@ namespace Gabut { _status = value; switch (value) { case StatusMode.PAUSED: - start_button.icon_name = "media-playback-pause"; + start_button.icon_name = "com.github.gabutakut.gabutdm.pause"; start_button.tooltip_text = _("Paused"); remove_timeout (); labeltransfer = @"$(GLib.format_size (transferred)) of $(GLib.format_size (totalsize))"; @@ -107,6 +107,7 @@ namespace Gabut { if (filename != null) { GLib.Application.get_default ().lookup_action ("destroy").activate (new Variant.string (ariagid)); notify_app (_("Download Complete"), filename, imagefile.gicon); + play_sound ("complete"); if (bool.parse (get_dbsetting (DBSettings.DIALOGNOTIF))) { if (pathname != null && pathname != "" && fileordir != "" && fileordir != null) { send_dialog (); @@ -151,6 +152,7 @@ namespace Gabut { labeltransfer = get_aria_error (int.parse (aria_tell_status (ariagid, TellStatus.ERRORCODE))); if (filename != null) { notify_app (_("Download Error"), filename, imagefile.gicon); + play_sound ("dialog-error"); } aria_remove (ariagid); } @@ -165,7 +167,7 @@ namespace Gabut { add_timeout (); break; default: - start_button.icon_name = "media-playback-start"; + start_button.icon_name = "com.github.gabutakut.gabutdm.active"; start_button.tooltip_text = _("Downloading"); add_timeout (); break; @@ -381,7 +383,7 @@ namespace Gabut { attributes = set_attribute (Pango.Weight.SEMIBOLD) }; - start_button = new Gtk.Button.from_icon_name ("media-playback-start") { + start_button = new Gtk.Button.from_icon_name ("com.github.gabutakut.gabutdm.active") { valign = Gtk.Align.CENTER }; start_button.clicked.connect (()=> { @@ -462,6 +464,7 @@ namespace Gabut { } else { notify_app (_("Starting"), url, new ThemedIcon ("com.github.gabutakut.gabutdm.insertlink")); } + play_sound ("device-added"); } public void idle_progress () { @@ -659,62 +662,56 @@ namespace Gabut { } public Gtk.Popover get_menu () { - var btnopn = new Gtk.Button () { - child = box_btn ("folder-open", _("Open folder")) - }; - var btnclr = new Gtk.Button () { - child = box_btn ("user-trash-full", _("Move to Trash")) - }; - var btnprop = new Gtk.Button () { - child = box_btn ("document-properties", _("Properties")) - }; - var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) { + var downloadmn = new Gtk.FlowBox () { + orientation = Gtk.Orientation.HORIZONTAL, + width_request = 70, margin_top = 4, - margin_bottom = 4, - margin_start = 4, - margin_end = 4 + margin_bottom = 4 }; - box.append (btnopn); - box.append (btnclr); - box.append (btnprop); + foreach (var dmmenu in DownloadMenu.get_all ()) { + downloadmn.append (new GdmMenu (dmmenu)); + } var urisel_popover = new Gtk.Popover () { - child = box + child = downloadmn }; - urisel_popover.show.connect (()=> { - box.grab_focus (); + urisel_popover.show.connect (() => { + downloadmn.unselect_all (); }); - btnclr.clicked.connect (()=> { - if (pathname != null) { - remove_down (); - try { - var filec = File.new_for_path (@"$(pathname).aria2"); - if (filec.query_exists ()) { - filec.trash (); + downloadmn.child_activated.connect ((dmmenu)=> { + urisel_popover.hide (); + var gdmmenu = dmmenu as GdmMenu; + switch (gdmmenu.downloadmenu) { + case DownloadMenu.MOVETOTRASH: + if (pathname != null) { + remove_down (); + try { + var filec = File.new_for_path (@"$(pathname).aria2"); + if (filec.query_exists ()) { + filec.trash (); + } + var filep = File.new_for_path (pathname); + if (filep.query_exists ()) { + filep.trash (); + } + } catch (Error e) { + GLib.warning (e.message); + } } - var filep = File.new_for_path (pathname); - if (filep.query_exists ()) { - filep.trash (); + break; + case DownloadMenu.PROPERTIES: + gsmproperties (); + break; + default: + if (pathname != null) { + var file = File.new_for_path (pathname); + if (fileordir == "inode/directory") { + open_fileman.begin (file.get_uri ()); + } else { + open_fileman.begin (file.get_parent ().get_uri ()); + } } - } catch (Error e) { - GLib.warning (e.message); - } - } - urisel_popover.hide (); - }); - btnopn.clicked.connect (()=> { - if (pathname != null) { - var file = File.new_for_path (pathname); - if (fileordir == "inode/directory") { - open_fileman.begin (file.get_uri ()); - } else { - open_fileman.begin (file.get_parent ().get_uri ()); - } + break; } - urisel_popover.hide (); - }); - btnprop.clicked.connect (()=> { - myproperty (); - urisel_popover.hide (); }); return urisel_popover; } diff --git a/src/Downloader.vala b/src/Downloader.vala index 318f9a1..c444288 100644 --- a/src/Downloader.vala +++ b/src/Downloader.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 @@ -37,12 +37,11 @@ namespace Gabut { private Gtk.SpinButton down_limit; private Gtk.SpinButton up_limit; private Gtk.SpinButton bt_req_limit; - private Gtk.ListStore torrstore; - private Gtk.ListStore peerstore; - private Gtk.ListStore serverstore; - private Gtk.TreeView servertree; - private Gtk.TreeView torrenttree; - private Gtk.TreeView peerstree; + private Gtk.ListBox listboxtorrent; + private Gee.ArrayList listtorrent; + private Gtk.ListBox lisboxserver; + private Gtk.ListBox listboxpeers; + private Gee.ArrayList listpeers; private Gtk.TextView infotorrent; private Gtk.TextView commenttext; private Gtk.Button server_button; @@ -78,7 +77,7 @@ namespace Gabut { } set { _status = value; - switch (value) { + switch (_status) { case StatusMode.PAUSED: start_button.set_label (_("Start")); statuslabel.label = _("Paused"); @@ -197,6 +196,7 @@ namespace Gabut { construct { view_mode = new ModeButton () { hexpand = true, + homogeneous = true, halign = Gtk.Align.CENTER, valign = Gtk.Align.CENTER }; @@ -216,7 +216,6 @@ namespace Gabut { commenttext.buffer.text = commenttorrent.contains ("\\/")? GLib.Uri.unescape_string (commenttorrent.replace ("\\/", "/")) : commenttorrent; break; case 2: - torrstore.clear (); show_files (); break; case 3: @@ -294,7 +293,8 @@ namespace Gabut { var downstatusgrid = new Gtk.Grid () { hexpand = true, height_request = 150, - margin_bottom = 5 + margin_bottom = 4, + valign = Gtk.Align.CENTER }; downstatusgrid.attach (headerlabel (_("Status"), 100), 0, 0, 1, 1); downstatusgrid.attach (statuslabel, 1, 0, 1, 1); @@ -370,17 +370,8 @@ namespace Gabut { torrentinfo.attach (headerlabel (_("Comment:"), 250), 1, 1, 1, 1); torrentinfo.attach (comment, 1, 2, 1, 1); - peerstore = new Gtk.ListStore (TorrentPeers.N_COLUMNS, typeof (string), typeof (string), typeof (string), typeof (string), typeof (string), typeof (string), typeof (string), typeof (string)); - peerstree = new Gtk.TreeView () { - hexpand = true, - valign = Gtk.Align.FILL, - model = peerstore - }; - peerstree.append_column (text_column (_("Host"), TorrentPeers.HOST)); - peerstree.append_column (text_column (_("Client"), TorrentPeers.PEERID, true, 14, "text", color_attribute (60000, 37000, 0, false))); - peerstree.append_column (text_column (_("Choking"), TorrentPeers.PEERCHOKING)); - peerstree.append_column (text_column (_("D"), TorrentPeers.DOWNLOADSPEED, true, 14, "text")); - peerstree.append_column (text_column (_("U"), TorrentPeers.UPLOADSPEED, true, 14, "text", color_attribute (60000, 30000, 19764, false))); + listboxpeers = new Gtk.ListBox (); + listpeers = new Gee.ArrayList (); var peerscrolled = new Gtk.ScrolledWindow () { hexpand = true, @@ -388,23 +379,10 @@ namespace Gabut { height_request = 160, margin_bottom = 10, valign = Gtk.Align.FILL, - child = peerstree - }; - - torrstore = new Gtk.ListStore (FileCol.N_COLUMNS, typeof (bool), typeof (string), typeof (string), typeof (string), typeof (string), typeof (string), typeof (int), typeof (string)); - torrenttree = new Gtk.TreeView () { - hexpand = true, - model = torrstore, - margin_bottom = 10 + child = listboxpeers }; - torrenttree.append_column (toggle_column (_("#"), FileCol.SELECTED)); - torrenttree.append_column (text_column (_("N"), FileCol.ROW, false, 3)); - torrenttree.append_column (text_column (_("Name"), FileCol.NAME)); - torrenttree.append_column (text_column (_("Downloaded"), FileCol.DOWNLOADED)); - torrenttree.append_column (text_column (_("Size"), FileCol.SIZE)); - torrenttree.append_column (progress_column (_("%"), FileCol.PERCEN)); - torrenttree.append_column (text_column (_("Info Uris Status"), FileCol.URIS)); - torrenttree.set_tooltip_column (FileCol.FILEPATH); + listboxtorrent = new Gtk.ListBox (); + listtorrent = new Gee.ArrayList (); var torrscrolled = new Gtk.ScrolledWindow () { hexpand = true, @@ -412,7 +390,7 @@ namespace Gabut { height_request = 140, margin_bottom = 5, margin_top = 5, - child = torrenttree + child = listboxtorrent }; down_limit = new Gtk.SpinButton.with_range (0, 999999, 1) { @@ -432,6 +410,7 @@ namespace Gabut { var limitergrid = new Gtk.Grid () { hexpand = true, + valign = Gtk.Align.CENTER, height_request = 150 }; limitergrid.attach (headerlabel (_("Max Download Limit (in Kb):"), 550), 0, 0, 1, 1); @@ -517,15 +496,7 @@ namespace Gabut { centerbox.set_start_widget (server_button); centerbox.set_end_widget (box_action); - serverstore = new Gtk.ListStore (ServersCol.N_COLUMNS, typeof (int), typeof (string), typeof (string), typeof (string)); - servertree = new Gtk.TreeView () { - hexpand = true, - valign = Gtk.Align.FILL, - model = serverstore, - }; - servertree.append_column (text_column (_("No"), ServersCol.NO, false, 1)); - servertree.append_column (text_column (_("Download Speed"), ServersCol.DOWNLOADSPEED, false, 8, "text")); - servertree.append_column (text_column (_("Uris"), ServersCol.CURRENTURI)); + lisboxserver = new Gtk.ListBox (); var servscrolled = new Gtk.ScrolledWindow () { hexpand = true, @@ -533,7 +504,7 @@ namespace Gabut { height_request = 160, margin_bottom = 10, valign = Gtk.Align.FILL, - child = servertree + child = lisboxserver }; connpeers = new Gtk.Stack () { hexpand = true, @@ -561,12 +532,12 @@ namespace Gabut { notify["switch-rev"].connect (()=> { revcon.queue_allocate (); if (switch_rev) { - servertree.show (); - peerstree.show (); + lisboxserver.show (); + listboxpeers.show (); revcon.reveal_child = true; } else { - servertree.hide (); - peerstree.hide (); + lisboxserver.hide (); + listboxpeers.hide (); revcon.reveal_child = false; } revcon.queue_allocate (); @@ -596,73 +567,6 @@ namespace Gabut { update_progress (); } - private Gtk.TreeViewColumn text_column (string title, int column, bool resizable = true, int width = 14, string markup = "markup", Pango.AttrList attribute = color_attribute (0, 60000, 0, false)) { - var celltext = new Gtk.CellRendererText () { - attributes = attribute - }; - var server_coll = new Gtk.TreeViewColumn.with_attributes (title, celltext, markup, column) { - resizable = resizable, - clickable = true, - expand = resizable, - sort_indicator = true, - sort_column_id = column, - min_width = width - }; - return server_coll; - } - - private Gtk.TreeViewColumn toggle_column (string title, int column) { - var selected = new Gtk.CellRendererToggle (); - selected.toggled.connect ((path)=> { - Gtk.TreeIter iter; - bool active; - torrstore.get_iter (out iter, new Gtk.TreePath.from_string (path)); - torrstore.get (iter, 0, out active); - torrstore.set (iter, 0, !active); - var builder = new StringBuilder (); - uint hashb = builder.str.hash (); - torrstore.foreach ((model, path, ite) => { - string index; - bool activated; - model.get (ite, 0, out activated, 1, out index); - if (activated) { - if (hashb == builder.str.hash ()) { - builder.append (index); - } else { - builder.append (","); - builder.append (index); - } - } - return false; - }); - if (hashb == builder.str.hash ()) { - return; - } - string aria_gid = sendselected (ariagid, builder.str); - this.ariagid = aria_gid; - update_progress (); - }); - - var server_coll = new Gtk.TreeViewColumn.with_attributes (title, selected, "active", column) { - resizable = false, - clickable = true, - expand = false, - sort_indicator = true, - sort_column_id = column - }; - return server_coll; - } - - private Gtk.TreeViewColumn progress_column (string title, int column) { - var server_coll = new Gtk.TreeViewColumn.with_attributes (title, new Gtk.CellRendererProgress (), "value", column) { - resizable = true, - clickable = true, - expand = true, - sort_column_id = column - }; - return server_coll; - } - public void get_active_status () { status = status_aria (aria_tell_status (ariagid, TellStatus.STATUS)); } @@ -711,7 +615,6 @@ namespace Gabut { } } - int64 delaytime = 0; private bool update_progress () { var pack_data = aria_v2_status (ariagid); totalsize = int64.parse (pharse_tells (pack_data, TellStatus.TOTALLENGTH)); @@ -741,26 +644,20 @@ namespace Gabut { show_files (); } if (switch_rev) { - if (delaytime % 2 == 0) { - if (connpeers.get_visible_child_name () == "serverconn") { - serverstore.clear (); - aria_servers_store (ariagid).foreach ((model, path, ite)=> { - string uri, speed, curi; - model.get (ite, ServersCol.URI, out uri, ServersCol.DOWNLOADSPEED, out speed, ServersCol.CURRENTURI, out curi); - Gtk.TreeIter iter; - serverstore.append (out iter); - serverstore.set (iter, ServersCol.NO, serverstore.iter_n_children (null), ServersCol.URI, Markup.escape_text (uri), ServersCol.DOWNLOADSPEED, GLib.format_size (int64.parse (speed)), ServersCol.CURRENTURI, curi != null? Markup.escape_text (curi.replace ("\\/", "/")) : curi); - return false; - }); - } else { - show_peers (); - } - delaytime = 0; + if (connpeers.get_visible_child_name () == "serverconn") { + lisboxserver.remove_all (); + aria_servers_store (ariagid).foreach ((serverrow)=> { + lisboxserver.append (serverrow); + serverrow.show (); + return true; + }); + } else { + show_peers (); } - delaytime++; } else { - if (peerstore.iter_n_children (null) > 0) { - peerstore.clear (); + if (listpeers.size > 1) { + listboxpeers.remove_all (); + listpeers.clear (); } } status = status_aria (aria_tell_status (ariagid, TellStatus.STATUS)); @@ -771,98 +668,111 @@ namespace Gabut { } private void show_peers () { - var inc = peerstore.iter_n_children (null); - int decress = 0; - for (int n = 0; n < inc; n++) { - Gtk.TreeIter iter; - peerstore.get_iter_from_string (out iter, (n - decress).to_string ()); - if (peerstore.iter_is_valid (iter)) { - string host; - peerstore.get (iter, TorrentPeers.HOST, out host); - if (!aria_peers (host)) { - if (peerstore.iter_is_valid (iter)) { - peerstore.remove (ref iter); - decress++; - } + var arraypeers = aria_get_peers (ariagid); + arraypeers.foreach ((peersrow) => { + bool exist = false; + listpeers.foreach ((peersrow2) => { + if (peersrow2.host == peersrow.key) { + exist = true; + peersrow2.peerid = peersrow.value.peerid; + peersrow2.downloadspeed = peersrow.value.downloadspeed; + peersrow2.uploadspeed = peersrow.value.uploadspeed; + peersrow2.peerschoking = peersrow.value.peerschoking; + peersrow2.seeder = peersrow.value.seeder; + peersrow2.amchoking = peersrow.value.amchoking; + peersrow2.bitfield = peersrow.value.bitfield; + } + return true; + }); + if (!exist) { + if (!peer_exist (peersrow.key)) { + listboxpeers.append (peersrow.value); + listpeers.add (peersrow.value); + peersrow.value.show (); } } - } - aria_get_peers (ariagid).foreach ((model, path, iter) => { - if (!peers_exist (model, iter)) { - string host, peerid, downloadspeed, uploadspeed, seeder, bitfield, amchoking, peerchoking; - model.get (iter, TorrentPeers.HOST, out host, TorrentPeers.PEERID, out peerid, TorrentPeers.DOWNLOADSPEED, out downloadspeed, TorrentPeers.UPLOADSPEED, out uploadspeed, TorrentPeers.SEEDER, out seeder, TorrentPeers.BITFIELD, out bitfield, TorrentPeers.AMCHOKING, out amchoking, TorrentPeers.PEERCHOKING, out peerchoking); - Gtk.TreeIter iters; - peerstore.append (out iters); - peerstore.set (iters, TorrentPeers.HOST, host, TorrentPeers.PEERID, peerid, TorrentPeers.DOWNLOADSPEED, downloadspeed, TorrentPeers.UPLOADSPEED, uploadspeed, TorrentPeers.SEEDER, seeder, TorrentPeers.BITFIELD, bitfield, TorrentPeers.AMCHOKING, amchoking, TorrentPeers.PEERCHOKING, peerchoking); - } - return false; + return true; }); - } - - private void show_files () { - aria_files_store (ariagid).foreach ((model, path, iter) => { - bool select; - string index, name, download, size, uris, pathname; - int persen; - model.get (iter, FileCol.FILEPATH, out pathname); - if (pathname == "" || pathname == null) { - return false; - } - if (pathname.contains ("[METADATA]")) { - return false; - } - model.get (iter, FileCol.SELECTED, out select, FileCol.ROW, out index, FileCol.NAME, out name, FileCol.DOWNLOADED, out download, FileCol.SIZE, out size, FileCol.PERCEN, out persen, FileCol.URIS, out uris); - if (name == null || download == null || size == null) { - return false; + listpeers.foreach ((peersrow2) => { + if (!arraypeers.has_key (peersrow2.host)) { + listpeers.remove (peersrow2); } - if (!files_exist (select, index, Markup.escape_text (name), Markup.escape_text (pathname), download, size, persen.abs (), Markup.escape_text (uris))) { - Gtk.TreeIter iters; - torrstore.append (out iters); - torrstore.set (iters, FileCol.SELECTED, select, FileCol.ROW, index, FileCol.NAME, Markup.escape_text (name), FileCol.FILEPATH, Markup.escape_text (pathname), FileCol.DOWNLOADED, download, FileCol.SIZE, size, FileCol.PERCEN, persen.abs (), FileCol.URIS, Markup.escape_text (uris)); - } - return false; + return true; }); + arraypeers.clear (); } - private bool aria_peers (string host) { + private bool peer_exist (string host) { bool exist = false; - aria_get_peers (ariagid).foreach ((mode, pat, ite) => { - string hosts; - mode.get (ite, TorrentPeers.HOST, out hosts); - if (host == hosts) { + listpeers.foreach ((peersrow2) => { + if (peersrow2.host == host) { exist = true; } - return false; + return true; }); return exist; } - private bool peers_exist (Gtk.TreeModel mode, Gtk.TreeIter ite) { - string host, peerid, downloadspeed, uploadspeed, seeder, bitfield, amchoking, peerchoking; - mode.get (ite, TorrentPeers.HOST, out host, TorrentPeers.PEERID, out peerid, TorrentPeers.DOWNLOADSPEED, out downloadspeed, TorrentPeers.UPLOADSPEED, out uploadspeed, TorrentPeers.SEEDER, out seeder, TorrentPeers.BITFIELD, out bitfield, TorrentPeers.AMCHOKING, out amchoking, TorrentPeers.PEERCHOKING, out peerchoking); - bool exist = false; - peerstore.foreach ((model, path, iter) => { - string hosts; - model.get (iter, TorrentPeers.HOST, out hosts); - if (host == hosts) { - exist = true; - peerstore.set (iter, TorrentPeers.PEERID, peerid, TorrentPeers.DOWNLOADSPEED, downloadspeed, TorrentPeers.UPLOADSPEED, uploadspeed, TorrentPeers.SEEDER, seeder, TorrentPeers.BITFIELD, bitfield, TorrentPeers.AMCHOKING, amchoking, TorrentPeers.PEERCHOKING, peerchoking); + private void show_files () { + aria_files_store (ariagid).foreach ((torrentstore) => { + if (torrentstore.filepath == "" || torrentstore.filepath == null) { + return true; } - return false; + if (torrentstore.filepath.contains ("[METADATA]")) { + return true; + } + if (torrentstore.filebasename == null || torrentstore.filesize == null || torrentstore.completesize == null) { + return true; + } + if (!files_exist (torrentstore)) { + listtorrent.add (torrentstore); + listboxtorrent.append (torrentstore); + torrentstore.show (); + torrentstore.selecting.connect ((index, selected)=> { + var builder = new StringBuilder (); + uint hashb = builder.str.hash (); + listtorrent.foreach ((torrentrow)=> { + var selectfile = torrentrow.selected; + if (torrentrow.index == index) { + selectfile = selected; + } + if (selectfile) { + if (hashb == builder.str.hash ()) { + builder.append (torrentrow.index.to_string ()); + } else { + builder.append (","); + builder.append (torrentrow.index.to_string ()); + } + } + return true; + }); + if (hashb == builder.str.hash ()) { + return; + } + string aria_gid = sendselected (ariagid, builder.str); + this.ariagid = aria_gid; + update_progress (); + }); + } + return true; }); - return exist; } - private bool files_exist (bool select, string index, string name, string pathname, string download, string size, int persen, string uris) { + private bool files_exist (TorrentRow torrentrw) { bool exist = false; - torrstore.foreach ((model, path, iter) => { - string filename; - model.get (iter, FileCol.FILEPATH, out filename); - if (filename == pathname) { + listtorrent.foreach ((torrentrow)=> { + if (torrentrow.filepath == torrentrw.filepath) { exist = true; - torrstore.set (iter, FileCol.SELECTED, select, FileCol.ROW, index, FileCol.NAME, name, FileCol.DOWNLOADED, download, FileCol.SIZE, size, FileCol.PERCEN, persen, FileCol.URIS, uris); + torrentrow.index = torrentrw.index; + torrentrow.selected = torrentrw.selected; + torrentrow.filebasename = torrentrw.filebasename; + torrentrow.filesize = torrentrw.filesize; + torrentrow.completesize = torrentrw.completesize; + torrentrow.fraction = torrentrw.fraction; + torrentrow.status = torrentrw.status; + torrentrow.persen = torrentrw.persen; } - return false; + return true; }); return exist; } diff --git a/src/FileAllocation.vala b/src/FileAllocation.vala index 8758adc..f300cda 100755 --- a/src/FileAllocation.vala +++ b/src/FileAllocation.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/GabutServer.vala b/src/GabutServer.vala index 3eb1b3b..1ed2090 100644 --- a/src/GabutServer.vala +++ b/src/GabutServer.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 @@ -76,8 +76,6 @@ namespace Gabut { } private void upload_handler (Soup.Server server, Soup.ServerMessage msg, string path, GLib.HashTable? query) { - unowned GabutServer self = server as GabutServer; - self.pause_message (msg); if (msg.get_method () == "POST") { string result = (string) msg.get_request_body ().data; if (msg.get_request_headers ().get_content_type (null) == Soup.FORM_MIME_TYPE_MULTIPART) { @@ -93,37 +91,34 @@ namespace Gabut { if (!filed.query_exists ()) { write_file.begin (body, filed.get_path ()); notify_app (_("File Transfered"), _("%s").printf (filename), new ThemedIcon (GLib.ContentType.get_generic_icon_name (headers.get_content_type (null)))); + play_sound ("complete"); } else { notify_app (_("File Exist"), _("%s").printf (filename), new ThemedIcon (GLib.ContentType.get_generic_icon_name (headers.get_content_type (null)))); + play_sound ("dialog-error"); } } msg.set_status (Soup.Status.OK, "OK"); - self.unpause_message (msg); } else if (Regex.match_simple ("openlink=(.*?)", result)) { string reslink = result.replace ("openlink=", "").strip (); if (reslink != "") { if (reslink.has_prefix ("http://") || reslink.has_prefix ("https://") || reslink.has_prefix ("ftp://") || reslink.has_prefix ("sftp://")) { notify_app (_("Open Link"), reslink, new ThemedIcon ("insert-link")); open_fileman.begin (reslink); + play_sound ("complete"); } } msg.set_response ("text/html", Soup.MemoryUse.COPY, get_upload ().data); msg.set_status (Soup.Status.OK, "OK"); - self.unpause_message (msg); } else { msg.set_status (Soup.Status.INTERNAL_SERVER_ERROR, "Error"); - self.unpause_message (msg); } } else if (msg.get_method () == "GET") { msg.set_response ("text/html", Soup.MemoryUse.COPY, get_upload ().data); msg.set_status (Soup.Status.OK, "OK"); - self.unpause_message (msg); } } private void dialog_handler (Soup.Server server, Soup.ServerMessage msg, string path, GLib.HashTable? query) { - unowned GabutServer self = server as GabutServer; - self.pause_message (msg); if (msg.get_method () == "POST") { string result = (string) msg.get_request_body ().data; if (result.contains ("actiondm")) { @@ -143,13 +138,10 @@ namespace Gabut { msg.set_response ("text/html", Soup.MemoryUse.COPY, get_not_found ().data); msg.set_status (Soup.Status.INTERNAL_SERVER_ERROR, "Error"); } - self.unpause_message (msg); } } private void home_handler (Soup.Server server, Soup.ServerMessage msg, string path, GLib.HashTable? query) { - unowned GabutServer self = server as GabutServer; - self.pause_message (msg); if (path != "/" && path != "favicon.ico") { if (msg.get_method () == "POST") { var meseg = (string) msg.get_request_body ().data; @@ -163,17 +155,14 @@ namespace Gabut { msg.set_status (Soup.Status.OK, "OK"); if (ftype == FileType.DIRECTORY) { directory_mode.begin (msg, filegbt, sourcef); - self.unpause_message (msg); return; } else if (ftype == FileType.REGULAR) { open_file.begin (msg, filegbt); - self.unpause_message (msg); return; } if (!filegbt.query_exists (null)) { var pathfile = @"$(filegbt.get_parent ().get_path ().split (sourcef.get_path ())[1])/"; msg.set_redirect (Soup.Status.TEMPORARY_REDIRECT, pathfile == "/"? "/Home" : pathfile); - self.unpause_message (msg); return; } } @@ -190,21 +179,17 @@ namespace Gabut { msg.set_response ("text/html", Soup.MemoryUse.COPY, get_not_found ().data); msg.set_status (Soup.Status.INTERNAL_SERVER_ERROR, "Error"); } - self.unpause_message (msg); } catch (Error e) { GLib.warning (e.message); } } else if (msg.get_method () == "GET") { msg.set_response ("text/html", Soup.MemoryUse.COPY, get_home ().data); msg.set_status (Soup.Status.OK, "OK"); - self.unpause_message (msg); } } private void gabut_handler (Soup.Server server, Soup.ServerMessage msg, string path, GLib.HashTable? query) { - unowned GabutServer self = server as GabutServer; string pathname = path.split ("/")[1].strip (); - self.pause_message (msg); if (msg.get_method () == "POST") { string result = (string) msg.get_request_body ().data; var hashoption = new Gee.HashMap (); @@ -221,7 +206,6 @@ namespace Gabut { } msg.set_response ("text/html", Soup.MemoryUse.COPY, get_dm (pathname, html_dm (path), javascr_dm (path), username).data); msg.set_status (Soup.Status.OK, "OK"); - self.unpause_message (msg); } else if (msg.get_request_headers ().get_content_type (null) == Soup.FORM_MIME_TYPE_MULTIPART) { var multipart = new Soup.Multipart.from_message (msg.get_request_headers () , msg.get_request_body ().flatten ()); Soup.MessageHeaders headers; @@ -240,31 +224,25 @@ namespace Gabut { } msg.set_response ("text/html", Soup.MemoryUse.COPY, get_dm (pathname, html_dm (path), javascr_dm (path), username).data); msg.set_status (Soup.Status.OK, "OK"); - self.unpause_message (msg); } else if (result.contains ("actiondm")) { updat_row (result.slice (result.last_index_of ("+") + 1, result.last_index_of ("="))); msg.set_response ("text/html", Soup.MemoryUse.COPY, get_dm (pathname, html_dm (path), javascr_dm (path), username).data); msg.set_status (Soup.Status.OK, "OK"); - self.unpause_message (msg); } else if (result.contains ("actiondelete")) { delete_row (result.slice (result.last_index_of ("+") + 1, result.last_index_of ("="))); msg.set_response ("text/html", Soup.MemoryUse.COPY, get_dm (pathname, html_dm (path), javascr_dm (path), username).data); msg.set_status (Soup.Status.OK, "OK"); - self.unpause_message (msg); } else if (!result.contains ("+") && result.contains ("sort")) { update_user (username, UserID.SHORTBY, result.split ("=")[1]); msg.set_response ("text/html", Soup.MemoryUse.COPY, get_dm (pathname, html_dm (path), javascr_dm (path), username).data); msg.set_status (Soup.Status.OK, "OK"); - self.unpause_message (msg); } else { msg.set_response ("text/html", Soup.MemoryUse.COPY, get_not_found ().data); msg.set_status (Soup.Status.INTERNAL_SERVER_ERROR, "Error"); - self.unpause_message (msg); } } else if (msg.get_method () == "GET") { msg.set_response ("text/html", Soup.MemoryUse.COPY, get_dm (pathname, html_dm (path), javascr_dm (path), username).data); msg.set_status (Soup.Status.OK, "OK"); - self.unpause_message (msg); } } @@ -390,8 +368,6 @@ namespace Gabut { } private void share_handler (Soup.Server server, Soup.ServerMessage msg, string path, GLib.HashTable? query) { - unowned GabutServer self = server as GabutServer; - self.pause_message (msg); if (bool.parse (get_dbsetting (DBSettings.SWITCHDIR))) { if (msg.get_method () == "POST") { var meseg = (string) msg.get_request_body ().data; @@ -402,11 +378,9 @@ namespace Gabut { msg.set_status (Soup.Status.OK, _("OK")); File sourcef = File.new_for_path (get_dbsetting (DBSettings.SHAREDIR)); directory_mode.begin (msg, sourcef, sourcef); - self.unpause_message (msg); } else { msg.set_response ("text/html", Soup.MemoryUse.COPY, get_not_found ().data); msg.set_status (Soup.Status.OK, "OK"); - self.unpause_message (msg); } } @@ -442,8 +416,9 @@ namespace Gabut { } private int path_lenght = 0; + private bool firstscan = false; private async void directory_mode (Soup.ServerMessage msg, File file, File sourcef) throws Error { - var filesorter = new Gtk.ListStore (FSorter.N_COLUMNS, typeof (string), typeof (string), typeof (bool), typeof (int64), typeof (int), typeof (FileInfo), typeof (string)); + var filesorters = new Gee.ArrayList (); GLib.FileEnumerator enumerator = file.enumerate_children ("*", GLib.FileQueryInfoFlags.NOFOLLOW_SYMLINKS); GLib.FileInfo info; GLib.File fileout; @@ -457,9 +432,15 @@ namespace Gabut { fileordir = true; container = get_container (fileout); } - Gtk.TreeIter iter; - filesorter.append (out iter); - filesorter.set (iter, FSorter.NAME, info.get_name (), FSorter.MIMETYPE, info.get_content_type (), FSorter.FILEORDIR, fileordir, FSorter.SIZE, info.get_size (), FSorter.FILEINDIR, container, FSorter.FILEINFO, info, FSorter.DATE, info.get_modification_date_time ().to_string ()); + var fsorter = FSorter (); + fsorter.name = info.get_name (); + fsorter.mimetype = info.get_content_type (); + fsorter.fileordir = fileordir; + fsorter.size = info.get_size (); + fsorter.fileindir = container; + fsorter.fileinfo = info; + fsorter.date = info.get_modification_date_time ().to_string (); + filesorters.add (fsorter); } var pathfile = @"$(file.get_path ().split (sourcef.get_path ())[1])/"; var htmlstr = ""; @@ -492,24 +473,18 @@ namespace Gabut { } switch (int.parse (get_db_user (UserID.SHORTBY, username))) { case 1: - filesorter.set_sort_column_id (FSorter.FILEINDIR, Gtk.SortType.ASCENDING); - htmlstr += load_item (filesorter, pathfile, 1); - filesorter.set_sort_column_id (FSorter.SIZE, Gtk.SortType.ASCENDING); - htmlstr += load_item (filesorter, pathfile, 2); - break; case 2: - filesorter.set_sort_column_id (FSorter.NAME, Gtk.SortType.ASCENDING); - htmlstr += load_item (filesorter, pathfile, 1); - filesorter.set_sort_column_id (FSorter.MIMETYPE, Gtk.SortType.ASCENDING); - htmlstr += load_item (filesorter, pathfile, 2); + firstscan = true; + filesorters.sort ((GLib.CompareDataFunc) sort_sfile); + htmlstr += load_item (filesorters, pathfile, 1); + firstscan = false; + filesorters.sort ((GLib.CompareDataFunc) sort_sfile); + htmlstr += load_item (filesorters, pathfile, 2); break; case 3: - filesorter.set_sort_column_id (FSorter.DATE, Gtk.SortType.ASCENDING); - htmlstr += load_item (filesorter, pathfile, 0); - break; default: - filesorter.set_sort_column_id (FSorter.NAME, Gtk.SortType.ASCENDING); - htmlstr += load_item (filesorter, pathfile, 0); + filesorters.sort ((GLib.CompareDataFunc) sort_sfile); + htmlstr += load_item (filesorters, pathfile, 0); break; } htmlstr += ""; @@ -518,29 +493,100 @@ namespace Gabut { path_lenght = pathfile.length; } - private string load_item (Gtk.ListStore filesorter, string pathfile, int dirfirst) { + [CCode (instance_pos = -1)] + private int sort_sfile (FSorter row1, FSorter row2) { + var sortpos = int.parse (get_db_user (UserID.SHORTBY, username)); + if (sortpos == 0) { + if (row1.name != null && row2.name != null) { + var name1 = row1.name.down (); + var name2 = row2.name.down (); + if (name1 > name2) { + return 1; + } + if (name1 < name2) { + return -1; + } + } else { + return 0; + } + } else if (sortpos == 1) { + if (firstscan) { + var fileindir1 = row1.fileindir; + var fileindir2 = row2.fileindir; + if (fileindir1 > fileindir2) { + return 1; + } + if (fileindir1 < fileindir2) { + return -1; + } + } else { + var size1 = row1.size; + var size2 = row2.size; + if (size1 > size2) { + return 1; + } + if (size1 < size2) { + return -1; + } + } + } else if (sortpos == 2) { + if (firstscan) { + if (row1.name != null && row2.name != null) { + var name1 = row1.name.down (); + var name2 = row2.name.down (); + if (name1 > name2) { + return 1; + } + if (name1 < name2) { + return -1; + } + } else { + return 0; + } + } else { + if (row1.mimetype != null && row2.mimetype != null) { + var mime1 = row1.mimetype.down (); + var mime2 = row2.mimetype.down (); + if (mime1 > mime2) { + return 1; + } + if (mime1 < mime2) { + return -1; + } + } else { + return 0; + } + } + } else { + var timeadded1 = row1.date; + var timeadded2 = row2.date; + if (timeadded1 > timeadded2) { + return 1; + } + if (timeadded1 < timeadded2) { + return -1; + } + } + return 0; + } + + private string load_item (Gee.ArrayList filesorter, string pathfile, int dirfirst) { string htmlstr = ""; - filesorter.foreach ((model, path, iter) => { - string name, mime; - int infolder; - int64 fsize; - bool filordir; - FileInfo infofile; - model.get (iter, FSorter.NAME, out name, FSorter.MIMETYPE, out mime, FSorter.FILEORDIR, out filordir, FSorter.SIZE, out fsize, FSorter.FILEINDIR, out infolder, FSorter.FILEINFO, out infofile); + filesorter.foreach ((fsorter) => { switch (dirfirst) { case 1: - if (filordir) { - htmlstr += loaddiv (pathfile + name, infofile, false, filordir, mime, fsize, infolder); + if (fsorter.fileordir) { + htmlstr += loaddiv (pathfile + fsorter.name, fsorter.fileinfo, false, fsorter.fileordir, fsorter.mimetype, fsorter.size, fsorter.fileindir); } - return false; + return true; case 2: - if (!filordir) { - htmlstr += loaddiv (pathfile + name, infofile, false, filordir, mime, fsize, infolder); + if (!fsorter.fileordir) { + htmlstr += loaddiv (pathfile + fsorter.name, fsorter.fileinfo, false, fsorter.fileordir, fsorter.mimetype, fsorter.size, fsorter.fileindir); } - return false; + return true; default: - htmlstr += loaddiv (pathfile + name, infofile, false, filordir, mime, fsize, infolder); - return false; + htmlstr += loaddiv (pathfile + fsorter.name, fsorter.fileinfo, false, fsorter.fileordir, fsorter.mimetype, fsorter.size, fsorter.fileindir); + return true; } }); return htmlstr; diff --git a/src/GabutSucces.vala b/src/GabutSucces.vala index 7e6ba94..0b965ae 100755 --- a/src/GabutSucces.vala +++ b/src/GabutSucces.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/GabutWindow.vala b/src/GabutWindow.vala index f293708..85bf662 100644 --- a/src/GabutWindow.vala +++ b/src/GabutWindow.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 @@ -43,8 +43,6 @@ namespace Gabut { private CanonicalDbusmenu dbusserver; private DbusIndicator dbusindicator; private Gtk.MenuButton shortbutton; - private Gtk.FlowBox sort_flow; - private Gtk.FlowBox deas_flow; private Gtk.CheckButton showtime; private Gtk.CheckButton showdate; private int64 animation = 0; @@ -167,10 +165,17 @@ namespace Gabut { opentormenu.property_set (MenuItem.ICON_NAME.to_string (), "document-open"); opentormenu.property_set_bool (MenuItem.VISIBLE.to_string (), true); opentormenu.item_activated.connect (()=> { - var files = run_open_file (this); - foreach (var file in files) { - send_file (file.get_uri ()); - } + run_open_file.begin (this, OpenFiles.OPENFILES, (obj, res)=> { + try { + GLib.File[] files; + run_open_file.end (res, out files); + foreach (var file in files) { + send_file (file.get_uri ()); + } + } catch (GLib.Error e) { + critical (e.message); + } + }); }); var setmenu = new DbusmenuItem (); @@ -181,13 +186,13 @@ namespace Gabut { var startmenu = new DbusmenuItem (); startmenu.property_set (MenuItem.LABEL.to_string (), _("Start All")); - startmenu.property_set (MenuItem.ICON_NAME.to_string (), "media-playback-start"); + startmenu.property_set (MenuItem.ICON_NAME.to_string (), "com.github.gabutakut.gabutdm.active"); startmenu.property_set_bool (MenuItem.VISIBLE.to_string (), true); startmenu.item_activated.connect (start_all); var pausemenu = new DbusmenuItem (); pausemenu.property_set (MenuItem.LABEL.to_string (), _("Pause All")); - pausemenu.property_set (MenuItem.ICON_NAME.to_string (), "media-playback-pause"); + pausemenu.property_set (MenuItem.ICON_NAME.to_string (), "com.github.gabutakut.gabutdm.pause"); pausemenu.property_set_bool (MenuItem.VISIBLE.to_string (), true); pausemenu.item_activated.connect (stop_all); @@ -308,18 +313,25 @@ namespace Gabut { }; headerbar.pack_start (torrentbutton); torrentbutton.clicked.connect (()=> { - var files = run_open_file (this); - foreach (var file in files) { - send_file (file.get_uri ()); - } + run_open_file.begin (this, OpenFiles.OPENFILES, (obj, res)=> { + try { + GLib.File[] files; + run_open_file.end (res, out files); + foreach (var file in files) { + send_file (file.get_uri ()); + } + } catch (GLib.Error e) { + critical (e.message); + } + }); }); - var resumeall_button = new Gtk.Button.from_icon_name ("media-playback-start") { + var resumeall_button = new Gtk.Button.from_icon_name ("com.github.gabutakut.gabutdm.active") { tooltip_text = _("Start All") }; headerbar.pack_start (resumeall_button); resumeall_button.clicked.connect (start_all); - var stopall_button = new Gtk.Button.from_icon_name ("media-playback-pause") { + var stopall_button = new Gtk.Button.from_icon_name ("com.github.gabutakut.gabutdm.pause") { tooltip_text = _("Pause All") }; headerbar.pack_start (stopall_button); @@ -403,12 +415,13 @@ namespace Gabut { private Gtk.CenterBox bottom_action () { var actionbar = new Gtk.CenterBox () { - hexpand = true, + hexpand = false, margin_top = 4, - margin_bottom = 4 + margin_bottom = 4, + orientation = Gtk.Orientation.HORIZONTAL }; var property_button = new Gtk.MenuButton () { - child = image_btn ("format-justify-center", 16), + child = new Gtk.Image.from_icon_name ("com.github.gabutakut.gabutdm.menu"), direction = Gtk.ArrowType.UP, margin_start = 10, tooltip_text = _("Property") @@ -419,7 +432,7 @@ namespace Gabut { if (rw != null) { var row = (DownloadRow) rw; property_button.popover = row.get_menu (); - row.myproperty.connect (()=> { + row.gsmproperties.connect (()=> { if (!property_active (row)) { var property = new AddUrl.Property (application) { transient_for = this, @@ -454,23 +467,22 @@ namespace Gabut { property_button.popover = null; } }); - view_mode = new ModeButton () { - hexpand = false - }; - view_mode.append_text (_("All")); - view_mode.append_text (_("Downloading")); - view_mode.append_text (_("Paused")); - view_mode.append_text (_("Complete")); - view_mode.append_text (_("Waiting")); - view_mode.append_text (_("Error")); + view_mode = new ModeButton (); + view_mode.append_icon_text ("com.github.gabutakut.gabutdm", "All"); + view_mode.append_icon_text ("com.github.gabutakut.gabutdm.active","Downloading"); + view_mode.append_icon_text ("com.github.gabutakut.gabutdm.pause", "Paused"); + view_mode.append_icon_text ("com.github.gabutakut.gabutdm.complete", "Complete"); + view_mode.append_icon_text ("com.github.gabutakut.gabutdm.waiting", "Waiting"); + view_mode.append_icon_text ("com.github.gabutakut.gabutdm.error", "Error"); view_mode.selected = 0; actionbar.set_center_widget (view_mode); view_mode.notify["selected"].connect (view_status); + shortbutton = new Gtk.MenuButton () { direction = Gtk.ArrowType.UP, - child = image_btn ("format-justify-fill", 16), - margin_end = 10, + child = new Gtk.Image.from_icon_name ("com.github.gabutakut.gabutdm.opt"), popover = get_menu (), + margin_end = 10, tooltip_text = _("Sort by") }; actionbar.set_end_widget (shortbutton); @@ -478,36 +490,52 @@ namespace Gabut { } public Gtk.Popover get_menu () { - sort_flow = new Gtk.FlowBox () { + var sort_flow = new Gtk.FlowBox () { orientation = Gtk.Orientation.HORIZONTAL, width_request = 70, margin_top = 4, margin_bottom = 4 }; - deas_flow = new Gtk.FlowBox () { + var deas_flow = new Gtk.FlowBox () { orientation = Gtk.Orientation.HORIZONTAL, width_request = 70 }; showtime = new Gtk.CheckButton.with_label (_("Time")) { - margin_start = 6, + margin_start = 9, margin_top = 4, margin_bottom = 4, margin_end = 4, + width_request = 130, active = bool.parse (get_dbsetting (DBSettings.SHOWTIME)) }; ((Gtk.Label) showtime.get_last_child ()).attributes = set_attribute (Pango.Weight.BOLD); ((Gtk.Label) showtime.get_last_child ()).halign = Gtk.Align.CENTER; ((Gtk.Label) showtime.get_last_child ()).wrap_mode = Pango.WrapMode.WORD_CHAR; + var timeimg = new Gtk.Image () { + valign = Gtk.Align.CENTER, + gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.waiting") + }; + var centime = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); + centime.append (showtime); + centime.append (timeimg); showdate = new Gtk.CheckButton.with_label (_("Date")) { - margin_start = 6, + margin_start = 9, margin_top = 4, margin_bottom = 4, margin_end = 4, + width_request = 130, active = bool.parse (get_dbsetting (DBSettings.SHOWDATE)) }; ((Gtk.Label) showdate.get_last_child ()).attributes = set_attribute (Pango.Weight.BOLD); ((Gtk.Label) showdate.get_last_child ()).halign = Gtk.Align.CENTER; ((Gtk.Label) showdate.get_last_child ()).wrap_mode = Pango.WrapMode.WORD_CHAR; + var dateimg = new Gtk.Image () { + valign = Gtk.Align.CENTER, + gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.date") + }; + var cendate = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); + cendate.append (showdate); + cendate.append (dateimg); var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) { margin_top = 4, margin_bottom = 4 @@ -516,29 +544,22 @@ namespace Gabut { box.append (new Gtk.Separator (Gtk.Orientation.HORIZONTAL)); box.append (deas_flow); box.append (new Gtk.Separator (Gtk.Orientation.HORIZONTAL)); - box.append (showtime); - box.append (showdate); + box.append (centime); + box.append (cendate); var sort_popover = new Gtk.Popover () { position = Gtk.PositionType.TOP, width_request = 70, child = box }; - sort_popover.show.connect (() => { - if (sorttype != null) { - sort_flow.select_child (sorttype); - sorttype.grab_focus (); - } - if (deascend != null) { - deas_flow.unselect_child (deascend); - } - }); showdate.toggled.connect (()=> { sort_popover.hide (); + ((Gtk.Label) showdate.get_last_child ()).attributes = showdate.active? color_attribute (0, 60000, 0) : set_attribute (Pango.Weight.BOLD); set_dbsetting (DBSettings.SHOWDATE, showdate.active.to_string ()); set_listheader (); }); showtime.toggled.connect (()=> { sort_popover.hide (); + ((Gtk.Label) showtime.get_last_child ()).attributes = showtime.active? color_attribute (0, 60000, 0) : set_attribute (Pango.Weight.BOLD); set_dbsetting (DBSettings.SHOWTIME, showtime.active.to_string ()); set_listheader (); }); @@ -549,27 +570,36 @@ namespace Gabut { sort_flow.show (); sort_flow.child_activated.connect ((shorty)=> { sort_popover.hide (); + ((Gtk.Label)((SortBy) sorttype).get_last_child ()).attributes = set_attribute (Pango.Weight.BOLD); sorttype = shorty as SortBy; + ((Gtk.Label)sorttype.get_last_child ()).attributes = color_attribute (0, 60000, 0); list_box.set_sort_func ((Gtk.ListBoxSortFunc) sort_dm); listrow.sort (sort_dm); }); sorttype = sort_flow.get_child_at_index (int.parse (get_dbsetting (DBSettings.SORTBY))) as SortBy; + ((Gtk.Label)sorttype.get_last_child ()).attributes = color_attribute (0, 60000, 0); foreach (var deas in DeAscend.get_all ()) { deas_flow.append (new DeAscending (deas)); } deas_flow.show (); deas_flow.child_activated.connect ((deas)=> { sort_popover.hide (); + ((DeAscending) deascend).activebtn = false; + ((Gtk.Label)deascend.get_first_child ().get_last_child ().get_prev_sibling ()).attributes = set_attribute (Pango.Weight.BOLD); deascend = deas as DeAscending; - for (int i = 0; i <= DeAscend.DESCENDING; i++) { - ((DeAscending) deas_flow.get_child_at_index (i)).activebtn = false; - } - ((DeAscending) deas_flow.get_child_at_index (deascend.get_index ())).activebtn = true; + ((Gtk.Label)deascend.get_first_child ().get_last_child ().get_prev_sibling ()).attributes = color_attribute (0, 60000, 0); + deascend.activebtn = true; list_box.set_sort_func ((Gtk.ListBoxSortFunc) sort_dm); listrow.sort (sort_dm); }); deascend = deas_flow.get_child_at_index (int.parse (get_dbsetting (DBSettings.ASCEDESCEN))) as DeAscending; - ((DeAscending) deas_flow.get_child_at_index (deascend.get_index ())).activebtn = true; + ((Gtk.Label)deascend.get_first_child ().get_last_child ().get_prev_sibling ()).attributes = color_attribute (0, 60000, 0); + deascend.activebtn = true; + sort_popover.show.connect (() => { + sort_flow.select_child (sorttype); + sorttype.grab_focus (); + deas_flow.unselect_child (deascend); + }); return sort_popover; } diff --git a/src/GdmMenu.vala b/src/GdmMenu.vala new file mode 100755 index 0000000..19d785a --- /dev/null +++ b/src/GdmMenu.vala @@ -0,0 +1,48 @@ +/* +* Copyright (c) {2024} 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 GdmMenu : Gtk.FlowBoxChild { + public DownloadMenu downloadmenu { get; private set; } + + public GdmMenu (DownloadMenu downloadmenu) { + this.downloadmenu = downloadmenu; + halign = Gtk.Align.CENTER; + var title = new Gtk.Label (downloadmenu.to_string ()) { + halign = Gtk.Align.START, + wrap_mode = Pango.WrapMode.WORD_CHAR, + attributes = set_attribute (Pango.Weight.BOLD), + margin_top = 6, + margin_bottom = 6, + width_request = 130 + }; + var imgstatus = new Gtk.Image () { + valign = Gtk.Align.CENTER, + gicon = new ThemedIcon (downloadmenu.to_icon ()) + }; + var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); + box.append (imgstatus); + box.append (title); + child = box; + show (); + } + } +} diff --git a/src/GdmOutstream.vala b/src/GdmOutstream.vala index 17b3226..809fb51 100755 --- a/src/GdmOutstream.vala +++ b/src/GdmOutstream.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/GdmPaint.vala b/src/GdmPaint.vala new file mode 100644 index 0000000..03b436c --- /dev/null +++ b/src/GdmPaint.vala @@ -0,0 +1,49 @@ +/* +* Copyright (c) {2024} 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 GdmPaint : GLib.Object, Gdk.Paintable { + public signal void queue_draw (); + private Gdk.Paintable _paintable = null; + public Gdk.Paintable paintable { + get { + return _paintable; + } + set { + _paintable = value; + on_change (_paintable); + queue_draw (); + } + } + + public void snapshot (Gdk.Snapshot snapshot, double width, double height) { + on_snapshot ((Gtk.Snapshot)snapshot, width, height); + } + + protected virtual void on_change (Gdk.Paintable? paintable) { + _paintable = paintable; + } + + protected virtual void on_snapshot (Gtk.Snapshot snaps, double width, double height) { + snapshot (snaps, width, height); + } + } +} diff --git a/src/LoginUser.vala b/src/LoginUser.vala index 395235b..fbb5951 100755 --- a/src/LoginUser.vala +++ b/src/LoginUser.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/MediaEntry.vala b/src/MediaEntry.vala index bd5fc13..6ca5a65 100755 --- a/src/MediaEntry.vala +++ b/src/MediaEntry.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/ModeButton.vala b/src/ModeButton.vala index 0306b91..0e7ba04 100644 --- a/src/ModeButton.vala +++ b/src/ModeButton.vala @@ -9,7 +9,7 @@ namespace Gabut { public class ModeButton : Gtk.Box { - private class Item : Gtk.ToggleButton { + private class Item : Gtk.CheckButton { public int index { get; construct; } public Item (int index) { Object (index: index); @@ -35,25 +35,28 @@ namespace Gabut { private Gee.HashMap item_map; construct { - homogeneous = true; spacing = 0; item_map = new Gee.HashMap (); } - public int append_pixbuf (Gdk.Pixbuf pixbuf) { - return appends (new Gtk.Image.from_pixbuf (pixbuf)); - } - public int append_text (string text) { - return appends (new Gtk.Label (text)); + var label = new Gtk.Label (text) { + attributes = set_attribute (Pango.Weight.ULTRABOLD) + }; + return appends (label); } - public int append_icon (string icon_name, Gtk.IconSize size) { - var img = new Gtk.Image.from_icon_name (icon_name) { - icon_size = size, - pixel_size = size + public int append_icon_text (string icon_name, string name_label) { + var label = new Gtk.Label (name_label) { + attributes = set_attribute (Pango.Weight.ULTRABOLD) + }; + var gridn = new Gtk.Grid () { + column_spacing = 4, + margin_top = 7 }; - return appends (img); + gridn.attach (new Gtk.Image.from_icon_name (icon_name), 0, 1); + gridn.attach (label, 1, 1); + return appends (gridn); } public int appends (Gtk.Widget w) { @@ -93,7 +96,9 @@ namespace Gabut { if (new_item != null) { new_item.set_active (true); if (new_item.child.name == "GtkLabel") { - ((Gtk.Label) new_item.child).attributes = color_attribute (60000, 0, 0); + ((Gtk.Label) new_item.child).attributes = color_attribute (0, 60000, 0); + } else { + ((Gtk.Label) new_item.child.get_last_child ()).attributes = color_attribute (0, 60000, 0); } if (_selected == new_active_index) { return; @@ -102,7 +107,9 @@ namespace Gabut { _selected = new_active_index; if (old_item != null) { if (old_item.child.name == "GtkLabel") { - ((Gtk.Label) old_item.child).attributes = null; + ((Gtk.Label) old_item.child).attributes = set_attribute (Pango.Weight.ULTRABOLD); + } else { + ((Gtk.Label) old_item.child.get_last_child ()).attributes = set_attribute (Pango.Weight.ULTRABOLD); } old_item.set_active (false); } diff --git a/src/ModeTogle.vala b/src/ModeTogle.vala index e7aa174..d9649a8 100755 --- a/src/ModeTogle.vala +++ b/src/ModeTogle.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 @@ -20,9 +20,7 @@ */ namespace Gabut { - public class ModeTogle : GLib.Object { - public signal void item_activated (int id); - + public class ModeTogle : Gtk.Box { private int _id = 0; public int id { get { @@ -31,34 +29,27 @@ namespace Gabut { set { _id = value; if (menuchildren != null) { - menuchildren.foreach ((menu)=> { - if (menu.id == _id) { - menu.menucheckbox.active = true; - } - }); + menuchildren.nth_data (id).checkbtn.active = true; } } } - public GLib.List menuchildren = null; - public Gtk.CheckButton menucheckbox; + private GLib.List menuchildren = null; + public Gtk.CheckButton checkbtn; public ModeTogle.with_label (string value) { - menucheckbox.set_label (value); + checkbtn.set_label (value); } construct { - menucheckbox = new Gtk.CheckButton () { + orientation = Gtk.Orientation.VERTICAL; + checkbtn = new Gtk.CheckButton () { margin_top = 5 }; } - private Gtk.CheckButton get_checkbox () { - return menucheckbox; - } - public void set_label (string value) { - menucheckbox.set_label (value); + checkbtn.set_label (value); } private bool get_exist (ModeTogle children) { @@ -79,33 +70,17 @@ namespace Gabut { } if (!get_exist (child)) { menuchildren.append (child); - menuchildren.foreach ((item)=> { - item.id = menuchildren.index (item); - if (item.id > 0) { - item.menucheckbox.set_group (menuchildren.nth_data ((uint) item.id - 1).menucheckbox); + child.id = (int) menuchildren.length () - 1; + if (child.id > 0) { + child.checkbtn.set_group (menuchildren.nth_data ((uint) child.id - 1).checkbtn); + } + child.checkbtn.toggled.connect (()=> { + if (child.checkbtn.active) { + id = child.id; } }); + append (child.checkbtn); } } - - public Gtk.Box get_box () { - var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 2); - menuchildren.foreach ((menu)=> { - menu.menucheckbox.toggled.connect (()=> { - if (menu.menucheckbox.active) { - id = menu.id; - item_activated (id); - } - }); - box.append (menu.get_checkbox ()); - }); - return box; - } - - public void sensitive_box (bool sensitivebox) { - menuchildren.foreach ((menu)=> { - menu.menucheckbox.sensitive = sensitivebox; - }); - } } -} +} \ No newline at end of file diff --git a/src/PeersRow.vala b/src/PeersRow.vala new file mode 100644 index 0000000..6a7c90c --- /dev/null +++ b/src/PeersRow.vala @@ -0,0 +1,191 @@ +/* +* Copyright (c) {2024} 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 PeersRow : Gtk.ListBoxRow { + private Gtk.Label download_rate; + private Gtk.Label host_label; + private Gtk.Label client_id; + private Gtk.Label upload_rate; + private Gtk.Image seeder_img; + + private string _host; + public string host { + get { + return _host; + } + set { + _host = value; + host_label.label = _("%s").printf (_host); + } + } + + private string _peerschoking; + public string peerschoking { + get { + return _peerschoking; + } + set { + _peerschoking = value; + } + } + + private string _peerid; + public string peerid { + get { + return _peerid; + } + set { + _peerid = value; + client_id.label = _("%s").printf (_peerid); + } + } + + private string _downloadspeed; + public string downloadspeed { + get { + return _downloadspeed; + } + set { + _downloadspeed = value; + download_rate.label = _("%s").printf (_downloadspeed); + } + } + + private string _uploadspeed; + public string uploadspeed { + get { + return _uploadspeed; + } + set { + _uploadspeed = value; + upload_rate.label = _("%s").printf (_uploadspeed); + } + } + + private string _seeder; + public string seeder { + get { + return _seeder; + } + set { + _seeder = value; + seeder_img.gicon = new ThemedIcon (bool.parse (_seeder)? "com.github.gabutakut.gabutdm" : "com.github.gabutakut.gabutdm.seed"); + } + } + + private string _amchoking; + public string amchoking { + get { + return _amchoking; + } + set { + _amchoking = value; + } + } + private string _bitfield; + public string bitfield { + get { + return _bitfield; + } + set { + _bitfield = value; + } + } + construct { + seeder_img = new Gtk.Image () { + valign = Gtk.Align.CENTER, + tooltip_text = _("Seeder") + }; + var host_id = new Gtk.Image () { + valign = Gtk.Align.CENTER, + gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.gohome"), + tooltip_text = _("Host") + }; + + host_label = new Gtk.Label (null) { + xalign = 0, + use_markup = true, + width_request = 180, + valign = Gtk.Align.CENTER, + attributes = color_attribute (0, 30000, 50000) + }; + var peer_id = new Gtk.Image () { + valign = Gtk.Align.CENTER, + gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.client"), + tooltip_text = _("Client") + }; + + client_id = new Gtk.Label (null) { + xalign = 0, + use_markup = true, + width_request = 150, + valign = Gtk.Align.CENTER, + attributes = color_attribute (50000, 30000, 0) + }; + var label_download = new Gtk.Image () { + valign = Gtk.Align.CENTER, + gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.down"), + tooltip_text = _("Download Speed") + }; + download_rate = new Gtk.Label (null) { + xalign = 0, + use_markup = true, + width_request = 70, + valign = Gtk.Align.CENTER, + attributes = color_attribute (0, 60000, 0) + }; + var label_upload = new Gtk.Image () { + valign = Gtk.Align.CENTER, + gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.up"), + tooltip_text = _("Upload Speed") + }; + upload_rate = new Gtk.Label (null) { + xalign = 0, + use_markup = true, + width_request = 70, + valign = Gtk.Align.CENTER, + attributes = color_attribute (60000, 0, 0) + }; + + var grid = new Gtk.Grid () { + hexpand = true, + margin_start = 4, + margin_end = 4, + margin_top = 2, + margin_bottom = 2, + column_spacing = 4, + row_spacing = 2, + valign = Gtk.Align.CENTER + }; + grid.attach (seeder_img, 0, 0); + grid.attach (host_id, 1, 0); + grid.attach (host_label, 2, 0); + grid.attach (peer_id, 3, 0); + grid.attach (client_id, 4, 0); + grid.attach (label_download, 5, 0); + grid.attach (download_rate, 6, 0); + grid.attach (label_upload, 7, 0); + grid.attach (upload_rate, 8, 0); + child = grid; + } + } +} diff --git a/src/PieceSelector.vala b/src/PieceSelector.vala index 8035f5f..4ade1f2 100755 --- a/src/PieceSelector.vala +++ b/src/PieceSelector.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/Preferences.vala b/src/Preferences.vala index 7199425..ec622c5 100644 --- a/src/Preferences.vala +++ b/src/Preferences.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 @@ -100,6 +100,7 @@ namespace Gabut { construct { var view_mode = new ModeButton () { hexpand = false, + homogeneous = true, width_request = 300 }; view_mode.append_text (_("Default")); @@ -308,14 +309,21 @@ namespace Gabut { tooltip_text = _("Open Text Tracker") }; load_tr.clicked.connect (() => { - var file = run_open_text (this, OpenFiles.OPENTEXTONE); - if (file != null) { + run_open_text.begin (this, OpenFiles.OPENTEXTONE, (obj, res)=> { try { - trackertext.buffer.text = (string) file.load_bytes ().get_data (); - } catch (Error e) { - GLib.warning (e.message); + GLib.File file; + run_open_text.end (res, out file); + if (file != null) { + try { + trackertext.buffer.text = (string) file.load_bytes ().get_data (); + } catch (Error e) { + GLib.warning (e.message); + } + } + } catch (GLib.Error e) { + critical (e.message); } - } + }); }); var fformat_tr = new Gtk.Button.from_icon_name ("view-refresh") { @@ -361,14 +369,21 @@ namespace Gabut { tooltip_text = _("Open Text Tracker") }; load_etr.clicked.connect (() => { - var file = run_open_text (this, OpenFiles.OPENTEXTTWO); - if (file != null) { + run_open_text.begin (this, OpenFiles.OPENTEXTTWO, (obj, res)=> { try { - etrackertext.buffer.text = (string) file.load_bytes ().get_data (); - } catch (Error e) { - GLib.warning (e.message); + GLib.File file; + run_open_text.end (res, out file); + if (file != null) { + try { + etrackertext.buffer.text = (string) file.load_bytes ().get_data (); + } catch (Error e) { + GLib.warning (e.message); + } + } + } catch (GLib.Error e) { + critical (e.message); } - } + }); }); var fformat_etr = new Gtk.Button.from_icon_name ("view-refresh") { tooltip_text = _("Fix to Tracker") @@ -424,19 +439,33 @@ namespace Gabut { folder_location = new Gtk.Button (); folder_location.clicked.connect (()=> { - var file = run_open_fd (this, OpenFiles.OPENGLOBALFOLDER); - if (file != null) { - selectfd = file; - } + run_open_fd.begin (this, OpenFiles.OPENGLOBALFOLDER, (obj, res)=> { + try { + GLib.File file; + run_open_fd.end (res, out file); + if (file != null) { + selectfd = file; + } + } catch (GLib.Error e) { + critical (e.message); + } + }); }); selectfd = File.new_for_path (pharse_options (pack_data, AriaOptions.DIR).replace ("\\/", "/")); folder_sharing = new Gtk.Button (); folder_sharing.clicked.connect (()=> { - var file = run_open_fd (this, OpenFiles.OPENFOLDERSHARING); - if (file != null) { - selectfs = file; - } + run_open_fd.begin (this, OpenFiles.OPENFOLDERSHARING, (obj, res)=> { + try { + GLib.File file; + run_open_fd.end (res, out file); + if (file != null) { + selectfs = file; + } + } catch (GLib.Error e) { + critical (e.message); + } + }); }); selectfs = File.new_for_path (get_dbsetting (DBSettings.SHAREDIR)); @@ -479,7 +508,7 @@ namespace Gabut { boxuser.append (usergrid); boxuser.append (add_auth); var userscr = new Gtk.ScrolledWindow () { - width_request = 455, + width_request = 450, vexpand = true, child = boxuser }; @@ -644,16 +673,14 @@ namespace Gabut { label_mode.add_item (new ModeTogle.with_label (_("Total Speed"))); label_mode.id = int.parse (get_dbsetting (DBSettings.LABELMODE)); var label_rev = new Gtk.Revealer () { - child = label_mode.get_box () + child = label_mode }; label_rev.reveal_child = menuindicator.active; menuindicator.toggled.connect (()=> { label_rev.reveal_child = menuindicator.active; - label_mode.sensitive_box (dbusmenu.active && menuindicator.active); }); dbusmenu.toggled.connect (()=> { menuindicator.sensitive = dbusmenu.active; - label_mode.sensitive_box (dbusmenu.active && menuindicator.active); }); var tdefault = new Gtk.CheckButton.with_label (_("Theme")) { margin_top = 5, @@ -673,7 +700,7 @@ namespace Gabut { theme_mode.add_item (new ModeTogle.with_label (_("Custom"))); theme_mode.id = int.parse (get_dbsetting (DBSettings.THEMESELECT)); var gridtheme = new Gtk.Box (Gtk.Orientation.VERTICAL, 1); - gridtheme.append (theme_mode.get_box ()); + gridtheme.append (theme_mode); gridtheme.append (theme_entry); var theme_rev = new Gtk.Revealer () { child = gridtheme @@ -682,8 +709,8 @@ namespace Gabut { tdefault.toggled.connect (()=> { theme_rev.reveal_child = tdefault.active; }); - theme_mode.item_activated.connect ((id)=> { - theme_entry.sensitive = id == 1; + theme_mode.notify ["id"].connect ((id)=> { + theme_entry.sensitive = theme_mode.id == 1; }); theme_entry.sensitive = theme_mode.id == 1; var allowrepl = new Gtk.CheckButton.with_label (_("Replace File")) { @@ -710,7 +737,7 @@ namespace Gabut { height_request = 190 }; notifyopt.attach (headerlabel (_("Style:"), 450), 0, 0, 1, 1); - notifyopt.attach (style_mode.get_box (), 0, 1, 1, 1); + notifyopt.attach (style_mode, 0, 1, 1, 1); notifyopt.attach (tdefault, 0, 2, 1, 1); notifyopt.attach (theme_rev, 0, 3, 1, 1); notifyopt.attach (headerlabel (_("Settings:"), 450), 0, 4, 1, 1); @@ -728,7 +755,6 @@ namespace Gabut { notifyopt.attach (headerlabel (_("File Download:"), 450), 0, 16, 1, 1); notifyopt.attach (allowrepl, 0, 17, 1, 1); notifyopt.attach (autorename, 0, 18, 1, 1); - label_mode.sensitive_box (dbusmenu.active && menuindicator.active); var notyscr = new Gtk.ScrolledWindow () { width_request = 455, @@ -776,7 +802,7 @@ namespace Gabut { set_dbsetting (DBSettings.THEMESELECT, theme_mode.id.to_string ()); set_dbsetting (DBSettings.THEMECUSTOM, theme_entry.text); } - pantheon_theme.begin (); + gdm_theme.begin (); if (label_mode.id != int.parse (get_dbsetting (DBSettings.LABELMODE))) { set_dbsetting (DBSettings.LABELMODE, label_mode.id.to_string ()); } diff --git a/src/ProgressPaint.vala b/src/ProgressPaint.vala new file mode 100644 index 0000000..96a8a32 --- /dev/null +++ b/src/ProgressPaint.vala @@ -0,0 +1,48 @@ +/* +* Copyright (c) {2024} 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 ProgressPaintable : GdmPaint { + private double _progress = 0; + public double progress { + get { + return _progress; + } + set { + _progress = value; + queue_draw (); + } + } + protected override void on_snapshot (Gtk.Snapshot snapshot, double width, double height) { + var grect = Graphene.Rect (); + grect.init (-2, -2, (float) (width + 4), (float)(height + 4)); + var cr = snapshot.append_cairo (grect); + double arc_end = progress * GLib.Math.PI * 2 - GLib.Math.PI / 2; + cr.translate (width / 2.0, height / 2.0); + cr.set_source_rgba (0.0,1.0,0.0 , 1.0); + cr.arc (0, 0, width / 2.0 + 1, -GLib.Math.PI / 2, arc_end); + cr.stroke (); + cr.set_source_rgba (1.0,0.0,0.0, 1.0); + cr.arc (0, 0, width / 2.0 + 1, arc_end, 3.0 * GLib.Math.PI / 2.0); + cr.stroke (); + } + } +} diff --git a/src/ProxyMethod.vala b/src/ProxyMethod.vala index 43422bf..f91b0e3 100755 --- a/src/ProxyMethod.vala +++ b/src/ProxyMethod.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/ProxyType.vala b/src/ProxyType.vala index e2a988f..672844d 100755 --- a/src/ProxyType.vala +++ b/src/ProxyType.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/QrCode.vala b/src/QrCode.vala index b2ed02e..73761f5 100644 --- a/src/QrCode.vala +++ b/src/QrCode.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 @@ -54,7 +54,7 @@ namespace Gabut { }; overlay.add_overlay (icon_badge); - var primary = new Gtk.Label ("Scan QR Code") { + var primary = new Gtk.Label (_("Scan QR Code")) { ellipsize = Pango.EllipsizeMode.END, max_width_chars = 35, use_markup = true, @@ -63,7 +63,7 @@ namespace Gabut { attributes = set_attribute (Pango.Weight.ULTRABOLD, 1.6) }; - var secondary = new Gtk.Label ("Address Gabut Server") { + var secondary = new Gtk.Label (_("Address Gabut Server")) { ellipsize = Pango.EllipsizeMode.END, max_width_chars = 35, use_markup = true, @@ -88,17 +88,16 @@ namespace Gabut { imageqr = new Gtk.Image () { halign = Gtk.Align.START, - width_request = 250, - margin_bottom = 5, - pixel_size = 128 + valign = Gtk.Align.START, + pixel_size = 256, + margin_start = 10, + margin_end = 10 }; linkbutton = new Gtk.LinkButton (""); var link_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) { halign = Gtk.Align.CENTER, - valign = Gtk.Align.CENTER, - margin_top = 5, - margin_bottom = 5 + valign = Gtk.Align.CENTER }; link_box.append (linkbutton); @@ -129,19 +128,9 @@ namespace Gabut { box_action.attach (host_button, 0, 0); box_action.attach (close_button, 1, 0); - var maingrid = new Gtk.Grid () { - halign = Gtk.Align.CENTER, - valign = Gtk.Align.CENTER, - hexpand = true, - margin_top = 15, - margin_start = 10, - margin_end = 10 - }; - maingrid.attach (imageqr, 0, 0); - maingrid.attach (link_box, 0, 1); - maingrid.attach (box_action, 0, 2); - - child = maingrid; + get_content_area ().append (imageqr); + get_content_area ().append (link_box); + get_content_area ().append (box_action); } public override void show () { @@ -159,24 +148,26 @@ namespace Gabut { if (local_server) { host_button.label =_("Share Address"); ((Gtk.Label) linkbutton.get_last_child ()).attributes = color_attribute (60000, 0, 0); - icon_badge.gicon = new ThemedIcon ("media-playback-pause"); + icon_badge.gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.pause"); } else { host_button.label = _("Stop Share"); ((Gtk.Label) linkbutton.get_last_child ()).attributes = color_attribute (60000, 37000, 0); - icon_badge.gicon = new ThemedIcon ("media-playback-start"); + icon_badge.gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.active"); } string host = get_host (reboot); create_qrcode (host); linkbutton.uri = host; - linkbutton.label = host.contains ("0.0.0.0")? _("No Network Connected"): host; + linkbutton.label = host.contains ("0.0.0.0")? _("No Network Connected"): host.up (); } private void create_qrcode (string strinput) { var qrencode = new Qrencode.QRcode.encodeData (strinput.length, strinput.data, 1, Qrencode.EcLevel.M); int qrenwidth = qrencode.width; int sizeqrcode = 200 + qrenwidth * 40; - Cairo.ImageSurface surface = new Cairo.ImageSurface (Cairo.Format.RGB30, sizeqrcode, sizeqrcode); - Cairo.Context context = new Cairo.Context (surface); + var grect = Graphene.Rect (); + grect.init (0, 0, sizeqrcode, sizeqrcode); + var snapshot = new Gtk.Snapshot (); + Cairo.Context context = snapshot.append_cairo (grect); context.set_source_rgb (1.0, 1.0, 1.0); context.rectangle (0, 0, sizeqrcode, sizeqrcode); context.fill (); @@ -197,7 +188,9 @@ namespace Gabut { qrentdata++; } } - imageqr.set_from_pixbuf (Gdk.pixbuf_get_from_surface (surface, 0, 0, sizeqrcode, sizeqrcode)); + var grapinsize = Graphene.Size (); + grapinsize.init ( sizeqrcode, sizeqrcode); + imageqr.paintable = snapshot.free_to_paintable (grapinsize); } } } diff --git a/src/ServerComplete.vala b/src/ServerComplete.vala index 84f70b1..8f3a296 100644 --- a/src/ServerComplete.vala +++ b/src/ServerComplete.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/ServerCss.vala b/src/ServerCss.vala index 8916bb2..a4bdfcf 100644 --- a/src/ServerCss.vala +++ b/src/ServerCss.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/ServerDM.vala b/src/ServerDM.vala index 84300b6..c7b14ff 100644 --- a/src/ServerDM.vala +++ b/src/ServerDM.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/ServerHome.vala b/src/ServerHome.vala index cf12aac..9728542 100644 --- a/src/ServerHome.vala +++ b/src/ServerHome.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/ServerNotFound.vala b/src/ServerNotFound.vala index 363a7e4..52190df 100644 --- a/src/ServerNotFound.vala +++ b/src/ServerNotFound.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/ServerRow.vala b/src/ServerRow.vala new file mode 100644 index 0000000..5681ed5 --- /dev/null +++ b/src/ServerRow.vala @@ -0,0 +1,107 @@ +/* +* Copyright (c) {2024} 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 ServerRow : Gtk.ListBoxRow { + private Gtk.Label download_rate; + private Gtk.Label currenturi_label; + + private string _currenturi; + public string currenturi { + get { + return _currenturi; + } + set { + _currenturi = value; + currenturi_label.tooltip_text = currenturi_label.label = _currenturi; + } + } + + private string _downloadspeed; + public string downloadspeed { + get { + return _downloadspeed; + } + set { + _downloadspeed = value; + download_rate.label = _downloadspeed; + } + } + + private string _uriserver; + public string uriserver { + get { + return _uriserver; + } + set { + _uriserver = value; + } + } + + construct { + var gdm_id = new Gtk.Image () { + valign = Gtk.Align.CENTER, + gicon = new ThemedIcon ("com.github.gabutakut.gabutdm") + }; + + var label_download = new Gtk.Image () { + valign = Gtk.Align.CENTER, + gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.down") + }; + download_rate = new Gtk.Label (null) { + xalign = 0, + use_markup = true, + width_request = 60, + valign = Gtk.Align.CENTER, + attributes = color_attribute (0, 60000, 0) + }; + var label_uri = new Gtk.Image () { + valign = Gtk.Align.CENTER, + gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.uri") + }; + currenturi_label = new Gtk.Label (null) { + xalign = 0, + use_markup = true, + valign = Gtk.Align.CENTER, + max_width_chars = 100, + ellipsize = Pango.EllipsizeMode.END, + attributes = set_attribute (Pango.Weight.SEMIBOLD) + }; + + var grid = new Gtk.Grid () { + hexpand = true, + margin_start = 4, + margin_end = 4, + margin_top = 2, + margin_bottom = 2, + column_spacing = 4, + row_spacing = 2, + valign = Gtk.Align.CENTER + }; + grid.attach (gdm_id, 0, 0); + grid.attach (label_download, 1, 0); + grid.attach (download_rate, 2, 0); + grid.attach (label_uri, 3, 0); + grid.attach (currenturi_label, 4, 0); + child = grid; + } + } +} diff --git a/src/ServerShare.vala b/src/ServerShare.vala index acd3112..7903fcc 100644 --- a/src/ServerShare.vala +++ b/src/ServerShare.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/ServerUpload.vala b/src/ServerUpload.vala index 67bf75c..22ac023 100644 --- a/src/ServerUpload.vala +++ b/src/ServerUpload.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/SortBy.vala b/src/SortBy.vala index 8cba04d..1e7cdb5 100755 --- a/src/SortBy.vala +++ b/src/SortBy.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/SuccesDialog.vala b/src/SuccesDialog.vala index 652874a..664a9cd 100644 --- a/src/SuccesDialog.vala +++ b/src/SuccesDialog.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/TorrentRow.vala b/src/TorrentRow.vala new file mode 100644 index 0000000..9f45381 --- /dev/null +++ b/src/TorrentRow.vala @@ -0,0 +1,233 @@ +/* +* Copyright (c) {2024} 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 TorrentRow : Gtk.ListBoxRow { + public signal void selecting (int index, bool selected); + private Gtk.CheckButton checkbtn; + private Gtk.Image fileimg; + private Gtk.Image imgstatus; + private Gtk.Label file_label; + private Gtk.Label coplatelabel; + private Gtk.Label filesizelabel; + private Gtk.Label statuslabel; + private Gtk.Label persenlabel; + private ProgressPaintable progrespaint; + + private int _index; + public int index { + get { + return _index; + } + set { + _index = value; + checkbtn.tooltip_text = _index.to_string (); + } + } + + private bool _selected; + public bool selected { + get { + return _selected; + } + set { + _selected = value; + checkbtn.active = _selected; + } + } + + private string _filepath; + public string filepath { + get { + return _filepath; + } + set { + _filepath = value; + fileimg.gicon = GLib.ContentType.get_icon (get_mime_type (GLib.File.new_for_path (_filepath))); + } + } + + private string _filebasename; + public string filebasename { + get { + return _filebasename; + } + set { + _filebasename = value; + file_label.tooltip_text = file_label.label = _filebasename; + } + } + + private string _filesize; + public string filesize { + get { + return _filesize; + } + set { + _filesize = value; + filesizelabel.label = _filesize; + } + } + + private string _completesize; + public string completesize { + get { + return _completesize; + } + set { + _completesize = value; + coplatelabel.label = _completesize; + } + } + + private double _fraction; + public double fraction { + get { + return _fraction; + } + set { + _fraction = value; + progrespaint.progress = _fraction; + } + } + + private int _persen; + public int persen { + get { + return _persen; + } + set { + _persen = value; + persenlabel.label = _("%s%s").printf (_persen.to_string (), "%"); + } + } + + private string _status; + public string status { + get { + return _status; + } + set { + _status = value; + statuslabel.label = _status; + imgstatus.gicon = new ThemedIcon (_status.down () == "waiting"? "com.github.gabutakut.gabutdm.waiting" : "com.github.gabutakut.gabutdm.active"); + } + } + + construct { + checkbtn = new Gtk.CheckButton (); + checkbtn.toggled.connect (()=> { + selecting (index, !selected); + }); + + fileimg = new Gtk.Image () { + valign = Gtk.Align.CENTER + }; + + file_label = new Gtk.Label (null) { + xalign = 0, + use_markup = true, + width_request = 290, + max_width_chars = 40, + ellipsize = Pango.EllipsizeMode.MIDDLE, + valign = Gtk.Align.CENTER, + attributes = set_attribute (Pango.Weight.SEMIBOLD) + }; + + var downloadingimg = new Gtk.Image () { + valign = Gtk.Align.CENTER, + gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.down") + }; + + filesizelabel = new Gtk.Label (null) { + xalign = 0, + use_markup = true, + width_request = 55, + valign = Gtk.Align.CENTER, + attributes = color_attribute (0, 60000, 0) + }; + var imgfilesize = new Gtk.Image () { + valign = Gtk.Align.CENTER, + gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.hdd") + }; + coplatelabel = new Gtk.Label (null) { + xalign = 0, + use_markup = true, + width_request = 55, + valign = Gtk.Align.CENTER, + attributes = color_attribute (60000, 0, 0) + }; + + var progresimg = new Gtk.Image () { + valign = Gtk.Align.CENTER, + width_request = 20 + }; + progrespaint = new ProgressPaintable (); + progresimg.paintable = progrespaint; + progrespaint.queue_draw.connect (progresimg.queue_draw); + + persenlabel = new Gtk.Label (null) { + xalign = 0, + use_markup = true, + width_request = 35, + valign = Gtk.Align.CENTER, + halign = Gtk.Align.CENTER, + attributes = set_attribute (Pango.Weight.SEMIBOLD) + }; + + imgstatus = new Gtk.Image () { + valign = Gtk.Align.CENTER, + gicon = new ThemedIcon ("com.github.gabutakut.gabutdm.active"), + tooltip_text = _("Status") + }; + statuslabel = new Gtk.Label (null) { + xalign = 0, + use_markup = true, + width_request = 50, + valign = Gtk.Align.CENTER, + attributes = set_attribute (Pango.Weight.SEMIBOLD) + }; + + var grid = new Gtk.Grid () { + hexpand = true, + margin_start = 4, + margin_end = 4, + margin_top = 2, + margin_bottom = 2, + column_spacing = 4, + row_spacing = 2, + valign = Gtk.Align.CENTER + }; + grid.attach (checkbtn, 0, 0); + grid.attach (fileimg, 1, 0); + grid.attach (file_label, 2, 0); + grid.attach (downloadingimg, 3, 0); + grid.attach (filesizelabel, 4, 0); + grid.attach (imgfilesize, 5, 0); + grid.attach (coplatelabel, 6, 0); + grid.attach (progresimg, 7, 0); + grid.attach (persenlabel, 8, 0); + grid.attach (imgstatus, 9, 0); + grid.attach (statuslabel, 10, 0); + child = grid; + } + } +} \ No newline at end of file diff --git a/src/UriSelector.vala b/src/UriSelector.vala index c625b48..47b2c1d 100755 --- a/src/UriSelector.vala +++ b/src/UriSelector.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 diff --git a/src/Utils.vala b/src/Utils.vala index 92e5864..4bd2511 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) {2021} torikulhabib (https://github.com/gabutakut) +* Copyright (c) {2024} 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 @@ -1136,15 +1136,14 @@ namespace Gabut { N_COLUMNS } - private enum FSorter { - NAME, - MIMETYPE, - FILEORDIR, - SIZE, - FILEINDIR, - FILEINFO, - DATE, - N_COLUMNS + private struct FSorter { + public string name {get; set;} + public string mimetype {get; set;} + public bool fileordir {get; set;} + public int64 size {get; set;} + public int fileindir {get; set;} + public GLib.FileInfo fileinfo {get; set;} + public string date {get; set;} } public enum FileAllocations { @@ -1348,6 +1347,38 @@ namespace Gabut { } } + public enum DownloadMenu { + OPENFOLDER = 0, + MOVETOTRASH = 1, + PROPERTIES = 2; + + public string to_string () { + switch (this) { + case MOVETOTRASH: + return "Move to Trash"; + case PROPERTIES: + return "Properties"; + default: + return "Open Folder"; + } + } + + public string to_icon () { + switch (this) { + case MOVETOTRASH: + return "user-trash-full"; + case PROPERTIES: + return "document-properties"; + default: + return "folder-open"; + } + } + + public static DownloadMenu [] get_all () { + return { OPENFOLDER, MOVETOTRASH, PROPERTIES}; + } + } + public enum DeAscend { ASCENDING = 0, DESCENDING = 1; @@ -1361,6 +1392,15 @@ namespace Gabut { } } + public string to_icon () { + switch (this) { + case DESCENDING: + return "com.github.gabutakut.gabutdm.up"; + default: + return "com.github.gabutakut.gabutdm.down"; + } + } + public static DeAscend [] get_all () { return { ASCENDING, DESCENDING}; } @@ -1617,8 +1657,8 @@ namespace Gabut { return result_ret (result); } - private Gtk.ListStore aria_get_peers (string gid) { - var liststore = new Gtk.ListStore (TorrentPeers.N_COLUMNS, typeof (string), typeof (string), typeof (string), typeof (string), typeof (string), typeof (string), typeof (string), typeof (string)); + private Gee.HashMap aria_get_peers (string gid) { + var liststore = new Gee.HashMap (); string result = get_soupmess (@"{\"jsonrpc\":\"2.0\", \"id\":\"qwer\", \"method\":\"aria2.getPeers\", \"params\":[\"$(gid)\"]}"); if (!result.down ().contains ("result") || result == null) { return liststore; @@ -1629,9 +1669,17 @@ namespace Gabut { if (regex.match_full (result, -1, 0, 0, out match_info)) { while (match_info.matches ()) { string peerid = GLib.Uri.unescape_string (match_info.fetch (6)); - Gtk.TreeIter iter; - liststore.append (out iter); - liststore.set (iter, TorrentPeers.HOST, @"$(match_info.fetch (4)):$(match_info.fetch (7))", TorrentPeers.PEERID, peerid != "" && peerid != null? get_peerid (peerid.slice (1, 3)) : "Unknow", TorrentPeers.DOWNLOADSPEED, format_size (int64.parse (match_info.fetch (3))), TorrentPeers.UPLOADSPEED, match_info.fetch (9), TorrentPeers.SEEDER, match_info.fetch (8), TorrentPeers.BITFIELD, match_info.fetch (2), TorrentPeers.AMCHOKING, match_info.fetch (1), TorrentPeers.PEERCHOKING, match_info.fetch (5)); + var peersrow = new PeersRow () { + host = @"$(match_info.fetch (4)):$(match_info.fetch (7))", + peerid = peerid != "" && peerid != null? get_peerid (peerid.slice (1, 3)) : "Unknow", + downloadspeed = GLib.format_size (int64.parse (match_info.fetch (3))), + uploadspeed = GLib.format_size (int64.parse (match_info.fetch (9))), + peerschoking = match_info.fetch (5), + seeder = match_info.fetch (8), + amchoking = match_info.fetch (1), + bitfield = match_info.fetch (2) + }; + liststore.set (@"$(match_info.fetch (4)):$(match_info.fetch (7))", peersrow); match_info.next (); } } @@ -1736,11 +1784,11 @@ namespace Gabut { return listgid; } - private Gtk.ListStore aria_files_store (string gid) { - var liststore = new Gtk.ListStore (FileCol.N_COLUMNS, typeof (bool), typeof (string), typeof (string), typeof (string), typeof (string), typeof (string), typeof (int), typeof (string)); + private Gee.ArrayList aria_files_store (string gid) { + var torrentstore = new Gee.ArrayList (); string result = get_soupmess (@"{\"jsonrpc\":\"2.0\", \"id\":\"qwer\", \"method\":\"aria2.getFiles\", \"params\":[\"$(gid)\"]}"); if (!result.down ().contains ("result") || result == null) { - return liststore; + return torrentstore; } try { MatchInfo match_info; @@ -1751,42 +1799,55 @@ namespace Gabut { int64 transfer = int64.parse (match_info.fetch (1)).abs (); double fraction = (double) transfer / (double) total; int persen = total == 0 && transfer == 0? 0 : (int) (fraction * 100).abs (); - string uris = pharse_info (match_info.fetch (6)); + string status = pharse_info (match_info.fetch (6)); string path = match_info.fetch (4); - Gtk.TreeIter iter; var file = File.new_for_path (path.contains ("\\/")? path.replace ("\\/", "/") : path); - liststore.append (out iter); - liststore.set (iter, FileCol.SELECTED, bool.parse (match_info.fetch (5)), FileCol.ROW, match_info.fetch (2), FileCol.NAME, file.get_basename (), FileCol.FILEPATH, file.get_path (), FileCol.DOWNLOADED, format_size (transfer), FileCol.SIZE, format_size (total), FileCol.PERCEN, persen, FileCol.URIS, uris); + var torrentfile = new TorrentRow () { + selected = bool.parse (match_info.fetch (5)), + index = int.parse (match_info.fetch (2)), + filebasename = file.get_basename (), + filepath = file.get_path (), + completesize = GLib.format_size (total), + filesize = GLib.format_size (transfer), + fraction = fraction, + status = status, + persen = persen + }; + torrentstore.add (torrentfile); match_info.next (); } } } catch (Error e) { GLib.warning (e.message); } - return liststore; + return torrentstore; } - private Gtk.ListStore aria_servers_store (string gid) { - var liststore = new Gtk.ListStore (ServersCol.N_COLUMNS, typeof (int), typeof (string), typeof (string), typeof (string)); + private Gee.ArrayList aria_servers_store (string gid) { + var serverstore = new Gee.ArrayList (); string result = get_soupmess (@"{\"jsonrpc\":\"2.0\", \"id\":\"qwer\", \"method\":\"aria2.getServers\", \"params\":[\"$(gid)\"]}"); if (!result.down ().contains ("result") || result == null) { - return liststore; + return serverstore; } try { MatchInfo match_info; Regex regex = new Regex ("{\"currentUri\":\"(.*?)\".*?\"downloadSpeed\":\"(.*?)\".*?\"uri\":\"(.*?)\""); if (regex.match_full (result, -1, 0, 0, out match_info)) { while (match_info.matches ()) { - Gtk.TreeIter iter; - liststore.append (out iter); - liststore.set (iter, ServersCol.CURRENTURI, match_info.fetch (1), ServersCol.DOWNLOADSPEED, match_info.fetch (2), ServersCol.URI, match_info.fetch (3)); + var curi = match_info.fetch (1); + var serverrow = new ServerRow () { + uriserver = match_info.fetch (3), + downloadspeed = GLib.format_size (int64.parse (match_info.fetch (2))), + currenturi = curi != null? Markup.escape_text (curi.replace ("\\/", "/")) : curi + }; + serverstore.add (serverrow); match_info.next (); } } } catch (Error e) { GLib.warning (e.message); } - return liststore; + return serverstore; } private string aria_get_option (string gid, AriaOptions option) { @@ -2392,8 +2453,8 @@ namespace Gabut { attributes = set_attribute (Pango.Weight.SEMIBOLD), halign = Gtk.Align.START, xalign = 0, - margin_top = 7, - margin_bottom = 7 + margin_top = 6, + margin_bottom = 6 }; return hlabel; } @@ -2414,18 +2475,21 @@ namespace Gabut { } } - private File[] run_open_file (Gtk.Window window) { - var loopop = new GLib.MainLoop (null, false); - var filechooser = new Gtk.FileChooserNative (_("Open Torrent Or Metalink"), window, Gtk.FileChooserAction.OPEN, _("Open"), _("Cancel")) { - select_multiple = true - }; - if (db_lastop_exist (OpenFiles.OPENFILES)) { - try { - filechooser.set_current_folder (File.new_for_path (get_db_lastop (OpenFiles.OPENFILES))); - } catch (Error e) { - GLib.warning (e.message); - } + private static void play_sound (string canbera) { + if (!bool.parse (get_dbsetting (DBSettings.NOTIFSOUND))) { + return; } + Canberra.Context context; + Canberra.Proplist props; + Canberra.Context.create (out context); + Canberra.Proplist.create (out props); + props.sets (Canberra.PROP_EVENT_ID, canbera); + props.sets (Canberra.PROP_CANBERRA_CACHE_CONTROL, "permanent"); + props.sets (Canberra.PROP_MEDIA_ROLE, "event"); + context.play_full (0, props); + } + + private async void run_open_file (Gtk.Window window, OpenFiles location, out GLib.File[]? files) throws Error { var torrent = new Gtk.FileFilter (); torrent.set_filter_name (_("Torrent")); torrent.add_mime_type ("application/x-bittorrent"); @@ -2433,123 +2497,78 @@ namespace Gabut { metalink.set_filter_name (_("Metalink")); metalink.add_pattern ("application/metalink+xml"); metalink.add_pattern ("application/metalink4+xml"); - - filechooser.add_filter (torrent); - filechooser.add_filter (metalink); - - File[] files = null; - filechooser.response.connect ((pos)=> { - if (pos == Gtk.ResponseType.ACCEPT) { - for (int i = 0; i < filechooser.get_files ().get_n_items (); i++) { - files += (File) filechooser.get_files ().get_item (i); - } - if (!db_lastop_exist (OpenFiles.OPENFILES)) { - add_db_lastop (OpenFiles.OPENFILES, ((File) filechooser.get_files ().get_item (0)).get_parent ().get_path ()); - } else { - update_lastop_id (OpenFiles.OPENFILES, ((File) filechooser.get_files ().get_item (0)).get_parent ().get_path ()); - } - filechooser.destroy (); - } - loopop.quit (); - }); - filechooser.show (); - loopop.run (); - return files; - } - - private File run_open_text (Gtk.Window window, OpenFiles location) { - var loopop = new GLib.MainLoop (null, false); - var filechooser = new Gtk.FileChooserNative (_("Open Text Tracker"), window, Gtk.FileChooserAction.OPEN, _("Open"), _("Cancel")) { - select_multiple = false + var lstore = new GLib.ListStore (typeof (Gtk.FileFilter)); + lstore.append (torrent); + lstore.append (metalink); + var fdrecently = File.new_for_path (get_db_lastop (location)); + var filechooser = new Gtk.FileDialog () { + title = _("Open Torrent Or Metalink"), + accept_label = _("Open"), + filters = lstore, + initial_folder = fdrecently.query_exists (null)? fdrecently : null }; - if (db_lastop_exist (location)) { - try { - filechooser.set_current_folder (File.new_for_path (get_db_lastop (location))); - } catch (Error e) { - GLib.warning (e.message); - } + var listmodel = yield filechooser.open_multiple (window, null); + GLib.File[] nfiles = null; + for (int i = 0; i < listmodel.get_n_items (); i++) { + nfiles += (File) listmodel.get_item (i); + } + files = nfiles; + if (!db_lastop_exist (location)) { + add_db_lastop (location, files[0].get_parent ().get_path ()); + } else { + update_lastop_id (location, files[0].get_parent ().get_path ()); } + } + + private async void run_open_text (Gtk.Window window, OpenFiles location, out GLib.File? file) throws Error { var text_filter = new Gtk.FileFilter (); text_filter.set_filter_name (_("Text")); text_filter.add_mime_type ("text/*"); - filechooser.add_filter (text_filter); - - File file = null; - filechooser.response.connect ((pos)=> { - if (pos == Gtk.ResponseType.ACCEPT) { - file = filechooser.get_file (); - if (!db_lastop_exist (location)) { - add_db_lastop (location, filechooser.get_file ().get_parent ().get_path ()); - } else { - update_lastop_id (location, filechooser.get_file ().get_parent ().get_path ()); - } - filechooser.destroy (); - } - loopop.quit (); - }); - filechooser.show (); - loopop.run (); - return file; + var lstore = new GLib.ListStore (typeof (Gtk.FileFilter)); + lstore.append (text_filter); + var fdrecently = File.new_for_path (get_db_lastop (location)); + var filechooser = new Gtk.FileDialog () { + title = _("Open Text"), + accept_label = _("Open"), + filters = lstore, + initial_folder = fdrecently.query_exists (null)? fdrecently : null + }; + file = yield filechooser.open (window, null); + if (!db_lastop_exist (location)) { + add_db_lastop (location, file.get_parent ().get_path ()); + } else { + update_lastop_id (location, file.get_parent ().get_path ()); + } } - private File run_open_all (Gtk.Window window, OpenFiles location) { - var loopop = new GLib.MainLoop (null, false); - var filechooser = new Gtk.FileChooserNative (_("Open Cookies"), window, Gtk.FileChooserAction.OPEN, _("Open"), _("Cancel")) { - select_multiple = false + private async void run_open_all (Gtk.Window window, OpenFiles location, out GLib.File? file) throws Error { + var fdrecently = File.new_for_path (get_db_lastop (location)); + var filechooser = new Gtk.FileDialog () { + title = _("Open Cookies"), + accept_label = _("Open"), + initial_folder = fdrecently.query_exists (null)? fdrecently : null }; - if (db_lastop_exist (location)) { - try { - filechooser.set_current_folder (File.new_for_path (get_db_lastop (location))); - } catch (Error e) { - GLib.warning (e.message); - } + file = yield filechooser.open (window, null); + if (!db_lastop_exist (location)) { + add_db_lastop (location, file.get_parent ().get_path ()); + } else { + update_lastop_id (location, file.get_parent ().get_path ()); } - File file = null; - filechooser.response.connect ((pos)=> { - if (pos == Gtk.ResponseType.ACCEPT) { - file = filechooser.get_file (); - if (!db_lastop_exist (location)) { - add_db_lastop (location, filechooser.get_file ().get_parent ().get_path ()); - } else { - update_lastop_id (location, filechooser.get_file ().get_parent ().get_path ()); - } - filechooser.destroy (); - } - loopop.quit (); - }); - filechooser.show (); - loopop.run (); - return file; } - private File run_open_fd (Gtk.Window window, OpenFiles location) { - var loopop = new GLib.MainLoop (null, false); - var filechooser = new Gtk.FileChooserNative (_("Open Folder"), window, Gtk.FileChooserAction.SELECT_FOLDER, _("Open"), _("Cancel")) { - select_multiple = false + private async void run_open_fd (Gtk.Window window, OpenFiles location, out GLib.File? file) throws Error { + var fdrecently = File.new_for_path (get_db_lastop (location)); + var filechooser = new Gtk.FileDialog () { + title = _("Open Folder"), + accept_label = _("Open"), + initial_folder = fdrecently.query_exists (null)? fdrecently : null }; - if (db_lastop_exist (location)) { - try { - filechooser.set_current_folder (File.new_for_path (get_db_lastop (location))); - } catch (Error e) { - GLib.warning (e.message); - } + file = yield filechooser.select_folder (window, null); + if (!db_lastop_exist (location)) { + add_db_lastop (location, file.get_path ()); + } else { + update_lastop_id (location, file.get_path ()); } - File file = null; - filechooser.response.connect ((pos)=> { - if (pos == Gtk.ResponseType.ACCEPT) { - file = filechooser.get_file (); - if (!db_lastop_exist (location)) { - add_db_lastop (location, filechooser.get_file ().get_path ()); - } else { - update_lastop_id (location, filechooser.get_file ().get_path ()); - } - filechooser.destroy (); - } - loopop.quit (); - }); - filechooser.show (); - loopop.run (); - return file; } private Gtk.Grid button_chooser (GLib.File file, int widtc = 35) { @@ -2579,7 +2598,7 @@ namespace Gabut { halign = Gtk.Align.START, column_spacing = 5 }; - var img = new Gtk.Image.from_gicon (new ThemedIcon ("com.github.gabutakut.gabutdm")) { + var img = new Gtk.Image.from_gicon (new ThemedIcon ("com.github.gabutakut.gabutdm.cookie")) { icon_size = Gtk.IconSize.NORMAL }; var tittle = new Gtk.Label (none) { @@ -2592,26 +2611,6 @@ namespace Gabut { return grid; } - private Gtk.Image image_btn (string name, int size) { - var imginf = new Gtk.Image () { - pixel_size = size, - gicon = new ThemedIcon (name) - }; - return imginf; - } - - private Gtk.Box box_btn (string name, string labeln) { - var imginf = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 1); - imginf.append (image_btn (name, 16)); - var title = new Gtk.Label (labeln) { - halign = Gtk.Align.CENTER, - wrap_mode = Pango.WrapMode.WORD_CHAR, - attributes = set_attribute (Pango.Weight.BOLD) - }; - imginf.append (title); - return imginf; - } - private string get_mime_css (string mime) { if (mime.contains ("image/")) { return "image"; @@ -2794,7 +2793,7 @@ namespace Gabut { } if (db_get_cols ("users") < UserID.ACTIVE) { gabutdb.exec ("DROP TABLE users;"); - last_opened (gabutdb); + table_users (gabutdb); } } @@ -3839,49 +3838,53 @@ namespace Gabut { } private SourceFunc themecall; - private async void pantheon_theme () throws Error { + private async void gdm_theme () throws Error { if (themecall != null) { Idle.add ((owned)themecall); } - var gtk_settings = Gtk.Settings.get_default (); var tdefault = bool.parse (get_dbsetting (DBSettings.TDEFAULT)); + var adwt_settings = Adw.StyleManager.get_default (); + var gtk_settings = Gtk.Settings.get_default (); int themesel = int.parse (get_dbsetting (DBSettings.THEMESELECT)); var themename = get_dbsetting (DBSettings.THEMECUSTOM); - var themesys = get_dbsetting (DBSettings.THEMESYSTEM); switch (int.parse (get_dbsetting (DBSettings.STYLE))) { case 1: - if (tdefault) { - gtk_settings.gtk_theme_name = themesel == 0? "Default" : themename; + if (!tdefault) { + adwt_settings.color_scheme = Adw.ColorScheme.FORCE_LIGHT; + gtk_settings.gtk_theme_name = "Adwaita-empty"; } else { - gtk_settings.gtk_theme_name = themesys; + gtk_settings.gtk_application_prefer_dark_theme = false; + gtk_settings.gtk_theme_name = themesel == 0? "Default" : themename; } - gtk_settings.gtk_application_prefer_dark_theme = false; break; case 2: - if (tdefault) { - gtk_settings.gtk_theme_name = themesel == 0? "Default-dark" : themename + "-dark"; + if (!tdefault) { + adwt_settings.color_scheme = Adw.ColorScheme.FORCE_DARK; + gtk_settings.gtk_theme_name = "Adwaita-empty"; } else { - gtk_settings.gtk_theme_name = themesys + "-dark"; + gtk_settings.gtk_application_prefer_dark_theme = true; + gtk_settings.gtk_theme_name = themesel == 0? "Default" : themename; } - gtk_settings.gtk_application_prefer_dark_theme = true; break; default: PortalSettings portalsettings = yield GLib.Bus.get_proxy (GLib.BusType.SESSION, "org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop"); if (portalsettings != null) { - themecall = pantheon_theme.callback; - if (tdefault) { - gtk_settings.gtk_theme_name = portalsettings.read ("org.freedesktop.appearance", "color-scheme").get_variant ().get_uint32 () == 1? themesel == 0? "Default-dark" : themename + "-dark" : themesel == 0? "Default" : themename; + themecall = gdm_theme.callback; + if (!tdefault) { + adwt_settings.color_scheme = portalsettings.read ("org.freedesktop.appearance", "color-scheme").get_variant ().get_uint32 () == 1? Adw.ColorScheme.FORCE_DARK : Adw.ColorScheme.FORCE_LIGHT; + gtk_settings.gtk_theme_name = "Adwaita-empty"; } else { - gtk_settings.gtk_theme_name = themesys; + gtk_settings.gtk_application_prefer_dark_theme = portalsettings.read ("org.freedesktop.appearance", "color-scheme").get_variant ().get_uint32 () == 1? true : false; + gtk_settings.gtk_theme_name = themesel == 0? "Default" : themename; } - gtk_settings.gtk_application_prefer_dark_theme = portalsettings.read ("org.freedesktop.appearance", "color-scheme").get_variant ().get_uint32 () == 1? true : false; portalsettings.setting_changed.connect ((scheme, key, value) => { if (scheme == "org.freedesktop.appearance" && key == "color-scheme") { - gtk_settings.gtk_application_prefer_dark_theme = value.get_uint32 () == 1? true : false; - if (tdefault) { - gtk_settings.gtk_theme_name = value.get_uint32 () == 1? themesel == 0? "Default-dark" : themename + "-dark" : themesel == 0? "Default" : themename; + if (!tdefault) { + adwt_settings.color_scheme = value.get_uint32 () == 1? Adw.ColorScheme.FORCE_DARK : Adw.ColorScheme.FORCE_LIGHT; + gtk_settings.gtk_theme_name = "Adwaita-empty"; } else { - gtk_settings.gtk_theme_name = themesys; + gtk_settings.gtk_application_prefer_dark_theme = value.get_uint32 () == 1? true : false; + gtk_settings.gtk_theme_name = themesel == 0? "Default" : themename; } } }); @@ -3890,4 +3893,4 @@ namespace Gabut { break; } } -} +} \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index 1e874ea..a2fd232 100644 --- a/src/meson.build +++ b/src/meson.build @@ -35,5 +35,11 @@ sources = files ( 'SortBy.vala', 'DeAscending.vala', 'GdmOutstream.vala', - 'DbusIndicator.vala' + 'DbusIndicator.vala', + 'PeersRow.vala', + 'ServerRow.vala', + 'TorrentRow.vala', + 'GdmPaint.vala', + 'GdmMenu.vala', + 'ProgressPaint.vala' )