From ad676bbc13db24f158e4d36864da8016ec249a64 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 28 Nov 2019 09:03:52 +0100 Subject: [PATCH] Add rofi export. --- include/export/rofi.hpp | 39 +++++++++++++++++++++++++++++++++++++++ include/remwharead.hpp | 1 + include/types.hpp | 3 ++- src/cli/main.cpp | 14 ++++++++++++++ src/cli/parse_options.cpp | 4 ++++ src/lib/export/rofi.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 include/export/rofi.hpp create mode 100644 src/lib/export/rofi.cpp diff --git a/include/export/rofi.hpp b/include/export/rofi.hpp new file mode 100644 index 0000000..33ba8ec --- /dev/null +++ b/include/export/rofi.hpp @@ -0,0 +1,39 @@ +/* This file is part of remwharead. + * Copyright © 2019 tastytea + * + * 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 . + */ + +#ifndef REMWHAREAD_EXPORT_ROFI_HPP +#define REMWHAREAD_EXPORT_ROFI_HPP + +#include "export.hpp" + +namespace remwharead::Export +{ +/*! + * @brief Export title, tags and URL for consumption by rofi. + * + * @since 0.9.0 + * + * @headerfile rofi.hpp remwharead/export/rofi.hpp + */ +class Rofi : protected ExportBase +{ +public: + using ExportBase::ExportBase; + void print() const override; +}; +} // namespace remwharead::Export + +#endif // REMWHAREAD_EXPORT_ROFI_HPP diff --git a/include/remwharead.hpp b/include/remwharead.hpp index dfd005e..f078bde 100644 --- a/include/remwharead.hpp +++ b/include/remwharead.hpp @@ -47,6 +47,7 @@ #include "export/rss.hpp" #include "export/simple.hpp" #include "export/list.hpp" +#include "export/rofi.hpp" #include "search.hpp" #include "sqlite.hpp" #include "time.hpp" diff --git a/include/types.hpp b/include/types.hpp index 6f01510..e7ef292 100644 --- a/include/types.hpp +++ b/include/types.hpp @@ -37,7 +37,8 @@ enum class export_format simple, json, rss, - link + link, + rofi }; } // namespace remwharead diff --git a/src/cli/main.cpp b/src/cli/main.cpp index 1206732..edd971d 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -20,6 +20,7 @@ #include "export/csv.hpp" #include "export/json.hpp" #include "export/link.hpp" +#include "export/rofi.hpp" #include "export/rss.hpp" #include "export/simple.hpp" #include "search.hpp" @@ -228,6 +229,19 @@ int App::main(const std::vector &args) } break; } + case export_format::rofi: + { + if (file.is_open()) + { + Export::Rofi(entries, file).print(); + file.close(); + } + else + { + Export::Rofi(entries).print(); + } + break; + } default: { break; diff --git a/src/cli/parse_options.cpp b/src/cli/parse_options.cpp index acc0bf5..dae2c5c 100644 --- a/src/cli/parse_options.cpp +++ b/src/cli/parse_options.cpp @@ -156,6 +156,10 @@ void App::handle_options(const std::string &name, const std::string &value) { _format = export_format::link; } + else if (value == "rofi") + { + _format = export_format::rofi; + } else { cerr << "Error: Unknown format.\n"; diff --git a/src/lib/export/rofi.cpp b/src/lib/export/rofi.cpp new file mode 100644 index 0000000..69edcc1 --- /dev/null +++ b/src/lib/export/rofi.cpp @@ -0,0 +1,39 @@ +/* This file is part of remwharead. + * Copyright © 2019 tastytea + * + * 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 . + */ + +#include "export/rofi.hpp" +#include "sqlite.hpp" +#include + +namespace remwharead +{ +using std::string; + +void Export::Rofi::print() const +{ + _out << static_cast(0x00) << "markup-rows" + << static_cast(0x1f) << "true\n"; + + for (const Database::entry & entry : _entries) + { + _out << entry.title + << R"( ()" + << Database::tags_to_string(entry.tags) << ") " + << R"()" + << entry.uri << "\n"; + } +} +} // namespace remwharead