Mercurial > minori
changeset 221:53211cb1e7f5
library: add initial library stuff
nice
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Mon, 08 Jan 2024 13:21:08 -0500 |
parents | 79a87a6dd39d |
children | b9f111d84d95 |
files | CMakeLists.txt dep/animia/CMakeLists.txt dep/animia/src/win/wayland.cc include/core/config.h include/core/ini.h include/core/session.h src/core/config.cc src/core/filesystem.cc src/core/http.cc src/core/strings.cc src/gui/dialog/about.cc src/gui/pages/torrents.cc |
diffstat | 12 files changed, 111 insertions(+), 95 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Mon Jan 08 11:56:09 2024 -0500 +++ b/CMakeLists.txt Mon Jan 08 13:21:08 2024 -0500 @@ -99,6 +99,9 @@ src/services/services.cc src/services/anilist.cc + # Library + src/library/library.cc + # Tracking src/track/media.cc
--- a/dep/animia/CMakeLists.txt Mon Jan 08 11:56:09 2024 -0500 +++ b/dep/animia/CMakeLists.txt Mon Jan 08 13:21:08 2024 -0500 @@ -86,65 +86,68 @@ list(APPEND DEFINES HAVE_KVM_GETFILES) endif() # LIBKVM_HAS_GETFILES endif() # LINUX - - # X11 - find_package(X11 COMPONENTS X11 XRes) +endif() # WIN32 AND APPLE - if(X11_FOUND) - # Getting PIDs from windows... - if (X11_XRes_FOUND) - list(APPEND DEFINES HAVE_XRES) - else() # NOT X11_XRes_FOUND - message(WARNING "libXRes could not be found! Finding PIDs in X11 windows may not work correctly!") - endif() # X11_XRes_FOUND +# It's technically possible to have an X server on macOS, so we +# should compile X11 support. +# X11 +find_package(X11 COMPONENTS X11 XRes) - list(APPEND DEFINES X11) - list(APPEND SRC_FILES src/win/x11.cc) - list(APPEND INCLUDE_DIRS ${X11_INCLUDE_DIRS}) - list(APPEND LIBRARIES ${X11_LIBRARIES}) # This will include Xres, I think.. - else() # NOT X11_FOUND - # For some systems, i.e. Debian, FindX11 fails to find X11, so we have - # to use pkg_config as a fallback - find_package(PkgConfig) - if(PKG_CONFIG_FOUND) - pkg_check_modules(X11 x11) - if(X11_FOUND) - # Check for XRes the hard way - find_path(X11_XRes_HEADER "X11/extensions/XRes.h" PATHS ${X11_INCLUDE_DIRS}) - find_library(X11_XRes_LIB XRes PATHS ${X11_LIBRARY_DIRS}) +if(X11_FOUND) + # Getting PIDs from windows... + if (X11_XRes_FOUND) + list(APPEND DEFINES HAVE_XRES) + else() # NOT X11_XRes_FOUND + message(WARNING "libXRes could not be found! Finding PIDs in X11 windows may not work correctly!") + endif() # X11_XRes_FOUND - if(X11_XRes_HEADER AND X11_XRes_LIB) - # TODO: We should REALLY check for XResQueryClientIds here... - list(APPEND DEFINES HAVE_XRES) - list(APPEND LIBRARIES ${X11_XRes_LIB}) - else() - message(WARNING "libXRes could not be found! Finding PIDs in X11 windows may not work correctly!") - endif() - - list(APPEND DEFINES X11) - list(APPEND SRC_FILES src/win/x11.cc) - list(APPEND INCLUDE_DIRS ${X11_INCLUDE_DIRS}) - list(APPEND LIBRARIES ${X11_LINK_LIBRARIES}) - endif() # X11_FOUND - endif() # PKG_CONFIG_FOUND - endif() # X11_FOUND - + list(APPEND DEFINES X11) + list(APPEND SRC_FILES src/win/x11.cc) + list(APPEND INCLUDE_DIRS ${X11_INCLUDE_DIRS}) + list(APPEND LIBRARIES ${X11_LIBRARIES}) # This will include Xres, I think.. +else() # NOT X11_FOUND + # For some systems, i.e. Debian, FindX11 fails to find X11, so we have + # to use pkg_config as a fallback find_package(PkgConfig) if(PKG_CONFIG_FOUND) - pkg_check_modules(WAYLAND wayland-client) - if(WAYLAND_FOUND) - enable_language(C) - list(APPEND DEFINES WAYLAND) - list(APPEND SRC_FILES - src/win/wayland.cc - src/win/wayland/ext-foreign-toplevel-list-v1.c - src/win/wayland/wlr-foreign-toplevel-management-unstable-v1.c - ) - list(APPEND INCLUDE_DIRS ${WAYLAND_INCLUDE_DIRS}) - list(APPEND LIBRARIES ${WAYLAND_LINK_LIBRARIES}) - endif() # WAYLAND_FOUND + pkg_check_modules(X11 x11) + if(X11_FOUND) + # Check for XRes the hard way + find_path(X11_XRes_HEADER "X11/extensions/XRes.h" PATHS ${X11_INCLUDE_DIRS}) + find_library(X11_XRes_LIB XRes PATHS ${X11_LIBRARY_DIRS}) + + if(X11_XRes_HEADER AND X11_XRes_LIB) + # TODO: We should REALLY check for XResQueryClientIds here... + list(APPEND DEFINES HAVE_XRES) + list(APPEND LIBRARIES ${X11_XRes_LIB}) + else() + message(WARNING "libXRes could not be found! Finding PIDs in X11 windows may not work correctly!") + endif() + + list(APPEND DEFINES X11) + list(APPEND SRC_FILES src/win/x11.cc) + list(APPEND INCLUDE_DIRS ${X11_INCLUDE_DIRS}) + list(APPEND LIBRARIES ${X11_LINK_LIBRARIES}) + endif() # X11_FOUND endif() # PKG_CONFIG_FOUND -endif() # WIN32 AND APPLE +endif() # X11_FOUND + +# Wayland. +find_package(PkgConfig) +if(PKG_CONFIG_FOUND) + pkg_check_modules(WAYLAND wayland-client) + if(WAYLAND_FOUND) + enable_language(C) + list(APPEND DEFINES WAYLAND) + list(APPEND SRC_FILES + src/win/wayland.cc + src/win/wayland/ext-foreign-toplevel-list-v1.c + src/win/wayland/wlr-foreign-toplevel-management-unstable-v1.c + ) + list(APPEND INCLUDE_DIRS ${WAYLAND_INCLUDE_DIRS}) + list(APPEND LIBRARIES ${WAYLAND_LINK_LIBRARIES}) + endif() # WAYLAND_FOUND +endif() # PKG_CONFIG_FOUND add_library(animia SHARED ${SRC_FILES}) set_target_properties(animia PROPERTIES
--- a/dep/animia/src/win/wayland.cc Mon Jan 08 11:56:09 2024 -0500 +++ b/dep/animia/src/win/wayland.cc Mon Jan 08 13:21:08 2024 -0500 @@ -56,7 +56,8 @@ .state = zwlr_foreign_handle_handle_state, .done = zwlr_foreign_handle_handle_done, .closed = zwlr_foreign_handle_handle_closed, - .parent = zwlr_foreign_handle_handle_parent}; + .parent = zwlr_foreign_handle_handle_parent +}; static void zwlr_toplevel_manager_handle_toplevel(void* data, struct zwlr_foreign_toplevel_manager_v1* manager, struct zwlr_foreign_toplevel_handle_v1* handle) { @@ -89,6 +90,11 @@ reinterpret_cast<Window*>(data)->text = title; } +static void ext_foreign_handle_handle_identifier(void*, ext_foreign_toplevel_handle_v1*, const char* identifier) { + if (identifier) + reinterpret_cast<Window*>(data)->id = identifier; +} + static void ext_foreign_handle_handle_done(void* data, struct ext_foreign_toplevel_handle_v1* handle) { if (handle) ext_foreign_toplevel_handle_v1_destroy(handle); @@ -97,9 +103,6 @@ static void ext_foreign_handle_handle_closed(void*, struct ext_foreign_toplevel_handle_v1*) { } -static void ext_foreign_handle_handle_identifier(void*, ext_foreign_toplevel_handle_v1*, const char*) { -} - static const struct ext_foreign_toplevel_handle_v1_listener ext_handle_listener = { .closed = ext_foreign_handle_handle_closed, .done = ext_foreign_handle_handle_done,
--- a/include/core/config.h Mon Jan 08 11:56:09 2024 -0500 +++ b/include/core/config.h Mon Jan 08 13:21:08 2024 -0500 @@ -26,37 +26,36 @@ Locale::Locale locale; struct { - public: - Anime::TitleLanguage language; - Anime::ScoreFormat score_format; - bool display_aired_episodes; - bool display_available_episodes; - bool highlight_anime_if_available; - bool highlighted_anime_above_others; + Anime::TitleLanguage language; + Anime::ScoreFormat score_format; + bool display_aired_episodes; + bool display_available_episodes; + bool highlight_anime_if_available; + bool highlighted_anime_above_others; } anime_list; /* these should preferably be in an "auth" struct... */ struct { - public: - struct { - public: - std::string auth_token; - std::string username; - int user_id; - } anilist; + struct { + std::string auth_token; + std::string username; + int user_id; + } anilist; } auth; struct { - public: - bool detect_media_players; - std::vector<MediaPlayer> players; + bool detect_media_players; + std::vector<MediaPlayer> players; } recognition; struct { - public: - std::string feed_link; + std::string feed_link; } torrents; + + struct { + std::vector<std::string> paths; + } library; }; #if (defined(WIN32) || defined(MACOSX))
--- a/include/core/ini.h Mon Jan 08 11:56:09 2024 -0500 +++ b/include/core/ini.h Mon Jan 08 13:21:08 2024 -0500 @@ -13,22 +13,19 @@ /* very simple tutorial on how to give anyone who reads your code an aneurysm */ -template< class... > -using void_t = void; - template <typename T, typename = void> struct is_toutf8string_available : std::false_type {}; template<typename T> struct is_toutf8string_available<T, - void_t<decltype(Strings::ToUtf8String(std::declval<T>()))>> : std::true_type {}; + std::void_t<decltype(Strings::ToUtf8String(std::declval<T>()))>> : std::true_type {}; template <typename T, typename = void> struct is_translation_available : std::false_type {}; template<typename T> struct is_translation_available<T, - void_t<decltype(Translate::ToString(std::declval<T>()))>> : std::true_type {}; + std::void_t<decltype(Translate::ToString(std::declval<T>()))>> : std::true_type {}; template<typename T> T GetIniValue(const mINI::INIStructure& ini, const std::string& section, @@ -38,7 +35,7 @@ const std::string val = ini.get(section).get(value); - if constexpr (std::is_arithmetic<T>::value) { + if constexpr (std::is_integral<T>::value) { /* Integer? */ if constexpr (std::is_same<T, bool>::value) { /* Boolean? */ @@ -59,11 +56,11 @@ auto& ini_key = ini[section][key]; if constexpr (is_translation_available<T>::value) { + /* prioritize translation */ ini_key = Translate::ToString(value); } else if constexpr (std::is_same<T, std::string>::value) { + /* lmfao */ ini_key = value; - } else if constexpr (std::is_arithmetic<T>::value && !std::is_same<T, bool>::value) { - ini_key = std::to_string(value); } else if constexpr (is_toutf8string_available<T>::value) { ini_key = Strings::ToUtf8String(value); }
--- a/include/core/session.h Mon Jan 08 11:56:09 2024 -0500 +++ b/include/core/session.h Mon Jan 08 13:21:08 2024 -0500 @@ -5,6 +5,8 @@ #include "gui/locale.h" #include <QElapsedTimer> +#include "semver/semver.hpp" + struct Session { public: Session() { timer.start(); } @@ -14,6 +16,7 @@ int uptime() { return timer.elapsed(); } Config config; + static constexpr semver::version version{0, 1, 0, semver::prerelease::alpha, 1}; private: unsigned int requests = 0;
--- a/src/core/config.cc Mon Jan 08 11:56:09 2024 -0500 +++ b/src/core/config.cc Mon Jan 08 13:21:08 2024 -0500 @@ -24,7 +24,8 @@ #include <QTextStream> /* I'll use an INI-based config file instead of using an - XML file like Taiga. */ + * XML file like Taiga. +*/ int Config::Load() { std::filesystem::path cfg_path = Filesystem::GetConfigPath();
--- a/src/core/filesystem.cc Mon Jan 08 11:56:09 2024 -0500 +++ b/src/core/filesystem.cc Mon Jan 08 13:21:08 2024 -0500 @@ -7,10 +7,7 @@ # include <sys/types.h> #endif -#ifdef WIN32 -# define DELIM "\\" -#else -# define DELIM "/" +#ifndef WIN32 # include <errno.h> # include <unistd.h> # include <sys/stat.h>
--- a/src/core/http.cc Mon Jan 08 11:56:09 2024 -0500 +++ b/src/core/http.cc Mon Jan 08 13:21:08 2024 -0500 @@ -28,6 +28,7 @@ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteCallback); /* Use system certs... useful on Windows. */ curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA); + curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); // threading CURLcode res = curl_easy_perform(curl); session.IncrementRequests(); curl_easy_cleanup(curl); @@ -53,6 +54,7 @@ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteCallback); /* Use system certs... useful on Windows. */ curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA); + curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); // threading CURLcode res = curl_easy_perform(curl); session.IncrementRequests(); curl_easy_cleanup(curl);
--- a/src/core/strings.cc Mon Jan 08 11:56:09 2024 -0500 +++ b/src/core/strings.cc Mon Jan 08 13:21:08 2024 -0500 @@ -24,7 +24,7 @@ if (vector.size() < 1) return "-"; - std::string out = ""; + std::string out; for (unsigned long long i = 0; i < vector.size(); i++) { out.append(vector.at(i)); @@ -49,7 +49,8 @@ } /* This function is really only used for cleaning up the synopsis of - horrible HTML debris from AniList :) */ + * horrible HTML debris from AniList :) +*/ std::string ReplaceAll(std::string string, const std::string& find, const std::string& replace) { size_t pos = 0; while ((pos = string.find(find, pos)) != std::string::npos) { @@ -90,7 +91,10 @@ std::string ParseHtmlEntities(std::string string) { const std::unordered_map<std::string, std::string> map = { /* The only one of these I can understand using are the first - three. why do the rest of these exist? */ + * three. why do the rest of these exist? + * + * probably mojibake. + */ {"<", "<"}, {"&rt;", ">"}, {" ", "\xA0"}, @@ -117,7 +121,8 @@ } /* let Qt handle the heavy lifting of locale shit - I don't want to deal with */ + * I don't want to deal with +*/ std::string ToUpper(const std::string& string) { return ToUtf8String(session.config.locale.GetLocale().toUpper(ToQString(string))); }
--- a/src/gui/dialog/about.cc Mon Jan 08 11:56:09 2024 -0500 +++ b/src/gui/dialog/about.cc Mon Jan 08 13:21:08 2024 -0500 @@ -1,6 +1,5 @@ #include "gui/dialog/about.h" #include "core/json.h" -#include "core/version.h" #include "core/session.h" #include "core/strings.h" #include "gui/widgets/text.h" @@ -48,7 +47,7 @@ /* we have to generate this on-the-fly for localization purposes */ const QString html = QString( "<body>" - " <h2 style=\"font-weight: normal;\"><strong>Minori</strong> " + QString::fromUtf8(MINORI_VERSION.data(), MINORI_VERSION.size()) + "</h2>" + " <h2 style=\"font-weight: normal;\"><strong>Minori</strong> v" + Strings::ToQString(session.version.to_string()) + "</h2>" " <p>" " <strong>" + QCoreApplication::tr("Author:") + "</strong><br>" " Paper (@mrpapersonic)"
--- a/src/gui/pages/torrents.cc Mon Jan 08 11:56:09 2024 -0500 +++ b/src/gui/pages/torrents.cc Mon Jan 08 13:21:08 2024 -0500 @@ -83,6 +83,10 @@ case Keys::SIZE: torrent.SetSize(Strings::HumanReadableSizeToBytes(value)); break; + case Keys::AUTHORIZED: + if (torrent.GetGroup().empty() && value != "N/A") + torrent.SetGroup(value); + break; default: break; }