diff --git a/.clang-tidy b/.clang-tidy index 1c5c12f81204..9a4b69281e8b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -23,12 +23,14 @@ Checks: "*,\ -fuchsia-statically-constructed-objects,\ -readability-isolate-declaration,\ -fuchsia-multiple-inheritance,\ +-fuchsia-default-arguments-calls,\ -fuchsia-trailing-return,\ -portability-simd-intrinsics,\ -modernize-use-nodiscard,\ -hicpp-multiway-paths-covered,\ +-hicpp-deprecated-headers,\ -cert-msc32-c,\ -cert-msc51-cpp" -WarningsAsErrors: '*' +#WarningsAsErrors: '*' HeaderFilterRegex: '*.(h|hpp|hxx)' AnalyzeTemporaryDtors: false diff --git a/CMakeLists.txt b/CMakeLists.txt index 93c12e6d7679..f974d1547b56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) + add_definitions(-D_USE_MATH_DEFINES) # package version diff --git a/clang-format.sh b/clang-format.sh new file mode 100644 index 000000000000..fcbd737128b4 --- /dev/null +++ b/clang-format.sh @@ -0,0 +1,2 @@ +echo test +find ./include/* ./src/* ./test/* ./exe/* -type f -not -name "doctest.h" -a \( -name "*.cc" -o -name "*.h" -o -name "*.hpp" \) -exec clang-format -i -style=file {} \; \ No newline at end of file diff --git a/clang-tidy.sh b/clang-tidy.sh new file mode 100644 index 000000000000..acbcf5733224 --- /dev/null +++ b/clang-tidy.sh @@ -0,0 +1,2 @@ +echo test +find ./src/* -type f -not -name "doctest.h" -a \( -name "*.cc" -o -name "*.h" -o -name "*.hpp" \) -exec clang-tidy -format-style=file {} \; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3d73c386a157..0e3d3220c630 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,7 @@ ## Build poppler ## ## Basic variables ## +set(CMAKE_CXX_CLANG_TIDY "clang-tidy;--checks=;--fix-errors;--format-style=file;") include_directories ( "${PROJECT_BINARY_DIR}/src" @@ -22,7 +23,8 @@ if (WIN32) elseif (APPLE OR LINUX) # Nothing to do for APPLE and linux else () - add_definitions (-rdynamic) + set(CMAKE_EXE_LINKER_FLAGS -rdynamic ${CMAKE_EXE_LINKER_FLAGS}) + #add_definitions (-rdynamic) endif () option (DEBUG_COMPILE "Pass -Wall to CXX_FLAGS" OFF) diff --git a/src/control/Actions.cpp b/src/control/Actions.cpp index 974d0b6ef835..3281fe150b03 100644 --- a/src/control/Actions.cpp +++ b/src/control/Actions.cpp @@ -18,7 +18,7 @@ void ActionEnabledListener::registerListener(ActionHandler* handler) void ActionEnabledListener::unregisterListener() { - if (this->handler) + if (this->handler != nullptr) { this->handler->removeListener(this); this->handler = nullptr; diff --git a/src/control/ClipboardHandler.cpp b/src/control/ClipboardHandler.cpp index 77106c223f3c..c07252d859ef 100644 --- a/src/control/ClipboardHandler.cpp +++ b/src/control/ClipboardHandler.cpp @@ -26,7 +26,7 @@ ClipboardHandler::ClipboardHandler(ClipboardListener* listener, GtkWidget* widge this->listener->clipboardCutCopyEnabled(false); gtk_clipboard_request_contents(clipboard, gdk_atom_intern_static_string("TARGETS"), - (GtkClipboardReceivedFunc) receivedClipboardContents, this); + reinterpret_cast(receivedClipboardContents), this); } ClipboardHandler::~ClipboardHandler() @@ -41,19 +41,19 @@ auto ClipboardHandler::paste() -> bool if (this->containsXournal) { gtk_clipboard_request_contents(this->clipboard, atomXournal, - (GtkClipboardReceivedFunc) pasteClipboardContents, this); + reinterpret_cast(pasteClipboardContents), this); return true; } - else if (this->containsText) + if (this->containsText) { - gtk_clipboard_request_text(this->clipboard, - (GtkClipboardTextReceivedFunc) pasteClipboardText, this); + gtk_clipboard_request_text(this->clipboard, reinterpret_cast(pasteClipboardText), + this); return true; } - else if (this->containsImage) + if (this->containsImage) { gtk_clipboard_request_image(this->clipboard, - (GtkClipboardImageReceivedFunc) pasteClipboardImage, this); + reinterpret_cast(pasteClipboardImage), this); return true; } @@ -95,10 +95,9 @@ class ClipboardContents ~ClipboardContents() { g_object_unref(this->image); - g_string_free(this->str, true); + g_string_free(this->str, 1); } -public: static void getFunction(GtkClipboard* clipboard, GtkSelectionData* selection, guint info, ClipboardContents* contents) @@ -122,7 +121,8 @@ class ClipboardContents } else if (atomXournal == target) { - gtk_selection_data_set(selection, target, 8, (guchar*) contents->str->str, contents->str->len); + gtk_selection_data_set(selection, target, 8, reinterpret_cast(contents->str->str), + contents->str->len); } } @@ -140,13 +140,13 @@ class ClipboardContents static auto svgWriteFunction(GString* string, const unsigned char* data, unsigned int length) -> cairo_status_t { - g_string_append_len(string, (const gchar*) data, length); + g_string_append_len(string, reinterpret_cast(data), length); return CAIRO_STATUS_SUCCESS; } auto ClipboardHandler::copy() -> bool { - if (!this->selection) + if (this->selection == nullptr) { return false; } @@ -171,15 +171,15 @@ auto ClipboardHandler::copy() -> bool { if (e->getType() == ELEMENT_TEXT) { - textElements = g_list_insert_sorted(textElements, e, (GCompareFunc) ElementCompareFunc); + textElements = g_list_insert_sorted(textElements, e, reinterpret_cast(ElementCompareFunc)); } } - string text = ""; + string text = text; for (GList* l = textElements; l != nullptr; l = l->next) { - Text* e = (Text*) l->data; - if (text != "") + Text* e = static_cast(l->data); + if (!text.empty()) { text += "\n"; } @@ -216,10 +216,9 @@ auto ClipboardHandler::copy() -> bool GString* svgString = g_string_sized_new(1048576); // 1MB - cairo_surface_t* surfaceSVG = cairo_svg_surface_create_for_stream( - (cairo_write_func_t) svgWriteFunction, svgString, - selection->getWidth(), selection->getHeight() - ); + cairo_surface_t* surfaceSVG = + cairo_svg_surface_create_for_stream(reinterpret_cast(svgWriteFunction), svgString, + selection->getWidth(), selection->getHeight()); cairo_t* crSVG = cairo_create(surfaceSVG); view.drawSelection(crSVG, this->selection); @@ -232,8 +231,8 @@ auto ClipboardHandler::copy() -> bool ///////////////////////////////////////////////////////////////// GtkTargetList* list = gtk_target_list_new(nullptr, 0); - GtkTargetEntry* targets; - int n_targets; + GtkTargetEntry* targets = nullptr; + int n_targets = 0; // if we have text elements... if (!text.empty()) @@ -241,7 +240,7 @@ auto ClipboardHandler::copy() -> bool gtk_target_list_add_text_targets(list, 0); } // we always copy an image to clipboard - gtk_target_list_add_image_targets(list, 0, true); + gtk_target_list_add_image_targets(list, 0, 1); gtk_target_list_add(list, atomSvg1, 0, 0); gtk_target_list_add(list, atomSvg2, 0, 0); gtk_target_list_add(list, atomXournal, 0, 0); @@ -251,14 +250,14 @@ auto ClipboardHandler::copy() -> bool auto* contents = new ClipboardContents(text, image, svgString->str, out.getStr()); gtk_clipboard_set_with_data(this->clipboard, targets, n_targets, - (GtkClipboardGetFunc) ClipboardContents::getFunction, - (GtkClipboardClearFunc) ClipboardContents::clearFunction, contents); + reinterpret_cast(ClipboardContents::getFunction), + reinterpret_cast(ClipboardContents::clearFunction), contents); gtk_clipboard_set_can_store(this->clipboard, nullptr, 0); gtk_target_table_free(targets, n_targets); gtk_target_list_unref(list); - g_string_free(svgString, true); + g_string_free(svgString, 1); return true; } @@ -276,7 +275,7 @@ void ClipboardHandler::setCopyPasteEnabled(bool enabled) { listener->clipboardCutCopyEnabled(true); } - else if (!selection) + else if (selection == nullptr) { listener->clipboardCutCopyEnabled(false); } @@ -292,9 +291,8 @@ void ClipboardHandler::ownerChangedCallback(GtkClipboard* clip, GdkEvent* event, void ClipboardHandler::clipboardUpdated(GdkAtom atom) { - gtk_clipboard_request_contents(clipboard, - gdk_atom_intern_static_string("TARGETS"), - (GtkClipboardReceivedFunc) receivedClipboardContents, this); + gtk_clipboard_request_contents(clipboard, gdk_atom_intern_static_string("TARGETS"), + reinterpret_cast(receivedClipboardContents), this); } void ClipboardHandler::pasteClipboardImage(GtkClipboard* clipboard, GdkPixbuf* pixbuf, ClipboardHandler* handler) @@ -307,7 +305,8 @@ void ClipboardHandler::pasteClipboardContents(GtkClipboard* clipboard, GtkSelect { ObjectInputStream in; - if (in.read((const char*) gtk_selection_data_get_data(selectionData), gtk_selection_data_get_length(selectionData))) + if (in.read(reinterpret_cast(gtk_selection_data_get_data(selectionData)), + gtk_selection_data_get_length(selectionData))) { handler->listener->clipboardPasteXournal(in); } @@ -316,7 +315,7 @@ void ClipboardHandler::pasteClipboardContents(GtkClipboard* clipboard, GtkSelect void ClipboardHandler::pasteClipboardText(GtkClipboard* clipboard, const gchar* text, ClipboardHandler* handler) { - if (text) + if (text != nullptr) { handler->listener->clipboardPasteText(text); } @@ -324,17 +323,17 @@ void ClipboardHandler::pasteClipboardText(GtkClipboard* clipboard, const gchar* auto gtk_selection_data_targets_include_xournal(GtkSelectionData* selection_data) -> gboolean { - GdkAtom* targets; - gint n_targets; - gboolean result = false; + GdkAtom* targets = nullptr; + gint n_targets = 0; + gboolean result = 0; - if (gtk_selection_data_get_targets(selection_data, &targets, &n_targets)) + if (gtk_selection_data_get_targets(selection_data, &targets, &n_targets) != 0) { for (int i = 0; i < n_targets; i++) { if (targets[i] == atomXournal) { - result = true; + result = 1; break; } } @@ -347,9 +346,9 @@ auto gtk_selection_data_targets_include_xournal(GtkSelectionData* selection_data void ClipboardHandler::receivedClipboardContents(GtkClipboard* clipboard, GtkSelectionData* selectionData, ClipboardHandler* handler) { - handler->containsText = gtk_selection_data_targets_include_text(selectionData); - handler->containsXournal = gtk_selection_data_targets_include_xournal(selectionData); - handler->containsImage = gtk_selection_data_targets_include_image(selectionData, false); + handler->containsText = (gtk_selection_data_targets_include_text(selectionData) != 0); + handler->containsXournal = (gtk_selection_data_targets_include_xournal(selectionData) != 0); + handler->containsImage = (gtk_selection_data_targets_include_image(selectionData, 0) != 0); handler->listener->clipboardPasteEnabled(handler->containsText || handler->containsXournal || handler->containsImage); } diff --git a/src/control/Control.cpp b/src/control/Control.cpp index 3a7ad6345ac8..837b9af7beee 100644 --- a/src/control/Control.cpp +++ b/src/control/Control.cpp @@ -29,6 +29,8 @@ #include "jobs/CustomExportJob.h" #include "jobs/PdfExportJob.h" #include "jobs/SaveJob.h" +#include +#include #include "model/BackgroundImage.h" #include "model/FormatDefinitions.h" #include "model/StrokeStyle.h" @@ -122,7 +124,7 @@ Control::Control(GladeSearchpath* gladeSearchPath) /** * This is needed to update the previews */ - this->changeTimout = g_timeout_add_seconds(5, (GSourceFunc) checkChangedDocument, this); + this->changeTimout = g_timeout_add_seconds(5, reinterpret_cast(checkChangedDocument), this); this->pageBackgroundChangeController = new PageBackgroundChangeController(this); @@ -380,10 +382,10 @@ auto Control::autosaveCallback(Control* control) -> bool // do nothing, nothing changed return true; } - else - { - g_message("Info: autosave document..."); - } + + + g_message("Info: autosave document..."); + auto* job = new AutosaveJob(control); control->scheduler->addJob(job, JOB_PRIORITY_NONE); @@ -394,7 +396,7 @@ auto Control::autosaveCallback(Control* control) -> bool void Control::enableAutosave(bool enable) { - if (this->autosaveTimeout) + if (this->autosaveTimeout != 0) { g_source_remove(this->autosaveTimeout); this->autosaveTimeout = 0; @@ -403,7 +405,7 @@ void Control::enableAutosave(bool enable) if (enable) { int timeout = settings->getAutosaveTimeout() * 60; - this->autosaveTimeout = g_timeout_add_seconds(timeout, (GSourceFunc) autosaveCallback, this); + this->autosaveTimeout = g_timeout_add_seconds(timeout, reinterpret_cast(autosaveCallback), this); } } @@ -837,7 +839,7 @@ void Control::actionPerformed(ActionType type, ActionGroup group, GdkEvent* even break; case ACTION_SELECT_FONT: - if (win) + if (win != nullptr) { win->getToolMenuHandler()->showFontSelectionDlg(); } @@ -971,7 +973,7 @@ void Control::actionPerformed(ActionType type, ActionGroup group, GdkEvent* even case ACTION_AUDIO_RECORD: { - bool result; + bool result = 0; if (enabled) { result = audioController->startRecording(); @@ -984,7 +986,8 @@ void Control::actionPerformed(ActionType type, ActionGroup group, GdkEvent* even if (!result) { Util::execInUiThread([=]() { - gtk_toggle_tool_button_set_active((GtkToggleToolButton*) toolbutton, !enabled); + gtk_toggle_tool_button_set_active(reinterpret_cast(toolbutton), + static_cast(!enabled)); string msg = _("Recorder could not be started."); g_warning("%s", msg.c_str()); XojMsgBox::showErrorToUser(Control::getGtkWindow(), msg); @@ -1056,7 +1059,7 @@ void Control::actionPerformed(ActionType type, ActionGroup group, GdkEvent* even if (type >= ACTION_TOOL_PEN && type <= ACTION_TOOL_HAND) { - auto at = (ActionType)(toolHandler->getToolType() - TOOL_PEN + ACTION_TOOL_PEN); + auto at = static_cast(toolHandler->getToolType() - TOOL_PEN + ACTION_TOOL_PEN); if (type == at && !enabled) { fireActionSelected(GROUP_TOOL, at); @@ -1066,7 +1069,7 @@ void Control::actionPerformed(ActionType type, ActionGroup group, GdkEvent* even auto Control::copy() -> bool { - if (this->win && this->win->getXournal()->copy()) + if ((this->win != nullptr) && this->win->getXournal()->copy()) { return true; } @@ -1075,7 +1078,7 @@ auto Control::copy() -> bool auto Control::cut() -> bool { - if (this->win && this->win->getXournal()->cut()) + if ((this->win != nullptr) && this->win->getXournal()->cut()) { return true; } @@ -1084,7 +1087,7 @@ auto Control::cut() -> bool auto Control::paste() -> bool { - if (this->win && this->win->getXournal()->paste()) + if ((this->win != nullptr) && this->win->getXournal()->paste()) { return true; } @@ -1127,7 +1130,7 @@ void Control::selectFillAlpha(bool pen) void Control::clearSelectionEndText() { clearSelection(); - if (win) + if (win != nullptr) { win->getXournal()->endTextAllPages(); } @@ -1203,7 +1206,7 @@ void Control::customizeToolbars() } } - if (!this->dragDropHandler) + if (this->dragDropHandler == nullptr) { this->dragDropHandler = new ToolbarDragDropHandler(this); } @@ -1212,7 +1215,7 @@ void Control::customizeToolbars() void Control::endDragDropToolbar() { - if (!this->dragDropHandler) + if (this->dragDropHandler == nullptr) { return; } @@ -1222,7 +1225,7 @@ void Control::endDragDropToolbar() void Control::startDragDropToolbar() { - if (!this->dragDropHandler) + if (this->dragDropHandler == nullptr) { return; } @@ -1232,7 +1235,7 @@ void Control::startDragDropToolbar() auto Control::isInDragAndDropToolbar() -> bool { - if (!this->dragDropHandler) + if (this->dragDropHandler == nullptr) { return false; } @@ -1242,7 +1245,7 @@ auto Control::isInDragAndDropToolbar() -> bool void Control::setShapeTool(ActionType type, bool enabled) { - if (enabled == false) + if (!enabled) { // Disable all entries this->toolHandler->setDrawingType(DRAWING_TYPE_DEFAULT); @@ -1313,7 +1316,7 @@ void Control::disableSidebarTmp(bool disabled) void Control::addDefaultPage(string pageTemplate) { - if (pageTemplate == "") + if (pageTemplate.empty()) { pageTemplate = settings->getPageTemplate(); } @@ -1334,10 +1337,10 @@ void Control::addDefaultPage(string pageTemplate) void Control::updateDeletePageButton() { - if (this->win) + if (this->win != nullptr) { GtkWidget* w = this->win->get("menuDeletePage"); - gtk_widget_set_sensitive(w, this->doc->getPageCount() > 1); + gtk_widget_set_sensitive(w, static_cast(this->doc->getPageCount() > 1)); } } @@ -1439,10 +1442,10 @@ void Control::updateBackgroundSizeButton() GtkWidget* pageSize = win->get("menuJournalPaperFormat"); PageType bg = p->getBackgroundType(); - gtk_widget_set_sensitive(paperColor, !bg.isSpecial()); + gtk_widget_set_sensitive(paperColor, static_cast(!bg.isSpecial())); // PDF page size is defined, you cannot change it - gtk_widget_set_sensitive(pageSize, !bg.isPdfPage()); + gtk_widget_set_sensitive(pageSize, static_cast(!bg.isPdfPage())); } void Control::paperTemplate() @@ -1567,8 +1570,8 @@ void Control::setViewPresentationMode(bool enabled) fireEnableAction(ACTION_ZOOM_100, !enabled); fireEnableAction(ACTION_FOOTER_ZOOM_SLIDER, !enabled); - gtk_widget_set_sensitive(win->get("menuitemLayout"), !enabled); - gtk_widget_set_sensitive(win->get("menuitemViewDimensions"), !enabled); + gtk_widget_set_sensitive(win->get("menuitemLayout"), static_cast(!enabled)); + gtk_widget_set_sensitive(win->get("menuitemViewDimensions"), static_cast(!enabled)); // disable selection of scroll hand tool fireEnableAction(ACTION_TOOL_HAND, !enabled); @@ -1582,7 +1585,7 @@ void Control::setViewPresentationMode(bool enabled) void Control::setPairsOffset(int numOffset) { settings->setPairsOffset(numOffset); - fireActionSelected(GROUP_PAIRED_PAGES, numOffset ? ACTION_SET_PAIRS_OFFSET : ACTION_NOT_SELECTED); + fireActionSelected(GROUP_PAIRED_PAGES, numOffset != 0 ? ACTION_SET_PAIRS_OFFSET : ACTION_NOT_SELECTED); int currentPage = getCurrentPageNo(); win->getXournal()->layoutPages(); scrollHandler->scrollToPage(currentPage); @@ -1593,7 +1596,7 @@ void Control::setViewColumns(int numColumns) settings->setViewColumns(numColumns); settings->setViewFixedRows(false); - ActionType action; + ActionType action{}; switch (numColumns) { @@ -1637,7 +1640,7 @@ void Control::setViewRows(int numRows) settings->setViewRows(numRows); settings->setViewFixedRows(true); - ActionType action; + ActionType action{}; switch (numRows) { @@ -1680,7 +1683,7 @@ void Control::setViewLayoutVert(bool vert) { settings->setViewLayoutVert(vert); - ActionType action; + ActionType action{}; if (vert) { @@ -1702,7 +1705,10 @@ void Control::setViewLayoutR2L(bool r2l) { settings->setViewLayoutR2L(r2l); - ActionType action; + ActionType action = 0 = 0 = 0 = 0; + { + 0; + }; if (r2l) { @@ -1724,7 +1730,10 @@ void Control::setViewLayoutB2T(bool b2t) { settings->setViewLayoutB2T(b2t); - ActionType action; + ActionType action = 0 = 0 = 0 = 0; + { + 0; + }; if (b2t) { @@ -1775,7 +1784,7 @@ void Control::zoomCallback(ActionType type, bool enabled) auto Control::getCurrentPageNo() -> size_t { - if (this->win) + if (this->win != nullptr) { return this->win->getXournal()->getCurrentPage(); } @@ -1831,7 +1840,7 @@ void Control::selectTool(ToolType type) { toolHandler->selectTool(type); - if (win) + if (win != nullptr) { (win->getXournal()->getViewFor(getCurrentPageNo()))->rerenderPage(); } @@ -1848,7 +1857,7 @@ void Control::toolChanged() ToolType type = toolHandler->getToolType(); // Convert enum values, enums has to be in the same order! - auto at = (ActionType)(type - TOOL_PEN + ACTION_TOOL_PEN); + auto at = static_cast(type - TOOL_PEN + ACTION_TOOL_PEN); fireActionSelected(GROUP_TOOL, at); @@ -1918,7 +1927,7 @@ void Control::toolChanged() if (type != TOOL_TEXT) { - if (win) + if (win != nullptr) { win->getXournal()->endTextAllPages(); } @@ -2081,10 +2090,10 @@ void Control::toolColorChanged(bool userSelection) fireActionSelected(GROUP_COLOR, ACTION_SELECT_COLOR); getCursor()->updateCursor(); - if (userSelection && this->win && toolHandler->getColor() != -1) + if (userSelection && (this->win != nullptr) && toolHandler->getColor() != -1) { EditSelection* sel = this->win->getXournal()->getSelection(); - if (sel) + if (sel != nullptr) { UndoAction* undo = sel->setColor(toolHandler->getColor()); // move into selection @@ -2293,7 +2302,7 @@ auto Control::openFile(Path filename, int scrollToPage, bool forceOpen) -> bool } } - if (!loadedDocument) + if (loadedDocument == nullptr) { string msg = FS(_F("Error opening file \"{1}\"") % filename.str()) + "\n" + loadHandler.getLastError(); XojMsgBox::showErrorToUser(getGtkWindow(), msg); @@ -2301,20 +2310,20 @@ auto Control::openFile(Path filename, int scrollToPage, bool forceOpen) -> bool fileLoaded(scrollToPage); return false; } - else - { - this->closeDocument(); - this->doc->lock(); - this->doc->clearDocument(); - *this->doc = *loadedDocument; - this->doc->unlock(); - // Set folder as last save path, so the next save will be at the current document location - // This is important because of the new .xopp format, where Xournal .xoj handled as import, - // not as file to load - settings->setLastSavePath(filename.getParentPath()); - } + this->closeDocument(); + + this->doc->lock(); + this->doc->clearDocument(); + *this->doc = *loadedDocument; + this->doc->unlock(); + + // Set folder as last save path, so the next save will be at the current document location + // This is important because of the new .xopp format, where Xournal .xoj handled as import, + // not as file to load + settings->setLastSavePath(filename.getParentPath()); + fileLoaded(scrollToPage); return true; @@ -2339,7 +2348,7 @@ auto Control::loadPdf(const Path& filename, int scrollToPage) -> bool tmp = loadHandler.loadDocument(f.str()); } - if (tmp) + if (tmp != nullptr) { this->doc->lock(); this->doc->clearDocument(); @@ -2388,7 +2397,7 @@ void Control::fileLoaded(int scrollToPage) } loadMetadata(md); - recent->addRecentFileFilename(file); + RecentManager::addRecentFileFilename(file); } else { @@ -2405,7 +2414,8 @@ void Control::fileLoaded(int scrollToPage) class MetadataCallbackData { public: - Control* ctrl; + Control* ctrl{}; + {}; MetadataEntry md; }; @@ -2448,7 +2458,7 @@ void Control::loadMetadata(MetadataEntry md) data->md = std::move(md); data->ctrl = this; - g_idle_add((GSourceFunc) loadMetadataCallback, data); + g_idle_add(reinterpret_cast(loadMetadataCallback), data); } auto Control::annotatePdf(Path filename, bool attachPdf, bool attachToDocument) -> bool @@ -2477,7 +2487,7 @@ auto Control::annotatePdf(Path filename, bool attachPdf, bool attachToDocument) if (res) { - this->recent->addRecentFileFilename(filename.c_str()); + RecentManager::addRecentFileFilename(filename.c_str()); this->doc->lock(); Path file = this->doc->getEvMetadataFilename(); @@ -2605,7 +2615,7 @@ auto Control::showSaveDialog() -> bool GTK_RESPONSE_OK, nullptr); - gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(dialog), true); + gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(dialog), 1); GtkFileFilter* filterXoj = gtk_file_filter_new(); gtk_file_filter_set_name(filterXoj, _("Xournal++ files")); @@ -2621,7 +2631,7 @@ auto Control::showSaveDialog() -> bool gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), suggested_name.c_str()); gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(dialog), this->settings->getLastOpenPath().c_str(), nullptr); - gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), false); // handled below + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), 0); // handled below gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(this->getWindow()->getWindow())); @@ -2665,7 +2675,7 @@ auto Control::showSaveDialog() -> bool void Control::updateWindowTitle() { - string title = ""; + string title = title; this->doc->lock(); if (doc->getFilename().isEmpty()) @@ -2750,7 +2760,7 @@ void Control::resetSavedStatus() this->doc->unlock(); this->undoRedo->documentSaved(); - this->recent->addRecentFileFilename(filename); + RecentManager::addRecentFileFilename(filename); this->updateWindowTitle(); } @@ -2867,7 +2877,7 @@ auto Control::checkExistingFile(Path& folder, Path& filename) -> bool void Control::resetShapeRecognizer() { - if (this->win) + if (this->win != nullptr) { this->win->getXournal()->resetShapeRecognizer(); } @@ -3000,7 +3010,7 @@ void Control::clipboardPasteXournal(ObjectInputStream& in) XojPageView* view = win->getXournal()->getViewFor(pNr); - if (!view || !page) + if ((view == nullptr) || (page == nullptr)) { this->doc->unlock(); return; @@ -3083,7 +3093,7 @@ void Control::clipboardPasteXournal(ObjectInputStream& in) { g_warning("could not paste, Exception occurred: %s", e.what()); Stacktrace::printStracktrace(); - if (selection) + if (selection != nullptr) { for (Element* e: *selection->getElements()) { @@ -3096,7 +3106,7 @@ void Control::clipboardPasteXournal(ObjectInputStream& in) void Control::deleteSelection() { - if (win) + if (win != nullptr) { win->getXournal()->deleteSelection(); } @@ -3104,7 +3114,7 @@ void Control::deleteSelection() void Control::clearSelection() { - if (this->win) + if (this->win != nullptr) { this->win->getXournal()->clearSelection(); } @@ -3112,7 +3122,7 @@ void Control::clearSelection() void Control::setClipboardHandlerSelection(EditSelection* selection) { - if (this->clipboardHandler) + if (this->clipboardHandler != nullptr) { this->clipboardHandler->setSelection(selection); } @@ -3126,12 +3136,12 @@ void Control::setCopyPasteEnabled(bool enabled) void Control::setFill(bool fill) { EditSelection* sel = nullptr; - if (this->win) + if (this->win != nullptr) { sel = this->win->getXournal()->getSelection(); } - if (sel) + if (sel != nullptr) { undoRedo->addUndoAction(UndoActionPtr( sel->setFill(fill ? toolHandler->getPenFill() : -1, fill ? toolHandler->getHilighterFill() : -1))); @@ -3154,13 +3164,13 @@ void Control::setLineStyle(const string& style) LineStyle stl = StrokeStyle::parseStyle(style.c_str()); EditSelection* sel = nullptr; - if (this->win) + if (this->win != nullptr) { sel = this->win->getXournal()->getSelection(); } - // TODO allow to change selection - if (sel) + // TODO(fabian): allow to change selection + if (sel != nullptr) { // UndoAction* undo = sel->setSize(size, toolHandler->getToolThickness(TOOL_PEN), // toolHandler->getToolThickness(TOOL_HILIGHTER), @@ -3174,12 +3184,12 @@ void Control::setLineStyle(const string& style) void Control::setToolSize(ToolSize size) { EditSelection* sel = nullptr; - if (this->win) + if (this->win != nullptr) { sel = this->win->getXournal()->getSelection(); } - if (sel) + if (sel != nullptr) { undoRedo->addUndoAction(UndoActionPtr(sel->setSize(size, toolHandler->getToolThickness(TOOL_PEN), @@ -3195,17 +3205,17 @@ void Control::fontChanged() settings->setFont(font); EditSelection* sel = nullptr; - if (this->win) + if (this->win != nullptr) { sel = this->win->getXournal()->getSelection(); } - if (sel) + if (sel != nullptr) { undoRedo->addUndoAction(UndoActionPtr(sel->setFont(font))); } TextEditor* editor = getTextEditor(); - if (editor) + if (editor != nullptr) { editor->setFont(font); } @@ -3288,7 +3298,7 @@ void Control::gridSnappingToggle() auto Control::getTextEditor() -> TextEditor* { - if (this->win) + if (this->win != nullptr) { return this->win->getXournal()->getTextEditor(); } diff --git a/src/control/FullscreenHandler.cpp b/src/control/FullscreenHandler.cpp index e58203e6ac9d..1b066b6bdf24 100644 --- a/src/control/FullscreenHandler.cpp +++ b/src/control/FullscreenHandler.cpp @@ -5,7 +5,6 @@ #include -auto gtk_invisible_new() -> GtkWidget*; FullscreenHandler::FullscreenHandler(Settings* settings) : settings(settings) @@ -39,7 +38,7 @@ void FullscreenHandler::hideWidget(MainWindow* win, const string& widgetName) GtkWidget* mainMenubar = win->get("mainMenubar"); GtkWidget* mainBox = win->get("mainBox"); - if (mainMenubar == nullptr || !gtk_widget_is_visible(mainMenubar)) + if (mainMenubar == nullptr || (gtk_widget_is_visible(mainMenubar) == 0)) { // Menu not visible (global menu or something like this) return; @@ -55,7 +54,7 @@ void FullscreenHandler::hideWidget(MainWindow* win, const string& widgetName) gtk_widget_show(fix); - gtk_box_pack_end(GTK_BOX(mainBox), fix, false, false, 0); + gtk_box_pack_end(GTK_BOX(mainBox), fix, 0, 0, 0); menubarHidden = true; @@ -72,7 +71,7 @@ void FullscreenHandler::hideWidget(MainWindow* win, const string& widgetName) return; } - if (gtk_widget_get_visible(w)) + if (gtk_widget_get_visible(w) != 0) { gtk_widget_hide(w); hiddenFullscreenWidgets.push_back(w); @@ -115,7 +114,7 @@ void FullscreenHandler::disableFullscreen(MainWindow* win) // Remove menu from parent gtk_container_remove(GTK_CONTAINER(parent), mainMenubar); - gtk_box_pack_start(GTK_BOX(mainBox), mainMenubar, false, true, 0); + gtk_box_pack_start(GTK_BOX(mainBox), mainMenubar, 0, 1, 0); GValue value = G_VALUE_INIT; @@ -172,14 +171,14 @@ static void gtk_invisible_menu_get_preferred_height(GtkWidget *widget, gint *min static auto gtk_invisible_menu_draw(GtkWidget* widget, cairo_t* cr) -> gboolean { - return false; + return 0; } static void gtk_invisible_menu_class_init(GtkInvisibleMenuClass* klass) { - GtkWidgetClass* widget_class; + GtkWidgetClass* widget_class = nullptr; - widget_class = (GtkWidgetClass*) klass; + widget_class = reinterpret_cast(klass); widget_class->get_preferred_width = gtk_invisible_menu_get_preferred_width; widget_class->get_preferred_height = gtk_invisible_menu_get_preferred_height; widget_class->draw = gtk_invisible_menu_draw; @@ -189,35 +188,31 @@ auto gtk_invisible_get_type() -> GType { static GType gtk_invisible_menu_type = 0; - if (!gtk_invisible_menu_type) + if (gtk_invisible_menu_type == 0u) { - static const GTypeInfo gtk_inivisible_menu_info = - { - sizeof(GtkInvisibleMenuClass), - // base initialize - nullptr, - // base finalize - nullptr, - // class initialize - (GClassInitFunc) gtk_invisible_menu_class_init, - // class finalize - nullptr, - // class data, - nullptr, - // instance size - sizeof(GtkInvisibleMenu), - // n_preallocs - 0, - // instance init - nullptr, - // value table - (const GTypeValueTable*) nullptr - }; - - gtk_invisible_menu_type = g_type_register_static(GTK_TYPE_FIXED, - "GtkInvisibleMenu", - >k_inivisible_menu_info, - (GTypeFlags) 0); + static const GTypeInfo gtk_inivisible_menu_info = { + sizeof(GtkInvisibleMenuClass), + // base initialize + nullptr, + // base finalize + nullptr, + // class initialize + reinterpret_cast(gtk_invisible_menu_class_init), + // class finalize + nullptr, + // class data, + nullptr, + // instance size + sizeof(GtkInvisibleMenu), + // n_preallocs + 0, + // instance init + nullptr, + // value table + (const GTypeValueTable*) nullptr}; + + gtk_invisible_menu_type = g_type_register_static( + GTK_TYPE_FIXED, "GtkInvisibleMenu", >k_inivisible_menu_info, static_cast(0)); } return gtk_invisible_menu_type; diff --git a/src/control/LatexController.cpp b/src/control/LatexController.cpp index bb6919ac9309..398f3e7d2545 100644 --- a/src/control/LatexController.cpp +++ b/src/control/LatexController.cpp @@ -71,7 +71,7 @@ LatexController::~LatexController() auto LatexController::findTexDependencies() -> LatexController::FindDependencyStatus { gchar* pdflatex = g_find_program_in_path("pdflatex"); - if (!pdflatex) + if (pdflatex == nullptr) { string msg = _("Could not find pdflatex in PATH.\nPlease install pdflatex first and make sure it's in the PATH."); @@ -84,7 +84,7 @@ auto LatexController::findTexDependencies() -> LatexController::FindDependencySt static gchar* kpsewhichArgs[] = {g_strdup("kpsewhich"), g_strdup("standalone"), nullptr}; auto kpsewhichFlags = GSpawnFlags(G_SPAWN_DEFAULT | G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL); GError* kpsewhichErr = nullptr; - gint kpsewhichStatus; + gint kpsewhichStatus = 0; g_spawn_sync(nullptr, kpsewhichArgs, nullptr, @@ -101,7 +101,7 @@ auto LatexController::findTexDependencies() -> LatexController::FindDependencySt string msg = _("Could not find kpsewhich in PATH; please install kpsewhich and put it on path."); return LatexController::FindDependencyStatus(false, msg); } - else if (kpsewhichStatus != 0) + if (kpsewhichStatus != 0) { string msg = FS(_F("Could not find the LaTeX package 'standalone'.\nPlease install standalone (found in texlive-latex-extra) and make sure " "it's accessible by your LaTeX installation.")); @@ -122,7 +122,7 @@ auto LatexController::runCommandAsync(const string& texString) -> std::unique_pt Path texFile = this->texTmpDir / "tex.tex"; GError* err = nullptr; - if (!g_file_set_contents(texFile.c_str(), texContents.c_str(), texContents.length(), &err)) + if (g_file_set_contents(texFile.c_str(), texContents.c_str(), texContents.length(), &err) == 0) { XojMsgBox::showErrorToUser(control->getGtkWindow(), FS(_F("Could not save .tex file: {1}") % err->message)); g_error_free(err); @@ -141,7 +141,8 @@ auto LatexController::runCommandAsync(const string& texString) -> std::unique_pt this->setUpdating(true); this->lastPreviewedTex = texString; - bool success = g_spawn_async(texTmpDir.c_str(), argv, nullptr, flags, nullptr, nullptr, pdflatexPid.get(), &err); + bool success = + g_spawn_async(texTmpDir.c_str(), argv, nullptr, flags, nullptr, nullptr, pdflatexPid.get(), &err) != 0; if (!success) { string message = FS(_F("Could not start pdflatex: {1} (exit code: {2})") % err->message % err->code); @@ -185,7 +186,7 @@ void LatexController::findSelectedTexElement() this->selectedTexImage = view->getSelectedTex(); this->selectedText = view->getSelectedText(); - if (this->selectedTexImage || this->selectedText) + if ((this->selectedTexImage != nullptr) || (this->selectedText != nullptr)) { // this will get the position of the Latex properly EditSelection* theSelection = control->getWindow()->getXournal()->getSelection(); @@ -255,7 +256,7 @@ auto LatexController::showTexEditDialog() -> string string result = this->dlg.getFinalTex(); // If the user cancelled, there is no change in the latex string. - result = result == "" ? initialTex : result; + result = result.empty() ? initialTex : result; return result; } @@ -298,7 +299,7 @@ void LatexController::onPdfRenderComplete(GPid pid, gint returnCode, LatexContro if (err != nullptr) { self->isValidTex = false; - if (!g_error_matches(err, G_SPAWN_EXIT_ERROR, 1)) + if (g_error_matches(err, G_SPAWN_EXIT_ERROR, 1) == 0) { // The error was not caused by invalid LaTeX. string message = FS(_F("pdflatex encountered an error: {1} (exit code: {2})") % err->message % err->code); @@ -348,7 +349,7 @@ void LatexController::setUpdating(bool newValue) // needed. buttonEnabled = buttonEnabled && this->isValidTex; - gtk_widget_set_sensitive(okButton, buttonEnabled); + gtk_widget_set_sensitive(okButton, static_cast(buttonEnabled)); GtkLabel* errorLabel = GTK_LABEL(this->dlg.get("texErrorLabel")); gtk_label_set_text(errorLabel, this->isValidTex ? "" : N_("The formula is empty when rendered or invalid.")); @@ -365,7 +366,7 @@ void LatexController::deleteOldImage() this->view->getXournal()->deleteSelection(&selection); this->selectedTexImage = nullptr; } - else if (this->selectedText) + else if (this->selectedText != nullptr) { g_assert(this->selectedTexImage == nullptr); EditSelection selection(control->getUndoRedoHandler(), selectedText, view, page); @@ -393,7 +394,7 @@ auto LatexController::convertDocumentToImage(PopplerDocument* doc, string formul img->setY(posy); img->setText(std::move(formula)); - if (imgheight) + if (imgheight != 0) { double ratio = pageWidth / pageHeight; if (ratio == 0) @@ -427,7 +428,7 @@ auto LatexController::loadRendered(string renderedTex) -> std::unique_ptrgetGtkWindow(), FS(_F("Could not load LaTeX PDF file, File Error: {1}") % err->message)); diff --git a/src/control/PageBackgroundChangeController.cpp b/src/control/PageBackgroundChangeController.cpp index 4314cfbe8319..327382205769 100644 --- a/src/control/PageBackgroundChangeController.cpp +++ b/src/control/PageBackgroundChangeController.cpp @@ -4,6 +4,9 @@ #include "control/pagetype/PageTypeHandler.h" #include "gui/dialog/backgroundSelect/ImagesDialog.h" #include "gui/dialog/backgroundSelect/PdfPagesDialog.h" +#include +#include +#include #include "stockdlg/ImageOpenDlg.h" #include "undo/GroupUndoAction.h" #include "undo/PageBackgroundChangedUndoAction.h" @@ -123,7 +126,7 @@ void PageBackgroundChangeController::changeCurrentPageBackground(PageType& pageT * * @return true on success, false if the user cancels */ -auto PageBackgroundChangeController::applyImageBackground(PageRef page) -> bool +auto PageBackgroundChangeController::applyImageBackground(PageRef& page) -> bool { Document* doc = control->getDocument(); @@ -149,37 +152,36 @@ auto PageBackgroundChangeController::applyImageBackground(PageRef page) -> bool // The user canceled return false; } - else - { - char* name = g_file_get_path(file); - filename = name; - g_free(name); - name = nullptr; - g_object_unref(file); - file = nullptr; - } + + + char* name = g_file_get_path(file); + filename = name; + g_free(name); + name = nullptr; + g_object_unref(file); + file = nullptr; + BackgroundImage newImg; GError* err = nullptr; newImg.loadFile(filename, &err); newImg.setAttach(attach); - if (err) + if (err != nullptr) { XojMsgBox::showErrorToUser(control->getGtkWindow(), FS(_F("This image could not be loaded. Error message: {1}") % err->message)); g_error_free(err); return false; } - else - { - page->setBackgroundImage(newImg); - page->setBackgroundType(PageType(PageTypeFormat::Image)); - } + + + page->setBackgroundImage(newImg); + page->setBackgroundType(PageType(PageTypeFormat::Image)); } // Apply correct page size GdkPixbuf* pixbuf = page->getBackgroundImage().getPixbuf(); - if (pixbuf) + if (pixbuf != nullptr) { page->setSize(gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf)); @@ -199,7 +201,7 @@ auto PageBackgroundChangeController::applyImageBackground(PageRef page) -> bool * * @return true on success, false if the user cancels */ -auto PageBackgroundChangeController::applyPdfBackground(PageRef page) -> bool +auto PageBackgroundChangeController::applyPdfBackground(PageRef& page) -> bool { Document* doc = control->getDocument(); @@ -221,7 +223,7 @@ auto PageBackgroundChangeController::applyPdfBackground(PageRef page) -> bool int selected = dlg->getSelectedPage(); delete dlg; - if (selected >= 0 && selected < (int) doc->getPdfPageCount()) + if (selected >= 0 && selected < static_cast(doc->getPdfPageCount())) { // no need to set a type, if we set the page number the type is also set page->setBackgroundPdfPageNr(selected); @@ -238,27 +240,26 @@ auto PageBackgroundChangeController::applyPdfBackground(PageRef page) -> bool * * @return true on success, false if the user cancels */ -auto PageBackgroundChangeController::applyPageBackground(PageRef page, PageType pt) -> bool +auto PageBackgroundChangeController::applyPageBackground(PageRef& page, PageType pt) -> bool { if (pt.isPdfPage()) { return applyPdfBackground(page); } - else if (pt.isImagePage()) + if (pt.isImagePage()) { return applyImageBackground(page); } - else - { - page->setBackgroundType(pt); - return true; - } + + + page->setBackgroundType(pt); + return true; } /** * Copy the background from source to target */ -void PageBackgroundChangeController::copyBackgroundFromOtherPage(PageRef target, PageRef source) +void PageBackgroundChangeController::copyBackgroundFromOtherPage(PageRef& target, PageRef& source) { // Copy page size target->setSize(source->getWidth(), source->getHeight()); diff --git a/src/control/PageBackgroundChangeController.h b/src/control/PageBackgroundChangeController.h index eae13db42804..3e022d3a9688 100644 --- a/src/control/PageBackgroundChangeController.h +++ b/src/control/PageBackgroundChangeController.h @@ -53,28 +53,28 @@ class PageBackgroundChangeController : public PageTypeMenuChangeListener, public /** * Copy the background from source to target */ - void copyBackgroundFromOtherPage(PageRef target, PageRef source); + static void copyBackgroundFromOtherPage(PageRef &target, PageRef &source); /** * Apply the background to the page, asks for PDF Page or Image, if needed * * @return true on success, false if the user cancels */ - bool applyPageBackground(PageRef page, PageType pt); + bool applyPageBackground(PageRef &page, PageType pt); /** * Apply a new PDF Background, asks the user which page should be selected * * @return true on success, false if the user cancels */ - bool applyPdfBackground(PageRef page); + bool applyPdfBackground(PageRef &page); /** * Apply a new Image Background, asks the user which image should be inserted * * @return true on success, false if the user cancels */ - bool applyImageBackground(PageRef page); + bool applyImageBackground(PageRef &page); private: Control* control = nullptr; diff --git a/src/control/PdfCache.h b/src/control/PdfCache.h index dc47e4c528af..8755d93c8261 100644 --- a/src/control/PdfCache.h +++ b/src/control/PdfCache.h @@ -40,7 +40,7 @@ class PdfCache void cache(XojPdfPageSPtr popplerPage, cairo_surface_t* img); private: - GMutex renderMutex; + GMutex renderMutex{}; list data; list::size_type size = 0; diff --git a/src/control/PrintHandler.cpp b/src/control/PrintHandler.cpp index e0ae4c64db47..7053c4e484a1 100644 --- a/src/control/PrintHandler.cpp +++ b/src/control/PrintHandler.cpp @@ -3,6 +3,9 @@ #include "Util.h" #include "control/settings/Settings.h" +#include +#include +#include #include "model/Document.h" #include "view/DocumentView.h" @@ -22,8 +25,10 @@ void PrintHandler::drawPage(GtkPrintOperation* operation, GtkPrintContext* conte return; } - double width = page->getWidth(); - double height = page->getHeight(); + double width = NAN; + page->getWidth(); + double height = NAN; + page->getHeight(); if (width > height) { @@ -91,7 +96,7 @@ void PrintHandler::print(Document* doc, int currentPage) gtk_print_operation_set_current_page(op, currentPage); gtk_print_operation_set_job_name(op, "Xournal++"); gtk_print_operation_set_unit(op, GTK_UNIT_POINTS); - gtk_print_operation_set_use_full_page(op, true); + gtk_print_operation_set_use_full_page(op, 1); g_signal_connect(op, "draw_page", G_CALLBACK(drawPage), this); g_signal_connect(op, "request-page-setup", G_CALLBACK(requestPageSetup), this); diff --git a/src/control/RecentManager.cpp b/src/control/RecentManager.cpp index ebcc14251471..b34e3ef99d45 100644 --- a/src/control/RecentManager.cpp +++ b/src/control/RecentManager.cpp @@ -27,7 +27,7 @@ RecentManager::RecentManager() RecentManager::~RecentManager() { - if (this->recentHandlerId) + if (this->recentHandlerId != 0) { GtkRecentManager* recentManager = gtk_recent_manager_get_default(); g_signal_handler_disconnect(recentManager, this->recentHandlerId); @@ -49,8 +49,8 @@ void RecentManager::recentManagerChangedCallback(GtkRecentManager* manager, Rece void RecentManager::addRecentFileFilename(const Path& filename) { - GtkRecentManager* recentManager; - GtkRecentData* recentData; + GtkRecentManager* recentManager = nullptr; + GtkRecentData* recentData = nullptr; static gchar* groups[2] = { g_strdup(GROUP), nullptr}; @@ -63,17 +63,17 @@ void RecentManager::addRecentFileFilename(const Path& filename) if (filename.hasExtension(".pdf")) { - recentData->mime_type = (gchar*) g_strdup(MIME_PDF); + recentData->mime_type = g_strdup(MIME_PDF); } else { - recentData->mime_type = (gchar*) g_strdup(MIME); + recentData->mime_type = g_strdup(MIME); } - recentData->app_name = (gchar*) g_get_application_name(); + recentData->app_name = const_cast(g_get_application_name()); recentData->app_exec = g_strjoin(" ", g_get_prgname(), "%u", nullptr); recentData->groups = groups; - recentData->is_private = false; + recentData->is_private = 0; GFile* file = g_file_new_for_path(filename.c_str()); gchar* uri = g_file_get_uri(file); @@ -147,10 +147,10 @@ auto RecentManager::filterRecent(GList* items, bool xoj) -> GList* // filter for (GList* l = items; l != nullptr; l = l->next) { - auto* info = (GtkRecentInfo*) l->data; + auto* info = static_cast(l->data); const gchar * uri = gtk_recent_info_get_uri(info); - if( !uri ) // issue #1071 + if (uri == nullptr) // issue #1071 { continue; } @@ -174,14 +174,14 @@ auto RecentManager::filterRecent(GList* items, bool xoj) -> GList* } // sort - filteredItems = g_list_sort(filteredItems, (GCompareFunc) sortRecentsEntries); + filteredItems = g_list_sort(filteredItems, reinterpret_cast(sortRecentsEntries)); return filteredItems; } void RecentManager::recentsMenuActivateCallback(GtkAction* action, RecentManager* recentManager) { - auto* info = (GtkRecentInfo*) g_object_get_data(G_OBJECT(action), "gtk-recent-info"); + auto* info = static_cast(g_object_get_data(G_OBJECT(action), "gtk-recent-info")); g_return_if_fail(info != nullptr); Path p = Path::fromUri(gtk_recent_info_get_uri(info)); @@ -226,12 +226,12 @@ void RecentManager::addRecentMenu(GtkRecentInfo* info, int i) gtk_widget_set_tooltip_text(item, tip.c_str()); g_object_set_data_full(G_OBJECT(item), "gtk-recent-info", gtk_recent_info_ref(info), - (GDestroyNotify) gtk_recent_info_unref); + reinterpret_cast(gtk_recent_info_unref)); g_signal_connect(item, "activate", G_CALLBACK(recentsMenuActivateCallback), this); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); - gtk_widget_set_visible(GTK_WIDGET(item), true); + gtk_widget_set_visible(GTK_WIDGET(item), 1); this->menuItemList.push_back(item); } @@ -248,7 +248,7 @@ void RecentManager::updateMenu() int xojCount = 0; for (GList* l = filteredItemsXoj; l != nullptr; l = l->next) { - auto* info = (GtkRecentInfo*) l->data; + auto* info = static_cast(l->data); if (xojCount >= maxRecent) { @@ -262,14 +262,14 @@ void RecentManager::updateMenu() GtkWidget* separator = gtk_separator_menu_item_new(); gtk_menu_shell_append(GTK_MENU_SHELL(menu), separator); - gtk_widget_set_visible(GTK_WIDGET(separator), true); + gtk_widget_set_visible(GTK_WIDGET(separator), 1); this->menuItemList.push_back(separator); int pdfCount = 0; for (GList* l = filteredItemsPdf; l != nullptr; l = l->next) { - auto* info = (GtkRecentInfo*) l->data; + auto* info = static_cast(l->data); if (pdfCount >= maxRecent) { @@ -281,6 +281,6 @@ void RecentManager::updateMenu() } g_list_free(filteredItemsPdf); - g_list_foreach(items, (GFunc) gtk_recent_info_unref, nullptr); + g_list_foreach(items, reinterpret_cast(gtk_recent_info_unref), nullptr); g_list_free(items); } diff --git a/src/control/RecentManager.h b/src/control/RecentManager.h index 57a082ba8ca2..48a85dce0ac6 100644 --- a/src/control/RecentManager.h +++ b/src/control/RecentManager.h @@ -43,13 +43,13 @@ class RecentManager * Adds a file to the underlying GtkRecentManager * without altering the menu */ - void addRecentFileFilename(const Path& filename); + static void addRecentFileFilename(const Path& filename); /** * Removes a file from the underlying GtkRecentManager * without altering the menu */ - void removeRecentFileFilename(const Path& filename); + static void removeRecentFileFilename(const Path& filename); /** * Removes all of the menu items corresponding to recent files @@ -100,7 +100,7 @@ class RecentManager * @return A pointer to a GList containing the relevant GtkRecentInfo%s sorted according to their * modification dates */ - GList* filterRecent(GList* items, bool xoj); + static GList* filterRecent(GList* items, bool xoj); void addRecentMenu(GtkRecentInfo* info, int i); /** diff --git a/src/control/ScrollHandler.cpp b/src/control/ScrollHandler.cpp index 16727f8b92d9..afdb0d2ae616 100644 --- a/src/control/ScrollHandler.cpp +++ b/src/control/ScrollHandler.cpp @@ -14,7 +14,7 @@ ScrollHandler::~ScrollHandler() = default; void ScrollHandler::goToPreviousPage() { - if (this->control->getWindow()) + if (this->control->getWindow() != nullptr) { scrollToPage(this->control->getWindow()->getXournal()->getCurrentPage() - 1); } @@ -22,7 +22,7 @@ void ScrollHandler::goToPreviousPage() void ScrollHandler::goToNextPage() { - if (this->control->getWindow()) + if (this->control->getWindow() != nullptr) { scrollToPage(this->control->getWindow()->getXournal()->getCurrentPage() + 1); } @@ -30,7 +30,7 @@ void ScrollHandler::goToNextPage() void ScrollHandler::goToLastPage() { - if (this->control->getWindow()) + if (this->control->getWindow() != nullptr) { scrollToPage(this->control->getDocument()->getPageCount() - 1); } @@ -38,7 +38,7 @@ void ScrollHandler::goToLastPage() void ScrollHandler::goToFirstPage() { - if (this->control->getWindow()) + if (this->control->getWindow() != nullptr) { scrollToPage(0); } @@ -72,7 +72,7 @@ void ScrollHandler::scrollToPage(size_t page, double top) void ScrollHandler::scrollToSpinPage() { - if (!this->control->getWindow()) + if (this->control->getWindow() == nullptr) { return; } @@ -87,7 +87,7 @@ void ScrollHandler::scrollToSpinPage() void ScrollHandler::scrollToAnnotatedPage(bool next) { - if (!this->control->getWindow()) + if (this->control->getWindow() == nullptr) { return; } @@ -109,9 +109,9 @@ void ScrollHandler::scrollToAnnotatedPage(bool next) auto ScrollHandler::isPageVisible(size_t page, int* visibleHeight) -> bool { - if (!this->control->getWindow()) + if (this->control->getWindow() == nullptr) { - if (visibleHeight) + if (visibleHeight != nullptr) { *visibleHeight = 0; } diff --git a/src/control/SearchControl.cpp b/src/control/SearchControl.cpp index 477293beeb30..483f093c22db 100644 --- a/src/control/SearchControl.cpp +++ b/src/control/SearchControl.cpp @@ -41,7 +41,12 @@ auto SearchControl::search(string text, int* occures, double* top) -> bool { freeSearchResults(); - if (text.empty()) return true; + if (text.empty()) + { + { + return true; + } + } if (this->pdf) { @@ -59,7 +64,7 @@ auto SearchControl::search(string text, int* occures, double* top) -> bool { if (e->getType() == ELEMENT_TEXT) { - Text* t = (Text*) e; + Text* t = dynamic_cast(e); vector textResult = TextView::findText(t, text); @@ -68,14 +73,14 @@ auto SearchControl::search(string text, int* occures, double* top) -> bool } } - if (occures) + if (occures != nullptr) { *occures = this->results.size(); } - if (top) + if (top != nullptr) { - if (this->results.size() == 0) + if (this->results.empty()) { *top = 0; } @@ -94,5 +99,5 @@ auto SearchControl::search(string text, int* occures, double* top) -> bool } } - return this->results.size() > 0; + return !this->results.empty(); } diff --git a/src/control/Tool.h b/src/control/Tool.h index cf14e0ab83af..bc73b7dea33d 100644 --- a/src/control/Tool.h +++ b/src/control/Tool.h @@ -18,7 +18,7 @@ class Tool : public ToolBase { public: - Tool(string name, ToolType tool, int color, int capabilities, double* thickness); + Tool(string name, ToolType type, int color, int capabilities, double* thickness); virtual ~Tool(); public: diff --git a/src/control/ToolEnums.cpp b/src/control/ToolEnums.cpp index b71a290e8351..45b9882b44c9 100644 --- a/src/control/ToolEnums.cpp +++ b/src/control/ToolEnums.cpp @@ -16,13 +16,62 @@ auto toolSizeToString(ToolSize size) -> string auto toolSizeFromString(const string& size) -> ToolSize { - if (size == "veryThin") return TOOL_SIZE_VERY_FINE; - else if (size == "thin") return TOOL_SIZE_FINE; - else if (size == "medium") return TOOL_SIZE_MEDIUM; - else if (size == "thick") return TOOL_SIZE_THICK; - else if (size == "veryThick") return TOOL_SIZE_VERY_THICK; - else if (size == "none") return TOOL_SIZE_NONE; - else return TOOL_SIZE_NONE; + if (size == "veryThin") + { + { + { + return TOOL_SIZE_VERY_FINE; + } + } + } + if (size == "thin") + { + { + { + return TOOL_SIZE_FINE; + } + } + } + else if (size == "medium") + { + { + { + return TOOL_SIZE_MEDIUM; + } + } + } + else if (size == "thick") + { + { + { + return TOOL_SIZE_THICK; + } + } + } + else if (size == "veryThick") + { + { + { + return TOOL_SIZE_VERY_THICK; + } + } + } + else if (size == "none") + { + { + { + return TOOL_SIZE_NONE; + } + } + } + else + { + { + { + return TOOL_SIZE_NONE; + } + } + } } auto drawingTypeToString(DrawingType type) -> string @@ -43,15 +92,78 @@ auto drawingTypeToString(DrawingType type) -> string auto drawingTypeFromString(const string& type) -> DrawingType { - if (type == "dontChange") return DRAWING_TYPE_DONT_CHANGE; - else if (type == "line") return DRAWING_TYPE_LINE; - else if (type == "rectangle") return DRAWING_TYPE_RECTANGLE; - else if (type == "circle") return DRAWING_TYPE_CIRCLE; - else if (type == "arrow") return DRAWING_TYPE_ARROW; - else if (type == "strokeRecognizer") return DRAWING_TYPE_STROKE_RECOGNIZER; - else if (type == "drawCoordinateSystem") return DRAWING_TYPE_COORDINATE_SYSTEM; - else if (type == "default") return DRAWING_TYPE_DEFAULT; - else return DRAWING_TYPE_DEFAULT; + if (type == "dontChange") + { + { + { + return DRAWING_TYPE_DONT_CHANGE; + } + } + } + if (type == "line") + { + { + { + return DRAWING_TYPE_LINE; + } + } + } + else if (type == "rectangle") + { + { + { + return DRAWING_TYPE_RECTANGLE; + } + } + } + else if (type == "circle") + { + { + { + return DRAWING_TYPE_CIRCLE; + } + } + } + else if (type == "arrow") + { + { + { + return DRAWING_TYPE_ARROW; + } + } + } + else if (type == "strokeRecognizer") + { + { + { + return DRAWING_TYPE_STROKE_RECOGNIZER; + } + } + } + else if (type == "drawCoordinateSystem") + { + { + { + return DRAWING_TYPE_COORDINATE_SYSTEM; + } + } + } + else if (type == "default") + { + { + { + return DRAWING_TYPE_DEFAULT; + } + } + } + else + { + { + { + return DRAWING_TYPE_DEFAULT; + } + } + } } auto toolTypeToString(ToolType type) -> string @@ -81,23 +193,142 @@ auto toolTypeToString(ToolType type) -> string auto toolTypeFromString(const string& type) -> ToolType { - if (type == "none") return TOOL_NONE; - else if (type == "pen") return TOOL_PEN; - else if (type == "eraser") return TOOL_ERASER; - else if (type == "hilighter") return TOOL_HILIGHTER; - else if (type == "image") return TOOL_IMAGE; - else if (type == "selectRect") return TOOL_SELECT_RECT; - else if (type == "selectRegion") return TOOL_SELECT_REGION; - else if (type == "selectObject") return TOOL_SELECT_OBJECT; - else if (type == "playObject") return TOOL_PLAY_OBJECT; - else if (type == "verticalSpace") return TOOL_VERTICAL_SPACE; - else if (type == "hand") return TOOL_HAND; - else if (type == "drawRect") return TOOL_DRAW_RECT; - else if (type == "drawCircle") return TOOL_DRAW_CIRCLE; - else if (type == "drawArrow") return TOOL_DRAW_ARROW; - else if (type == "drawCoordinateSystem") return TOOL_DRAW_COORDINATE_SYSTEM; - else if (type == "showFloatingToolbox") return TOOL_FLOATING_TOOLBOX; - else return TOOL_NONE; + if (type == "none") + { + { + { + return TOOL_NONE; + } + } + } + if (type == "pen") + { + { + { + return TOOL_PEN; + } + } + } + else if (type == "eraser") + { + { + { + return TOOL_ERASER; + } + } + } + else if (type == "hilighter") + { + { + { + return TOOL_HILIGHTER; + } + } + } + else if (type == "image") + { + { + { + return TOOL_IMAGE; + } + } + } + else if (type == "selectRect") + { + { + { + return TOOL_SELECT_RECT; + } + } + } + else if (type == "selectRegion") + { + { + { + return TOOL_SELECT_REGION; + } + } + } + else if (type == "selectObject") + { + { + { + return TOOL_SELECT_OBJECT; + } + } + } + else if (type == "playObject") + { + { + { + return TOOL_PLAY_OBJECT; + } + } + } + else if (type == "verticalSpace") + { + { + { + return TOOL_VERTICAL_SPACE; + } + } + } + else if (type == "hand") + { + { + { + return TOOL_HAND; + } + } + } + else if (type == "drawRect") + { + { + { + return TOOL_DRAW_RECT; + } + } + } + else if (type == "drawCircle") + { + { + { + return TOOL_DRAW_CIRCLE; + } + } + } + else if (type == "drawArrow") + { + { + { + return TOOL_DRAW_ARROW; + } + } + } + else if (type == "drawCoordinateSystem") + { + { + { + return TOOL_DRAW_COORDINATE_SYSTEM; + } + } + } + else if (type == "showFloatingToolbox") + { + { + { + return TOOL_FLOATING_TOOLBOX; + } + } + } + else + { + { + { + return TOOL_NONE; + } + } + } } auto eraserTypeToString(EraserType type) -> string @@ -114,10 +345,45 @@ auto eraserTypeToString(EraserType type) -> string auto eraserTypeFromString(const string& type) -> EraserType { - if (type == "none") return ERASER_TYPE_NONE; - else if (type == "default") return ERASER_TYPE_DEFAULT; - else if (type == "whiteout") return ERASER_TYPE_WHITEOUT; - else if (type == "deleteStroke") return ERASER_TYPE_DELETE_STROKE; - else return ERASER_TYPE_NONE; + if (type == "none") + { + { + { + return ERASER_TYPE_NONE; + } + } + } + if (type == "default") + { + { + { + return ERASER_TYPE_DEFAULT; + } + } + } + else if (type == "whiteout") + { + { + { + return ERASER_TYPE_WHITEOUT; + } + } + } + else if (type == "deleteStroke") + { + { + { + return ERASER_TYPE_DELETE_STROKE; + } + } + } + else + { + { + { + return ERASER_TYPE_NONE; + } + } + } } diff --git a/src/control/ToolHandler.cpp b/src/control/ToolHandler.cpp index 66b87022efc5..884a04a90731 100644 --- a/src/control/ToolHandler.cpp +++ b/src/control/ToolHandler.cpp @@ -152,7 +152,7 @@ void ToolHandler::selectTool(ToolType type, bool fireToolChanged) void ToolHandler::fireToolChanged() { - if (listener) + if (listener != nullptr) { listener->toolChanged(); } @@ -275,15 +275,14 @@ auto ToolHandler::getHilighterFill() -> int auto ToolHandler::getThickness() -> double { - if (this->current->thickness) + if (this->current->thickness != nullptr) { return this->current->thickness[this->current->getSize()]; } - else - { - g_warning("Request size of \"%s\"", this->current->getName().c_str()); + + + g_warning("Request size of \"%s\"", this->current->getName().c_str()); return 0; - } } void ToolHandler::setSize(ToolSize size) @@ -415,7 +414,7 @@ void ToolHandler::saveSettings() if (tool->type == TOOL_PEN || tool->type == TOOL_HILIGHTER) { - st.setInt("fill", tool->getFill()); + st.setInt("fill", static_cast(tool->getFill())); st.setInt("fillAlpha", tool->getFillAlpha()); } @@ -475,7 +474,7 @@ void ToolHandler::loadSettings() int fill = -1; if (st.getInt("fill", fill)) { - tool->setFill(fill); + tool->setFill(fill != 0); } int fillAlpha = -1; if (st.getInt("fillAlpha", fillAlpha)) @@ -493,16 +492,53 @@ void ToolHandler::loadSettings() if (tool->hasCapability(TOOL_CAP_SIZE) && st.getString("size", value)) { if (value == "VERY_FINE") - tool->setSize(TOOL_SIZE_VERY_FINE); + { + { + { + tool->setSize(TOOL_SIZE_VERY_FINE); + } + } + } else if (value == "THIN") - tool->setSize(TOOL_SIZE_FINE); + { + { + { + tool->setSize(TOOL_SIZE_FINE); + } + } + } else if (value == "MEDIUM") - tool->setSize(TOOL_SIZE_MEDIUM); + { + { + { + tool->setSize(TOOL_SIZE_MEDIUM); + } + } + } else if (value == "BIG") - tool->setSize(TOOL_SIZE_THICK); + { + { + { + tool->setSize(TOOL_SIZE_THICK); + } + } + } else if (value == "VERY_BIG") - tool->setSize(TOOL_SIZE_VERY_THICK); - else g_warning("Settings::Unknown tool size: %s\n", value.c_str()); + { + { + { + tool->setSize(TOOL_SIZE_VERY_THICK); + } + } + } + else + { + { + { + g_warning("Settings::Unknown tool size: %s\n", value.c_str()); + } + } + } } if (tool->type == TOOL_ERASER) @@ -511,9 +547,30 @@ void ToolHandler::loadSettings() if (st.getString("type", type)) { - if (type == "deleteStroke") setEraserType(ERASER_TYPE_DELETE_STROKE); - else if (type == "whiteout") setEraserType(ERASER_TYPE_WHITEOUT); - else setEraserType(ERASER_TYPE_DEFAULT); + if (type == "deleteStroke") + { + { + { + setEraserType(ERASER_TYPE_DELETE_STROKE); + } + } + } + else if (type == "whiteout") + { + { + { + setEraserType(ERASER_TYPE_WHITEOUT); + } + } + } + else + { + { + { + setEraserType(ERASER_TYPE_DEFAULT); + } + } + } eraserTypeChanged(); } } @@ -586,8 +643,11 @@ auto ToolHandler::isSinglePageTool() -> bool ToolType toolType = this->getToolType(); DrawingType drawingType = this->getDrawingType(); - return toolType == (TOOL_PEN && (drawingType == DRAWING_TYPE_ARROW || drawingType == DRAWING_TYPE_CIRCLE || drawingType == DRAWING_TYPE_COORDINATE_SYSTEM - || drawingType == DRAWING_TYPE_LINE || drawingType == DRAWING_TYPE_RECTANGLE)) - || toolType == TOOL_SELECT_REGION || toolType == TOOL_SELECT_RECT || toolType == TOOL_SELECT_OBJECT || toolType == TOOL_DRAW_RECT || toolType == TOOL_DRAW_CIRCLE - || toolType == TOOL_DRAW_COORDINATE_SYSTEM || toolType == TOOL_DRAW_ARROW|| toolType==TOOL_FLOATING_TOOLBOX; + return toolType == static_cast((TOOL_PEN != 0u) && + (drawingType == DRAWING_TYPE_ARROW || drawingType == DRAWING_TYPE_CIRCLE || + drawingType == DRAWING_TYPE_COORDINATE_SYSTEM || + drawingType == DRAWING_TYPE_LINE || drawingType == DRAWING_TYPE_RECTANGLE)) || + toolType == TOOL_SELECT_REGION || toolType == TOOL_SELECT_RECT || toolType == TOOL_SELECT_OBJECT || + toolType == TOOL_DRAW_RECT || toolType == TOOL_DRAW_CIRCLE || toolType == TOOL_DRAW_COORDINATE_SYSTEM || + toolType == TOOL_DRAW_ARROW || toolType == TOOL_FLOATING_TOOLBOX; } diff --git a/src/control/UndoRedoController.cpp b/src/control/UndoRedoController.cpp index 44fdf02d8b75..f598b2cffb98 100644 --- a/src/control/UndoRedoController.cpp +++ b/src/control/UndoRedoController.cpp @@ -49,7 +49,7 @@ void UndoRedoController::after() size_t pageNo = doc->indexOf(page); XojPageView* view = control->getWindow()->getXournal()->getViewFor(pageNo); - if (!view || !page) + if ((view == nullptr) || !page) { return; } diff --git a/src/control/XournalMain.cpp b/src/control/XournalMain.cpp index ab9357447b8e..efefd0a2712e 100644 --- a/src/control/XournalMain.cpp +++ b/src/control/XournalMain.cpp @@ -88,10 +88,10 @@ void XournalMain::checkForErrorlog() vector errorList; - const gchar* file; + const gchar* file = nullptr; while ((file = g_dir_read_name(home)) != nullptr) { - if (g_file_test(file, G_FILE_TEST_IS_REGULAR)) + if (g_file_test(file, G_FILE_TEST_IS_REGULAR) != 0) { if (StringUtils::startsWith(file, "errorlog.")) { @@ -239,7 +239,7 @@ auto XournalMain::exportImg(const char* input, const char* output) -> int exportRange.clear(); string errorMsg = imgExport.getLastErrorMsg(); - if (errorMsg != "") + if (!errorMsg.empty()) { g_message("Error exporting image: %s\n", errorMsg.c_str()); return -3; @@ -309,23 +309,23 @@ auto XournalMain::run(int argc, char* argv[]) -> int g_option_context_add_main_entries(context, options, GETTEXT_PACKAGE); // parse options, so we don't need gtk_init, but don't init display (so we have a commandline mode) - g_option_context_add_group(context, gtk_get_option_group(false)); - if (!g_option_context_parse(context, &argc, &argv, &error)) + g_option_context_add_group(context, gtk_get_option_group(0)); + if (g_option_context_parse(context, &argc, &argv, &error) == 0) { g_error("%s", error->message); g_error_free(error); - gchar* help = g_option_context_get_help(context, true, nullptr); + gchar* help = g_option_context_get_help(context, 1, nullptr); g_message("%s", help); g_free(help); error = nullptr; } g_option_context_free(context); - if (pdfFilename && optFilename && *optFilename) + if ((pdfFilename != nullptr) && (optFilename != nullptr) && (*optFilename != nullptr)) { return exportPdf(*optFilename, pdfFilename); } - if (imgFilename && optFilename && *optFilename) + if ((imgFilename != nullptr) && (optFilename != nullptr) && (*optFilename != nullptr)) { return exportImg(*optFilename, imgFilename); } @@ -335,7 +335,7 @@ auto XournalMain::run(int argc, char* argv[]) -> int const char* imModule = g_getenv("GTK_IM_MODULE"); if (imModule != nullptr && strcmp(imModule, "xim") == 0) { - g_setenv("GTK_IM_MODULE", "ibus", true); + g_setenv("GTK_IM_MODULE", "ibus", 1); g_warning("Unsupported input method: xim, changed to: ibus"); } @@ -367,7 +367,7 @@ auto XournalMain::run(int argc, char* argv[]) -> int win->show(nullptr); bool opened = false; - if (optFilename) + if (optFilename != nullptr) { if (g_strv_length(optFilename) != 1) { @@ -514,7 +514,7 @@ void XournalMain::initResourcePath(GladeSearchpath* gladePath, const gchar* rela { string uiPath = findResourcePath(relativePathAndFile); //i.e. relativePathAndFile = "ui/about.glade" - if (uiPath != "") + if (!uiPath.empty()) { gladePath->addSearchDirectory(uiPath); return; diff --git a/src/control/XournalMain.h b/src/control/XournalMain.h index 4ca8d6a186e8..eb97b2fe6c8c 100644 --- a/src/control/XournalMain.h +++ b/src/control/XournalMain.h @@ -27,18 +27,19 @@ class XournalMain int run(int argc, char* argv[]); private: - void initLocalisation(); + static void initLocalisation(); - void checkForErrorlog(); - void checkForEmergencySave(Control* control); + static void checkForErrorlog(); + static void checkForEmergencySave(Control* control); - int exportPdf(const char* input, const char* output); - int exportImg(const char* input, const char* output); + static int exportPdf(const char* input, const char* output); + static int exportImg(const char* input, const char* output); void initSettingsPath(); void initResourcePath(GladeSearchpath* gladePath); - void initResourcePath(GladeSearchpath* gladePath, const gchar* relativePathAndFile, bool failIfNotFound = true); - string findResourcePath(const string& searchFile); + static void initResourcePath(GladeSearchpath* gladePath, const gchar* relativePathAndFile, + bool failIfNotFound = true); + static string findResourcePath(const string& searchFile); private: }; diff --git a/src/pdf/popplerapi/PopplerGlibAction.cpp b/src/pdf/popplerapi/PopplerGlibAction.cpp index 52e7a53d6327..7e61c6b603a4 100644 --- a/src/pdf/popplerapi/PopplerGlibAction.cpp +++ b/src/pdf/popplerapi/PopplerGlibAction.cpp @@ -12,7 +12,7 @@ PopplerGlibAction::~PopplerGlibAction() poppler_action_free(action); action = nullptr; - if (document) + if (document != nullptr) { g_object_unref(document); document = nullptr; @@ -28,7 +28,7 @@ auto PopplerGlibAction::getDestination() -> XojLinkDest* // every other action is not supported in Xournal if (action->type == POPPLER_ACTION_GOTO_DEST) { - auto* actionDest = (PopplerActionGotoDest*) action; + auto* actionDest = reinterpret_cast(action); PopplerDest* pDest = actionDest->dest; if (pDest == nullptr) @@ -61,21 +61,21 @@ void PopplerGlibAction::linkFromDest(LinkDestination* link, PopplerDest* pDest) double pageHeight = 0; poppler_page_get_size(page, &pageWidth, &pageHeight); - if (pDest->left) - { + if (pDest->left != 0.0) + { link->setChangeLeft(pDest->left); } - else if (pDest->right) - { + else if (pDest->right != 0.0) + { link->setChangeLeft(pageWidth - pDest->right); } - if (pDest->top) - { + if (pDest->top != 0.0) + { link->setChangeTop(pageHeight - std::min(pageHeight, pDest->top)); } - else if (pDest->bottom) - { + else if (pDest->bottom != 0.0) + { link->setChangeTop(pageHeight - std::min(pageHeight, pageHeight - pDest->bottom)); } @@ -129,5 +129,5 @@ void PopplerGlibAction::linkFromDest(LinkDestination* link, PopplerDest* pDest) auto PopplerGlibAction::getTitle() -> string { - return ((PopplerActionAny*)action)->title; + return (reinterpret_cast(action))->title; } diff --git a/src/pdf/popplerapi/PopplerGlibDocument.cpp b/src/pdf/popplerapi/PopplerGlibDocument.cpp index 87ce4caef298..40b477e8e5f3 100644 --- a/src/pdf/popplerapi/PopplerGlibDocument.cpp +++ b/src/pdf/popplerapi/PopplerGlibDocument.cpp @@ -11,7 +11,7 @@ PopplerGlibDocument::PopplerGlibDocument() = default; PopplerGlibDocument::PopplerGlibDocument(const PopplerGlibDocument& doc) : document(doc.document) { - if (document) + if (document != nullptr) { g_object_ref(document); } @@ -19,7 +19,7 @@ PopplerGlibDocument::PopplerGlibDocument(const PopplerGlibDocument& doc) PopplerGlibDocument::~PopplerGlibDocument() { - if (document) + if (document != nullptr) { g_object_unref(document); document = nullptr; @@ -28,13 +28,13 @@ PopplerGlibDocument::~PopplerGlibDocument() void PopplerGlibDocument::assign(XojPdfDocumentInterface* doc) { - if (document) + if (document != nullptr) { g_object_unref(document); } - document = ((PopplerGlibDocument*)doc)->document; - if (document) + document = (dynamic_cast(doc))->document; + if (document != nullptr) { g_object_ref(document); } @@ -42,7 +42,7 @@ void PopplerGlibDocument::assign(XojPdfDocumentInterface* doc) auto PopplerGlibDocument::equals(XojPdfDocumentInterface* doc) -> bool { - return document == ((PopplerGlibDocument*)doc)->document; + return document == (dynamic_cast(doc))->document; } auto PopplerGlibDocument::save(Path filename, GError** error) -> bool @@ -57,7 +57,7 @@ auto PopplerGlibDocument::save(Path filename, GError** error) -> bool { return false; } - return poppler_document_save(document, uri.c_str(), error); + return poppler_document_save(document, uri.c_str(), error) != 0; } auto PopplerGlibDocument::load(Path filename, string password, GError** error) -> bool @@ -68,7 +68,7 @@ auto PopplerGlibDocument::load(Path filename, string password, GError** error) - return false; } - if (document) + if (document != nullptr) { g_object_unref(document); } @@ -79,7 +79,7 @@ auto PopplerGlibDocument::load(Path filename, string password, GError** error) - auto PopplerGlibDocument::load(gpointer data, gsize length, string password, GError** error) -> bool { - if (document) + if (document != nullptr) { g_object_unref(document); } diff --git a/src/pdf/popplerapi/PopplerGlibPage.cpp b/src/pdf/popplerapi/PopplerGlibPage.cpp index c3c7b42c2ce5..9901456f4acf 100644 --- a/src/pdf/popplerapi/PopplerGlibPage.cpp +++ b/src/pdf/popplerapi/PopplerGlibPage.cpp @@ -21,7 +21,7 @@ PopplerGlibPage::PopplerGlibPage(const PopplerGlibPage& other) PopplerGlibPage::~PopplerGlibPage() { - if (page) + if (page != nullptr) { g_object_unref(page); page = nullptr; @@ -30,7 +30,7 @@ PopplerGlibPage::~PopplerGlibPage() void PopplerGlibPage::operator=(const PopplerGlibPage& other) { - if (page) + if (page != nullptr) { g_object_unref(page); page = nullptr; @@ -83,9 +83,9 @@ auto PopplerGlibPage::findText(string& text) -> vector double height = getHeight(); GList* matches = poppler_page_find_text(page, text.c_str()); - for (GList* l = matches; l && l->data; l = g_list_next(l)) + for (GList* l = matches; (l != nullptr) && (l->data != nullptr); l = g_list_next(l)) { - auto* rect = (PopplerRectangle*) l->data; + auto* rect = static_cast(l->data); findings.emplace_back(rect->x1, height - rect->y1, rect->x2, height - rect->y2); diff --git a/src/pdf/popplerapi/PopplerGlibPageBookmarkIterator.cpp b/src/pdf/popplerapi/PopplerGlibPageBookmarkIterator.cpp index 0f00e4e0e55f..d387dc2b1460 100644 --- a/src/pdf/popplerapi/PopplerGlibPageBookmarkIterator.cpp +++ b/src/pdf/popplerapi/PopplerGlibPageBookmarkIterator.cpp @@ -12,7 +12,7 @@ PopplerGlibPageBookmarkIterator::~PopplerGlibPageBookmarkIterator() poppler_index_iter_free(iter); iter = nullptr; - if (document) + if (document != nullptr) { g_object_unref(document); document = nullptr; @@ -21,12 +21,12 @@ PopplerGlibPageBookmarkIterator::~PopplerGlibPageBookmarkIterator() auto PopplerGlibPageBookmarkIterator::next() -> bool { - return poppler_index_iter_next(iter); + return poppler_index_iter_next(iter) != 0; } auto PopplerGlibPageBookmarkIterator::isOpen() -> bool { - return poppler_index_iter_is_open(iter); + return poppler_index_iter_is_open(iter) != 0; } auto PopplerGlibPageBookmarkIterator::getChildIter() -> XojPdfBookmarkIterator* diff --git a/src/util/CrashHandler.cpp b/src/util/CrashHandler.cpp index 3457ffd6da15..ebbcb84843f5 100644 --- a/src/util/CrashHandler.cpp +++ b/src/util/CrashHandler.cpp @@ -11,7 +11,6 @@ #include -using std::to_string; #include static Document* document = nullptr; diff --git a/src/util/DeviceListHelper.cpp b/src/util/DeviceListHelper.cpp index 8977656decbe..8236e11f5244 100644 --- a/src/util/DeviceListHelper.cpp +++ b/src/util/DeviceListHelper.cpp @@ -24,7 +24,7 @@ void addDevicesToList(std::vector& deviceList, GList* devList, bool { while (devList != nullptr) { - auto dev = (GdkDevice*) devList->data; + auto dev = static_cast(devList->data); if (GDK_SOURCE_KEYBOARD == gdk_device_get_source(dev)) { // Skip keyboard @@ -60,8 +60,8 @@ auto DeviceListHelper::getDeviceList(Settings* settings, bool ignoreTouchDevices deviceList.end()); } - GList* pointerSlaves; - // TODO remove after completely switching to gtk 3.20 or use c++17 if constexpr (predicate){...} else{...} ... + GList* pointerSlaves = nullptr; + // TODO(fabian): remove after completely switching to gtk 3.20 or use c++17 if constexpr (predicate){...} else{...} ... #if (GDK_MAJOR_VERSION >= 3 && GDK_MINOR_VERSION >= 22) GdkDisplay* display = gdk_display_get_default(); GdkSeat* defaultSeat = gdk_display_get_default_seat(display); @@ -117,28 +117,28 @@ auto InputDevice::getType() const -> string { return _("mouse"); } - else if (source == GDK_SOURCE_PEN) + if (source == GDK_SOURCE_PEN) { return _("pen"); } - else if (source == GDK_SOURCE_ERASER) + if (source == GDK_SOURCE_ERASER) { return _("eraser"); } - else if (source == GDK_SOURCE_CURSOR) + if (source == GDK_SOURCE_CURSOR) { return _("cursor"); } - else if (source == GDK_SOURCE_KEYBOARD) + if (source == GDK_SOURCE_KEYBOARD) { // not used: filtered above return _("keyboard"); } - else if (source == GDK_SOURCE_TOUCHSCREEN) + if (source == GDK_SOURCE_TOUCHSCREEN) { return _("touchscreen"); } - else if (source == GDK_SOURCE_TOUCHPAD) + if (source == GDK_SOURCE_TOUCHPAD) { return _("touchpad"); } diff --git a/src/util/OutputStream.cpp b/src/util/OutputStream.cpp index fd22ccfe4298..6a5b1c6cd9da 100644 --- a/src/util/OutputStream.cpp +++ b/src/util/OutputStream.cpp @@ -36,7 +36,7 @@ GzOutputStream::GzOutputStream(const Path& filename) GzOutputStream::~GzOutputStream() { - if (this->fp) + if (this->fp != nullptr) { close(); } @@ -55,7 +55,7 @@ void GzOutputStream::write(const char* data, int len) void GzOutputStream::close() { - if (this->fp) + if (this->fp != nullptr) { gzclose(this->fp); this->fp = nullptr; diff --git a/src/util/OutputStream.h b/src/util/OutputStream.h index a48571fee787..cf75cf52c780 100644 --- a/src/util/OutputStream.h +++ b/src/util/OutputStream.h @@ -23,7 +23,7 @@ class OutputStream virtual ~OutputStream(); public: - virtual void write(const char* data); + virtual void write(const char* str); virtual void write(const char* data, int len) = 0; virtual void write(const string& str); diff --git a/src/util/PageRange.cpp b/src/util/PageRange.cpp index 3d024627b7e1..3b41f1612203 100644 --- a/src/util/PageRange.cpp +++ b/src/util/PageRange.cpp @@ -35,12 +35,12 @@ auto PageRange::parse(const char* str) -> PageRangeVector return data; } - int start, end; + int start = 0, end = 0; char* next = nullptr; const char* p = str; - while (*p) + while (*p != 0) { - while (isspace(*p)) + while (isspace(*p) != 0) { p++; } @@ -52,7 +52,7 @@ auto PageRange::parse(const char* str) -> PageRangeVector } else { - start = (int) strtol(p, &next, 10); + start = static_cast(strtol(p, &next, 10)); if (start < 1) { start = 1; @@ -62,7 +62,7 @@ auto PageRange::parse(const char* str) -> PageRangeVector end = start; - while (isspace(*p)) + while (isspace(*p) != 0) { p++; } @@ -70,7 +70,7 @@ auto PageRange::parse(const char* str) -> PageRangeVector if (*p == '-') { p++; - end = (int) strtol(p, &next, 10); + end = static_cast(strtol(p, &next, 10)); if (next == p) // a half-open range like 2- { end = 0; @@ -84,13 +84,13 @@ auto PageRange::parse(const char* str) -> PageRangeVector data.push_back(new PageRangeEntry(start - 1, end - 1)); // Skip until end or separator - while (*p && !isSeparator(*p)) + while ((*p != 0) && !isSeparator(*p)) { p++; } // if not at end, skip separator - if (*p) + if (*p != 0) { p++; } diff --git a/src/util/Path.cpp b/src/util/Path.cpp index e6d3b70cbc6c..923832d3bebc 100644 --- a/src/util/Path.cpp +++ b/src/util/Path.cpp @@ -107,7 +107,7 @@ auto Path::isEmpty() const -> bool auto Path::exists() const -> bool { - return g_file_test(path.c_str(), G_FILE_TEST_EXISTS); + return g_file_test(path.c_str(), G_FILE_TEST_EXISTS) != 0; } auto Path::deleteFile() -> bool diff --git a/src/util/PathUtil.cpp b/src/util/PathUtil.cpp index 22e90a69c2da..dd3c2202a1cd 100644 --- a/src/util/PathUtil.cpp +++ b/src/util/PathUtil.cpp @@ -18,45 +18,44 @@ auto PathUtil::readString(string& output, Path& path, bool showErrorToUser) -> b gchar* contents = nullptr; gsize length = 0; GError* error = nullptr; - if (g_file_get_contents(path.c_str(), &contents, &length, &error)) + if (g_file_get_contents(path.c_str(), &contents, &length, &error) != 0) { output = contents; g_free(contents); return true; } - else - { - if (showErrorToUser) + + + if (showErrorToUser) { XojMsgBox::showErrorToUser(nullptr, error->message); } g_error_free(error); return false; - } } auto PathUtil::copy(const Path& src, const Path& dest) -> bool { char buffer[16384]; // 16k - FILE* fpRead = g_fopen(src.c_str(), "rb"); - if (!fpRead) + FILE* fpRead = g_fopen(src.c_str(), "rbe"); + if (fpRead == nullptr) { return false; } - FILE* fpWrite = g_fopen(dest.c_str(), "wb"); - if (!fpWrite) + FILE* fpWrite = g_fopen(dest.c_str(), "wbe"); + if (fpWrite == nullptr) { fclose(fpRead); return false; } - while (!feof(fpRead)) + while (feof(fpRead) == 0) { size_t bytes = fread(buffer, 1, sizeof(buffer), fpRead); - if (bytes) + if (bytes != 0u) { fwrite(buffer, 1, bytes, fpWrite); } diff --git a/src/util/PlaceholderString.cpp b/src/util/PlaceholderString.cpp index 9e0c2c542dda..cba1053d075a 100644 --- a/src/util/PlaceholderString.cpp +++ b/src/util/PlaceholderString.cpp @@ -11,7 +11,7 @@ class PlaceholderElement { public: virtual ~PlaceholderElement() = default; -public: + virtual auto format(string format) -> string = 0; }; @@ -20,12 +20,12 @@ class PlaceholderElement { */ class PlaceholderElementString : public PlaceholderElement{ public: - PlaceholderElementString(string text) + explicit explicit PlaceholderElementString(string text) : text(std::move(text)) { } -public: + auto format(string format) -> string override { return text; @@ -41,12 +41,12 @@ class PlaceholderElementString : public PlaceholderElement{ */ class PlaceholderElementInt : public PlaceholderElement{ public: - PlaceholderElementInt(int64_t value) + explicit explicit PlaceholderElementInt(int64_t value) : value(value) { } -public: + auto format(string format) -> string override { return std::to_string(value); @@ -98,7 +98,7 @@ auto PlaceholderString::formatPart(string format) -> string format = format.substr(0, comma); } - int index; + int index = 0; try { index = std::stoi(format); @@ -112,7 +112,7 @@ auto PlaceholderString::formatPart(string format) -> string // Placeholder index starting at 1, vector at 0 index--; - if (index < 0 || index >= (int)data.size()) + if (index < 0 || index >= static_cast(data.size())) { string notFound = "{"; notFound += std::to_string(index + 1); @@ -127,7 +127,7 @@ auto PlaceholderString::formatPart(string format) -> string void PlaceholderString::process() { - if (processed != "") + if (!processed.empty()) { // Already processed return; diff --git a/src/util/Rectangle.cpp b/src/util/Rectangle.cpp index b3002db416ab..dc249f71064d 100644 --- a/src/util/Rectangle.cpp +++ b/src/util/Rectangle.cpp @@ -1,6 +1,7 @@ #include "Rectangle.h" #include "Range.h" +#include "math.h" Rectangle::Rectangle() = default; @@ -24,8 +25,8 @@ Rectangle::~Rectangle() = default; auto Rectangle::intersects(const Rectangle& other, Rectangle* dest) const -> bool { - double destX, destY; - double destW, destH; + double destX = NAN, destY = NAN; + double destW = NAN, destH = NAN; bool returnVal = false; @@ -36,7 +37,7 @@ auto Rectangle::intersects(const Rectangle& other, Rectangle* dest) const -> boo if (destW > 0 && destH > 0) { - if (dest) + if (dest != nullptr) { dest->x = destX; dest->y = destY; @@ -45,7 +46,7 @@ auto Rectangle::intersects(const Rectangle& other, Rectangle* dest) const -> boo } returnVal = true; } - else if (dest) + else if (dest != nullptr) { dest->width = 0; dest->height = 0; diff --git a/src/util/Util.cpp b/src/util/Util.cpp index d2817cc63b27..8fd3a0b7a338 100644 --- a/src/util/Util.cpp +++ b/src/util/Util.cpp @@ -38,7 +38,8 @@ static auto execInUiThreadCallback(CallbackUiData* cb) -> bool */ void Util::execInUiThread(std::function&& callback) { - gdk_threads_add_idle((GSourceFunc) execInUiThreadCallback, new CallbackUiData(std::move(callback))); + gdk_threads_add_idle(reinterpret_cast(execInUiThreadCallback), + new CallbackUiData(std::move(callback))); } auto Util::rgb_to_GdkRGBA(const uint32_t color) -> GdkRGBA @@ -167,7 +168,7 @@ auto Util::paintBackgroundWhite(GtkWidget* widget, cairo_t* cr, void*) -> gboole cairo_set_source_rgb(cr, 1, 1, 1); cairo_rectangle(cr, 0, 0, alloc.width, alloc.height); cairo_fill(cr); - return false; + return 0; } void Util::writeCoordinateString(OutputStream* out, double xVal, double yVal) diff --git a/src/util/XojMsgBox.cpp b/src/util/XojMsgBox.cpp index 714b8aa20b3a..4a159298c19a 100644 --- a/src/util/XojMsgBox.cpp +++ b/src/util/XojMsgBox.cpp @@ -98,7 +98,7 @@ void XojMsgBox::showHelp(GtkWindow* win) GError* error = nullptr; gtk_show_uri(gtk_window_get_screen(win), XOJ_HELP, gtk_get_current_event_time(), &error); - if (error) + if (error != nullptr) { string msg = FS(_F("There was an error displaying help: {1}") % error->message); XojMsgBox::showErrorToUser(win, msg); diff --git a/src/util/XojPreviewExtractor.cpp b/src/util/XojPreviewExtractor.cpp index dd977314d1db..0bed07d3b7c0 100644 --- a/src/util/XojPreviewExtractor.cpp +++ b/src/util/XojPreviewExtractor.cpp @@ -112,10 +112,10 @@ auto XojPreviewExtractor::readFile(const Path& file) -> PreviewExtractResult int zipError = 0; zip_t* zipFp = zip_open(file.c_str(), ZIP_RDONLY, &zipError); - if (!zipFp && zipError == ZIP_ER_NOZIP) + if ((zipFp == nullptr) && zipError == ZIP_ER_NOZIP) { gzFile fp = GzUtil::openPath(file, "r"); - if (!fp) + if (fp == nullptr) { return PREVIEW_RESULT_COULD_NOT_OPEN_FILE; } @@ -130,7 +130,8 @@ auto XojPreviewExtractor::readFile(const Path& file) -> PreviewExtractResult gzclose(fp); return result; - } else if (!zipFp) + } + if (zipFp == nullptr) { return PREVIEW_RESULT_COULD_NOT_OPEN_FILE; } @@ -142,7 +143,7 @@ auto XojPreviewExtractor::readFile(const Path& file) -> PreviewExtractResult return PREVIEW_RESULT_NO_PREVIEW; } - if (thumbStat.valid & ZIP_STAT_SIZE) + if ((thumbStat.valid & ZIP_STAT_SIZE) != 0u) { dataLen = thumbStat.size; } else @@ -152,12 +153,12 @@ auto XojPreviewExtractor::readFile(const Path& file) -> PreviewExtractResult zip_file_t* thumb = zip_fopen(zipFp, "thumbnails/thumbnail.png", 0); - if (!thumb) + if (thumb == nullptr) { return PREVIEW_RESULT_ERROR_READING_PREVIEW; } - data = (unsigned char *)g_malloc(thumbStat.size); + data = static_cast(g_malloc(thumbStat.size)); zip_uint64_t readBytes = 0; while (readBytes < dataLen) { diff --git a/src/util/audio/DeviceInfo.h b/src/util/audio/DeviceInfo.h index 0ecfb001930e..c6771cf07db6 100644 --- a/src/util/audio/DeviceInfo.h +++ b/src/util/audio/DeviceInfo.h @@ -30,8 +30,8 @@ class DeviceInfo private: const string deviceName; - const PaDeviceIndex index; - const bool selected; - const int inputChannels; - const int outputChannels; + const PaDeviceIndex index{}; + const bool selected{}; + const int inputChannels{}; + const int outputChannels{}; }; diff --git a/src/util/audio/PortAudioConsumer.cpp b/src/util/audio/PortAudioConsumer.cpp index 65b36ce97dd5..2dad38c6b31f 100644 --- a/src/util/audio/PortAudioConsumer.cpp +++ b/src/util/audio/PortAudioConsumer.cpp @@ -1,5 +1,6 @@ #include "PortAudioConsumer.h" #include "AudioPlayer.h" +#include PortAudioConsumer::PortAudioConsumer(AudioPlayer* audioPlayer, AudioQueue* audioQueue) : sys(portaudio::System::instance()), audioPlayer(audioPlayer), audioQueue(audioQueue) { @@ -56,8 +57,8 @@ auto PortAudioConsumer::startPlaying() -> bool this->outputStream->abort(); } - double sampleRate; - unsigned int channels; + double sampleRate = NAN; + unsigned int channels = 0; this->audioQueue->getAudioAttributes(sampleRate, channels); if (sampleRate == -1) @@ -78,7 +79,7 @@ auto PortAudioConsumer::startPlaying() -> bool return false; } - if ((unsigned int) device->maxOutputChannels() < channels) + if (static_cast(device->maxOutputChannels()) < channels) { this->audioQueue->signalEndOfStream(); g_warning("Output device has not enough channels to play audio file. (Requires at least 2 channels)"); @@ -116,15 +117,16 @@ auto PortAudioConsumer::startPlaying() -> bool auto PortAudioConsumer::playCallback(const void* inputBuffer, void* outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags) -> int { - if (statusFlags) + if (statusFlags != 0u) { g_warning("PortAudioConsumer: PortAudio reported a stream warning: %s", std::to_string(statusFlags).c_str()); } if (outputBuffer != nullptr) { - size_t outputBufferLength; - this->audioQueue->pop(((float*) outputBuffer), outputBufferLength, framesPerBuffer * this->outputChannels); + size_t outputBufferLength = 0; + this->audioQueue->pop((static_cast(outputBuffer)), outputBufferLength, + framesPerBuffer * this->outputChannels); // Fill buffer to requested length if necessary @@ -136,7 +138,7 @@ auto PortAudioConsumer::playCallback(const void* inputBuffer, void* outputBuffer g_warning("PortAudioConsumer: Not enough audio samples available to fill requested frame"); } - auto outputBufferImpl = (float*) outputBuffer; + auto outputBufferImpl = static_cast(outputBuffer); if (outputBufferLength > this->outputChannels) { @@ -162,10 +164,9 @@ auto PortAudioConsumer::playCallback(const void* inputBuffer, void* outputBuffer this->audioPlayer->disableAudioPlaybackButtons(); return paComplete; } - else - { - return paContinue; - } + + + return paContinue; } // The output buffer is no longer available - Abort! diff --git a/src/util/audio/PortAudioProducer.cpp b/src/util/audio/PortAudioProducer.cpp index 0492877351ce..3bf12abcd6a2 100644 --- a/src/util/audio/PortAudioProducer.cpp +++ b/src/util/audio/PortAudioProducer.cpp @@ -106,7 +106,7 @@ auto PortAudioProducer::recordCallback(const void* inputBuffer, void* outputBuff const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags) -> int { - if (statusFlags) + if (statusFlags != 0u) { g_message("PortAudioProducer: statusFlag: %s", std::to_string(statusFlags).c_str()); } diff --git a/src/util/audio/VorbisConsumer.cpp b/src/util/audio/VorbisConsumer.cpp index ba39ed71b01c..4a631641b707 100644 --- a/src/util/audio/VorbisConsumer.cpp +++ b/src/util/audio/VorbisConsumer.cpp @@ -1,4 +1,6 @@ #include + +#include "math.h" #include "VorbisConsumer.h" VorbisConsumer::VorbisConsumer(Settings* settings, AudioQueue* audioQueue) @@ -11,8 +13,8 @@ VorbisConsumer::~VorbisConsumer() = default; auto VorbisConsumer::start(const string& filename) -> bool { - double sampleRate; - unsigned int channels; + double sampleRate = NAN; + unsigned int channels = 0; this->audioQueue->getAudioAttributes(sampleRate, channels); if (sampleRate == -1) @@ -39,8 +41,8 @@ auto VorbisConsumer::start(const string& filename) -> bool std::unique_lock lock(audioQueue->syncMutex()); float buffer[64 * channels]; - size_t bufferLength; - double audioGain = this->settings->getAudioGain(); + size_t bufferLength = 0; + double audioGain = this->settings->getAudioGain(); while (!(this->stopConsumer || (audioQueue->hasStreamEnded() && audioQueue->empty()))) { @@ -71,7 +73,7 @@ auto VorbisConsumer::start(const string& filename) -> bool void VorbisConsumer::join() { // Join the consumer thread to wait for completion - if (this->consumerThread && this->consumerThread->joinable()) + if ((this->consumerThread != nullptr) && this->consumerThread->joinable()) { this->consumerThread->join(); } diff --git a/src/util/audio/VorbisProducer.cpp b/src/util/audio/VorbisProducer.cpp index aea84fe49651..e7fac0e5d246 100644 --- a/src/util/audio/VorbisProducer.cpp +++ b/src/util/audio/VorbisProducer.cpp @@ -77,7 +77,7 @@ void VorbisProducer::abort() void VorbisProducer::stop() { // Wait for producer to finish - if (this->producerThread && this->producerThread->joinable()) + if ((this->producerThread != nullptr) && this->producerThread->joinable()) { this->producerThread->join(); } diff --git a/src/util/audio/VorbisProducer.h b/src/util/audio/VorbisProducer.h index 117e900e07e5..32836a270bca 100644 --- a/src/util/audio/VorbisProducer.h +++ b/src/util/audio/VorbisProducer.h @@ -35,9 +35,10 @@ class VorbisProducer private: const int sample_buffer_size = 16384; - protected: + +protected: bool stopProducer = false; - SF_INFO sfInfo; + SF_INFO sfInfo{}; SNDFILE_tag* sfFile = nullptr; AudioQueue* audioQueue = nullptr; diff --git a/src/util/pixbuf-utils.cpp b/src/util/pixbuf-utils.cpp index 9031520c7da2..7cbb49f95aff 100644 --- a/src/util/pixbuf-utils.cpp +++ b/src/util/pixbuf-utils.cpp @@ -51,7 +51,7 @@ const cairo_user_data_key_t format_key = { 0 }; auto f_image_surface_create(cairo_format_t format, int width, int height) -> cairo_surface_t* { - int size; + int size = 0; switch (format) { @@ -74,7 +74,7 @@ auto f_image_surface_create(cairo_format_t format, int width, int height) -> cai break; } - auto* pixels = (unsigned char*) g_malloc(width * height * size); + auto* pixels = static_cast(g_malloc(width * height * size)); cairo_surface_t* surface = cairo_image_surface_create_for_data(pixels, format, width, height, width * size); cairo_surface_set_user_data(surface, &pixel_key, pixels, g_free); @@ -90,7 +90,7 @@ auto f_image_surface_get_data(cairo_surface_t* surface) -> void* auto f_image_surface_get_format(cairo_surface_t* surface) -> cairo_format_t { - return (cairo_format_t) GPOINTER_TO_INT(cairo_surface_get_user_data(surface, &format_key)); + return static_cast GPOINTER_TO_INT(cairo_surface_get_user_data(surface, &format_key)); } auto f_image_surface_get_width(cairo_surface_t* surface) -> int @@ -113,20 +113,12 @@ auto f_pixbuf_to_cairo_surface(GdkPixbuf* pixbuf) -> cairo_surface_t* int gdk_rowstride = gdk_pixbuf_get_rowstride(pixbuf); int n_channels = gdk_pixbuf_get_n_channels(pixbuf); - cairo_format_t format; - if (n_channels == 3) - { - format = CAIRO_FORMAT_RGB24; - } - else - { - format = CAIRO_FORMAT_ARGB32; - } + cairo_format_t format = n_channels == 3 ? CAIRO_FORMAT_RGB24 : CAIRO_FORMAT_ARGB32; cairo_surface_t* surface = f_image_surface_create(format, width, height); - auto* cairo_pixels = (guchar*) f_image_surface_get_data(surface); + auto* cairo_pixels = static_cast(f_image_surface_get_data(surface)); - for (int j = height; j; j--) + for (int j = height; j != 0; j--) { guchar* p = gdk_pixels; guchar* q = cairo_pixels; @@ -153,9 +145,15 @@ auto f_pixbuf_to_cairo_surface(GdkPixbuf* pixbuf) -> cairo_surface_t* else { guchar* end = p + 4 * width; - guint t1, t2, t3; + guint t1 = 0, t2 = 0, t3 = 0; -#define MULT(d,c,a,t) G_STMT_START { t = c * a + 0x7f; d = ((t >> 8) + t) >> 8; } G_STMT_END +#define MULT(d, c, a, t) \ + G_STMT_START \ + { \ + (t) = (c) * (a) + 0x7f; \ + (d) = (((t) >> 8) + (t)) >> 8; \ + } \ + G_STMT_END while (p < end) { @@ -225,7 +223,7 @@ convert_alpha(guchar* dest_data, int dest_stride, guchar* src_data, int src_stri for (int y = 0; y < height; y++) { - auto* src = (guint32*) src_data; + auto* src = reinterpret_cast(src_data); for (int x = 0; x < width; x++) { @@ -259,7 +257,7 @@ convert_no_alpha(guchar* dest_data, int dest_stride, guchar* src_data, int src_s for (int y = 0; y < height; y++) { - auto* src = (guint32*) src_data; + auto* src = reinterpret_cast(src_data); for (int x = 0; x < width; x++) { @@ -299,25 +297,40 @@ auto xoj_pixbuf_get_from_surface(cairo_surface_t* surface, gint src_x, gint src_ g_return_val_if_fail(surface != nullptr, nullptr); g_return_val_if_fail(width > 0 && height > 0, nullptr); - auto content = (cairo_content_t)(cairo_surface_get_content(surface) | CAIRO_CONTENT_COLOR); - GdkPixbuf* dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, !!(content & CAIRO_CONTENT_ALPHA), 8, width, height); + auto content = static_cast(cairo_surface_get_content(surface) | CAIRO_CONTENT_COLOR); + GdkPixbuf* dest = gdk_pixbuf_new( + GDK_COLORSPACE_RGB, + static_cast(static_cast(static_cast((((content & CAIRO_CONTENT_ALPHA))) == 0) == 0)), 8, + width, height); surface = gdk_cairo_surface_coerce_to_image(surface, content, src_x, src_y, width, height); cairo_surface_flush(surface); - if (cairo_surface_status(surface) || dest == nullptr) + if ((cairo_surface_status(surface) != 0u) || dest == nullptr) { cairo_surface_destroy(surface); return nullptr; } - if (gdk_pixbuf_get_has_alpha(dest)) - convert_alpha(gdk_pixbuf_get_pixels(dest), gdk_pixbuf_get_rowstride(dest), - cairo_image_surface_get_data(surface), cairo_image_surface_get_stride(surface), - 0, 0, width, height); + if (gdk_pixbuf_get_has_alpha(dest) != 0) + { + { + { + convert_alpha(gdk_pixbuf_get_pixels(dest), gdk_pixbuf_get_rowstride(dest), + cairo_image_surface_get_data(surface), cairo_image_surface_get_stride(surface), 0, 0, + width, height); + } + } + } else - convert_no_alpha(gdk_pixbuf_get_pixels(dest), gdk_pixbuf_get_rowstride(dest), - cairo_image_surface_get_data(surface), cairo_image_surface_get_stride(surface), - 0, 0, width, height); + { + { + { + convert_no_alpha(gdk_pixbuf_get_pixels(dest), gdk_pixbuf_get_rowstride(dest), + cairo_image_surface_get_data(surface), cairo_image_surface_get_stride(surface), 0, 0, + width, height); + } + } + } cairo_surface_destroy(surface); return dest; diff --git a/src/util/serializing/BinObjectEncoding.cpp b/src/util/serializing/BinObjectEncoding.cpp index 5ffb5ae5bb4f..c1ba9a35540b 100644 --- a/src/util/serializing/BinObjectEncoding.cpp +++ b/src/util/serializing/BinObjectEncoding.cpp @@ -6,5 +6,5 @@ BinObjectEncoding::~BinObjectEncoding() = default; void BinObjectEncoding::addData(const void* data, int len) { - g_string_append_len(this->data, (const char*) data, len); + g_string_append_len(this->data, static_cast(data), len); } diff --git a/src/util/serializing/HexObjectEncoding.cpp b/src/util/serializing/HexObjectEncoding.cpp index ebca4779705c..7dcc8d7e18d3 100644 --- a/src/util/serializing/HexObjectEncoding.cpp +++ b/src/util/serializing/HexObjectEncoding.cpp @@ -8,7 +8,7 @@ HexObjectEncoding::~HexObjectEncoding() = default; void HexObjectEncoding::addData(const void* data, int len) { - char* buffer = (char*) g_malloc(len * 2); + char* buffer = static_cast(g_malloc(len * 2)); for (int i = 0; i < len; i++) { diff --git a/src/util/serializing/ObjectInputStream.cpp b/src/util/serializing/ObjectInputStream.cpp index 7d0bca2b9b13..345fce0ea6c8 100644 --- a/src/util/serializing/ObjectInputStream.cpp +++ b/src/util/serializing/ObjectInputStream.cpp @@ -8,18 +8,18 @@ ObjectInputStream::ObjectInputStream() = default; ObjectInputStream::~ObjectInputStream() { - if (this->str) + if (this->str != nullptr) { - g_string_free(this->str, true); + g_string_free(this->str, 1); this->str = nullptr; } } auto ObjectInputStream::read(const char* data, int len) -> bool { - if (this->str) + if (this->str != nullptr) { - g_string_free(this->str, true); + g_string_free(this->str, 1); } this->str = g_string_new_len(data, len); this->pos = 0; @@ -89,7 +89,7 @@ auto ObjectInputStream::readInt() -> int throw InputStreamException("End reached, but try to read an integer", __FILE__, __LINE__); } - int i = *((int*) (this->str->str + this->pos)); + int i = *(reinterpret_cast(this->str->str + this->pos)); this->pos += sizeof(int); return i; } @@ -103,7 +103,7 @@ auto ObjectInputStream::readDouble() -> double throw InputStreamException("End reached, but try to read an double", __FILE__, __LINE__); } - double d = *((double*) (this->str->str + this->pos)); + double d = *(reinterpret_cast(this->str->str + this->pos)); this->pos += sizeof(double); return d; } @@ -117,7 +117,7 @@ auto ObjectInputStream::readSizeT() -> size_t throw InputStreamException("End reached, but try to read an integer", __FILE__, __LINE__); } - size_t st = *((size_t*) (this->str->str + this->pos)); + size_t st = *(reinterpret_cast(this->str->str + this->pos)); this->pos += sizeof(size_t); return st; } @@ -131,7 +131,7 @@ auto ObjectInputStream::readString() -> string throw InputStreamException("End reached, but try to read an string", __FILE__, __LINE__); } - int len = *((int*) (this->str->str + this->pos)); + int len = *(reinterpret_cast(this->str->str + this->pos)); this->pos += sizeof(int); if (this->pos + len >= this->str->len) @@ -153,10 +153,10 @@ void ObjectInputStream::readData(void** data, int* length) throw InputStreamException("End reached, but try to read data", __FILE__, __LINE__); } - int len = *((int*) (this->str->str + this->pos)); + int len = *(reinterpret_cast(this->str->str + this->pos)); this->pos += sizeof(int); - int width = *((int*) (this->str->str + this->pos)); + int width = *(reinterpret_cast(this->str->str + this->pos)); this->pos += sizeof(int); if (this->pos + (len * width) >= this->str->len) @@ -220,7 +220,7 @@ auto ObjectInputStream::readImage() -> cairo_surface_t* throw InputStreamException("End reached, but try to read an image", __FILE__, __LINE__); } - int len = *((int*) (this->str->str + this->pos)); + int len = *(reinterpret_cast(this->str->str + this->pos)); //this->pos += sizeof(int); //totally not equivalent! this->pos += sizeof(gsize); @@ -232,7 +232,8 @@ auto ObjectInputStream::readImage() -> cairo_surface_t* PngDatasource source(this->str->str + this->pos, len); //cairo_surface_t * img = cairo_image_surface_create_from_png_stream((cairo_read_func_t) cairoReadFunction, &source); - cairo_surface_t* img = cairo_image_surface_create_from_png_stream((cairo_read_func_t) &cairoReadFunction, &source); + cairo_surface_t* img = cairo_image_surface_create_from_png_stream( + reinterpret_cast(&cairoReadFunction), &source); this->pos += len; diff --git a/src/util/serializing/ObjectInputStream.h b/src/util/serializing/ObjectInputStream.h index 8657e88faead..8c5c23d64f99 100644 --- a/src/util/serializing/ObjectInputStream.h +++ b/src/util/serializing/ObjectInputStream.h @@ -42,7 +42,7 @@ class ObjectInputStream private: void checkType(char type); - string getType(char type); + static string getType(char type); private: GString* str = nullptr; diff --git a/src/util/serializing/ObjectOutputStream.cpp b/src/util/serializing/ObjectOutputStream.cpp index 74a43f1c6372..c469a2882852 100644 --- a/src/util/serializing/ObjectOutputStream.cpp +++ b/src/util/serializing/ObjectOutputStream.cpp @@ -75,7 +75,7 @@ void ObjectOutputStream::writeData(const void* data, int len, int width) static auto cairoWriteFunction(GString* string, const unsigned char* data, unsigned int length) -> cairo_status_t { - g_string_append_len(string, (const gchar*) data, length); + g_string_append_len(string, reinterpret_cast(data), length); return CAIRO_STATUS_SUCCESS; } @@ -83,14 +83,14 @@ void ObjectOutputStream::writeImage(cairo_surface_t* img) { GString* imgStr = g_string_sized_new(102400); - cairo_surface_write_to_png_stream(img, (cairo_write_func_t) &cairoWriteFunction, imgStr); + cairo_surface_write_to_png_stream(img, reinterpret_cast(&cairoWriteFunction), imgStr); this->encoder->addStr("_m"); this->encoder->addData(&imgStr->len, sizeof(gsize)); this->encoder->addData(imgStr->str, imgStr->len); - g_string_free(imgStr, true); + g_string_free(imgStr, 1); } auto ObjectOutputStream::getStr() -> GString*