Skip to content

Commit

Permalink
booru/page: Keep selected image aligned while loading
Browse files Browse the repository at this point in the history
  • Loading branch information
ahodesuka committed May 13, 2018
1 parent 7bb1f32 commit 216eae6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
25 changes: 22 additions & 3 deletions src/booru/page.cc
Expand Up @@ -23,6 +23,7 @@ Page::Page(Gtk::Menu *menu)
m_Page(0),
m_Saving(false),
m_LastPage(false),
m_KeepAligned(false),
m_SaveCancel(Gio::Cancellable::create())
{
set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
Expand Down Expand Up @@ -54,7 +55,7 @@ Page::Page(Gtk::Menu *menu)
m_Tab->signal_button_release_event().connect(sigc::mem_fun(*this, &Page::on_tab_button_release_event));
// }}}

get_vadjustment()->signal_value_changed().connect(sigc::mem_fun(*this, &Page::on_value_changed));
m_ScrollConn = get_vadjustment()->signal_value_changed().connect(sigc::mem_fun(*this, &Page::on_value_changed));

m_IconView->set_model(m_ListStore);
m_IconView->set_selection_mode(Gtk::SELECTION_BROWSE);
Expand All @@ -77,8 +78,8 @@ Page::Page(Gtk::Menu *menu)
m_ImageList->signal_thumbnails_loaded().connect([&]()
{
on_selection_changed();
on_value_changed();

if (!m_KeepAligned)
on_value_changed();
});

add(*m_IconView);
Expand All @@ -95,6 +96,18 @@ Page::~Page()
cancel_save();
}

void Page::set_pixbuf(const size_t index, const Glib::RefPtr<Gdk::Pixbuf> &pixbuf)
{
m_ScrollConn.block();
ImageList::Widget::set_pixbuf(index, pixbuf);
while (Gtk::Main::events_pending())
Gtk::Main::iteration();
m_ScrollConn.unblock();

if (m_KeepAligned)
scroll_to_selected();
}

void Page::set_selected(const size_t index)
{
get_window()->freeze_updates();
Expand All @@ -114,7 +127,11 @@ void Page::scroll_to_selected()
{
Gtk::TreePath path = paths[0];
if (path)
{
m_ScrollConn.block();
m_IconView->scroll_to_path(path, false, 0, 0);
m_ScrollConn.unblock();
}
}
}

Expand Down Expand Up @@ -240,6 +257,7 @@ void Page::cancel_save()
void Page::get_posts()
{
std::string tags = m_SearchTags;
m_KeepAligned = true;

if (m_Tags.find("rating:") == std::string::npos)
{
Expand Down Expand Up @@ -421,6 +439,7 @@ void Page::on_value_changed()
limit = get_vadjustment()->get_upper() -
get_vadjustment()->get_page_size() -
get_vadjustment()->get_step_increment() * 3;
m_KeepAligned = false;

if (value >= limit)
get_next_page();
Expand Down
6 changes: 4 additions & 2 deletions src/booru/page.h
Expand Up @@ -34,6 +34,7 @@ namespace AhoViewer
SignalDownloadErrorType signal_no_results() const { return m_SignalDownloadError; }
SignalSaveProgressType signal_save_progress() const { return m_SignalSaveProgress; }
protected:
virtual void set_pixbuf(const size_t index, const Glib::RefPtr<Gdk::Pixbuf> &pixbuf) override;
virtual void set_selected(const size_t index) override;
virtual void scroll_to_selected() override;
private:
Expand Down Expand Up @@ -73,7 +74,7 @@ namespace AhoViewer
m_SaveImagesTotal;
std::atomic<size_t> m_SaveImagesCurrent;
std::atomic<bool> m_Saving;
bool m_LastPage;
bool m_LastPage, m_KeepAligned;
std::unique_ptr<xml::Document> m_Posts;

Glib::RefPtr<Gio::Cancellable> m_SaveCancel;
Expand All @@ -82,7 +83,8 @@ namespace AhoViewer
Glib::Dispatcher m_SignalPostsDownloaded,
m_SignalSaveProgressDisp;

sigc::connection m_GetNextPageConn;
sigc::connection m_GetNextPageConn,
m_ScrollConn;

SignalClosedType m_SignalClosed;
SignalDownloadErrorType m_SignalDownloadError;
Expand Down
2 changes: 1 addition & 1 deletion src/imagelist.cc
Expand Up @@ -319,7 +319,7 @@ void ImageList::on_thumbnail_loaded()

m_ThumbnailLoadedConn.unblock();

if (m_ThumbnailQueue.empty())
if (!m_ThreadPool.active())
m_SignalThumbnailsLoaded();
}

Expand Down

0 comments on commit 216eae6

Please sign in to comment.