mirror of
https://gitlab.com/liyaowhen/youtubecollector-git.git
synced 2026-10-01 01:12:59 +00:00
updated ytsearchbar, bugs when reopening the ytsearchbar
This commit is contained in:
@@ -7,6 +7,8 @@ namespace Song {
|
|||||||
public PlaylistObject current_playlist;
|
public PlaylistObject current_playlist;
|
||||||
private Gtk.Revealer add_button_revealer = new Gtk.Revealer();
|
private Gtk.Revealer add_button_revealer = new Gtk.Revealer();
|
||||||
private Gtk.Revealer controls_revealer = new Gtk.Revealer();
|
private Gtk.Revealer controls_revealer = new Gtk.Revealer();
|
||||||
|
private Gtk.Revealer exit_yt_search_mode_revealer = new Gtk.Revealer();
|
||||||
|
private Adw.HeaderBar action_bar;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -46,11 +48,22 @@ namespace Song {
|
|||||||
popover.present(this);
|
popover.present(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
var action_bar = new Adw.HeaderBar();
|
var exit_yt_search_mode = new Gtk.Button.from_icon_name("go-previous-symbolic");
|
||||||
|
exit_yt_search_mode.valign = Gtk.Align.CENTER;
|
||||||
|
exit_yt_search_mode_revealer.set_child(exit_yt_search_mode);
|
||||||
|
exit_yt_search_mode_revealer.set_reveal_child(false);
|
||||||
|
exit_yt_search_mode_revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_RIGHT;
|
||||||
|
|
||||||
|
exit_yt_search_mode.clicked.connect(() => {
|
||||||
|
SignalHub.get_instance().exit_yt_search_mode();
|
||||||
|
});
|
||||||
|
|
||||||
|
action_bar = new Adw.HeaderBar();
|
||||||
action_bar.show_back_button = false;
|
action_bar.show_back_button = false;
|
||||||
action_bar.title_widget = new YtSearchBar();
|
action_bar.title_widget = new YtSearchBar();
|
||||||
action_bar.pack_start(collapse_button);
|
action_bar.pack_start(collapse_button);
|
||||||
action_bar.pack_start(add_button_revealer);
|
action_bar.pack_start(add_button_revealer);
|
||||||
|
action_bar.pack_start(exit_yt_search_mode_revealer);
|
||||||
action_bar.margin_start = 5;
|
action_bar.margin_start = 5;
|
||||||
|
|
||||||
collapse_button.clicked.connect(() => {
|
collapse_button.clicked.connect(() => {
|
||||||
@@ -100,11 +113,16 @@ namespace Song {
|
|||||||
signal_hub.enter_yt_search_mode.connect(() => {
|
signal_hub.enter_yt_search_mode.connect(() => {
|
||||||
add_button_revealer.set_reveal_child(false);
|
add_button_revealer.set_reveal_child(false);
|
||||||
controls_revealer.set_reveal_child(false);
|
controls_revealer.set_reveal_child(false);
|
||||||
|
exit_yt_search_mode_revealer.set_reveal_child(true);
|
||||||
|
action_bar.set_margin_start(-5);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
signal_hub.exit_yt_search_mode.connect(() => {
|
signal_hub.exit_yt_search_mode.connect(() => {
|
||||||
add_button_revealer.set_reveal_child(true);
|
add_button_revealer.set_reveal_child(true);
|
||||||
controls_revealer.set_reveal_child(true);
|
controls_revealer.set_reveal_child(true);
|
||||||
|
exit_yt_search_mode_revealer.set_reveal_child(false);
|
||||||
|
action_bar.set_margin_start(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+55
-55
@@ -66,41 +66,17 @@ namespace Song {
|
|||||||
|
|
||||||
private void instanciate_signals() {
|
private void instanciate_signals() {
|
||||||
var signal_hub = SignalHub.get_instance();
|
var signal_hub = SignalHub.get_instance();
|
||||||
signal_hub.mouse_clicked.connect(() => {
|
|
||||||
if (!isMouseInside && isEnlarged) {
|
|
||||||
//shrink();
|
|
||||||
//signal_hub.exit_yt_search_mode();
|
|
||||||
} else if (!isEnlarged && isMouseInside) {
|
|
||||||
enlarge();
|
|
||||||
signal_hub.enter_yt_search_mode();
|
|
||||||
} else if (!isEnlarged && !isMouseInside && state == YtSearchBarStates.ENLARGING) {
|
|
||||||
requesting_state = YtSearchBarStates.SHRINKING;
|
|
||||||
Timeout.add(1, () => {
|
|
||||||
if (requesting_state != YtSearchBarStates.SHRINKING) return false;
|
|
||||||
if (isEnlarged) {
|
|
||||||
shrink();
|
|
||||||
signal_hub.exit_yt_search_mode();
|
|
||||||
requesting_state = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
} else if (isEnlarged && isMouseInside && state == YtSearchBarStates.SHRINKING) {
|
|
||||||
requesting_state = YtSearchBarStates.ENLARGING;
|
|
||||||
Timeout.add(1, () => {
|
|
||||||
if (requesting_state != YtSearchBarStates.ENLARGING) return false;
|
|
||||||
if (!isEnlarged) {
|
|
||||||
enlarge();
|
|
||||||
signal_hub.enter_yt_search_mode();
|
|
||||||
requesting_state = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
search_entry.changed.connect((i) => {
|
search_entry.changed.connect((i) => {
|
||||||
|
if (i.text != "") {
|
||||||
|
if (state != YtSearchBarStates.ENLARGING && isEnlarged != true && requesting_state != YtSearchBarStates.ENLARGING) {
|
||||||
|
enlarge();
|
||||||
|
signal_hub.enter_yt_search_mode();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
shrink();
|
||||||
|
signal_hub.exit_yt_search_mode();
|
||||||
|
}
|
||||||
signal_hub.request_search(i.get_text());
|
signal_hub.request_search(i.get_text());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -135,19 +111,20 @@ namespace Song {
|
|||||||
|
|
||||||
public class YtSearchView : Gtk.Box {
|
public class YtSearchView : Gtk.Box {
|
||||||
|
|
||||||
private Gtk.Label label = new Gtk.Label("");
|
|
||||||
private YtSearchViewStates state = YtSearchViewStates.IDLE;
|
private YtSearchViewStates state = YtSearchViewStates.IDLE;
|
||||||
|
|
||||||
private Cancellable active_search_query;
|
private Cancellable active_search_query;
|
||||||
private Gee.HashSet<YtSearchItem> results = new Gee.HashSet<YtSearchItem>();
|
private Gee.HashSet<YtSearchItem> results = new Gee.HashSet<YtSearchItem>();
|
||||||
private Gee.HashSet<Gtk.Widget> result_widgets = new Gee.HashSet<Gtk.Widget>();
|
private Gee.HashSet<Gtk.Widget> result_widgets = new Gee.HashSet<Gtk.Widget>();
|
||||||
|
private Gtk.FlowBox flow_box = new Gtk.FlowBox();
|
||||||
|
|
||||||
private Subprocess? search_process = null;
|
private Subprocess? search_process = null;
|
||||||
|
|
||||||
construct {
|
construct {
|
||||||
|
|
||||||
orientation = Gtk.Orientation.VERTICAL;
|
orientation = Gtk.Orientation.VERTICAL;
|
||||||
append(label);
|
append(flow_box);
|
||||||
|
flow_box.set_max_children_per_line(4);
|
||||||
|
|
||||||
instanciate_signals();
|
instanciate_signals();
|
||||||
|
|
||||||
@@ -170,6 +147,11 @@ namespace Song {
|
|||||||
motion_sensor.enter.connect(() => {
|
motion_sensor.enter.connect(() => {
|
||||||
signal_hub.yt_search_bar.isMouseInside = true;
|
signal_hub.yt_search_bar.isMouseInside = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
hexpand = true;
|
||||||
|
hexpand_set = true;
|
||||||
|
vexpand = true;
|
||||||
|
vexpand_set = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void instanciate_signals() {
|
private void instanciate_signals() {
|
||||||
@@ -179,11 +161,11 @@ namespace Song {
|
|||||||
state = YtSearchViewStates.SEARCHING;
|
state = YtSearchViewStates.SEARCHING;
|
||||||
});
|
});
|
||||||
|
|
||||||
label.label = signal_hub.yt_search_bar.search_entry.text;
|
//label.label = signal_hub.yt_search_bar.search_entry.text;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void search(string query) {
|
private async void search(string query) {
|
||||||
label.label = query;
|
//label.label = query;
|
||||||
string temp_file = Path.build_path("/", Environment.get_tmp_dir(), "yt_search_tmp.json");
|
string temp_file = Path.build_path("/", Environment.get_tmp_dir(), "yt_search_tmp.json");
|
||||||
|
|
||||||
string[] command = {
|
string[] command = {
|
||||||
@@ -200,11 +182,6 @@ namespace Song {
|
|||||||
|
|
||||||
MainLoop loop = new MainLoop ();
|
MainLoop loop = new MainLoop ();
|
||||||
try {
|
try {
|
||||||
GLib.Pid child_pid;
|
|
||||||
int std_out;
|
|
||||||
int std_input;
|
|
||||||
int std_error;
|
|
||||||
|
|
||||||
|
|
||||||
//TODO: remove ghost processes
|
//TODO: remove ghost processes
|
||||||
|
|
||||||
@@ -232,7 +209,7 @@ namespace Song {
|
|||||||
out std_error
|
out std_error
|
||||||
);*/
|
);*/
|
||||||
|
|
||||||
if (search_process != null && !search_process.get_if_exited()) {
|
if (search_process != null && search_process.get_identifier() != null) {
|
||||||
search_process.force_exit();
|
search_process.force_exit();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -464,35 +441,37 @@ namespace Song {
|
|||||||
results.foreach((result) => {
|
results.foreach((result) => {
|
||||||
var label = new Gtk.Label(result.title);
|
var label = new Gtk.Label(result.title);
|
||||||
var link = new Gtk.LinkButton(result.url);
|
var link = new Gtk.LinkButton(result.url);
|
||||||
var thumbnail = new Gtk.Image();
|
var thumbnail = new Gtk.Picture();
|
||||||
thumbnail.hexpand = true;
|
|
||||||
thumbnail.hexpand_set = true;
|
|
||||||
thumbnail.vexpand = true;
|
thumbnail.vexpand = true;
|
||||||
thumbnail.vexpand_set = true;
|
thumbnail.vexpand_set = true;
|
||||||
thumbnail.icon_size = Gtk.IconSize.LARGE;
|
thumbnail.can_shrink = false;
|
||||||
load_url_to_image(thumbnail, result.thumbnail_url);
|
load_url_to_image.begin(thumbnail, result.thumbnail_url);
|
||||||
var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 5);
|
var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 5);
|
||||||
var options_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 5);
|
var options_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 5);
|
||||||
options_box.append(label);
|
options_box.append(label);
|
||||||
box.append(thumbnail);
|
var overlay = new Gtk.Overlay();
|
||||||
box.append(options_box);
|
overlay.set_child(thumbnail);
|
||||||
append(box);
|
overlay.add_overlay(options_box);
|
||||||
result_widgets.add(box);
|
append(overlay);
|
||||||
|
result_widgets.add(overlay);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void load_url_to_image (Gtk.Image? image, string url) {
|
private async void load_url_to_image (Gtk.Picture? image, string url) {
|
||||||
Soup.Session session = new Soup.Session ();
|
Soup.Session session = new Soup.Session ();
|
||||||
Soup.Message message = new Soup.Message ("GET", url);
|
Soup.Message message = new Soup.Message ("GET", url);
|
||||||
|
|
||||||
GLib.Bytes bytes = session.send_and_read(message, null);
|
session.send_and_read_async.begin(message, 1, null, (o, object) => {
|
||||||
|
var bytes = session.send_and_read_async.end(object);
|
||||||
var stream = new GLib.MemoryInputStream();
|
var stream = new GLib.MemoryInputStream();
|
||||||
stream.add_bytes(bytes);
|
stream.add_bytes(bytes);
|
||||||
var pixbuf = new Gdk.Pixbuf.from_stream(stream, null);
|
var pixbuf = new Gdk.Pixbuf.from_stream(stream, null);
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
image.set_from_pixbuf(pixbuf);
|
image.set_pixbuf(pixbuf);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,4 +480,25 @@ namespace Song {
|
|||||||
public string url = "";
|
public string url = "";
|
||||||
public string thumbnail_url = "";
|
public string thumbnail_url = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ExpandableImage : Gtk.DrawingArea {
|
||||||
|
public Gdk.Pixbuf? pixbuf = null;
|
||||||
|
|
||||||
|
public ExpandableImage () {
|
||||||
|
var frame = new Gtk.Frame(null);
|
||||||
|
|
||||||
|
this.set_draw_func((drawing_area, cairo_context, i) => {
|
||||||
|
if (pixbuf != null) {
|
||||||
|
Gdk.cairo_set_source_pixbuf(cairo_context, pixbuf, 0, 0);
|
||||||
|
} else {
|
||||||
|
cairo_context.set_source_rgb(200, 200, 200);
|
||||||
|
}
|
||||||
|
cairo_context.paint();
|
||||||
|
});
|
||||||
|
|
||||||
|
queue_draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user