This is an automated email from the git hooks/post-receive script. thansen pushed a commit to branch master in repository aseprite.
commit 1ce74d3c5a6f1f95d75f7618f1d5051282fc3c17 Author: David Capello <[email protected]> Date: Tue May 17 16:21:56 2016 -0300 Abort loading news file if the application is being closed --- src/app/res/http_loader.cpp | 20 ++++++++++++-------- src/app/res/http_loader.h | 10 +++++++--- src/app/ui/news_listbox.cpp | 16 +++++++++++++++- src/app/ui/news_listbox.h | 3 ++- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/app/res/http_loader.cpp b/src/app/res/http_loader.cpp index 719d2db..839a989 100644 --- a/src/app/res/http_loader.cpp +++ b/src/app/res/http_loader.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2016 David Capello // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -28,7 +28,7 @@ namespace app { HttpLoader::HttpLoader(const std::string& url) : m_url(url) , m_done(false) - , m_cancel(false) + , m_request(nullptr) , m_thread(base::Bind<void>(&HttpLoader::threadHttpRequest, this)) { } @@ -38,9 +38,10 @@ HttpLoader::~HttpLoader() m_thread.join(); } -void HttpLoader::cancel() +void HttpLoader::abort() { - m_cancel = true; + if (m_request) + m_request->abort(); } void HttpLoader::threadHttpRequest() @@ -61,12 +62,12 @@ void HttpLoader::threadHttpRequest() fn = base::join_path(dir, fn); std::ofstream output(FSTREAM_PATH(fn), std::ofstream::binary); - net::HttpRequest http(m_url); + m_request = new net::HttpRequest(m_url); net::HttpResponse response(&output); - http.send(response); - - if (response.status() == 200) + if (m_request->send(response) && + response.status() == 200) { m_filename = fn; + } LOG("Response: %d\n", response.status()); } @@ -76,6 +77,9 @@ void HttpLoader::threadHttpRequest() catch (...) { LOG("Unexpected unknown exception sending http request\n"); } + + delete m_request; + m_request = nullptr; } } // namespace app diff --git a/src/app/res/http_loader.h b/src/app/res/http_loader.h index 00ee6ab..242f680 100644 --- a/src/app/res/http_loader.h +++ b/src/app/res/http_loader.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2016 David Capello // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -12,6 +12,10 @@ #include "base/thread.h" #include <string> +namespace net { + class HttpRequest; +} + namespace app { class HttpLoader { @@ -19,7 +23,7 @@ namespace app { HttpLoader(const std::string& url); ~HttpLoader(); - void cancel(); + void abort(); bool isDone() const { return m_done; } std::string filename() const { return m_filename; } @@ -28,7 +32,7 @@ namespace app { std::string m_url; bool m_done; - bool m_cancel; + net::HttpRequest* m_request; base::thread m_thread; std::string m_filename; }; diff --git a/src/app/ui/news_listbox.cpp b/src/app/ui/news_listbox.cpp index 8379a21..2f63c43 100644 --- a/src/app/ui/news_listbox.cpp +++ b/src/app/ui/news_listbox.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2016 David Capello // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -21,6 +21,7 @@ #include "base/string.h" #include "base/time.h" #include "ui/link_label.h" +#include "ui/message.h" #include "ui/paint_event.h" #include "ui/size_hint_event.h" #include "ui/view.h" @@ -219,6 +220,19 @@ void NewsListBox::reload() m_timer.start(); } +bool NewsListBox::onProcessMessage(ui::Message* msg) +{ + switch (msg->type()) { + + case kCloseMessage: + if (m_loader) + m_loader->abort(); + break; + } + + return ListBox::onProcessMessage(msg); +} + void NewsListBox::onTick() { if (!m_loader || !m_loader->isDone()) diff --git a/src/app/ui/news_listbox.h b/src/app/ui/news_listbox.h index 16e0645..24f7117 100644 --- a/src/app/ui/news_listbox.h +++ b/src/app/ui/news_listbox.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2016 David Capello // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -26,6 +26,7 @@ namespace app { void reload(); private: + bool onProcessMessage(ui::Message* msg) override; void onTick(); void parseFile(const std::string& filename); bool validCache(const std::string& filename); -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git _______________________________________________ Pkg-games-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits

