summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbogdasar1985 <bogdasar1985@gmail.com>2023-10-11 15:24:03 +0500
committerAlexander Batischev <eual.jp@gmail.com>2024-10-01 19:12:43 +0300
commitc84ba2535c76a4915bbdbf0ac29ade4247082dfb (patch)
treeeb1532dd2dcf67ee72c5ebc0cfd039fb08440de4
parent05986ce2344c32ab95e82f91a616f630e38ae889 (diff)
Migrate Download to Filepath
-rw-r--r--include/download.h12
-rw-r--r--src/download.cpp45
-rw-r--r--src/poddlthread.cpp5
-rw-r--r--src/queueloader.cpp2
4 files changed, 49 insertions, 15 deletions
diff --git a/include/download.h b/include/download.h
index 409dc4e2..3c6386b9 100644
--- a/include/download.h
+++ b/include/download.h
@@ -4,6 +4,8 @@
#include <functional>
#include <string>
+#include "filepath.h"
+
namespace podboat {
enum class DlStatus {
@@ -23,6 +25,8 @@ class Download {
public:
explicit Download(std::function<void()> cb_require_view_update);
~Download();
+ Download(const Download& download);
+ Download& operator=(const Download& download);
double percents_finished() const;
const std::string status_text() const;
DlStatus status() const
@@ -33,10 +37,10 @@ public:
{
return msg;
}
- const std::string filename() const;
- const std::string basename() const;
+ const newsboat::Filepath filename() const;
+ const newsboat::Filepath basename() const;
const std::string url() const;
- void set_filename(const std::string& str);
+ void set_filename(const newsboat::Filepath& str);
void set_url(const std::string& url);
void set_progress(double downloaded, double total);
void set_status(DlStatus dls, const std::string& msg_ = {});
@@ -54,7 +58,7 @@ public:
}
private:
- std::string fn;
+ newsboat::Filepath fn;
std::string url_;
DlStatus download_status;
std::string msg;
diff --git a/src/download.cpp b/src/download.cpp
index ed0d3dfa..3ff9be53 100644
--- a/src/download.cpp
+++ b/src/download.cpp
@@ -23,19 +23,48 @@ Download::Download(std::function<void()> cb_require_view_update_)
Download::~Download() {}
-const std::string Download::filename() const
+Download::Download(const Download& download) :
+ url_(download.url_),
+ download_status(download.download_status),
+ msg(download.msg),
+ cursize(download.cursize),
+ totalsize(download.totalsize),
+ curkbps(download.curkbps),
+ offs(download.offs),
+ cb_require_view_update(download.cb_require_view_update)
{
- return fn;
+ fn = download.fn.clone();
}
-const std::string Download::basename() const
+Download& Download::operator=(const Download& download)
{
- std::string::size_type start = fn.rfind(NEWSBEUTER_PATH_SEP);
+ if (this == &download) {
+ return *this;
+ }
+ url_ = download.url_;
+ download_status = download.download_status;
+ msg = download.msg;
+ cursize = download.cursize;
+ totalsize = download.totalsize;
+ curkbps = download.curkbps;
+ offs = download.offs;
+ fn = download.fn.clone();
+ return *this;
+}
+
+const newsboat::Filepath Download::filename() const
+{
+ return fn.clone();
+}
+
+const newsboat::Filepath Download::basename() const
+{
+ std::string::size_type start = fn.to_locale_string().rfind(NEWSBEUTER_PATH_SEP);
if (start != std::string::npos) {
- return fn.substr(start+1);
+ return fn.to_locale_string().substr(start+1);
}
- return fn;
+ return fn.clone();
}
const std::string Download::url() const
@@ -43,9 +72,9 @@ const std::string Download::url() const
return url_;
}
-void Download::set_filename(const std::string& str)
+void Download::set_filename(const newsboat::Filepath& str)
{
- fn = str;
+ fn = str.clone();
}
double Download::percents_finished() const
diff --git a/src/poddlthread.cpp b/src/poddlthread.cpp
index efabc66d..3675ca6e 100644
--- a/src/poddlthread.cpp
+++ b/src/poddlthread.cpp
@@ -73,7 +73,7 @@ void PodDlThread::run()
struct stat sb;
Filepath filename =
- dl->filename() + newsboat::ConfigContainer::PARTIAL_FILE_SUFFIX;
+ dl->filename().join(newsboat::ConfigContainer::PARTIAL_FILE_SUFFIX);
if (stat(filename.to_locale_string().c_str(), &sb) == -1) {
LOG(Level::INFO,
@@ -120,7 +120,8 @@ void PodDlThread::run()
LOG(Level::DEBUG,
"PodDlThread::run: download complete, deleting "
"temporary suffix");
- if (rename(filename.to_locale_string().c_str(), dl->filename().c_str()) == 0) {
+ if (rename(filename.to_locale_string().c_str(),
+ dl->filename().to_locale_string().c_str()) == 0) {
dl->set_status(DlStatus::READY);
} else {
dl->set_status(DlStatus::RENAME_FAILED, strerror(errno));
diff --git a/src/queueloader.cpp b/src/queueloader.cpp
index bdf9f8ca..ec2577dd 100644
--- a/src/queueloader.cpp
+++ b/src/queueloader.cpp
@@ -253,7 +253,7 @@ void QueueLoader::delete_played_files(const CategorizedDownloads& downloads)
const
{
for (const auto& dl : downloads.to_delete) {
- const Filepath filename = dl.filename();
+ const Filepath filename = dl.filename().clone();
LOG(Level::INFO, "Deleting file %s", filename);
if (std::remove(filename.to_locale_string().c_str()) != 0) {
if (errno != ENOENT) {