Add rofi export.

This commit is contained in:
tastytea 2019-11-28 09:03:52 +01:00
parent f8fd9b8c6d
commit ad676bbc13
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
6 changed files with 99 additions and 1 deletions

39
include/export/rofi.hpp Normal file
View File

@ -0,0 +1,39 @@
/* This file is part of remwharead.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* 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 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

View File

@ -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"

View File

@ -37,7 +37,8 @@ enum class export_format
simple,
json,
rss,
link
link,
rofi
};
} // namespace remwharead

View File

@ -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<std::string> &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;

View File

@ -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";

39
src/lib/export/rofi.cpp Normal file
View File

@ -0,0 +1,39 @@
/* This file is part of remwharead.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* 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/>.
*/
#include "export/rofi.hpp"
#include "sqlite.hpp"
#include <string>
namespace remwharead
{
using std::string;
void Export::Rofi::print() const
{
_out << static_cast<char>(0x00) << "markup-rows"
<< static_cast<char>(0x1f) << "true\n";
for (const Database::entry & entry : _entries)
{
_out << entry.title
<< R"( <span size="small" weight="light" style="italic">()"
<< Database::tags_to_string(entry.tags) << ")</span> "
<< R"(<span size="xx-small" weight="ultralight">)"
<< entry.uri << "</span>\n";
}
}
} // namespace remwharead