From 238e7a2bb961eb448dee1542e03cbdb84dea027d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?=
Date: Sun, 11 Jun 2023 16:18:21 +0200 Subject: [PATCH] Merge TUI and GUI binaries, using a new name The appropriate interface will be chosen automatically. --- .gitignore | 12 +-- CMakeLists.txt | 120 +++++++++++++++--------------- LICENSE | 2 +- README.adoc | 29 ++++---- config.h.in | 1 + docs/{sdtui.1.adoc => tdv.1.adoc} | 24 +++--- po/{sdtui.pot => tdv.pot} | 0 src/query-tool.c | 2 +- src/{sdgui.c => tdv-gui.c} | 40 ++-------- src/{sdtui.c => tdv-tui.c} | 51 +------------ src/tdv.c | 98 ++++++++++++++++++++++++ sdgui.desktop => tdv.desktop | 8 +- sdtui.png => tdv.png | Bin sdgui.svg => tdv.svg | 0 sdgui.xml => tdv.xml | 0 15 files changed, 208 insertions(+), 179 deletions(-) rename docs/{sdtui.1.adoc => tdv.1.adoc} (81%) rename po/{sdtui.pot => tdv.pot} (100%) rename src/{sdgui.c => tdv-gui.c} (95%) rename src/{sdtui.c => tdv-tui.c} (97%) create mode 100644 src/tdv.c rename sdgui.desktop => tdv.desktop (63%) rename sdtui.png => tdv.png (100%) rename sdgui.svg => tdv.svg (100%) rename sdgui.xml => tdv.xml (100%) diff --git a/.gitignore b/.gitignore index 4d504d9..576f5fc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,9 +3,9 @@ # Qt Creator files /CMakeLists.txt.user* -/sdtui.cflags -/sdtui.cxxflags -/sdtui.config -/sdtui.files -/sdtui.creator* -/sdtui.includes +/tdv.cflags +/tdv.cxxflags +/tdv.config +/tdv.files +/tdv.creator* +/tdv.includes diff --git a/CMakeLists.txt b/CMakeLists.txt index 86c49ff..9d4c494 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,15 @@ cmake_minimum_required (VERSION 3.0) -project (sdtui VERSION 0.1.0 LANGUAGES C) +project (tdv VERSION 0.1.0 LANGUAGES C) -# Moar warnings +# Adjust warnings if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUCC) set (ignores "-Wno-missing-field-initializers -Wno-cast-function-type") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 ${ignores}") set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra") endif () +add_definitions (-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_38) + # For custom modules set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) @@ -108,6 +110,7 @@ if (WITH_GUI) message (FATAL_ERROR "GTK+ not found") endif () + include_directories (${gtk_INCLUDE_DIRS}) link_directories (${gtk_LIBRARY_DIRS}) endif () @@ -198,25 +201,7 @@ configure_file (${PROJECT_SOURCE_DIR}/config.h.in ${PROJECT_BINARY_DIR}/config.h) include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR}) -# Primary target source files -set (project_sources - src/${PROJECT_NAME}.c) -set (project_headers - ${project_common_headers}) - -# Build the main executable and link it -add_definitions (-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_38) -if (NOT WIN32) - add_executable (${PROJECT_NAME} - ${project_sources} ${project_headers} ${project_common_sources}) - target_link_libraries (${PROJECT_NAME} ${project_common_libraries} - ${Ncursesw_LIBRARIES} termo-static) - if (WITH_X11) - target_link_libraries (${PROJECT_NAME} ${xcb_LIBRARIES}) - endif () -endif (NOT WIN32) - -# The same for the alternative GTK+ UI +# Icon generation utilities if (NOT ${CMAKE_VERSION} VERSION_LESS 3.18.0) set (find_program_REQUIRE REQUIRED) endif () @@ -224,7 +209,7 @@ endif () function (icon_to_png svg size output_dir output) set (_dimensions ${size}x${size}) set (_png_path ${output_dir}/hicolor/${_dimensions}/apps) - set (_png ${_png_path}/sdgui.png) + set (_png ${_png_path}/${PROJECT_NAME}.png) set (${output} ${_png} PARENT_SCOPE) find_program (rsvg_convert_EXECUTABLE rsvg-convert ${find_program_REQUIRE}) @@ -244,8 +229,17 @@ function (icon_for_win32 pngs ico) COMMENT "Generating Windows program icon" VERBATIM) endfunction () +# Build the main executable and link it +set (project_libraries + ${project_common_libraries}) +set (project_sources + ${project_common_sources} + src/${PROJECT_NAME}.c) +set (project_headers + ${project_common_headers}) + if (WITH_GUI) - set (icon_svg ${PROJECT_SOURCE_DIR}/sdgui.svg) + set (icon_svg ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.svg) set (icon_base ${PROJECT_BINARY_DIR}/icons) # The largest size is mainly for an appropriately sized Windows icon @@ -254,31 +248,42 @@ if (WITH_GUI) icon_to_png (${icon_svg} ${icon_size} ${icon_base} icon_png) list (APPEND icon_png_list ${icon_png}) endforeach () - add_custom_target (sdgui-icons ALL DEPENDS ${icon_png_list}) - - set (sdgui_sources - src/sdgui.c - src/stardict-view.c - ${project_common_sources}) - - if (WIN32) - set (icon_ico ${PROJECT_BINARY_DIR}/sdgui.ico) - icon_for_win32 ("${icon_png_list}" ${icon_ico}) - - set (resource_file ${PROJECT_BINARY_DIR}/sdgui.rc) - list (APPEND sdgui_sources ${resource_file}) - add_custom_command (OUTPUT ${resource_file} - COMMAND ${CMAKE_COMMAND} -E echo "1 ICON \"sdgui.ico\"" - > ${resource_file} VERBATIM) - set_property (SOURCE ${resource_file} - APPEND PROPERTY OBJECT_DEPENDS ${icon_ico}) - endif () + add_custom_target (icons ALL DEPENDS ${icon_png_list}) +endif () - add_executable (sdgui WIN32 ${sdgui_sources}) - target_include_directories (sdgui PUBLIC ${gtk_INCLUDE_DIRS}) - target_link_libraries (sdgui ${project_common_libraries} ${gtk_LIBRARIES}) +if (WIN32) + set (icon_ico ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.ico) + icon_for_win32 ("${icon_png_list}" ${icon_ico}) + + set (resource_file ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.rc) + list (APPEND project_sources ${resource_file}) + add_custom_command (OUTPUT ${resource_file} + COMMAND ${CMAKE_COMMAND} -E echo "1 ICON \"${PROJECT_NAME}.ico\"" + > ${resource_file} VERBATIM) + set_property (SOURCE ${resource_file} + APPEND PROPERTY OBJECT_DEPENDS ${icon_ico}) +else () + list (APPEND project_libraries ${Ncursesw_LIBRARIES} termo-static) + list (APPEND project_sources + src/${PROJECT_NAME}-tui.c) endif () +if (WITH_X11) + list (APPEND project_libraries ${xcb_LIBRARIES}) +endif () +if (WITH_GUI) + list (APPEND project_libraries ${gtk_LIBRARIES}) + list (APPEND project_sources + src/${PROJECT_NAME}-gui.c + src/stardict-view.c) + + add_executable (${PROJECT_NAME} WIN32 ${project_sources} ${project_headers}) +else () + add_executable (${PROJECT_NAME} ${project_sources} ${project_headers}) +endif () + +target_link_libraries (${PROJECT_NAME} ${project_libraries}) + # Tools set (tools tabfile add-pronunciation query-tool transform) foreach (tool ${tools}) @@ -311,14 +316,13 @@ if (NOT WIN32) install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR}) if (WITH_GUI) - install (TARGETS sdgui DESTINATION ${CMAKE_INSTALL_BINDIR}) - install (FILES sdgui.svg + install (FILES ${PROJECT_NAME}.svg DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps) install (DIRECTORY ${PROJECT_BINARY_DIR}/icons DESTINATION ${CMAKE_INSTALL_DATADIR}) - install (FILES sdgui.desktop + install (FILES ${PROJECT_NAME}.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications) - install (FILES sdgui.xml + install (FILES ${PROJECT_NAME}.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/mime/packages) endif () @@ -329,7 +333,7 @@ if (NOT WIN32) endforeach () elseif (WITH_GUI) # This rather crude filter has been mostly copied over from logdiag - install (TARGETS sdgui DESTINATION .) + install (TARGETS ${PROJECT_NAME} DESTINATION .) install (DIRECTORY ${win32_deps_prefix}/bin/ DESTINATION . @@ -377,7 +381,7 @@ if (BUILD_TESTING) find_program (xmlwf_EXECUTABLE xmlwf) find_program (xmllint_EXECUTABLE xmllint) - foreach (xml sdgui.xml) + foreach (xml ${PROJECT_NAME}.xml) if (xmlwf_EXECUTABLE) add_test (test-xmlwf-${xml} ${xmlwf_EXECUTABLE} ${PROJECT_SOURCE_DIR}/${xml}) @@ -397,7 +401,7 @@ if (BUILD_TESTING) endif () # CPack -set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "StarDict TUI and GUI") +set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Translation dictionary viewer") set (CPACK_PACKAGE_VENDOR "Premysl Eric Janouch") set (CPACK_PACKAGE_CONTACT "Přemysl Eric Janouch
") set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE") @@ -413,17 +417,17 @@ set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}") set (CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON) set (CPACK_PACKAGE_INSTALL_REGISTRY_KEY "${PROJECT_NAME}") -set (CPACK_NSIS_INSTALLED_ICON_NAME sdgui.exe) -set (CPACK_PACKAGE_EXECUTABLES sdgui sdgui) +set (CPACK_NSIS_INSTALLED_ICON_NAME ${PROJECT_NAME}.exe) +set (CPACK_PACKAGE_EXECUTABLES ${PROJECT_NAME} ${PROJECT_NAME}) set (CPACK_NSIS_EXECUTABLES_DIRECTORY .) set (CPACK_NSIS_EXTRA_INSTALL_COMMANDS [[ - WriteRegStr HKCR '.ifo' '' 'sdgui.Dictionary' - WriteRegStr HKCR 'sdgui.Dictionary' '' 'StarDict Dictionary' - WriteRegStr HKCR 'sdgui.Dictionary\\shell\\open\\command' '' '\"$INSTDIR\\sdgui.exe\" \"%1\"' + WriteRegStr HKCR '.ifo' '' 'tdv.Dictionary' + WriteRegStr HKCR 'tdv.Dictionary' '' 'StarDict Dictionary' + WriteRegStr HKCR 'tdv.Dictionary\\shell\\open\\command' '' '\"$INSTDIR\\tdv.exe\" \"%1\"' System::Call 'shell32::SHChangeNotify(i,i,i,i) (0x08000000, 0x1000, 0, 0)' ]]) set (CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS [[ - DeleteRegKey HKCR 'sdgui.Dictionary' + DeleteRegKey HKCR 'tdv.Dictionary' System::Call 'shell32::SHChangeNotify(i,i,i,i) (0x08000000, 0x1000, 0, 0)' ]]) diff --git a/LICENSE b/LICENSE index f1407c8..7f1d888 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2013 - 2022, Přemysl Eric Janouch
+Copyright (c) 2013 - 2023, Přemysl Eric Janouch
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. diff --git a/README.adoc b/README.adoc index 9667784..0d9ca4e 100644 --- a/README.adoc +++ b/README.adoc @@ -1,20 +1,19 @@ -StarDict Terminal and Graphical UI -================================== +Translation dictionary viewer +============================= -'sdtui' aims to provide an easy way of viewing translation as well as other -kinds of dictionaries in your terminal, and is inspired by the dictionary -component of PC Translator. I wasn't successful in finding any free software -of this kind, GUI or not, and thus decided to write my own. +'tdv' aims to provide an easy way of viewing translation as well as other kinds +of StarDict dictionaries, and is inspired by the dictionary component +of PC Translator. I was unsuccessful in finding any free software of this kind, +and thus decided to write my own. The project is covered by a permissive license, unlike vast majority of other similar projects, and can serve as a base for implementing other dictionary software. -image::sdtui.png[align="center"] +image::tdv.png[align="center"] -As a recent addition, there is now an alternative GTK+ 3 based frontend as well, -called 'sdgui'. It shares its dictionary list with 'sdtui', but styling will -follow your theme, and may be customized from 'gtk.css'. +As a recent addition, the program also offers a GTK+ 3 based user interface, +whose styling will follow your theme, and may be customized from 'gtk.css'. Packages -------- @@ -23,7 +22,7 @@ a package with the latest development version from Archlinux's AUR. Documentation ------------- -See the link:docs/sdtui.1.adoc[man page] for information about usage. +See the link:docs/tdv.1.adoc[man page] for information about usage. The rest of this README will concern itself with externalities. Building and Running @@ -51,16 +50,16 @@ To install the application, you can do either the usual: Or you can try telling CMake to make a package for you. For Debian it is: $ cpack -G DEB - # dpkg -i sdtui-*.deb + # dpkg -i tdv-*.deb Having the program installed, simply run it with a StarDict '.ifo' file as an argument. It is, however, preferable to -link:docs/sdtui.1.adoc#_configuration[configure it] to load your dictionaries +link:docs/tdv.1.adoc#_configuration[configure it] to load your dictionaries automatically. Windows ~~~~~~~ -With the help of Mingw-w64 and WINE, 'sdgui' will successfully cross-compile +With the help of Mingw-w64 and WINE, 'tdv' will successfully cross-compile for Windows. It isn't particularly usable on that system, if only because selection watching is a very X11/Wayland-specific feature. Beware that build dependencies take up almost a gigabyte of disk space. @@ -91,7 +90,7 @@ https://mega.co.nz/#!axtD0QRK!sbtBgizksyfkPqKvKEgr8GQ11rsWhtqyRgUUV0B7pwg[CZ <-- Further Development ------------------- -While I've been successfully using 'sdtui' for many years now, some issues +While I've been successfully using 'tdv' for many years now, some issues should be addressed before including the software in regular Linux and/or BSD distributions: diff --git a/config.h.in b/config.h.in index 4fef753..eae452a 100644 --- a/config.h.in +++ b/config.h.in @@ -8,6 +8,7 @@ #define GETTEXT_DIRNAME "${CMAKE_INSTALL_PREFIX}/share/locale" #cmakedefine WITH_X11 +#cmakedefine WITH_GUI #cmakedefine HAVE_RESIZETERM #endif // ! CONFIG_H diff --git a/docs/sdtui.1.adoc b/docs/tdv.1.adoc similarity index 81% rename from docs/sdtui.1.adoc rename to docs/tdv.1.adoc index 71bd904..f7961e2 100644 --- a/docs/sdtui.1.adoc +++ b/docs/tdv.1.adoc @@ -1,21 +1,21 @@ -sdtui(1) -======== +tdv(1) +====== :doctype: manpage -:manmanual: sdtui Manual -:mansource: sdtui {release-version} +:manmanual: tdv Manual +:mansource: tdv {release-version} Name ---- -sdtui - StarDict terminal UI +tdv - Translation dictionary viewer Synopsis -------- -*sdtui* [_OPTION_]... [_DICTIONARY_.ifo]... +*tdv* [_OPTION_]... [_DICTIONARY_.ifo]... Description ----------- -*sdtui* is a StarDict dictionary viewer, custom-tailored for translation -dictionaries, with a simple curses-based terminal UI. +*tdv* is a StarDict dictionary viewer, custom-tailored for translation +dictionaries, with a simple curses-based terminal UI, and a GTK+ graphical UI. Without any command line arguments, the program expects to find a list of dictionaries to load on start-up in its configuration file. The _.ifo_ files @@ -32,7 +32,7 @@ Options Configuration ------------- -You can start your _sdtui.conf_ file with the following snippet: +You can start your _tdv.conf_ file with the following snippet: [Settings] center-search = true # Ensure visibility of preceding entries? @@ -75,16 +75,16 @@ Extensions ---------- Because the StarDict file format is a bit of a clusterfuck with regard to collation of dictionary entries, this software introduces an additional, -optional "collation" field into the _.ifo_ file. When *sdtui* discovers this +optional "collation" field into the _.ifo_ file. When *tdv* discovers this field while reading a dictionary, it automatically reorders the index according to that locale (e.g., "cs_CZ"). This operation may take a little while, in the order of seconds. Files ----- -*sdtui* follows the XDG Base Directory Specification. +*tdv* follows the XDG Base Directory Specification. -_~/.config/sdtui/sdtui.conf_:: +_~/.config/tdv/tdv.conf_:: The configuration file. Reporting bugs diff --git a/po/sdtui.pot b/po/tdv.pot similarity index 100% rename from po/sdtui.pot rename to po/tdv.pot diff --git a/src/query-tool.c b/src/query-tool.c index 825bada..6cfdc66 100644 --- a/src/query-tool.c +++ b/src/query-tool.c @@ -6,7 +6,7 @@ * finalised with an empty line. Newlines are escaped with `\n', * backslashes with `\\'. * - * So far only the `m', `g`, and `x` fields are supported, as in sdtui. + * So far only the `m', `g`, and `x` fields are supported, as in tdv. * * Copyright (c) 2013 - 2021, Přemysl Eric Janouch
*
diff --git a/src/sdgui.c b/src/tdv-gui.c
similarity index 95%
rename from src/sdgui.c
rename to src/tdv-gui.c
index 993d1f5..fcb254f 100644
--- a/src/sdgui.c
+++ b/src/tdv-gui.c
@@ -19,7 +19,6 @@
#include
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+#include "config.h"
+
+#include