Browse Source

remove extra members

CPP-GTK4
yggverse 4 months ago
parent
commit
2a0b9f194f
  1. 13
      src/app/browser/main/tab/page/content/text/gemini.cpp
  2. 166
      src/app/browser/main/tab/page/content/text/gemini/reader.cpp
  3. 15
      src/app/browser/main/tab/page/content/text/gemini/reader.hpp

13
src/app/browser/main/tab/page/content/text/gemini.cpp

@ -10,20 +10,15 @@ Gemini::Gemini( @@ -10,20 +10,15 @@ Gemini::Gemini(
NULL,
NULL
) {
// Init components
auto geminiReader = Gtk::make_managed<gemini::Reader>(
GEMTEXT
);
// Grab title
title = geminiReader->get_title();
// Init widget
set_scroll_to_focus(
false
);
set_child(
* geminiReader
* Gtk::make_managed<gemini::Reader>(
GEMTEXT,
title
)
);
}

166
src/app/browser/main/tab/page/content/text/gemini/reader.cpp

@ -3,8 +3,83 @@ @@ -3,8 +3,83 @@
using namespace app::browser::main::tab::page::content::text::gemini;
Reader::Reader(
const Glib::ustring & GEMTEXT
const Glib::ustring & GEMTEXT,
Glib::ustring & title
) {
// Build markup
Glib::ustring markup;
std::istringstream stream(
GEMTEXT
);
std::string line;
while (std::getline(stream, line))
{
// Header
int level;
Glib::ustring header;
if (Line::Match::header(line, level, header))
{
markup.append(
Make::header(
level,
header
)
);
if (title.empty())
{
title = header;
}
continue;
}
// Link
Glib::ustring address;
Glib::ustring date;
Glib::ustring alt;
if (Line::Match::link(line, address, date, alt))
{
markup.append(
Make::link(
address,
date,
alt
)
);
continue;
}
// Quote
Glib::ustring quote;
if (Line::Match::quote(line, quote))
{
markup.append(
Make::quote(
quote
)
);
continue;
}
// @TODO other tags..
// Default
markup.append(
Make::plain(
line
)
);
}
// Init widget
set_valign(
Gtk::Align::START
@ -23,9 +98,7 @@ Reader::Reader( @@ -23,9 +98,7 @@ Reader::Reader(
);
set_markup(
make(
GEMTEXT
)
markup
);
// Connect CSS
@ -52,12 +125,6 @@ Reader::Reader( @@ -52,12 +125,6 @@ Reader::Reader(
);
}
// Getters
Glib::ustring Reader::get_title()
{
return title;
}
// Match tools
bool Reader::Line::Match::header(
const Glib::ustring & GEMTEXT,
@ -132,85 +199,6 @@ bool Reader::Line::Match::quote( @@ -132,85 +199,6 @@ bool Reader::Line::Match::quote(
}
// Markup tools
Glib::ustring Reader::make(
const Glib::ustring & GEMTEXT
) {
Glib::ustring pango;
std::istringstream stream(
GEMTEXT
);
std::string line;
while (std::getline(stream, line))
{
// Header
int level;
Glib::ustring header;
if (Line::Match::header(line, level, header))
{
pango.append(
Make::header(
level,
header
)
);
if (title.empty())
{
title = header;
}
continue;
}
// Link
Glib::ustring address;
Glib::ustring date;
Glib::ustring alt;
if (Line::Match::link(line, address, date, alt))
{
pango.append(
Make::link(
address,
date,
alt
)
);
continue;
}
// Quote
Glib::ustring quote;
if (Line::Match::quote(line, quote))
{
pango.append(
Make::quote(
quote
)
);
continue;
}
// @TODO other tags..
// Default
pango.append(
Make::plain(
line
)
);
}
return pango;
}
Glib::ustring Reader::Make::header(
const int & LEVEL,
const Glib::ustring & TEXT

15
src/app/browser/main/tab/page/content/text/gemini/reader.hpp

@ -62,26 +62,15 @@ namespace app::browser::main::tab::page::content::text::gemini @@ -62,26 +62,15 @@ namespace app::browser::main::tab::page::content::text::gemini
);
};
Glib::ustring make(
const Glib::ustring & GEMTEXT
);
/*
* Private members
*/
Glib::ustring title;
/*
* Reader class API
*/
public:
Reader(
const Glib::ustring & GEMTEXT
const Glib::ustring & GEMTEXT,
Glib::ustring & title
);
// Getters
Glib::ustring get_title();
};
}

Loading…
Cancel
Save