Skip to content

Commit

Permalink
Merge pull request #57 from oliwer/tempdir
Browse files Browse the repository at this point in the history
booru: use a different TempDir for each tab
  • Loading branch information
ahodesuka committed Nov 8, 2017
2 parents 0a3c57f + 1442340 commit 2861e1c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
27 changes: 25 additions & 2 deletions src/booru/imagelist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using namespace AhoViewer::Booru;

#include "image.h"
#include "page.h"
#include "tempdir.h"

ImageList::ImageList(Widget *w)
: AhoViewer::ImageList(w),
Expand All @@ -11,12 +12,34 @@ ImageList::ImageList(Widget *w)

}

ImageList::~ImageList()
{
clear();
}

void ImageList::clear()
{
AhoViewer::ImageList::clear();
if (!m_Path.empty()) {
TempDir::get_instance().remove_dir(m_Path);
m_Path.clear();
}
m_Size = 0;
}

std::string ImageList::get_path()
{
static int id = 1;

if (m_Path.empty())
{
m_Path = TempDir::get_instance().make_dir(std::to_string(id++));
g_mkdir_with_parents(Glib::build_filename(m_Path, "thumbnails").c_str(), 0755);
}

return m_Path;
}

void ImageList::load(const xmlDocument &posts, const Page &page)
{
std::string c = posts.get_attribute("count");
Expand All @@ -26,10 +49,10 @@ void ImageList::load(const xmlDocument &posts, const Page &page)
for (const xmlDocument::Node &post : posts.get_children())
{
std::string thumbUrl = post.get_attribute("preview_url"),
thumbPath = Glib::build_filename(page.get_site()->get_path(), "thumbnails",
thumbPath = Glib::build_filename(get_path(), "thumbnails",
Glib::uri_unescape_string(Glib::path_get_basename(thumbUrl))),
imageUrl = post.get_attribute("file_url"),
imagePath = Glib::build_filename(page.get_site()->get_path(),
imagePath = Glib::build_filename(get_path(),
Glib::uri_unescape_string(Glib::path_get_basename(imageUrl)));

std::istringstream ss(post.get_attribute("tags"));
Expand Down
3 changes: 3 additions & 0 deletions src/booru/imagelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ namespace AhoViewer
{
public:
ImageList(Widget *w);
virtual ~ImageList() override;

std::string get_path();
virtual size_t get_size() const override { return m_Size ? m_Size : AhoViewer::ImageList::get_size(); }
size_t get_vector_size() const { return m_Images.size(); }

virtual void clear() override;
void load(const xmlDocument &posts, const Page &page);
private:
std::string m_Path;
size_t m_Size;
};
}
Expand Down
13 changes: 1 addition & 12 deletions src/booru/site.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include <chrono>
#include <fstream>
#include <iostream>
#include <glib/gstdio.h>

#include "site.h"
using namespace AhoViewer::Booru;

#include "settings.h"
#include "tempdir.h"

#ifdef HAVE_LIBSECRET
#include <libsecret/secret.h>
Expand Down Expand Up @@ -293,17 +293,6 @@ void Site::cleanup_cookie() const
g_unlink(m_CookiePath.c_str());
}

std::string Site::get_path()
{
if (m_Path.empty())
{
m_Path = TempDir::get_instance().make_dir(m_Name);
g_mkdir_with_parents(Glib::build_filename(m_Path, "thumbnails").c_str(), 0755);
}

return m_Path;
}

Glib::RefPtr<Gdk::Pixbuf> Site::get_icon_pixbuf(const bool update)
{
if (!m_IconPixbuf || update)
Expand Down
4 changes: 1 addition & 3 deletions src/booru/site.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ namespace AhoViewer
std::string get_cookie();
void cleanup_cookie() const;

std::string get_path();
Glib::RefPtr<Gdk::Pixbuf> get_icon_pixbuf(const bool update = false);

void save_tags() const;
Expand Down Expand Up @@ -95,8 +94,7 @@ namespace AhoViewer
m_Password,
m_IconPath,
m_TagsPath,
m_CookiePath,
m_Path;
m_CookiePath;
Type m_Type;
bool m_NewAccount;
uint64_t m_CookieTS;
Expand Down

0 comments on commit 2861e1c

Please sign in to comment.