From c1c36e4ac65261e01820f3c3ce204085cb65a7e5 Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Fri, 24 Dec 2021 10:24:05 +0100 Subject: [PATCH] FIX: Solves most of compilation errors on clang /!\ Not tested for the moment, do only minor compiler driven refactor /!\ --- CMakeLists.txt | 47 +++++++++++-------- inc/lektor/common.h | 22 +++++++-- inc/lektor/lib/strv.h | 42 ++++++++--------- ...module_qt_window.c => module_qt_window.cc} | 39 +++++++-------- ...module_qt_window.h => module_qt_window.hh} | 19 ++------ .../{mainwindow.cpp => mainwindow.cc} | 0 src/module/qt_window/mainwindow.hh | 9 ++-- .../qt_window/{mpvwidget.cpp => mpvwidget.cc} | 43 +++++++++++++---- src/module/qt_window/mpvwidget.hh | 10 +--- ...t_interface.cpp => mpvwidget_interface.cc} | 9 ++-- ...get_interface.h => mpvwidget_interface.hh} | 14 +----- .../qt_window/{qthelper.cpp => qthelper.hh} | 34 +++++++++----- 12 files changed, 156 insertions(+), 132 deletions(-) rename src/module/{module_qt_window.c => module_qt_window.cc} (79%) rename src/module/{module_qt_window.h => module_qt_window.hh} (56%) rename src/module/qt_window/{mainwindow.cpp => mainwindow.cc} (100%) rename src/module/qt_window/{mpvwidget.cpp => mpvwidget.cc} (78%) rename src/module/qt_window/{mpvwidget_interface.cpp => mpvwidget_interface.cc} (84%) rename src/module/qt_window/{mpvwidget_interface.h => mpvwidget_interface.hh} (68%) rename src/module/qt_window/{qthelper.cpp => qthelper.hh} (93%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e9a04eb..dcbea4cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,13 @@ set(Clang_C_FLAGS -Wno-unknown-warning-option -fcolor-diagnostics ) +set(Clang_CXX_FLAGS + $<$<COMPILE_LANGUAGE:CXX>:-Wno-c++98-compat-pedantic> + $<$<COMPILE_LANGUAGE:CXX>:-Wno-redundant-parens> + $<$<COMPILE_LANGUAGE:CXX>:-Wno-inconsistent-missing-override> + $<$<COMPILE_LANGUAGE:CXX>:-Wno-suggest-override> + $<$<COMPILE_LANGUAGE:CXX>:-Wno-deprecated-declaration> +) set(GNU_C_FLAGS -fdiagnostics-color=always ) @@ -61,23 +68,21 @@ set(GNU_C_FLAGS # FIND DEPENDENCIES # ### ### -find_library(MPV_LIBRARY mpv REQUIRED) # tested with 0.32.0 -find_library(SQLITE3_LIBRARY sqlite3 REQUIRED version>=3.31.0) # tested with 3.34.1 +find_library(MPV_LIBRARY mpv REQUIRED) # tested with 0.32.0 +find_library(SQLITE3_LIBRARY sqlite3 REQUIRED version>=3.31.0) # tested with 3.34.1 -find_package(SDL2 REQUIRED version>=2.0) # tested with 2.0.14 -find_package(SDL2_image REQUIRED version>=2.0) # same as above ^ -find_package(CURL REQUIRED HTTP HTTPS) # tested with 7.74.0 +find_package(SDL2 REQUIRED version>=2.0) # tested with 2.0.14 +find_package(SDL2_image REQUIRED version>=2.0) # same as above ^ +find_package(CURL REQUIRED HTTP HTTPS) # tested with 7.74.0 +find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) -# For Qt set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) -# Find Qt dependencies -find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) -find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) -find_program(MKVPROPEDIT mkvpropedit REQUIRED) # To DL karas and apply metadata -find_program(XXD xxd REQUIRED) # To embed the sqlite db schemas into the binary +find_program(MKVPROPEDIT mkvpropedit REQUIRED) # To DL karas and apply metadata +find_program(XXD xxd REQUIRED) # To embed the sqlite db schemas into the binary message(STATUS "The installation prefix is ${CMAKE_INSTALL_PREFIX}") @@ -147,12 +152,12 @@ set(lektor_module_SOURCES src/module/module_repo.c src/module/mpv.c src/module/module_sdl2.c - src/module/module_qt_window.c - src/module/qt_window/mpvwidget.cpp - src/module/qt_window/mpvwidget_interface.cpp - src/module/qt_window/qthelper.cpp - src/module/qt_window/mainwindow.cpp src/module/thread.c + + src/module/module_qt_window.cc + src/module/qt_window/mpvwidget.cc + src/module/qt_window/mpvwidget_interface.cc + src/module/qt_window/mainwindow.cc ) set(lektor_mkv_SOURCES @@ -320,8 +325,7 @@ target_compile_definitions(luka PRIVATE ${common_DEFINITIONS}) # target_precompile_headers(lkt PRIVATE ${common_HEADERS}) # target_precompile_headers(luka PRIVATE ${common_HEADERS}) -target_compile_options(lektord PRIVATE ${COMMON_C_FLAGS} ${${CMAKE_C_COMPILER_ID}_C_FLAGS}) -# Prepare for Qt6 +target_compile_options(lektord PRIVATE ${COMMON_C_FLAGS} ${${CMAKE_C_COMPILER_ID}_C_FLAGS} ${${CMAKE_CXX_COMPILER_ID}_CXX_FLAGS}) target_compile_definitions(lektord PRIVATE QT_DISABLE_DEPRECATED_BEFORE=0x050F00 QT_NO_CAST_TO_ASCII @@ -329,8 +333,11 @@ target_compile_definitions(lektord PRIVATE QTCREATOR_UTILS_STATIC_LIB ) -target_compile_options(lkt PRIVATE ${COMMON_C_FLAGS} ${${CMAKE_C_COMPILER_ID}_C_FLAGS}) -target_compile_options(luka PRIVATE ${COMMON_C_FLAGS} ${${CMAKE_C_COMPILER_ID}_C_FLAGS}) +target_compile_options(lkt PRIVATE ${COMMON_C_FLAGS} ${${CMAKE_C_COMPILER_ID}_C_FLAGS} ${${CMAKE_CXX_COMPILER_ID}_CXX_FLAGS}) +target_compile_options(luka PRIVATE ${COMMON_C_FLAGS} ${${CMAKE_C_COMPILER_ID}_C_FLAGS} ${${CMAKE_CXX_COMPILER_ID}_CXX_FLAGS}) + +set_property(TARGET lektord PROPERTY CXX_STANDARD 20) +set_property(TARGET luka PROPERTY CXX_STANDARD 20) ### ### # THE INSTALL DIRECTIVES # diff --git a/inc/lektor/common.h b/inc/lektor/common.h index 01b985a8..8acd54cc 100644 --- a/inc/lektor/common.h +++ b/inc/lektor/common.h @@ -4,6 +4,7 @@ #include <lektor/internal/os.h> #if defined(__cplusplus) +#define LKT_INCLUDE_CXX extern "C" { #endif @@ -35,19 +36,25 @@ extern EXIT_FUNCTION ___not_implemented(const char *func, char *file, int line); #define MIN(a, b) ((a) > (b) ? (b) : (a)) #endif /* MIN */ +#if defined(LKT_INCLUDE_CXX) +#define ___LKT_TO_BOOL(cond) static_cast<bool>(static_cast<int>(cond)) +#else +#define ___LKT_TO_BOOL(cond) (bool)(int)(cond) +#endif + #define RETURN_IF(cond, msg, ret) \ - if ((bool)(int)(cond)) { \ + if (___LKT_TO_BOOL(cond)) { \ LOG_DEBUG("DEBUG", "%s", msg); \ return ret; \ } #define GOTO_IF(cond, msg, label) \ - if ((bool)(int)(cond)) { \ + if (___LKT_TO_BOOL(cond)) { \ LOG_DEBUG("DEBUG", "%s", msg); \ goto label; \ } #define FAIL_IF(cond, ...) \ { \ - if ((bool)(int)(cond)) { \ + if (___LKT_TO_BOOL(cond)) { \ LOG_FATAL(__VA_ARGS__); \ } \ } @@ -264,12 +271,21 @@ int safe_vsnprintf(char *dest, const size_t max_len, const char *format, va_list char *safe_strncpy(char *dest, const char *src, size_t n); /* Helpers for malloc functions. */ +#if defined(LKT_INCLUDE_CXX) +#define LKT_ALLOC(___struct___) static_cast<___struct___ *>(safe_malloc(sizeof(___struct___))) +#define LKT_ALLOC_STRUCT(___struct___) LKT_ALLOC(struct ___struct___) +#define LKT_ALLOC_ARRAY(___struct___, ___count___) \ + static_cast<___struct___ *>(safe_malloc(sizeof(___struct___) * (size_t)(___count___))) +#define LKT_ALLOC_STRUCT_ARRAY(___struct___, ___count___) \ + LKT_ALLOC_ARRAY(struct ___struct___, ___count___) + #else #define LKT_ALLOC(___struct___) (___struct___ *)safe_malloc(sizeof(___struct___)) #define LKT_ALLOC_STRUCT(___struct___) LKT_ALLOC(struct ___struct___) #define LKT_ALLOC_ARRAY(___struct___, ___count___) \ (___struct___ *)safe_malloc(sizeof(___struct___) * (size_t)(___count___)) #define LKT_ALLOC_STRUCT_ARRAY(___struct___, ___count___) \ LKT_ALLOC_ARRAY(struct ___struct___, ___count___) + #endif /* Iterate throught a string, copy each element in the dest string. The save ptr must contains a null integer. */ diff --git a/inc/lektor/lib/strv.h b/inc/lektor/lib/strv.h index d0b84a63..f073cdb4 100644 --- a/inc/lektor/lib/strv.h +++ b/inc/lektor/lib/strv.h @@ -16,45 +16,43 @@ struct strv { #define STRV_FMT "%.*s" /* Format string for a string view */ #define STRV_ARG(sv) ((sv).count), ((sv).data) /* Unpack the string view */ -#define STRV_DEF __attribute__((unused)) - /* Create a string view from a slice or a C string. */ -STRV_DEF struct strv strv_from_slice(const char *data, int count); -STRV_DEF struct strv strv_from_str(const char *); +struct strv strv_from_slice(const char *data, int count); +struct strv strv_from_str(const char *); /* Copy a string view */ -STRV_DEF struct strv strv_copy(const struct strv sv); +struct strv strv_copy(const struct strv sv); /* Copy back a string view to a C string */ -STRV_DEF _Bool strv_as_str(const struct strv, char *data, int len); +_Bool strv_as_str(const struct strv, char *data, int len); /* Convert strv to an integet, in decimal notation */ -STRV_DEF int strv_to_int(const struct strv); +int strv_to_int(const struct strv); /* Get the length of the string view */ -STRV_DEF int strv_len(struct strv sv); +int strv_len(struct strv sv); /* Different ways of trimming the strings */ -STRV_DEF struct strv strv_trim_l(struct strv); -STRV_DEF struct strv strv_trim_r(struct strv); -STRV_DEF struct strv strv_trim(struct strv); +struct strv strv_trim_l(struct strv); +struct strv strv_trim_r(struct strv); +struct strv strv_trim(struct strv); -STRV_DEF struct strv strv_take_left_while(struct strv, _Bool (*)(char)); -STRV_DEF struct strv strv_chop_by_delim(struct strv *, char); -STRV_DEF _Bool strv_try_chop_by_delim(struct strv *, char delim, struct strv *chunk); -STRV_DEF struct strv strv_chop_left(struct strv *, int); -STRV_DEF struct strv strv_chop_right(struct strv *, int); -STRV_DEF struct strv strv_chop_left_while(struct strv *, _Bool (*)(char)); +struct strv strv_take_left_while(struct strv, _Bool (*)(char)); +struct strv strv_chop_by_delim(struct strv *, char); +_Bool strv_try_chop_by_delim(struct strv *, char delim, struct strv *chunk); +struct strv strv_chop_left(struct strv *, int); +struct strv strv_chop_right(struct strv *, int); +struct strv strv_chop_left_while(struct strv *, _Bool (*)(char)); /* Find substrings or characters in a string view. Returns 1 if found, 0 * otherwise. For the index_of function the index of the character is placed * inside `index` if the pointer is not NULL. */ -STRV_DEF _Bool strv_index_of(struct strv sv, char c, int *index); -STRV_DEF _Bool strv_starts_with(struct strv sv, struct strv prefix); -STRV_DEF _Bool strv_ends_with(struct strv sv, struct strv suffix); +_Bool strv_index_of(struct strv sv, char c, int *index); +_Bool strv_starts_with(struct strv sv, struct strv prefix); +_Bool strv_ends_with(struct strv sv, struct strv suffix); /* Compare two string views */ -STRV_DEF _Bool strv_equal(struct strv a, struct strv b); -STRV_DEF _Bool strv_equal_nocase(struct strv a, struct strv b); +_Bool strv_equal(struct strv a, struct strv b); +_Bool strv_equal_nocase(struct strv a, struct strv b); /* Private implementation of some functions to not include some headers */ diff --git a/src/module/module_qt_window.c b/src/module/module_qt_window.cc similarity index 79% rename from src/module/module_qt_window.c rename to src/module/module_qt_window.cc index 4eb13565..6787e9f4 100644 --- a/src/module/module_qt_window.c +++ b/src/module/module_qt_window.cc @@ -1,13 +1,12 @@ #define __LKT_MODULE_MAIN_SOURCE__ -#include "module_qt_window.h" -#include <lektor/lktmodule.h> +#include "module_qt_window.hh" +#include <lektor/lktmodule.h> +#include <sched.h> #include "mpv.h" #include "thread.h" -#include <sched.h> - -#include "qt_window/mpvwidget_interface.h" +#include "qt_window/mpvwidget_interface.hh" /************************ * Function definitions * @@ -30,9 +29,8 @@ static int mod_new(va_list *va) { va_list copy; - struct module_qt_window_s **win; va_copy(copy, *va); - win = (struct module_qt_window_s **)va_arg(copy, void **); + struct module_qt_window_s **win= reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **)); struct queue *queue = va_arg(copy, struct queue *); lkt_db *db = va_arg(copy, lkt_db *); bool ret = module_qt_window_new(win, queue, db); @@ -45,7 +43,7 @@ mod_close(va_list *va) { va_list copy; va_copy(copy, *va); - struct module_qt_window_s **win = (struct module_qt_window_s **)va_arg(copy, void **); + struct module_qt_window_s **win = reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **)); module_qt_window_close(*win); va_end(copy); return 0; @@ -56,7 +54,7 @@ mod_free(va_list *va) { va_list copy; va_copy(copy, *va); - struct module_qt_window_s **win = (struct module_qt_window_s **)va_arg(copy, void **); + struct module_qt_window_s **win = reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **)); module_qt_window_free(*win); va_end(copy); return 0; @@ -66,9 +64,8 @@ static int mod_toggle_pause(va_list *va) { va_list copy; - struct module_qt_window_s **win; va_copy(copy, *va); - win = (struct module_qt_window_s **)va_arg(copy, void **); + struct module_qt_window_s **win= reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **)); bool ret = ___module_qt_window_toggle_pause(*win); va_end(copy); return !ret; @@ -78,9 +75,8 @@ static int mod_load_file(va_list *va) { va_list copy; - struct module_qt_window_s **win; va_copy(copy, *va); - win = (struct module_qt_window_s **)va_arg(copy, void **); + struct module_qt_window_s **win = reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **)); const char *file = va_arg(copy, const char *); const bool ret = ___module_qt_window_load_file(*win, file); va_end(copy); @@ -92,7 +88,7 @@ mod_set_volume(va_list *va) { va_list copy; va_copy(copy, *va); - struct module_qt_window_s **win = (struct module_qt_window_s **)va_arg(copy, void **); + struct module_qt_window_s **win = reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **)); const int volume = va_arg(copy, int); const bool ret = ___module_qt_window_set_volume(*win, volume); va_end(copy); @@ -104,7 +100,7 @@ mod_set_paused(va_list *va) { va_list copy; va_copy(copy, *va); - struct module_qt_window_s **win = (struct module_qt_window_s **)va_arg(copy, void **); + struct module_qt_window_s **win = reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **)); const int state = va_arg(copy, int); const bool ret = ___module_qt_window_set_paussed(*win, state); va_end(copy); @@ -116,7 +112,7 @@ mod_set_position(va_list *va) { va_list copy; va_copy(copy, *va); - struct module_qt_window_s **win = (struct module_qt_window_s **)va_arg(copy, void **); + struct module_qt_window_s **win = reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **)); const int seconds = va_arg(copy, int); const bool ret = ___module_qt_window_set_position(*win, seconds); va_end(copy); @@ -127,9 +123,8 @@ static int mod_get_duration(va_list *va) { va_list copy; - struct module_qt_window_s **win; va_copy(copy, *va); - win = (struct module_qt_window_s **)va_arg(copy, void **); + struct module_qt_window_s **win= reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **)); int *duration = va_arg(copy, int *); bool ret = ___module_qt_window_get_duration(*win, duration); va_end(copy); @@ -142,7 +137,7 @@ mod_get_elapsed(va_list *va) va_list copy; struct module_qt_window_s **win; va_copy(copy, *va); - win = (struct module_qt_window_s **)va_arg(copy, void **); + win = reinterpret_cast<struct module_qt_window_s **>(va_arg(copy, void **)); int *elapsed = va_arg(copy, int *); const bool ret = ___module_qt_window_get_elapsed(*win, elapsed); va_end(copy); @@ -153,6 +148,7 @@ mod_get_elapsed(va_list *va) * The module stuff * ********************/ +extern "C" { REG_BEGIN(qt_window_reg) REG_ADD_NAMED("new", mod_new) REG_ADD_NAMED("free", mod_free) @@ -168,6 +164,7 @@ REG_END() #if !defined(LKT_STATIC_MODULE) REG_EXPORT(qt_window_reg) #endif +} /**************************** * Private helper functions * @@ -187,8 +184,8 @@ module_qt_window_new(struct module_qt_window_s **win, struct queue *queue, lkt_d RETURN_UNLESS(win, "Invalid arguments", false); struct poller_thread_arg *arg; - if (*win == NULL) { - *win = calloc(1, sizeof(struct module_qt_window_s)); + if (*win == nullptr) { + *win = LKT_ALLOC_STRUCT(module_qt_window_s); RETURN_UNLESS(*win, "Out of memory", false); memset(*win, 0, sizeof(struct module_qt_window_s)); diff --git a/src/module/module_qt_window.h b/src/module/module_qt_window.hh similarity index 56% rename from src/module/module_qt_window.h rename to src/module/module_qt_window.hh index 7cc63cb5..db40722f 100644 --- a/src/module/module_qt_window.h +++ b/src/module/module_qt_window.hh @@ -1,15 +1,7 @@ -#ifndef __LKT_MODULE_QT_WINDOW_H__ -#define __LKT_MODULE_QT_WINDOW_H__ +#pragma once -#if defined( __cplusplus) -extern "C" { -#define DECLARE_CPP_CLASS(c) class c; -#else -#define DECLARE_CPP_CLASS(c) typedef struct c c; -#endif -DECLARE_CPP_CLASS(MpvWidget) -DECLARE_CPP_CLASS(MainWindow) -#undef DECLARE_CPP_CLASS +class MpvWidget; +class MainWindow; #include <lektor/common.h> #include "thread.h" @@ -28,8 +20,3 @@ struct module_qt_window_s { struct queue *queue; lkt_db *db; }; - -#if defined(__cplusplus) -} -#endif -#endif // __LKT_MODULE_QT_WINDOW_H__ diff --git a/src/module/qt_window/mainwindow.cpp b/src/module/qt_window/mainwindow.cc similarity index 100% rename from src/module/qt_window/mainwindow.cpp rename to src/module/qt_window/mainwindow.cc diff --git a/src/module/qt_window/mainwindow.hh b/src/module/qt_window/mainwindow.hh index ad3e5142..d7a3c412 100644 --- a/src/module/qt_window/mainwindow.hh +++ b/src/module/qt_window/mainwindow.hh @@ -1,17 +1,14 @@ -#ifndef __LKT_MODULE_QT_WINDOW_MAINWINDOW__ -#define __LKT_MODULE_QT_WINDOW_MAINWINDOW__ +#pragma once #include <QtWidgets/QWidget> #include <QtGui> #include <QMainWindow> -#include "../module_qt_window.h" +#include "../module_qt_window.hh" #include "mpvwidget.hh" class MainWindow : public QMainWindow { Q_OBJECT public: - explicit MainWindow(struct module_qt_window_s *qt_window, QWidget *parent = 0); + explicit MainWindow(struct module_qt_window_s *qt_window, QWidget *parent = nullptr); }; - -#endif // __LKT_MODULE_QT_WINDOW_MAINWINDOW__ diff --git a/src/module/qt_window/mpvwidget.cpp b/src/module/qt_window/mpvwidget.cc similarity index 78% rename from src/module/qt_window/mpvwidget.cpp rename to src/module/qt_window/mpvwidget.cc index 558674b6..2422fff5 100644 --- a/src/module/qt_window/mpvwidget.cpp +++ b/src/module/qt_window/mpvwidget.cc @@ -4,12 +4,12 @@ #include <QtGui/QOpenGLContext> #include <QtCore/QMetaObject> -#include "qthelper.cpp" +#include "qthelper.hh" #include "../mpv.h" static void wakeup(void *ctx) { - QMetaObject::invokeMethod((MpvWidget*)ctx, "on_mpv_events", Qt::QueuedConnection); + QMetaObject::invokeMethod(static_cast<MpvWidget*>(ctx), "on_mpv_events", Qt::QueuedConnection); } static void *get_proc_address(void *ctx, const char *name) { @@ -116,21 +116,46 @@ void MpvWidget::handle_mpv_event(mpv_event *event) { switch (event->event_id) { case MPV_EVENT_PROPERTY_CHANGE: { - mpv_event_property *prop = (mpv_event_property *)event->data; + mpv_event_property *prop = static_cast<mpv_event_property *>(event->data); if (strcmp(prop->name, "time-pos") == 0) { if (prop->format == MPV_FORMAT_DOUBLE) { - double time = *(double *)prop->data; - Q_EMIT positionChanged((int)time); + double time = *static_cast<double *>(prop->data); + Q_EMIT positionChanged(static_cast<int>(time)); } } else if (strcmp(prop->name, "duration") == 0) { if (prop->format == MPV_FORMAT_DOUBLE) { - double time = *(double *)prop->data; - Q_EMIT durationChanged((int)time); + double time = *static_cast<double *>(prop->data); + Q_EMIT durationChanged(static_cast<int>(time)); } } break; } - default: ; + + case MPV_EVENT_SHUTDOWN: + case MPV_EVENT_LOG_MESSAGE: + case MPV_EVENT_GET_PROPERTY_REPLY: + case MPV_EVENT_SET_PROPERTY_REPLY: + case MPV_EVENT_NONE: + case MPV_EVENT_COMMAND_REPLY: + case MPV_EVENT_START_FILE: + case MPV_EVENT_END_FILE: + case MPV_EVENT_FILE_LOADED: + case MPV_EVENT_TRACKS_CHANGED: + case MPV_EVENT_TRACK_SWITCHED: + case MPV_EVENT_IDLE: + case MPV_EVENT_PAUSE: + case MPV_EVENT_UNPAUSE: + case MPV_EVENT_TICK: + case MPV_EVENT_SCRIPT_INPUT_DISPATCH: + case MPV_EVENT_CLIENT_MESSAGE: + case MPV_EVENT_VIDEO_RECONFIG: + case MPV_EVENT_AUDIO_RECONFIG: + case MPV_EVENT_METADATA_UPDATE: + case MPV_EVENT_SEEK: + case MPV_EVENT_CHAPTER_CHANGE: + case MPV_EVENT_PLAYBACK_RESTART: + case MPV_EVENT_QUEUE_OVERFLOW: + case MPV_EVENT_HOOK:{ break; } // Ignore uninteresting or unknown events. } } @@ -157,7 +182,7 @@ void MpvWidget::maybeUpdate() void MpvWidget::on_update(void *ctx) { - QMetaObject::invokeMethod((MpvWidget*)ctx, "maybeUpdate"); + QMetaObject::invokeMethod(static_cast<MpvWidget*>(ctx), "maybeUpdate"); } bool diff --git a/src/module/qt_window/mpvwidget.hh b/src/module/qt_window/mpvwidget.hh index 86ea4662..1ac917de 100644 --- a/src/module/qt_window/mpvwidget.hh +++ b/src/module/qt_window/mpvwidget.hh @@ -1,21 +1,17 @@ -#ifndef __LKT_MODULE_QT_WINDOW__ -#define __LKT_MODULE_QT_WINDOW__ +#pragma once #include <QtWidgets/QOpenGLWidget> #include <mpv/client.h> #include <mpv/render_gl.h> #include <QtGui> - -extern "C" { #include <lektor/common.h> -} class MpvWidget Q_DECL_FINAL: public QOpenGLWidget { Q_OBJECT public: MpvWidget(struct queue *queue, lkt_db *db, QWidget* parent); - ~MpvWidget(); + virtual ~MpvWidget() override; void command(const QVariant& params); void setProperty(const QString& name, const QVariant& value); QVariant getProperty(const QString& name) const; @@ -49,5 +45,3 @@ public: bool load_file(const char *); bool toggle_pause(); }; - -#endif // __LKT_MODULE_QT_WINDOW__ diff --git a/src/module/qt_window/mpvwidget_interface.cpp b/src/module/qt_window/mpvwidget_interface.cc similarity index 84% rename from src/module/qt_window/mpvwidget_interface.cpp rename to src/module/qt_window/mpvwidget_interface.cc index 8067387a..0c3423ef 100644 --- a/src/module/qt_window/mpvwidget_interface.cpp +++ b/src/module/qt_window/mpvwidget_interface.cc @@ -1,4 +1,4 @@ -#include "mpvwidget_interface.h" +#include "mpvwidget_interface.hh" #include "mainwindow.hh" #include <QApplication> @@ -7,14 +7,15 @@ void* ___create_mpv_widget(struct poller_thread_arg *arg){ lkt_thread_set_name("lektord/qt-win"); - struct module_qt_window_s* qt_window = (struct module_qt_window_s*)arg->args; + /* Unsage reinterpret cast, but isok */ + struct module_qt_window_s* qt_window = reinterpret_cast<struct module_qt_window_s*>(arg->args); int argc = 0; - QApplication a(argc, NULL); + QApplication a(argc, nullptr); setlocale(LC_NUMERIC, "C"); qt_window->main_window = new MainWindow(qt_window); a.exec(); - return NULL; + return nullptr; } bool diff --git a/src/module/qt_window/mpvwidget_interface.h b/src/module/qt_window/mpvwidget_interface.hh similarity index 68% rename from src/module/qt_window/mpvwidget_interface.h rename to src/module/qt_window/mpvwidget_interface.hh index 9964c70b..89b6a42b 100644 --- a/src/module/qt_window/mpvwidget_interface.h +++ b/src/module/qt_window/mpvwidget_interface.hh @@ -1,12 +1,7 @@ -#ifndef __LKT_MODULE_QT_WINDOW_MPVWIDGET_INTERFACE_H__ -#define __LKT_MODULE_QT_WINDOW_MPVWIDGET_INTERFACE_H__ - -#if defined( __cplusplus) -extern "C" { -#endif +#pragma once #include <lektor/common.h> -#include "../module_qt_window.h" +#include "../module_qt_window.hh" void * ___create_mpv_widget(struct poller_thread_arg *arg); @@ -17,8 +12,3 @@ bool ___module_qt_window_set_volume(struct module_qt_window_s *, int); bool ___module_qt_window_set_position(struct module_qt_window_s *, int); bool ___module_qt_window_load_file(struct module_qt_window_s *, const char *); bool ___module_qt_window_toggle_pause(struct module_qt_window_s *); - -#if defined(__cplusplus) -} -#endif -#endif // __LKT_MODULE_QT_WINDOW_MPVWIDGET_INTERFACE_H__ diff --git a/src/module/qt_window/qthelper.cpp b/src/module/qt_window/qthelper.hh similarity index 93% rename from src/module/qt_window/qthelper.cpp rename to src/module/qt_window/qthelper.hh index 09c28c10..0aad6140 100644 --- a/src/module/qt_window/qthelper.cpp +++ b/src/module/qt_window/qthelper.hh @@ -12,8 +12,7 @@ #include <QSharedPointer> #include <QMetaType> -namespace mpv { -namespace qt { +namespace mpv::qt { // Wrapper around mpv_handle. Does refcounting under the hood. class Handle @@ -40,7 +39,7 @@ public: } // Return the raw handle; for use with the libmpv C API. - operator mpv_handle*() const { return sptr ? (*sptr).mpv : 0; } + operator mpv_handle*() const { return sptr ? (*sptr).mpv : nullptr; } }; static inline QVariant node_to_variant(const mpv_node *node) @@ -70,7 +69,10 @@ static inline QVariant node_to_variant(const mpv_node *node) } return QVariant(qmap); } - default: // MPV_FORMAT_NONE, unknown values (e.g. future extensions) + case MPV_FORMAT_OSD_STRING: + case MPV_FORMAT_NONE: + case MPV_FORMAT_NODE: + case MPV_FORMAT_BYTE_ARRAY: return QVariant(); } } @@ -92,24 +94,24 @@ private: dst->u.list = list; if (!list) goto err; - list->values = new mpv_node[num](); + list->values = new mpv_node[static_cast<size_t>(num)](); if (!list->values) goto err; if (is_map) { - list->keys = new char*[num](); + list->keys = new char*[static_cast<size_t>(num)](); if (!list->keys) goto err; } return list; err: free_node(dst); - return NULL; + return nullptr; } char *dup_qstring(const QString &s) { QByteArray b = s.toUtf8(); - char *r = new char[b.size() + 1]; + char *r = new char[static_cast<size_t>(b.size() + 1)]; if (r) - std::memcpy(r, b.data(), (size_t)b.size() + 1); + std::memcpy(r, b.data(), static_cast<size_t>(b.size() + 1)); return r; } bool test_type(const QVariant &v, QMetaType::Type t) { @@ -188,7 +190,14 @@ private: delete list; break; } - default: ; + case MPV_FORMAT_OSD_STRING: + case MPV_FORMAT_NONE: + case MPV_FORMAT_NODE: + case MPV_FORMAT_FLAG: + case MPV_FORMAT_INT64: + case MPV_FORMAT_DOUBLE: + case MPV_FORMAT_BYTE_ARRAY: + break; } dst->format = MPV_FORMAT_NONE; } @@ -211,6 +220,7 @@ struct node_autofree { * * @param name the property name */ +[[deprecated]] static inline QVariant get_property_variant(mpv_handle *ctx, const QString &name) { mpv_node node; @@ -225,6 +235,7 @@ static inline QVariant get_property_variant(mpv_handle *ctx, const QString &name * @deprecated use set_property() instead */ + [[deprecated]] static inline int set_property_variant(mpv_handle *ctx, const QString &name, const QVariant &v) { @@ -237,6 +248,7 @@ static inline int set_property_variant(mpv_handle *ctx, const QString &name, * * @deprecated use set_property() instead */ + [[deprecated]] static inline int set_option_variant(mpv_handle *ctx, const QString &name, const QVariant &v) { @@ -250,6 +262,7 @@ static inline int set_option_variant(mpv_handle *ctx, const QString &name, * * @deprecated use command() instead */ + [[deprecated]] static inline QVariant command_variant(mpv_handle *ctx, const QVariant &args) { node_builder node(args); @@ -345,7 +358,6 @@ static inline QVariant command(mpv_handle *ctx, const QVariant &args) return node_to_variant(&res); } -} } Q_DECLARE_METATYPE(mpv::qt::ErrorReturn) -- GitLab