diff --git a/CMakeLists.txt b/CMakeLists.txt index 64e9e19..0a2b447 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,46 +1,168 @@ cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) +# add project files +set(HEADER_FILES + application/main.h + application/utils.h + cli/clidownloadinteraction.h + cli/mainfeatures.h + model/downloadfinderresultsmodel.h + model/downloadmodel.h + network/authenticationcredentials.h + network/bitsharedownload.h + network/download.h + network/downloadrange.h + network/filenukedownload.h + network/finder/downloadfinder.h + network/finder/groovesharksearcher.h + network/finder/linkfinder.h + network/finder/youtubeplaylist.h + network/groovesharkdownload.h + network/httpdownload.h + network/httpdownloadwithinforequst.h + network/misc/contentdispositionparser.h + network/optiondata.h + network/permissionstatus.h + network/socksharedownload.h + network/spotifydownload.h + network/testdownload.h + network/vimeodownload.h + network/youtubedownload.h +) +set(SRC_FILES + application/main.cpp + application/utils.cpp + cli/clidownloadinteraction.cpp + cli/mainfeatures.cpp + model/downloadfinderresultsmodel.cpp + model/downloadmodel.cpp + network/bitsharedownload.cpp + network/download.cpp + network/downloadrange.cpp + network/filenukedownload.cpp + network/finder/downloadfinder.cpp + network/finder/groovesharksearcher.cpp + network/finder/linkfinder.cpp + network/finder/youtubeplaylist.cpp + network/groovesharkdownload.cpp + network/httpdownload.cpp + network/httpdownloadwithinforequst.cpp + network/misc/contentdispositionparser.cpp + network/optiondata.cpp + network/socksharedownload.cpp + network/spotifydownload.cpp + network/testdownload.cpp + network/vimeodownload.cpp + network/youtubedownload.cpp + +) +set(WIDGETS_HEADER_FILES + gui/downloadwidget.h + gui/adddownloaddialog.h + gui/addmultipledownloadswizard.h + gui/downloadinteraction.h + gui/initiate.h + gui/mainwindow.h + gui/setrangedialog.h + gui/settings.h + model/downloadfinderresultsmodel.h + model/downloadmodel.h +) +set(WIDGETS_SRC_FILES + gui/adddownloaddialog.cpp + gui/addmultipledownloadswizard.cpp + gui/downloadinteraction.cpp + gui/downloadwidget.cpp + gui/initiate.cpp + gui/mainwindow.cpp + gui/setrangedialog.cpp + gui/settings.cpp + itemdelegates/comboboxitemdelegate.cpp + itemdelegates/progressbaritemdelegate.cpp + resources/icons.qrc +) +#set(QUICK_HEADER_FILES +#) +#set(QUICK_SRC_FILES +#) +#set(TS_FILES +# translations/${META_PROJECT_NAME}_de_DE.ts +# translations/${META_PROJECT_NAME}_en_US.ts +#) + # meta data set(META_PROJECT_NAME videodownloader) set(META_APP_NAME "Video Downloader") set(META_APP_AUTHOR "Martchus") set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}") -set(META APP_DESCRIPTION "A video downloader with Qt GUI (currently only YouTube and Vimeo are maintained).") +set(META_APP_DESCRIPTION "A video downloader with Qt GUI (currently only YouTube and Vimeo are maintained).") set(META_VERSION_MAJOR 1) set(META_VERSION_MINOR 2) set(META_VERSION_PATCH 1) -# define project -project(${META_PROJECT_NAME}) - # stringification of meta data set(META_PROJECT_NAME_STR "\"${META_PROJECT_NAME}\"") set(META_APP_NAME_STR "\"${META_APP_NAME}\"") set(META_APP_AUTHOR_STR "\"${META_APP_AUTHOR}\"") set(META_APP_URL_STR "\"${META_APP_URL}\"") -set(APP_DESCRIPTION_STR "\"${APP_DESCRIPTION}\"") -set(META_APP_VERSION_STR "\"${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}\"") +set(META_APP_DESCRIPTION_STR "\"${META_APP_DESCRIPTION}\"") +set(META_APP_VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}) +set(META_APP_VERSION_STR "\"${META_APP_VERSION}\"") + +# define project +project(${META_PROJECT_NAME}) # add configuration header -configure_file ( - "${PROJECT_SOURCE_DIR}/config.h.in" - "${PROJECT_BINARY_DIR}/config.h" +configure_file( + "${PROJECT_SOURCE_DIR}/resources/config.h.in" + "${PROJECT_BINARY_DIR}/resources/config.h" ) include_directories("${PROJECT_BINARY_DIR}") -# add source and header files -file(GLOB_RECURSE SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "application/*.cpp" "cli/*.cpp" "model/*.cpp" "network/*.cpp" "resources/json.qrc") -file(GLOB_RECURSE WIDGETS_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "gui/*.cpp" "itemdelegates/*.cpp" "resources/icons.qrc") -file(GLOB_RECURSE HEADER_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "application/*.h" "cli/*.h" "model/*.h" "network/*.h") -file(GLOB_RECURSE WIDGETS_HEADER_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "gui/*.h" "itemdelegates/*.h") +# set "GUI-type" to WIN32 to hide console under windows +if(WIN32) + set(GUI_TYPE WIN32) +endif(WIN32) -# enable only Qt Widgets GUI -add_definitions(-DGUI_QTWIDGETS -DMODEL_UNDO_SUPPORT) +# add windows resource file +if(MINGW) + # creation windows icon from png with ffmpeg if available + find_program(FFMPEG_BIN ffmpeg avconv) + if(FFMPEG_BIN) + set(PNG_ICON_PATH "${PROJECT_SOURCE_DIR}/resources/icons/hicolor/128x128/apps/${META_PROJECT_NAME}.png") + if(EXISTS ${PNG_ICON_PATH}) + set(WINDOWS_ICON_PATH "${PROJECT_BINARY_DIR}/${META_PROJECT_NAME}.ico") + set(WINDOWS_ICON_RC_ENTRY "IDI_ICON1 ICON DISCARDABLE \"${WINDOWS_ICON_PATH}\"") + add_custom_command( + OUTPUT "${WINDOWS_ICON_PATH}" + COMMAND ${FFMPEG_BIN} -y -i "${PNG_ICON_PATH}" -vf crop=iw-20:ih-20:10:10,scale=64:64 "${WINDOWS_ICON_PATH}" + ) + endif() + endif(FFMPEG_BIN) + # create windows rc file from template + set(WINDOWS_EXT "exe") + configure_file( + "${PROJECT_SOURCE_DIR}/resources/windows.rc.in" + "${PROJECT_BINARY_DIR}/resources/windows.rc" + ) + # set windres as resource compiler + set(RES_FILES "${PROJECT_BINARY_DIR}/resources/windows.rc") + set(CMAKE_RC_COMPILER_INIT windres) + set(CMAKE_RC_COMPILE_OBJECT " -O coff -i -o ") + enable_language(RC) +endif(MINGW) + +# enable Qt Widgets GUI +add_definitions( + -DGUI_QTWIDGETS + -DMODEL_UNDO_SUPPORT +) # check required Qt 5 modules find_package(Qt5Core REQUIRED) find_package(Qt5Gui REQUIRED) find_package(Qt5Widgets REQUIRED) +find_package(Qt5LinguistTools REQUIRED) find_package(Qt5Network REQUIRED) # enable moc, uic and rcc @@ -49,28 +171,65 @@ set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) -# executable and linking -add_executable(${META_PROJECT_NAME} ${HEADER_FILES} ${SRC_FILES} ${WIDGETS_HEADER_FILES} ${WIDGETS_SRC_FILES}) -target_link_libraries(${META_PROJECT_NAME} c++utilities qtutilities Qt5::Core Qt5::Widgets Qt5::Network) +# enable lrelease +qt5_add_translation(QM_FILES ${TS_FILES}) +ADD_CUSTOM_TARGET(translations ALL DEPENDS ${QM_FILES}) -# enable C++11 -set_property(TARGET ${META_PROJECT_NAME} PROPERTY CXX_STANDARD 11) +# executable and linking +add_executable(${META_PROJECT_NAME} ${GUI_TYPE} ${HEADER_FILES} ${SRC_FILES} ${WIDGETS_HEADER_FILES} ${WIDGETS_SRC_FILES} ${QM_FILES} ${RES_FILES} ${WINDOWS_ICON_PATH}) +target_link_libraries(${META_PROJECT_NAME} c++utilities qtutilities Qt5::Core Qt5::Widgets Qt5::Network) +set_target_properties(${META_PROJECT_NAME} PROPERTIES + CXX_STANDARD 11 +) # add install target install(TARGETS ${META_PROJECT_NAME} RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib + COMPONENT binary ) install(FILES resources/icons/hicolor/scalable/apps/${META_PROJECT_NAME}.svg DESTINATION share/icons/hicolor/scalable/apps + COMPONENT desktop ) install(FILES resources/desktop/applications/${META_PROJECT_NAME}.desktop DESTINATION share/applications + COMPONENT desktop +) +install(FILES ${QM_FILES} + DESTINATION share/${META_PROJECT_NAME}/translations + COMPONENT localization ) install(FILES resources/json/groovesharkauthenticationinfo.json DESTINATION share/${META_PROJECT_NAME}/json + COMPONENT config ) install(FILES resources/json/itaginfo.json DESTINATION share/${META_PROJECT_NAME}/json + COMPONENT config +) +add_custom_target(install-binary + DEPENDS ${META_PROJECT_NAME} + COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=binary -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" +) +add_custom_target(install-desktop + DEPENDS ${META_PROJECT_NAME} + COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=desktop -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" +) +add_custom_target(install-localization + DEPENDS ${META_PROJECT_NAME} + COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=localization -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" +) +add_custom_target(install-config + DEPENDS ${META_PROJECT_NAME} + COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=config -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" +) +add_custom_target(install-mingw-w64 + DEPENDS install-binary install-localization install-config +) +add_custom_target(install-binary-strip + DEPENDS ${META_PROJECT_NAME} + COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_DO_STRIP=1 -DCMAKE_INSTALL_COMPONENT=binary -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" +) +add_custom_target(install-mingw-w64-strip + DEPENDS install-binary-strip install-localization install-config ) diff --git a/application/main.cpp b/application/main.cpp index 2389aa9..e567918 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -3,7 +3,7 @@ // include configuration from separate header file when building with CMake #ifndef APP_METADATA_AVAIL -#include "config.h" +#include "resources/config.h" #endif #if defined(GUI_QTWIDGETS) || defined(GUI_QTQUICK) diff --git a/config.h.in b/config.h.in deleted file mode 100644 index 2f9ca46..0000000 --- a/config.h.in +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef APP_METADATA_AVAIL -#define APP_METADATA_AVAIL -#define PROJECT_NAME @META_PROJECT_NAME_STR@ -#define APP_NAME @META_APP_NAME_STR@ -#define APP_VERSION @META_APP_VERSION_STR@ -#define APP_AUTHOR @META_APP_AUTHOR_STR@ -#define APP_URL @META_APP_URL_STR@ -#define APP_DESCRIPTION @META_APP_DESCRIPTION_STR@ -#endif // APP_METADATA_AVAIL diff --git a/general.pri b/general.pri index 6e654cd..7072941 100644 --- a/general.pri +++ b/general.pri @@ -1,28 +1,12 @@ -#dirs +# specify build directories for moc, object and rcc files MOC_DIR = ./moc OBJECTS_DIR = ./obj RCC_DIR = ./res -# compiler flags + +# compiler flags: enable C++11 QMAKE_CXXFLAGS += -std=c++11 QMAKE_LFLAGS += -std=c++11 -# prefix -targetprefix = $$(TARGET_PREFIX) -message("Using target prefix \"$${targetprefix}\".") -# print install root -message("Using install root \"$$(INSTALL_ROOT)\".") -# target -CONFIG(debug, debug|release) { - TARGET = $${targetprefix}$${projectname}d -} else { - TARGET = $${targetprefix}$${projectname} -} -# add defines -DEFINES += "APP_METADATA_AVAIL" -DEFINES += "'PROJECT_NAME=\"$${projectname}\"'" -DEFINES += "'APP_NAME=\"$${appname}\"'" -DEFINES += "'APP_AUTHOR=\"$${appauthor}\"'" -DEFINES += "'APP_URL=\"$${appurl}\"'" -DEFINES += "'APP_VERSION=\"$${VERSION}\"'" + # variables to check target architecture win32-g++:QMAKE_TARGET.arch = $$QMAKE_HOST.arch win32-g++-32:QMAKE_TARGET.arch = x86 @@ -30,7 +14,30 @@ win32-g++-64:QMAKE_TARGET.arch = x86_64 linux-g++:QMAKE_TARGET.arch = $$QMAKE_HOST.arch linux-g++-32:QMAKE_TARGET.arch = x86 linux-g++-64:QMAKE_TARGET.arch = x86_64 -# configuration + +# determine and print target prefix +targetprefix = $$(TARGET_PREFIX) +message("Using target prefix \"$${targetprefix}\".") + +# print install root +message("Using install root \"$$(INSTALL_ROOT)\".") + +# set target +CONFIG(debug, debug|release) { + TARGET = $${targetprefix}$${projectname}d +} else { + TARGET = $${targetprefix}$${projectname} +} + +# add defines for meta data +DEFINES += "APP_METADATA_AVAIL" +DEFINES += "'PROJECT_NAME=\"$${projectname}\"'" +DEFINES += "'APP_NAME=\"$${appname}\"'" +DEFINES += "'APP_AUTHOR=\"$${appauthor}\"'" +DEFINES += "'APP_URL=\"$${appurl}\"'" +DEFINES += "'APP_VERSION=\"$${VERSION}\"'" + +# configure Qt modules and defines mobile { DEFINES += CONFIG_MOBILE } else:desktop { @@ -61,7 +68,7 @@ no-gui { } guiqtquick { message("Configured for Qt Quick GUI support.") - greaterThan(QT_MAJOR_VERSION, 4): QT += quick + QT += quick CONFIG(debug, debug|release) { CONFIG += qml_debug } @@ -69,11 +76,12 @@ guiqtquick { } guiqtwidgets { message("Configured for Qt widgets GUI support.") - greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + QT += widgets DEFINES += GUI_QTWIDGETS DEFINES += MODEL_UNDO_SUPPORT } -# Windows stuff: configuration for cross compliation with mingw-w64 + +# configuration for cross compliation with mingw-w64 win32 { QMAKE_TARGET_PRODUCT = "$${appname}" QMAKE_TARGET_COPYRIGHT = "by $${appauthor}" diff --git a/gui/initiate.cpp b/gui/initiate.cpp index cba124e..ae05845 100644 --- a/gui/initiate.cpp +++ b/gui/initiate.cpp @@ -4,7 +4,7 @@ // include configuration from separate header file when building with CMake #ifndef APP_METADATA_AVAIL -#include "config.h" +#include "resources/config.h" #endif #include diff --git a/gui/settings.cpp b/gui/settings.cpp index 304ec94..0eeec85 100644 --- a/gui/settings.cpp +++ b/gui/settings.cpp @@ -5,7 +5,7 @@ // include configuration from separate header file when building with CMake #ifndef APP_METADATA_AVAIL -#include "config.h" +#include "resources/config.h" #endif #include diff --git a/network/groovesharkdownload.cpp b/network/groovesharkdownload.cpp index bf325dc..389d943 100644 --- a/network/groovesharkdownload.cpp +++ b/network/groovesharkdownload.cpp @@ -4,7 +4,7 @@ // include configuration from separate header file when building with CMake #ifndef APP_METADATA_AVAIL -#include "config.h" +#include "resources/config.h" #endif #include diff --git a/network/youtubedownload.cpp b/network/youtubedownload.cpp index 1c2d0fe..5322eb4 100644 --- a/network/youtubedownload.cpp +++ b/network/youtubedownload.cpp @@ -4,7 +4,7 @@ // include configuration from separate header file when building with CMake #ifndef APP_METADATA_AVAIL -#include "config.h" +#include "resources/config.h" #endif #include diff --git a/resources/windowsicon.rc b/resources/windowsicon.rc deleted file mode 100644 index f94aaef..0000000 --- a/resources/windowsicon.rc +++ /dev/null @@ -1 +0,0 @@ -IDI_ICON1 ICON DISCARDABLE "resources/applicationicon.ico" \ No newline at end of file diff --git a/videodownloader.pro b/videodownloader.pro index f9d519d..c1427f5 100644 --- a/videodownloader.pro +++ b/videodownloader.pro @@ -1,3 +1,4 @@ +# meta data projectname = videodownloader appname = "Video Downloader" appauthor = Martchus @@ -12,19 +13,17 @@ VERSION = 1.2.1 } } +# basic configuration: application TEMPLATE = app +QT += core gui widgets network -QT += core gui network -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - +# add defines for configuration testdownload { DEFINES += CONFIG_TESTDOWNLOAD } - underconstruction { DEFINES += UNDER_CONSTRUCTION } - !notrayicon { DEFINES += CONFIG_USE_TRAY_ICON usetrayiconalways { @@ -32,39 +31,7 @@ underconstruction { } } -SOURCES += application/main.cpp \ - network/bitsharedownload.cpp \ - network/download.cpp \ - model/downloadmodel.cpp \ - network/downloadrange.cpp \ - network/filenukedownload.cpp \ - network/finder/downloadfinder.cpp \ - network/finder/groovesharksearcher.cpp \ - network/finder/youtubeplaylist.cpp \ - model/downloadfinderresultsmodel.cpp \ - network/finder/linkfinder.cpp \ - network/groovesharkdownload.cpp \ - network/httpdownload.cpp \ - network/httpdownloadwithinforequst.cpp \ - network/misc/contentdispositionparser.cpp \ - network/socksharedownload.cpp \ - network/youtubedownload.cpp \ - gui/adddownloaddialog.cpp \ - gui/addmultipledownloadswizard.cpp \ - gui/downloadwidget.cpp \ - gui/mainwindow.cpp \ - gui/setrangedialog.cpp \ - application/utils.cpp \ - itemdelegates/comboboxitemdelegate.cpp \ - itemdelegates/progressbaritemdelegate.cpp \ - gui/downloadinteraction.cpp \ - gui/settings.cpp \ - network/optiondata.cpp \ - gui/initiate.cpp \ - cli/mainfeatures.cpp \ - cli/clidownloadinteraction.cpp \ - network/vimeodownload.cpp - +# add project files HEADERS += application/main.h \ network/bitsharedownload.h \ network/download.h \ @@ -101,20 +68,57 @@ HEADERS += application/main.h \ cli/clidownloadinteraction.h \ network/vimeodownload.h +SOURCES += application/main.cpp \ + network/bitsharedownload.cpp \ + network/download.cpp \ + model/downloadmodel.cpp \ + network/downloadrange.cpp \ + network/filenukedownload.cpp \ + network/finder/downloadfinder.cpp \ + network/finder/groovesharksearcher.cpp \ + network/finder/youtubeplaylist.cpp \ + model/downloadfinderresultsmodel.cpp \ + network/finder/linkfinder.cpp \ + network/groovesharkdownload.cpp \ + network/httpdownload.cpp \ + network/httpdownloadwithinforequst.cpp \ + network/misc/contentdispositionparser.cpp \ + network/socksharedownload.cpp \ + network/youtubedownload.cpp \ + gui/adddownloaddialog.cpp \ + gui/addmultipledownloadswizard.cpp \ + gui/downloadwidget.cpp \ + gui/mainwindow.cpp \ + gui/setrangedialog.cpp \ + application/utils.cpp \ + itemdelegates/comboboxitemdelegate.cpp \ + itemdelegates/progressbaritemdelegate.cpp \ + gui/downloadinteraction.cpp \ + gui/settings.cpp \ + network/optiondata.cpp \ + gui/initiate.cpp \ + cli/mainfeatures.cpp \ + cli/clidownloadinteraction.cpp \ + network/vimeodownload.cpp + testdownload { - SOURCES += network/testdownload.cpp - HEADERS += network/testdownload.h + HEADERS += \ + network/testdownload.h + + SOURCES += \ + network/testdownload.cpp } underconstruction { -SOURCES += \ - network/spotifydownload.cpp + SOURCES += \ + network/spotifydownload.cpp -HEADERS += \ - network/spotifydownload.h + HEADERS += \ + network/spotifydownload.h } -FORMS += gui/adddownloaddialog.ui \ +FORMS += \ + gui/adddownloaddialog.ui \ gui/downloadwidget.ui \ gui/setrangedialog.ui \ gui/mainwindow.ui \ @@ -125,12 +129,17 @@ FORMS += gui/adddownloaddialog.ui \ RESOURCES += resources/icons.qrc \ resources/json.qrc -win32:include(windowsicon.pri) - OTHER_FILES += \ README.md \ - LICENSE + LICENSE \ + CMakeLists.txt \ + resources/config.h.in \ + resources/windows.rc.in +# make windows icon +win32:include(windowsicon.pri) + +# add libs CONFIG(debug, debug|release) { LIBS += -lc++utilitiesd !no-gui {