Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Commit

Permalink
improve bookmark support
Browse files Browse the repository at this point in the history
  • Loading branch information
Jigoku committed May 6, 2015
1 parent 973cba7 commit 7eee39f
Showing 1 changed file with 49 additions and 8 deletions.
57 changes: 49 additions & 8 deletions alluvion-gtk.pl
Original file line number Diff line number Diff line change
Expand Up @@ -328,17 +328,36 @@ sub populate_bookmarks {
chomp(@bookmark);

for my $item (@bookmark) {
my $button = Gtk2::Button->new;
$button->set_label($item);
$button->signal_connect('clicked',
my $hbox = Gtk2::HBox->new;
my $label = Gtk2::Label->new;
$label->set_markup("<span size='large'><b>".$item."</b></span>");

my $button_search = Gtk2::Button->new;
$button_search->set_label("search");
$button_search->signal_connect('clicked',
sub {
print $item . "\n";
$builder->get_object( 'notebook' )->set_current_page(0);
$builder->get_object( 'entry_query' )->set_text($item);
on_button_query_clicked();
}
);
$vbox->pack_start ($button, FALSE, FALSE, 0);

my $button_remove = Gtk2::Button->new;
$button_remove->set_label("remove");
$button_remove->signal_connect('clicked',
sub {
remove_bookmark($item);
populate_bookmarks();
}
);

my $hseparator = new Gtk2::HSeparator();

$hbox->pack_start($label, FALSE,FALSE,0);
$hbox->pack_end($button_remove, FALSE,FALSE,0);
$hbox->pack_end($button_search, FALSE,FALSE,0);
$vbox->pack_start ($hbox, FALSE, FALSE, 0);
$vbox->pack_start($hseparator, FALSE,FALSE,5);
}
$vbox->show_all;
}
Expand Down Expand Up @@ -577,6 +596,20 @@ sub on_button_query_clicked {
$vbox->pack_start($label, FALSE, FALSE, 5);
}

# bookmark button
my $button_bookmark = Gtk2::Button->new;
$button_bookmark->set_label("Bookmark this search");
$button_bookmark->set_image(Gtk2::Image->new_from_stock("gtk-add", 'button'));

$button_bookmark->signal_connect('clicked',
sub {
my $query = $builder->get_object( 'entry_query' )->get_text;
push @bookmark, $query;
}
);
$vbox->pack_start($button_bookmark, FALSE, FALSE, 5);

# the results
my $n = 0;

for (@{$data->{torrents}}) {
Expand Down Expand Up @@ -615,6 +648,13 @@ sub splice_thread {
splice @threads, $i, 1;
}

sub remove_bookmark($) {
my $item = shift;
my $i = 0;
$i++ until $bookmark[$i] eq $item or $i > $#bookmark;
splice @bookmark, $i, 1;
}

sub add_separated_item($$$$$$) {
# adds a label with markup and separator to a vbox
# (For list of search results)
Expand All @@ -639,6 +679,7 @@ ($$$$$$)
# }
# );


my $tooltip_title = Gtk2::Tooltips->new;
$tooltip_title->set_tip( $eventbox, $torrent_title );

Expand All @@ -652,8 +693,8 @@ ($$$$$$)
my $number = Gtk2::Label->new;
$number->set_markup("<span size='large'>".$n.".</span>");
$number->set_alignment(0,.5);
$number->set_width_chars(3);
$number->set_width_chars(4);

my $vboxinfo = Gtk2::VBox->new;

# create new label for truncated title with tooltip
Expand Down Expand Up @@ -1013,7 +1054,7 @@ sub on_window_check_resize {
my $container = $builder->get_object( 'vbox_query_results' );
my @children;

my $width_chars = int ($width * .10);
my $width_chars = int ($width * .09);
debug("[ !] width_chars = ". $width_chars . "\n");

# recursively loop until we find a label
Expand Down

0 comments on commit 7eee39f

Please sign in to comment.