summaryrefslogtreecommitdiff
path: root/include/configpaths.h
blob: 6d3ddae01f5db745dbbc6e84871af893c12af1be (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#ifndef NEWSBOAT_CONFIGPATHS_H_
#define NEWSBOAT_CONFIGPATHS_H_

#include <string>

#include "cliargsparser.h"

namespace newsboat {
class ConfigPaths {
	std::string m_env_home;
	std::string m_error_message;

	std::string m_data_dir;
	std::string m_config_dir;

	std::string m_url_file;
	std::string m_cache_file;
	std::string m_config_file;
	std::string m_lock_file;
	std::string m_queue_file;
	std::string m_search_file;
	std::string m_cmdline_file;

	bool m_silent = false;
	bool m_using_nonstandard_configs = false;

	bool find_dirs_xdg();
	void find_dirs();

	/// Looks for Newsbeuter's XDG directories and, if found, copies their
	/// contents to Newsboat's XDG dirs. Returns true if copied something,
	/// false otherwise.
	bool migrate_data_from_newsbeuter_xdg();

	/// Looks for Newsbeuter's dot directory and, if found, copies its contents
	/// to Newsboat's dotdir. Returns true if copied something, false
	/// otherwise.
	bool migrate_data_from_newsbeuter_dotdir();

	/// Looks for Newsbeuter's directories and, if found, copies their contents
	/// to corresponding Newsboat's directory. Returns true if copied
	/// something, false otherwise.
	bool migrate_data_from_newsbeuter();

public:
	ConfigPaths();

	/// \brief Indicates if the object can be used.
	///
	/// If this method returned `false`, the cause for initialization
	/// failure can be found using `error_message()`.
	bool initialized() const;

	/// Returns explanation why initialization failed.
	///
	/// \note You shouldn't call this unless `initialized()` returns
	/// `false`.
	std::string error_message() const;

	/// Initializes paths to config, cache etc. from CLI arguments.
	void process_args(const CliArgsParser& args);

	/// If user didn't specify paths to configs on the command line, and the
	/// config file wasn't found in the standard directories, looks for
	/// Newsbeuter's directories, and copies their contents if found. Returns
	/// true if copied something, false otherwise.
	bool try_migrate_from_newsbeuter();

	/// Creates Newsboat's dotdir or XDG config & data dirs (depending on what
	/// was configured during initialization, when processing CLI args, and if
	/// migration found anything).
	bool create_dirs() const;

	/// Path to the URLs file.
	std::string url_file() const
	{
		return m_url_file;
	}

	/// Path to the cache file.
	std::string cache_file() const
	{
		return m_cache_file;
	}

	/// Sets path to the cache file.
	// FIXME: this is actually a kludge that lets Controller change the path
	// midway. That logic should be moved into ConfigPaths, and this method
	// removed.
	void set_cache_file(const std::string&);

	/// Path to the config file.
	std::string config_file() const
	{
		return m_config_file;
	}

	/// Path to the lock file.
	///
	/// \note This changes when path to config file changes.
	std::string lock_file() const
	{
		return m_lock_file;
	}

	/// \brief Path to the queue file.
	///
	/// Queue file stores enqueued podcasts. It's written by Newsboat, and
	/// read by Podboat.
	std::string queue_file() const
	{
		return m_queue_file;
	}

	/// Path to the file with previous search queries.
	std::string search_file() const
	{
		return m_search_file;
	}

	/// Path to the file with command-line history.
	std::string cmdline_file() const
	{
		return m_cmdline_file;
	}
};
} // namespace newsboat

#endif /* NEWSBOAT_CONFIGPATHS_H_ */