mastorss/src/config.hpp

93 lines
2.3 KiB
C++
Raw Normal View History

2019-12-24 18:53:00 +01:00
/* This file is part of mastorss.
2020-05-10 17:01:20 +02:00
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
2019-12-24 18:53:00 +01:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTORSS_CONFIG_HPP
#define MASTORSS_CONFIG_HPP
#include <boost/filesystem.hpp>
2019-12-28 08:48:55 +01:00
#include <json/json.h>
2019-12-24 18:53:00 +01:00
#include <cstdint>
#include <list>
2019-12-24 18:53:00 +01:00
#include <string>
#include <string_view>
2020-05-10 17:01:20 +02:00
#include <utility>
2019-12-24 18:53:00 +01:00
namespace mastorss
{
namespace fs = boost::filesystem;
using std::list;
2020-08-24 16:39:32 +02:00
using std::pair;
2019-12-24 18:53:00 +01:00
using std::string;
using std::string_view;
2020-08-24 16:39:32 +02:00
using std::uint32_t;
2019-12-24 18:53:00 +01:00
/*!
* @brief The configuration for a profile as data structure.
*
* @since 0.10.0
*/
struct ProfileData
{
string access_token;
string append;
string feedurl;
list<string> fixes;
2020-01-01 12:43:04 +01:00
list<string> guids;
2019-12-24 18:53:00 +01:00
string instance;
bool keep_looking{false};
2019-12-24 18:53:00 +01:00
uint32_t interval{30};
size_t max_size{500};
list<string> skip;
2019-12-24 18:53:00 +01:00
bool titles_as_cw{false};
bool titles_only{false};
2020-05-10 17:01:20 +02:00
list<pair<string, string>> replacements;
2020-10-29 15:06:51 +01:00
bool add_hashtags{true};
2019-12-24 18:53:00 +01:00
2020-08-24 16:39:32 +02:00
friend std::ostream &operator<<(std::ostream &out, const ProfileData &data);
2019-12-24 18:53:00 +01:00
};
/*!
* @brief A configuration file.
*
* @since 0.10.0
*/
class Config
{
public:
explicit Config(string profile_name);
2019-12-24 18:53:00 +01:00
const string profile;
2019-12-28 09:01:17 +01:00
ProfileData profiledata;
constexpr static size_t max_guids{100};
2019-12-24 18:53:00 +01:00
2019-12-25 07:02:19 +01:00
void write();
2020-08-24 16:39:32 +02:00
[[nodiscard]] fs::path get_config_dir() const;
2019-12-25 06:25:11 +01:00
2019-12-24 18:53:00 +01:00
private:
Json::Value _json;
2020-08-24 16:39:32 +02:00
[[nodiscard]] fs::path get_filename() const;
2019-12-24 18:53:00 +01:00
void generate();
2020-08-24 16:39:32 +02:00
[[nodiscard]] string get_access_token(const string &instance) const;
2019-12-24 18:53:00 +01:00
void parse();
list<string> jsonarray_to_stringlist(const Json::Value &jsonarray) const;
Json::Value stringlist_to_jsonarray(const list<string> &stringlist) const;
2019-12-24 18:53:00 +01:00
};
} // namespace mastorss
2020-08-24 16:39:32 +02:00
#endif // MASTORSS_CONFIG_HPP