2 Commits

11 changed files with 170 additions and 223 deletions

View File

@@ -35,7 +35,7 @@ jobs:
libxkbcommon0 \
libgtk-3-bin libglib2.0-bin shared-mime-info gsettings-desktop-schemas \
liblua5.4-dev libpci-dev libperl-dev libssl-dev libayatana-appindicator3-dev \
perl python3 python3-minimal python3-dev python3-cffi mono-devel desktop-file-utils \
perl python3 python3-minimal python3-dev python3-cffi python3-sphinx mono-devel desktop-file-utils \
fonts-noto-color-emoji breeze-gtk-theme \
patchelf file curl

View File

@@ -40,6 +40,7 @@ jobs:
python -m pip install --upgrade pip
python -m pip install cffi
python -m pip install zstandard
python -m pip install sphinx
$ProgressPreference = 'SilentlyContinue'
function Download-WithRetry {

42
docs/build-docs.py Normal file
View File

@@ -0,0 +1,42 @@
#!/usr/bin/env python3
import os
import shutil
import subprocess
import sys
def main():
if len(sys.argv) != 4:
raise SystemExit("usage: build-docs.py SOURCE_DIR OUTPUT_DIR STAMP_FILE")
source_dir = os.path.abspath(sys.argv[1])
output_dir = os.path.abspath(sys.argv[2])
stamp_file = os.path.abspath(sys.argv[3])
doctree_dir = output_dir + ".doctrees"
shutil.rmtree(output_dir, ignore_errors=True)
shutil.rmtree(doctree_dir, ignore_errors=True)
os.makedirs(output_dir, exist_ok=True)
subprocess.run(
[
sys.executable,
"-m",
"sphinx",
"-b",
"html",
"-d",
doctree_dir,
source_dir,
output_dir,
],
check=True,
)
with open(stamp_file, "w", encoding="utf-8") as stamp:
stamp.write("built\n")
if __name__ == "__main__":
main()

36
docs/install-docs.py Normal file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/env python3
import os
import shutil
import sys
def main():
if len(sys.argv) != 4:
raise SystemExit("usage: install-docs.py STAMP_FILE SOURCE_DIR DATADIR")
_, source_dir, datadir = sys.argv[1:]
source_dir = os.path.abspath(source_dir)
if not os.path.isfile(sys.argv[1]):
raise SystemExit("documentation build did not produce its stamp file")
if not os.path.isfile(os.path.join(source_dir, "index.html")):
raise SystemExit("documentation build did not produce index.html")
if os.path.isabs(datadir):
destdir = os.environ.get("DESTDIR", "")
if destdir:
data_root = os.path.join(destdir, datadir.lstrip("/\\"))
else:
data_root = datadir
else:
data_root = os.path.join(os.environ["MESON_INSTALL_DESTDIR_PREFIX"], datadir)
destination = os.path.join(data_root, "doc", "zoitechat", "html")
shutil.rmtree(destination, ignore_errors=True)
os.makedirs(os.path.dirname(destination), exist_ok=True)
shutil.copytree(source_dir, destination)
if __name__ == "__main__":
main()

View File

@@ -54,6 +54,7 @@
"buildsystem": "meson",
"config-opts": [
"-Ddbus-service-use-appid=true",
"-Dinstall-docs=false",
"-Dwith-perl=perl",
"-Dwith-python=python3",
"-Dwith-lua=lua"

View File

@@ -35,6 +35,9 @@ config_h.set_quoted('PACKAGE_NAME', meson.project_name())
config_h.set_quoted('GETTEXT_PACKAGE', 'zoitechat')
config_h.set_quoted('LOCALEDIR', join_paths(get_option('prefix'),
get_option('datadir'), 'locale'))
config_h.set_quoted('ZOITECHAT_DOCDIR',
join_paths(get_option('prefix'), get_option('datadir'), 'doc', 'zoitechat', 'html')
)
config_h.set10('ENABLE_NLS', true)
# Optional features
@@ -160,6 +163,41 @@ foreach ldflag : test_ldflags
endforeach
add_project_link_arguments(global_ldflags, language: 'c')
if get_option('install-docs')
docs_python = find_program('python3', 'python')
docs_sphinx = run_command(docs_python, '-c', 'import sphinx', check: false)
if docs_sphinx.returncode() != 0
error('Sphinx is required to build the local HTML documentation. Install Sphinx or configure with -Dinstall-docs=false.')
endif
docs_source_dir = join_paths(meson.source_root(), 'docs')
docs_output_dir = join_paths(meson.build_root(), 'docs-html')
docs_build_script = join_paths(docs_source_dir, 'build-docs.py')
docs_install_script = join_paths(docs_source_dir, 'install-docs.py')
docs_target = custom_target(
'html-documentation',
output: 'html-documentation.stamp',
command: [
docs_python,
docs_build_script,
docs_source_dir,
docs_output_dir,
'@OUTPUT@',
],
build_by_default: true,
build_always_stale: true,
)
meson.add_install_script(
docs_python,
docs_install_script,
docs_target,
docs_output_dir,
get_option('datadir'),
)
endif
subdir('src')
if get_option('plugin')
subdir('plugins')

View File

@@ -33,6 +33,9 @@ option('install-appdata', type: 'boolean',
option('install-plugin-metainfo', type: 'boolean', value: false,
description: 'Installs metainfo files for enabled plugins, useful when distros create split packages'
)
option('install-docs', type: 'boolean', value: true,
description: 'Build and install the local HTML documentation'
)
# Plugins
option('with-checksum', type: 'boolean',

View File

@@ -15,6 +15,7 @@ BuildRequires: perl
BuildRequires: perl-devel
BuildRequires: python3
BuildRequires: python3-cffi
BuildRequires: python3-sphinx
BuildRequires: publicsuffix-list
BuildRequires: xwayland-run
BuildRequires: weston
@@ -87,6 +88,7 @@ xwfb-run -- /usr/bin/meson test -C %{_vpath_builddir} --num-processes %{_smp_bui
%{_datadir}/icons/hicolor/scalable/apps/net.zoite.Zoitechat.svg
%{_datadir}/metainfo/net.zoite.Zoitechat.appdata.xml
%{_datadir}/metainfo/net.zoite.Zoitechat*.metainfo.xml
%{_datadir}/doc/zoitechat/html/
%dir %{_libdir}/zoitechat
%dir %{_libdir}/zoitechat/plugins
%dir %{_libdir}/zoitechat/python

View File

@@ -925,217 +925,10 @@ mg_send_reply_or_text (session *sess, char *cmd)
mg_reply_update (sess);
}
typedef struct
{
gboolean bold;
gboolean italic;
gboolean underline;
gboolean strikethrough;
gboolean reverse;
gint foreground;
gint background;
gboolean pending_foreground;
gboolean pending_background;
} MgInputFormatState;
static void
mg_input_format_state_at_cursor (GtkEntry *entry, MgInputFormatState *state)
{
const char *text;
const char *cursor;
gsize limit;
gsize i;
gint cursor_pos;
memset (state, 0, sizeof (*state));
state->foreground = -1;
state->background = -1;
text = gtk_entry_get_text (entry);
cursor_pos = gtk_editable_get_position (GTK_EDITABLE (entry));
if (!text || cursor_pos < 0)
return;
cursor = g_utf8_offset_to_pointer (text, cursor_pos);
limit = (gsize) (cursor - text);
for (i = 0; i < limit;)
{
guchar ch = (guchar) text[i++];
switch (ch)
{
case ATTR_BOLD:
state->bold = !state->bold;
break;
case ATTR_ITALICS:
state->italic = !state->italic;
break;
case ATTR_UNDERLINE:
state->underline = !state->underline;
break;
case ATTR_STRIKETHROUGH:
state->strikethrough = !state->strikethrough;
break;
case ATTR_REVERSE:
state->reverse = !state->reverse;
break;
case ATTR_RESET:
case '\n':
state->bold = FALSE;
state->italic = FALSE;
state->underline = FALSE;
state->strikethrough = FALSE;
state->reverse = FALSE;
state->foreground = -1;
state->background = -1;
state->pending_foreground = FALSE;
state->pending_background = FALSE;
break;
case ATTR_COLOR:
{
gint value = 0;
gint digits = 0;
state->pending_foreground = FALSE;
state->pending_background = FALSE;
if (i >= limit)
{
state->pending_foreground = TRUE;
break;
}
if (!g_ascii_isdigit (text[i]))
{
state->foreground = -1;
state->background = -1;
break;
}
while (i < limit && digits < 2 && g_ascii_isdigit (text[i]))
{
value = (value * 10) + (text[i] - '0');
i++;
digits++;
}
state->foreground = value;
state->background = -1;
if (i < limit && text[i] == ',')
{
i++;
if (i >= limit)
{
state->pending_background = TRUE;
break;
}
value = 0;
digits = 0;
while (i < limit && digits < 2 && g_ascii_isdigit (text[i]))
{
value = (value * 10) + (text[i] - '0');
i++;
digits++;
}
if (digits > 0)
state->background = value;
}
}
break;
default:
break;
}
}
}
static void
mg_input_format_append (GString *summary, const char *text)
{
if (summary->len > 0)
g_string_append (summary, " · ");
g_string_append (summary, text);
}
static void
mg_input_format_update (GtkEntry *entry)
{
GtkWidget *format_box;
GtkWidget *format_label;
MgInputFormatState state;
GString *summary;
char color[48];
char *markup;
format_box = g_object_get_data (G_OBJECT (entry), "zoitechat-format-box");
format_label = g_object_get_data (G_OBJECT (entry), "zoitechat-format-label");
if (!format_box || !format_label)
return;
if (!prefs.hex_gui_input_attr)
{
gtk_widget_hide (format_box);
return;
}
mg_input_format_state_at_cursor (entry, &state);
summary = g_string_new (NULL);
if (state.bold)
mg_input_format_append (summary, "<b>Bold</b>");
if (state.italic)
mg_input_format_append (summary, "<i>Italic</i>");
if (state.underline)
mg_input_format_append (summary, "<u>Underline</u>");
if (state.strikethrough)
mg_input_format_append (summary, "<s>Strikethrough</s>");
if (state.reverse)
mg_input_format_append (summary, "Reverse");
if (state.foreground >= 0)
{
g_snprintf (color, sizeof (color), "Text color <b>%02d</b>", state.foreground);
mg_input_format_append (summary, color);
}
if (state.background >= 0)
{
g_snprintf (color, sizeof (color), "Background <b>%02d</b>", state.background);
mg_input_format_append (summary, color);
}
if (state.pending_foreground)
mg_input_format_append (summary, "Color: type foreground[,background]");
else if (state.pending_background)
mg_input_format_append (summary, "Background: type color");
if (summary->len == 0)
{
gtk_widget_hide (format_box);
g_string_free (summary, TRUE);
return;
}
markup = g_strdup_printf ("<span foreground='#7d8790'>Formatting · %s</span>", summary->str);
gtk_label_set_markup (GTK_LABEL (format_label), markup);
gtk_widget_show (format_label);
gtk_widget_show (format_box);
g_free (markup);
g_string_free (summary, TRUE);
}
static void
mg_inputbox_cursor_changed (GObject *object, GParamSpec *pspec, gpointer userdata)
{
(void) pspec;
(void) userdata;
mg_input_format_update (GTK_ENTRY (object));
}
static void
mg_inputbox_changed (GtkEditable *editable, session_gui *gui)
{
key_check_replace_on_change (editable, NULL);
mg_input_format_update (GTK_ENTRY (editable));
if (current_sess && current_sess->gui == gui)
mg_typing_update (current_sess, gtk_entry_get_text (GTK_ENTRY (editable)));
}
@@ -5006,7 +4799,7 @@ mg_create_search(session *sess, GtkWidget *box)
static void
mg_create_entry (session *sess, GtkWidget *box)
{
GtkWidget *hbox, *but, *entry, *format_box, *format_label;
GtkWidget *hbox, *but, *entry;
session_gui *gui = sess->gui;
const char *emoji_fallback_icon_names[] = {
"face-smile-symbolic",
@@ -5018,16 +4811,6 @@ mg_create_entry (session *sess, GtkWidget *box)
};
const char *emoji_fallback_icon_name;
format_box = mg_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 6);
gtk_widget_set_name (format_box, "zoitechat-formatbar");
gtk_widget_set_no_show_all (format_box, TRUE);
gtk_box_pack_start (GTK_BOX (box), format_box, 0, 0, 0);
format_label = gtk_label_new ("");
gtk_label_set_ellipsize (GTK_LABEL (format_label), PANGO_ELLIPSIZE_END);
gtk_box_pack_start (GTK_BOX (format_box), format_label, TRUE, TRUE, 8);
gtk_widget_show (format_label);
gtk_widget_hide (format_box);
gui->reply_box = mg_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 6);
gtk_widget_set_name (gui->reply_box, "zoitechat-replybar");
gtk_widget_set_no_show_all (gui->reply_box, TRUE);
@@ -5058,16 +4841,12 @@ mg_create_entry (session *sess, GtkWidget *box)
gui->input_box = entry = sexy_spell_entry_new ();
sexy_spell_entry_set_checked ((SexySpellEntry *)entry, prefs.hex_gui_input_spell);
sexy_spell_entry_set_parse_attributes ((SexySpellEntry *)entry, prefs.hex_gui_input_attr);
g_object_set_data (G_OBJECT (entry), "zoitechat-format-box", format_box);
g_object_set_data (G_OBJECT (entry), "zoitechat-format-label", format_label);
gtk_entry_set_max_length (GTK_ENTRY (gui->input_box), 0);
g_signal_connect (G_OBJECT (entry), "activate",
G_CALLBACK (mg_inputbox_cb), gui);
g_signal_connect (G_OBJECT (entry), "changed",
G_CALLBACK (mg_inputbox_changed), gui);
g_signal_connect (G_OBJECT (entry), "notify::cursor-position",
G_CALLBACK (mg_inputbox_cursor_changed), gui);
gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
gtk_widget_set_name (entry, "zoitechat-inputbox");

View File

@@ -1740,9 +1740,50 @@ menu_ctcpguiopen (void)
editlist_gui_open (NULL, NULL, ctcp_list, buf, "ctcpreply", "ctcpreply.conf", ctcp_help);
}
static char *
menu_find_local_docs (void)
{
char *path;
#ifdef WIN32
char *base_path;
base_path = g_win32_get_package_installation_directory_of_module (NULL);
if (!base_path)
return NULL;
path = g_build_filename (base_path, "share", "doc", "zoitechat", "html", "index.html", NULL);
g_free (base_path);
#else
const char *appdir;
appdir = g_getenv ("APPDIR");
if (appdir && *appdir)
path = g_build_filename (appdir, "usr", "share", "doc", "zoitechat", "html", "index.html", NULL);
else
path = g_build_filename (ZOITECHAT_DOCDIR, "index.html", NULL);
#endif
if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
return path;
g_free (path);
return NULL;
}
static void
menu_docs (GtkWidget *wid, gpointer none)
{
char *path;
path = menu_find_local_docs ();
if (path)
{
fe_open_url (path);
g_free (path);
return;
}
fe_open_url ("https://docs.zoitechat.org/en/latest/");
}

View File

@@ -30,6 +30,8 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Target Name="Build">
<Exec Command="&quot;$(Python3Path)\python.exe&quot; &quot;$(SolutionDir)..\docs\build-docs.py&quot; &quot;$(SolutionDir)..\docs&quot; &quot;$(ZoiteChatBuild)\$(ZoiteChatPlatform)\docs-html&quot; &quot;$(ZoiteChatBuild)\$(ZoiteChatPlatform)\html-documentation.stamp&quot;" />
<ItemGroup>
<None Include="$(DepsRoot)\bin\*atk-1.0-0.dll" />
<None Include="$(DepsRoot)\bin\*cairo*.dll" />
@@ -82,6 +84,7 @@
<GdkPixbufLoaderCache Include="$(DepsRoot)\lib\gdk-pixbuf-2.0\**\loaders.cache" />
<FontConfig Include="$(DepsRoot)\etc\fonts\*" />
<Docs Include="$(ZoiteChatBuild)\$(ZoiteChatPlatform)\docs-html\**\*" />
<Share Include="share\**\*" />
<Locale Include="$(ZoiteChatBin)locale\**\*;$(DepsRoot)\share\locale\**\*" />
<MSWindowsTheme Include="$(DepsRoot)\share\themes\MS-Windows\**\*" />
@@ -97,6 +100,7 @@
<Copy SourceFiles="@(GdkPixbufLoaderCache)" DestinationFiles="@(GdkPixbufLoaderCache->'$(ZoiteChatRel)\lib\gdk-pixbuf-2.0\%(RecursiveDir)%(Filename)%(Extension)')" />
<Copy SourceFiles="@(GSettingsSchemas)" DestinationFiles="@(GSettingsSchemas->'$(ZoiteChatRel)\share\glib-2.0\schemas\%(Filename)%(Extension)')" />
<Copy SourceFiles="@(Share)" DestinationFiles="@(Share->'$(ZoiteChatRel)\share\%(RecursiveDir)%(Filename)%(Extension)')" />
<Copy SourceFiles="@(Docs)" DestinationFiles="@(Docs->'$(ZoiteChatRel)\share\doc\zoitechat\html\%(RecursiveDir)%(Filename)%(Extension)')" />
<Copy SourceFiles="..\..\COPYING" DestinationFolder="$(ZoiteChatRel)\share\doc\zoitechat" />
<Copy SourceFiles="$(WinSparklePath)\COPYING" DestinationFolder="$(ZoiteChatRel)\share\doc\WinSparkle" />
<Copy SourceFiles="@(EnchantProviders)" DestinationFolder="$(ZoiteChatRel)\lib\enchant-2" />