Initial stuff. It doesnt work.
This commit is contained in:
parent
5cf599673d
commit
4a77524b05
293
CMakeLists.txt
293
CMakeLists.txt
@ -1,8 +1,8 @@
|
||||
cmake_minimum_required(VERSION 2.8.9)
|
||||
|
||||
IF(WIN32)
|
||||
# In Qt 5.1+ we have our own main() function, don't autolink to qtmain on Windows
|
||||
cmake_policy(SET CMP0020 OLD)
|
||||
# In Qt 5.1+ we have our own main() function, don't autolink to qtmain on Windows
|
||||
cmake_policy(SET CMP0020 OLD)
|
||||
ENDIF()
|
||||
|
||||
project(MultiMC)
|
||||
@ -22,22 +22,22 @@ SET(MMC_BIN "${PROJECT_BINARY_DIR}")
|
||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
|
||||
|
||||
IF(UNIX)
|
||||
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
|
||||
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
|
||||
ENDIF()
|
||||
|
||||
set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${PROJECT_BINARY_DIR}/jars)
|
||||
|
||||
######## Set compiler flags ########
|
||||
IF(APPLE)
|
||||
message(STATUS "Using APPLE CMAKE_CXX_FLAGS")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
|
||||
message(STATUS "Using APPLE CMAKE_CXX_FLAGS")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
|
||||
ELSEIF(UNIX)
|
||||
# assume GCC, add C++0x/C++11 stuff
|
||||
MESSAGE(STATUS "Using UNIX CMAKE_CXX_FLAGS")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
|
||||
# assume GCC, add C++0x/C++11 stuff
|
||||
MESSAGE(STATUS "Using UNIX CMAKE_CXX_FLAGS")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
|
||||
ELSEIF(MINGW)
|
||||
MESSAGE(STATUS "Using MINGW CMAKE_CXX_FLAGS")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -Wall")
|
||||
MESSAGE(STATUS "Using MINGW CMAKE_CXX_FLAGS")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -Wall")
|
||||
ENDIF()
|
||||
|
||||
################################ 3rd Party Libs ################################
|
||||
@ -51,21 +51,21 @@ find_package(Qt5Concurrent REQUIRED)
|
||||
find_package(Qt5LinguistTools REQUIRED)
|
||||
|
||||
include_directories(
|
||||
${Qt5Core_INCLUDE_DIRS}
|
||||
${Qt5Widgets_INCLUDE_DIRS}
|
||||
${Qt5Concurrent_INCLUDE_DIRS}
|
||||
${Qt5Network_INCLUDE_DIRS}
|
||||
${Qt5Test_INCLUDE_DIRS}
|
||||
${Qt5Core_INCLUDE_DIRS}
|
||||
${Qt5Widgets_INCLUDE_DIRS}
|
||||
${Qt5Concurrent_INCLUDE_DIRS}
|
||||
${Qt5Network_INCLUDE_DIRS}
|
||||
${Qt5Test_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
# The Qt5 cmake files don't provide its install paths, so ask qmake.
|
||||
get_target_property(QMAKE_EXECUTABLE Qt5::qmake LOCATION)
|
||||
function(QUERY_QMAKE VAR RESULT)
|
||||
exec_program(${QMAKE_EXECUTABLE} ARGS "-query ${VAR}" RETURN_VALUE return_code OUTPUT_VARIABLE output )
|
||||
if(NOT return_code)
|
||||
file(TO_CMAKE_PATH "${output}" output)
|
||||
set(${RESULT} ${output} PARENT_SCOPE)
|
||||
endif(NOT return_code)
|
||||
exec_program(${QMAKE_EXECUTABLE} ARGS "-query ${VAR}" RETURN_VALUE return_code OUTPUT_VARIABLE output )
|
||||
if(NOT return_code)
|
||||
file(TO_CMAKE_PATH "${output}" output)
|
||||
set(${RESULT} ${output} PARENT_SCOPE)
|
||||
endif(NOT return_code)
|
||||
endfunction(QUERY_QMAKE)
|
||||
|
||||
query_qmake(QT_INSTALL_PLUGINS QT_PLUGINS_DIR)
|
||||
@ -81,7 +81,7 @@ set(QT_MKSPECS_DIR ${QT_DATA_DIR}/mkspecs)
|
||||
INCLUDE(TestBigEndian)
|
||||
TEST_BIG_ENDIAN(BIGENDIAN)
|
||||
IF(${BIGENDIAN})
|
||||
ADD_DEFINITIONS(-DMULTIMC_BIG_ENDIAN)
|
||||
ADD_DEFINITIONS(-DMULTIMC_BIG_ENDIAN)
|
||||
ENDIF(${BIGENDIAN})
|
||||
|
||||
|
||||
@ -118,44 +118,44 @@ SET(MultiMC_NOTIFICATION_URL "" CACHE STRING "URL for checking for notifications
|
||||
|
||||
SET(MultiMC_RELEASE_VERSION_NAME "${MultiMC_VERSION_MAJOR}.${MultiMC_VERSION_MINOR}")
|
||||
IF (MultiMC_VERSION_HOTFIX GREATER 0)
|
||||
SET(MultiMC_RELEASE_VERSION_NAME "${MultiMC_RELEASE_VERSION_NAME}.${MultiMC_VERSION_HOTFIX}")
|
||||
SET(MultiMC_RELEASE_VERSION_NAME "${MultiMC_RELEASE_VERSION_NAME}.${MultiMC_VERSION_HOTFIX}")
|
||||
ENDIF()
|
||||
|
||||
# Build a version string to display in the configure logs.
|
||||
IF (MultiMC_VERSION_TYPE STREQUAL "Custom")
|
||||
MESSAGE(STATUS "Version Type: Custom")
|
||||
SET(MultiMC_VERSION_STRING "${MultiMC_RELEASE_VERSION_NAME}")
|
||||
MESSAGE(STATUS "Version Type: Custom")
|
||||
SET(MultiMC_VERSION_STRING "${MultiMC_RELEASE_VERSION_NAME}")
|
||||
ELSEIF (MultiMC_VERSION_TYPE STREQUAL "Release")
|
||||
MESSAGE(STATUS "Version Type: Stable Release")
|
||||
SET(MultiMC_VERSION_STRING "${MultiMC_RELEASE_VERSION_NAME}")
|
||||
MESSAGE(STATUS "Version Type: Stable Release")
|
||||
SET(MultiMC_VERSION_STRING "${MultiMC_RELEASE_VERSION_NAME}")
|
||||
ELSEIF (MultiMC_VERSION_TYPE STREQUAL "ReleaseCandidate")
|
||||
MESSAGE(STATUS "Version Type: Release Candidate")
|
||||
SET(MultiMC_VERSION_STRING "${MultiMC_RELEASE_VERSION_NAME}-rc${MultiMC_VERSION_BUILD}")
|
||||
MESSAGE(STATUS "Version Type: Release Candidate")
|
||||
SET(MultiMC_VERSION_STRING "${MultiMC_RELEASE_VERSION_NAME}-rc${MultiMC_VERSION_BUILD}")
|
||||
ELSEIF (MultiMC_VERSION_TYPE STREQUAL "Development")
|
||||
MESSAGE(STATUS "Version Type: Development")
|
||||
SET(MultiMC_VERSION_STRING "${MultiMC_RELEASE_VERSION_NAME}-dev${MultiMC_VERSION_BUILD}")
|
||||
MESSAGE(STATUS "Version Type: Development")
|
||||
SET(MultiMC_VERSION_STRING "${MultiMC_RELEASE_VERSION_NAME}-dev${MultiMC_VERSION_BUILD}")
|
||||
ELSE ()
|
||||
MESSAGE(ERROR "Invalid build type.")
|
||||
MESSAGE(ERROR "Invalid build type.")
|
||||
ENDIF ()
|
||||
|
||||
MESSAGE(STATUS "MultiMC 5 Version: ${MultiMC_VERSION_STRING}")
|
||||
|
||||
# If the update system is enabled, make sure MultiMC_CHANLIST_URL and MultiMC_VERSION_CHANNEL are set.
|
||||
IF (MultiMC_UPDATER)
|
||||
IF (MultiMC_VERSION_CHANNEL STREQUAL "")
|
||||
MESSAGE(FATAL_ERROR "Update system is enabled, but MultiMC_VERSION_CHANNEL is not set.\n"
|
||||
"Please ensure the CMake variables MultiMC_VERSION_CHANNEL, MultiMC_CHANLIST_URL, and MultiMC_VERSION_BUILD are set.")
|
||||
ENDIF ()
|
||||
IF (MultiMC_CHANLIST_URL STREQUAL "")
|
||||
MESSAGE(FATAL_ERROR "Update system is enabled, but MultiMC_CHANLIST_URL is not set.\n"
|
||||
"Please ensure the CMake variables MultiMC_VERSION_CHANNEL, MultiMC_CHANLIST_URL, and MultiMC_VERSION_BUILD are set.")
|
||||
ENDIF ()
|
||||
IF (MultiMC_VERSION_BUILD LESS 0)
|
||||
MESSAGE(FATAL_ERROR "Update system is enabled, but MultiMC_VERSION_BUILD is not set.\n"
|
||||
"Please ensure the CMake variables MultiMC_VERSION_CHANNEL, MultiMC_CHANLIST_URL, and MultiMC_VERSION_BUILD are set.")
|
||||
ENDIF ()
|
||||
IF (MultiMC_VERSION_CHANNEL STREQUAL "")
|
||||
MESSAGE(FATAL_ERROR "Update system is enabled, but MultiMC_VERSION_CHANNEL is not set.\n"
|
||||
"Please ensure the CMake variables MultiMC_VERSION_CHANNEL, MultiMC_CHANLIST_URL, and MultiMC_VERSION_BUILD are set.")
|
||||
ENDIF ()
|
||||
IF (MultiMC_CHANLIST_URL STREQUAL "")
|
||||
MESSAGE(FATAL_ERROR "Update system is enabled, but MultiMC_CHANLIST_URL is not set.\n"
|
||||
"Please ensure the CMake variables MultiMC_VERSION_CHANNEL, MultiMC_CHANLIST_URL, and MultiMC_VERSION_BUILD are set.")
|
||||
ENDIF ()
|
||||
IF (MultiMC_VERSION_BUILD LESS 0)
|
||||
MESSAGE(FATAL_ERROR "Update system is enabled, but MultiMC_VERSION_BUILD is not set.\n"
|
||||
"Please ensure the CMake variables MultiMC_VERSION_CHANNEL, MultiMC_CHANLIST_URL, and MultiMC_VERSION_BUILD are set.")
|
||||
ENDIF ()
|
||||
|
||||
MESSAGE(STATUS "Updater is enabled. Channel list URL: ${MultiMC_CHANLIST_URL}")
|
||||
MESSAGE(STATUS "Updater is enabled. Channel list URL: ${MultiMC_CHANLIST_URL}")
|
||||
ENDIF ()
|
||||
|
||||
#### Custom target to just print the version.
|
||||
@ -163,18 +163,18 @@ ADD_CUSTOM_TARGET(version echo "Version: ${MultiMC_VERSION_STRING}")
|
||||
|
||||
#### Check the current Git commit
|
||||
execute_process(COMMAND git rev-parse HEAD
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
RESULT_VARIABLE GIT_COMMIT_CHECK_RESULTVAR
|
||||
OUTPUT_VARIABLE GIT_COMMIT_CHECK_OUTVAR
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
RESULT_VARIABLE GIT_COMMIT_CHECK_RESULTVAR
|
||||
OUTPUT_VARIABLE GIT_COMMIT_CHECK_OUTVAR
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
IF(GIT_COMMIT_CHECK_RESULTVAR EQUAL 0)
|
||||
SET(MultiMC_GIT_COMMIT "${GIT_COMMIT_CHECK_OUTVAR}")
|
||||
MESSAGE(STATUS "Git commit: ${MultiMC_GIT_COMMIT}")
|
||||
SET(MultiMC_GIT_COMMIT "${GIT_COMMIT_CHECK_OUTVAR}")
|
||||
MESSAGE(STATUS "Git commit: ${MultiMC_GIT_COMMIT}")
|
||||
ELSE()
|
||||
SET(MultiMC_GIT_COMMIT "Unknown")
|
||||
MESSAGE(STATUS "Failed to check Git commit. ${GIT_COMMIT_CHECK_RESULTVAR}")
|
||||
SET(MultiMC_GIT_COMMIT "Unknown")
|
||||
MESSAGE(STATUS "Failed to check Git commit. ${GIT_COMMIT_CHECK_RESULTVAR}")
|
||||
ENDIF()
|
||||
|
||||
######## Configure header ########
|
||||
@ -190,29 +190,29 @@ ADD_DEFINITIONS(-DLIBUTIL_STATIC)
|
||||
######## Packaging/install paths setup ########
|
||||
|
||||
IF(UNIX AND APPLE)
|
||||
SET(BINARY_DEST_DIR MultiMC.app/Contents/MacOS)
|
||||
SET(PLUGIN_DEST_DIR MultiMC.app/Contents/MacOS)
|
||||
SET(QTCONF_DEST_DIR MultiMC.app/Contents/Resources)
|
||||
SET(APPS "\${CMAKE_INSTALL_PREFIX}/MultiMC.app")
|
||||
SET(BINARY_DEST_DIR MultiMC.app/Contents/MacOS)
|
||||
SET(PLUGIN_DEST_DIR MultiMC.app/Contents/MacOS)
|
||||
SET(QTCONF_DEST_DIR MultiMC.app/Contents/Resources)
|
||||
SET(APPS "\${CMAKE_INSTALL_PREFIX}/MultiMC.app")
|
||||
|
||||
SET(MACOSX_BUNDLE_BUNDLE_NAME "MultiMC")
|
||||
SET(MACOSX_BUNDLE_INFO_STRING "MultiMC Minecraft launcher and management utility.")
|
||||
SET(MACOSX_BUNDLE_GUI_IDENTIFIER "org.multimc.MultiMC5")
|
||||
SET(MACOSX_BUNDLE_BUNDLE_VERSION "${MultiMC_VERSION_MAJOR}.${MultiMC_VERSION_MINOR}.${MultiMC_VERSION_REV}.${MultiMC_VERSION_BUILD}")
|
||||
SET(MACOSX_BUNDLE_SHORT_VERSION_STRING "${MultiMC_VERSION_MAJOR}.${MultiMC_VERSION_MINOR}.${MultiMC_VERSION_REV}.${MultiMC_VERSION_BUILD}")
|
||||
SET(MACOSX_BUNDLE_LONG_VERSION_STRING "${MultiMC_VERSION_MAJOR}.${MultiMC_VERSION_MINOR}.${MultiMC_VERSION_REV}.${MultiMC_VERSION_BUILD}")
|
||||
SET(MACOSX_BUNDLE_ICON_FILE MultiMC.icns)
|
||||
SET(MACOSX_BUNDLE_COPYRIGHT "Copyright 2013 MultiMC Contributors")
|
||||
SET(MACOSX_BUNDLE_BUNDLE_NAME "MultiMC")
|
||||
SET(MACOSX_BUNDLE_INFO_STRING "MultiMC Minecraft launcher and management utility.")
|
||||
SET(MACOSX_BUNDLE_GUI_IDENTIFIER "org.multimc.MultiMC5")
|
||||
SET(MACOSX_BUNDLE_BUNDLE_VERSION "${MultiMC_VERSION_MAJOR}.${MultiMC_VERSION_MINOR}.${MultiMC_VERSION_REV}.${MultiMC_VERSION_BUILD}")
|
||||
SET(MACOSX_BUNDLE_SHORT_VERSION_STRING "${MultiMC_VERSION_MAJOR}.${MultiMC_VERSION_MINOR}.${MultiMC_VERSION_REV}.${MultiMC_VERSION_BUILD}")
|
||||
SET(MACOSX_BUNDLE_LONG_VERSION_STRING "${MultiMC_VERSION_MAJOR}.${MultiMC_VERSION_MINOR}.${MultiMC_VERSION_REV}.${MultiMC_VERSION_BUILD}")
|
||||
SET(MACOSX_BUNDLE_ICON_FILE MultiMC.icns)
|
||||
SET(MACOSX_BUNDLE_COPYRIGHT "Copyright 2013 MultiMC Contributors")
|
||||
ELSEIF(UNIX)
|
||||
SET(BINARY_DEST_DIR bin)
|
||||
SET(PLUGIN_DEST_DIR plugins)
|
||||
SET(QTCONF_DEST_DIR .)
|
||||
SET(APPS "\${CMAKE_INSTALL_PREFIX}/bin/MultiMC")
|
||||
SET(BINARY_DEST_DIR bin)
|
||||
SET(PLUGIN_DEST_DIR plugins)
|
||||
SET(QTCONF_DEST_DIR .)
|
||||
SET(APPS "\${CMAKE_INSTALL_PREFIX}/bin/MultiMC")
|
||||
ELSEIF(WIN32)
|
||||
SET(BINARY_DEST_DIR .)
|
||||
SET(PLUGIN_DEST_DIR .)
|
||||
SET(QTCONF_DEST_DIR .)
|
||||
SET(APPS "\${CMAKE_INSTALL_PREFIX}/MultiMC.exe")
|
||||
SET(BINARY_DEST_DIR .)
|
||||
SET(PLUGIN_DEST_DIR .)
|
||||
SET(QTCONF_DEST_DIR .)
|
||||
SET(APPS "\${CMAKE_INSTALL_PREFIX}/MultiMC.exe")
|
||||
ENDIF()
|
||||
|
||||
# directories to look for dependencies
|
||||
@ -308,6 +308,8 @@ gui/dialogs/AccountSelectDialog.h
|
||||
gui/dialogs/AccountSelectDialog.cpp
|
||||
gui/dialogs/UpdateDialog.h
|
||||
gui/dialogs/UpdateDialog.cpp
|
||||
gui/dialogs/ScreenshotDialog.h
|
||||
gui/dialogs/ScreenshotDialog.cpp
|
||||
|
||||
# GUI - widgets
|
||||
gui/widgets/Common.h
|
||||
@ -370,6 +372,8 @@ logic/net/HttpMetaCache.cpp
|
||||
logic/net/PasteUpload.h
|
||||
logic/net/PasteUpload.cpp
|
||||
logic/net/URLConstants.h
|
||||
logic/net/ScreenshotUploader.h
|
||||
logic/net/ScreenshotUploader.cpp
|
||||
|
||||
# Yggdrasil login stuff
|
||||
logic/auth/AuthSession.h
|
||||
@ -460,6 +464,8 @@ logic/lists/ForgeVersionList.h
|
||||
logic/lists/ForgeVersionList.cpp
|
||||
logic/lists/JavaVersionList.h
|
||||
logic/lists/JavaVersionList.cpp
|
||||
logic/lists/ScreenshotList.h
|
||||
logic/lists/ScreenshotList.cpp
|
||||
|
||||
# Icons
|
||||
logic/icons/MMCIcon.h
|
||||
@ -525,6 +531,7 @@ gui/dialogs/AccountListDialog.ui
|
||||
gui/dialogs/AccountSelectDialog.ui
|
||||
gui/dialogs/EditAccountDialog.ui
|
||||
gui/dialogs/UpdateDialog.ui
|
||||
gui/dialogs/ScreenshotDialog.ui
|
||||
|
||||
# Widgets/other
|
||||
gui/widgets/MCModInfoFrame.ui
|
||||
@ -546,11 +553,11 @@ ENDIF()
|
||||
|
||||
####### X11 Stuff #######
|
||||
IF(UNIX AND NOT APPLE)
|
||||
SET(MultiMC_QT_ADDITIONAL_MODULES ${MultiMC_QT_ADDITIONAL_MODULES} X11Extras)
|
||||
SET(MultiMC_LINK_ADDITIONAL_LIBS ${MultiMC_LINK_ADDITIONAL_LIBS} xcb)
|
||||
LIST(APPEND MULTIMC_SOURCES gui/Platform_X11.cpp)
|
||||
SET(MultiMC_QT_ADDITIONAL_MODULES ${MultiMC_QT_ADDITIONAL_MODULES} X11Extras)
|
||||
SET(MultiMC_LINK_ADDITIONAL_LIBS ${MultiMC_LINK_ADDITIONAL_LIBS} xcb)
|
||||
LIST(APPEND MULTIMC_SOURCES gui/Platform_X11.cpp)
|
||||
ELSE()
|
||||
LIST(APPEND MULTIMC_SOURCES gui/Platform_Other.cpp)
|
||||
LIST(APPEND MULTIMC_SOURCES gui/Platform_Other.cpp)
|
||||
ENDIF()
|
||||
|
||||
|
||||
@ -558,9 +565,9 @@ ENDIF()
|
||||
|
||||
# Link additional libraries
|
||||
IF(WIN32)
|
||||
SET(MultiMC_LINK_ADDITIONAL_LIBS ${MultiMC_LINK_ADDITIONAL_LIBS}
|
||||
Qt5::WinMain # Link WinMain
|
||||
)
|
||||
SET(MultiMC_LINK_ADDITIONAL_LIBS ${MultiMC_LINK_ADDITIONAL_LIBS}
|
||||
Qt5::WinMain # Link WinMain
|
||||
)
|
||||
ENDIF(WIN32)
|
||||
|
||||
OPTION(MultiMC_UPDATER_DRY_RUN "Enable updater dry-run mode -- for updater development." OFF)
|
||||
@ -568,11 +575,11 @@ OPTION(MultiMC_UPDATER_FORCE_LOCAL "Do not download updated updater -- for updat
|
||||
|
||||
OPTION(MultiMC_CODE_COVERAGE "Compiles for code coverage" OFF)
|
||||
IF(MultiMC_CODE_COVERAGE)
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 --coverage")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 --coverage")
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 --coverage")
|
||||
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -O0 --coverage")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O0 --coverage")
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 --coverage")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 --coverage")
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 --coverage")
|
||||
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -O0 --coverage")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O0 --coverage")
|
||||
ENDIF(MultiMC_CODE_COVERAGE)
|
||||
|
||||
# Tell CMake that MultiMCLauncher.jar is generated.
|
||||
@ -601,24 +608,24 @@ QT5_USE_MODULES(MultiMC_common Core Widgets Network Xml Concurrent ${MultiMC_QT_
|
||||
|
||||
#### Executable ####
|
||||
IF(APPLE AND UNIX) ## OSX
|
||||
INSTALL(TARGETS MultiMC
|
||||
BUNDLE DESTINATION . COMPONENT Runtime
|
||||
RUNTIME DESTINATION MultiMC.app/Contents/MacOS COMPONENT Runtime
|
||||
)
|
||||
INSTALL(TARGETS MultiMC
|
||||
BUNDLE DESTINATION . COMPONENT Runtime
|
||||
RUNTIME DESTINATION MultiMC.app/Contents/MacOS COMPONENT Runtime
|
||||
)
|
||||
|
||||
ELSEIF(UNIX) ## LINUX and similar
|
||||
INSTALL(TARGETS MultiMC
|
||||
BUNDLE DESTINATION . COMPONENT Runtime
|
||||
RUNTIME DESTINATION bin COMPONENT Runtime
|
||||
)
|
||||
INSTALL(PROGRAMS package/linux/MultiMC DESTINATION .)
|
||||
INSTALL(TARGETS MultiMC
|
||||
BUNDLE DESTINATION . COMPONENT Runtime
|
||||
RUNTIME DESTINATION bin COMPONENT Runtime
|
||||
)
|
||||
INSTALL(PROGRAMS package/linux/MultiMC DESTINATION .)
|
||||
|
||||
ELSEIF(WIN32) ## WINDOWS
|
||||
INSTALL(TARGETS MultiMC
|
||||
BUNDLE DESTINATION . COMPONENT Runtime
|
||||
LIBRARY DESTINATION . COMPONENT Runtime
|
||||
RUNTIME DESTINATION . COMPONENT Runtime
|
||||
)
|
||||
INSTALL(TARGETS MultiMC
|
||||
BUNDLE DESTINATION . COMPONENT Runtime
|
||||
LIBRARY DESTINATION . COMPONENT Runtime
|
||||
RUNTIME DESTINATION . COMPONENT Runtime
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
#### Dist package logic ####
|
||||
@ -626,70 +633,70 @@ ENDIF()
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
||||
# Image formats
|
||||
INSTALL(
|
||||
DIRECTORY "${QT_PLUGINS_DIR}/imageformats"
|
||||
DESTINATION ${PLUGIN_DEST_DIR}
|
||||
COMPONENT Runtime
|
||||
REGEX "tga|svg|tiff|mng" EXCLUDE
|
||||
DIRECTORY "${QT_PLUGINS_DIR}/imageformats"
|
||||
DESTINATION ${PLUGIN_DEST_DIR}
|
||||
COMPONENT Runtime
|
||||
REGEX "tga|svg|tiff|mng" EXCLUDE
|
||||
)
|
||||
|
||||
# Platform plugins
|
||||
INSTALL(
|
||||
DIRECTORY "${QT_PLUGINS_DIR}/platforms"
|
||||
DESTINATION ${PLUGIN_DEST_DIR}
|
||||
COMPONENT Runtime
|
||||
REGEX "minimal|linuxfb|offscreen" EXCLUDE
|
||||
DIRECTORY "${QT_PLUGINS_DIR}/platforms"
|
||||
DESTINATION ${PLUGIN_DEST_DIR}
|
||||
COMPONENT Runtime
|
||||
REGEX "minimal|linuxfb|offscreen" EXCLUDE
|
||||
)
|
||||
else()
|
||||
# Image formats
|
||||
INSTALL(
|
||||
DIRECTORY "${QT_PLUGINS_DIR}/imageformats"
|
||||
DESTINATION ${PLUGIN_DEST_DIR}
|
||||
COMPONENT Runtime
|
||||
REGEX "tga|svg|tiff|mng" EXCLUDE
|
||||
REGEX "d\\." EXCLUDE
|
||||
REGEX "_debug\\." EXCLUDE
|
||||
DIRECTORY "${QT_PLUGINS_DIR}/imageformats"
|
||||
DESTINATION ${PLUGIN_DEST_DIR}
|
||||
COMPONENT Runtime
|
||||
REGEX "tga|svg|tiff|mng" EXCLUDE
|
||||
REGEX "d\\." EXCLUDE
|
||||
REGEX "_debug\\." EXCLUDE
|
||||
)
|
||||
|
||||
# Platform plugins
|
||||
INSTALL(
|
||||
DIRECTORY "${QT_PLUGINS_DIR}/platforms"
|
||||
DESTINATION ${PLUGIN_DEST_DIR}
|
||||
COMPONENT Runtime
|
||||
REGEX "minimal|linuxfb|offscreen" EXCLUDE
|
||||
REGEX "d\\." EXCLUDE
|
||||
REGEX "_debug\\." EXCLUDE
|
||||
DIRECTORY "${QT_PLUGINS_DIR}/platforms"
|
||||
DESTINATION ${PLUGIN_DEST_DIR}
|
||||
COMPONENT Runtime
|
||||
REGEX "minimal|linuxfb|offscreen" EXCLUDE
|
||||
REGEX "d\\." EXCLUDE
|
||||
REGEX "_debug\\." EXCLUDE
|
||||
)
|
||||
IF(APPLE)
|
||||
# Accessible plugin to make buttons look decent on osx
|
||||
INSTALL(
|
||||
DIRECTORY "${QT_PLUGINS_DIR}/accessible"
|
||||
DESTINATION ${PLUGIN_DEST_DIR}
|
||||
COMPONENT Runtime
|
||||
REGEX "quick" EXCLUDE
|
||||
REGEX "d\\." EXCLUDE
|
||||
REGEX "_debug\\." EXCLUDE
|
||||
)
|
||||
# Accessible plugin to make buttons look decent on osx
|
||||
INSTALL(
|
||||
DIRECTORY "${QT_PLUGINS_DIR}/accessible"
|
||||
DESTINATION ${PLUGIN_DEST_DIR}
|
||||
COMPONENT Runtime
|
||||
REGEX "quick" EXCLUDE
|
||||
REGEX "d\\." EXCLUDE
|
||||
REGEX "_debug\\." EXCLUDE
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
endif()
|
||||
|
||||
# qtconf
|
||||
INSTALL(
|
||||
CODE "
|
||||
CODE "
|
||||
FILE(WRITE \"\${CMAKE_INSTALL_PREFIX}/${QTCONF_DEST_DIR}/qt.conf\" \"\")
|
||||
"
|
||||
COMPONENT Runtime
|
||||
COMPONENT Runtime
|
||||
)
|
||||
|
||||
# ICNS file for OS X
|
||||
IF(APPLE)
|
||||
INSTALL(FILES resources/MultiMC.icns DESTINATION MultiMC.app/Contents/Resources)
|
||||
INSTALL(FILES resources/MultiMC.icns DESTINATION MultiMC.app/Contents/Resources)
|
||||
ENDIF()
|
||||
|
||||
CONFIGURE_FILE(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/install_prereqs.cmake.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/install_prereqs.cmake"
|
||||
@ONLY)
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/install_prereqs.cmake.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/install_prereqs.cmake"
|
||||
@ONLY)
|
||||
INSTALL(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/install_prereqs.cmake" COMPONENT Runtime)
|
||||
|
||||
|
||||
@ -698,13 +705,13 @@ INSTALL(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/install_prereqs.cmake" COMPONENT Run
|
||||
|
||||
# Package with CPack
|
||||
IF(UNIX)
|
||||
if(APPLE)
|
||||
SET(CPACK_GENERATOR "ZIP")
|
||||
else()
|
||||
SET(CPACK_GENERATOR "TGZ")
|
||||
endif()
|
||||
if(APPLE)
|
||||
SET(CPACK_GENERATOR "ZIP")
|
||||
else()
|
||||
SET(CPACK_GENERATOR "TGZ")
|
||||
endif()
|
||||
ELSEIF(WIN32)
|
||||
SET(CPACK_GENERATOR "ZIP")
|
||||
SET(CPACK_GENERATOR "ZIP")
|
||||
ENDIF()
|
||||
SET(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
|
||||
|
||||
@ -736,16 +743,16 @@ file (GLOB TRANSLATIONS_FILES translations/*.ts)
|
||||
|
||||
option (UPDATE_TRANSLATIONS "Update source translation translations/*.ts files (WARNING: make clean will delete the source .ts files! Danger!)")
|
||||
IF(UPDATE_TRANSLATIONS)
|
||||
qt5_create_translation(QM_FILES ${FILES_TO_TRANSLATE} ${TRANSLATIONS_FILES})
|
||||
qt5_create_translation(QM_FILES ${FILES_TO_TRANSLATE} ${TRANSLATIONS_FILES})
|
||||
ELSE()
|
||||
qt5_add_translation(QM_FILES ${TRANSLATIONS_FILES})
|
||||
qt5_add_translation(QM_FILES ${TRANSLATIONS_FILES})
|
||||
ENDIF()
|
||||
|
||||
add_custom_target (translations DEPENDS ${QM_FILES})
|
||||
IF(APPLE AND UNIX) ## OSX
|
||||
install(FILES ${QM_FILES} DESTINATION MultiMC.app/Contents/MacOS/translations)
|
||||
install(FILES ${QM_FILES} DESTINATION MultiMC.app/Contents/MacOS/translations)
|
||||
ELSE()
|
||||
install(FILES ${QM_FILES} DESTINATION translations)
|
||||
install(FILES ${QM_FILES} DESTINATION translations)
|
||||
ENDIF()
|
||||
|
||||
|
||||
|
@ -43,7 +43,6 @@
|
||||
|
||||
#include "gui/Platform.h"
|
||||
|
||||
|
||||
#include "gui/widgets/LabeledToolButton.h"
|
||||
|
||||
#include "gui/dialogs/SettingsDialog.h"
|
||||
@ -61,6 +60,7 @@
|
||||
#include "gui/dialogs/AccountSelectDialog.h"
|
||||
#include "gui/dialogs/UpdateDialog.h"
|
||||
#include "gui/dialogs/EditAccountDialog.h"
|
||||
#include "gui/dialogs/ScreenshotDialog.h"
|
||||
|
||||
#include "gui/ConsoleWindow.h"
|
||||
|
||||
@ -80,6 +80,8 @@
|
||||
#include "logic/status/StatusChecker.h"
|
||||
|
||||
#include "logic/net/URLConstants.h"
|
||||
#include "logic/net/NetJob.h"
|
||||
#include "logic/net/ScreenshotUploader.h"
|
||||
|
||||
#include "logic/BaseInstance.h"
|
||||
#include "logic/InstanceFactory.h"
|
||||
@ -143,7 +145,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
{
|
||||
view = new GroupView(ui->centralWidget);
|
||||
|
||||
|
||||
view->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
// view->setCategoryDrawer(drawer);
|
||||
// view->setCollapsibleBlocks(true);
|
||||
@ -1499,3 +1500,69 @@ void MainWindow::checkSetDefaultJava()
|
||||
MMC->settings()->set("JavaPath", QString("java"));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionScreenshots_triggered()
|
||||
{
|
||||
if (!m_selectedInstance)
|
||||
return;
|
||||
ScreenshotList *list = new ScreenshotList(m_selectedInstance);
|
||||
Task *task = list->load();
|
||||
ProgressDialog prog(this);
|
||||
prog.exec(task);
|
||||
if (!task->successful())
|
||||
{
|
||||
CustomMessageBox::selectable(this, tr("Failed to load screenshots!"),
|
||||
task->failReason(), QMessageBox::Warning)->exec();
|
||||
return;
|
||||
}
|
||||
ScreenshotDialog dialog(list, this);
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
QList<ScreenShot *> screenshots = dialog.selected();
|
||||
if (screenshots.size() == 0)
|
||||
return;
|
||||
NetJob *job = new NetJob("Screenshot Upload");
|
||||
for (ScreenShot *shot : screenshots)
|
||||
job->addNetAction(ScreenShotUpload::make(shot));
|
||||
ProgressDialog prog2(this);
|
||||
prog2.exec(job);
|
||||
connect(job, &NetJob::failed, [this]
|
||||
{
|
||||
CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"),
|
||||
tr("Unknown error"), QMessageBox::Warning)->exec();
|
||||
});
|
||||
connect(job, &NetJob::succeeded, [this, screenshots]
|
||||
{ screenshotsUploaded(screenshots); });
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::screenshotsUploaded(QList<ScreenShot *> screenshots)
|
||||
{
|
||||
NetJob *job2 = new NetJob("Screenshot Data");
|
||||
for (ScreenShot *shot : screenshots)
|
||||
{
|
||||
job2->addNetAction(ScreenShotGet::make(shot));
|
||||
}
|
||||
ProgressDialog prog3(this);
|
||||
prog3.exec(job2);
|
||||
connect(job2, &NetJob::failed, [this]
|
||||
{
|
||||
CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"),
|
||||
tr("Unknown error"), QMessageBox::Warning)->exec();
|
||||
});
|
||||
connect(job2, &NetJob::succeeded, [this, screenshots]
|
||||
{ screenShotsGotten(screenshots); });
|
||||
}
|
||||
|
||||
void MainWindow::screenShotsGotten(QList<ScreenShot *> screenshots)
|
||||
{
|
||||
|
||||
QStringList urls;
|
||||
for (ScreenShot *shot : screenshots)
|
||||
{
|
||||
urls << QString("<a href=\"" + shot->url + "\">Image %s</a>")
|
||||
.arg(QString::number(shot->imgurIndex));
|
||||
}
|
||||
CustomMessageBox::selectable(this, tr("Done uploading!"), urls.join("\n"),
|
||||
QMessageBox::Information)->exec();
|
||||
}
|
||||
|
@ -138,7 +138,9 @@ slots:
|
||||
// called when an icon is changed in the icon model.
|
||||
void iconUpdated(QString);
|
||||
|
||||
void showInstanceContextMenu(const QPoint&);
|
||||
void showInstanceContextMenu(const QPoint &);
|
||||
|
||||
void on_actionScreenshots_triggered();
|
||||
|
||||
public
|
||||
slots:
|
||||
@ -167,11 +169,15 @@ slots:
|
||||
void updateStatusFailedUI();
|
||||
|
||||
void reloadStatus();
|
||||
|
||||
|
||||
void screenshotsUploaded(QList<class ScreenShot*> screenshots);
|
||||
|
||||
void screenShotsGotten(QList<class ScreenShot*> screenshots);
|
||||
|
||||
/*!
|
||||
* Runs the DownloadUpdateTask and installs updates.
|
||||
*/
|
||||
void downloadUpdates(QString repo, int versionId, bool installOnExit=false);
|
||||
void downloadUpdates(QString repo, int versionId, bool installOnExit = false);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *ev);
|
||||
@ -188,7 +194,7 @@ private:
|
||||
ConsoleWindow *console;
|
||||
LabeledToolButton *renameButton;
|
||||
QToolButton *changeIconButton;
|
||||
QToolButton* newsLabel;
|
||||
QToolButton *newsLabel;
|
||||
|
||||
BaseInstance *m_selectedInstance;
|
||||
QString m_currentInstIcon;
|
||||
|
@ -112,6 +112,8 @@
|
||||
<addaction name="actionEditInstNotes"/>
|
||||
<addaction name="actionChangeInstGroup"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionScreenshots"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionInstanceSettings"/>
|
||||
<addaction name="actionChangeInstMCVersion"/>
|
||||
<addaction name="actionChangeInstLWJGLVersion"/>
|
||||
@ -528,12 +530,19 @@
|
||||
<string>Launch the selected instance.</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionScreenshots">
|
||||
<property name="text">
|
||||
<string>Upload Screenshots</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>View and upload screenshots for this instance</p></body></html></string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources>
|
||||
<include location="../resources/instances/instances.qrc"/>
|
||||
<include location="../resources/multimc/multimc.qrc"/>
|
||||
<include location="../resources/backgrounds/backgrounds.qrc"/>
|
||||
<include location="../resources/instances/instances.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
28
gui/dialogs/ScreenshotDialog.cpp
Normal file
28
gui/dialogs/ScreenshotDialog.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include "ScreenshotDialog.h"
|
||||
#include "ui_ScreenshotDialog.h"
|
||||
#include "QModelIndex"
|
||||
|
||||
ScreenshotDialog::ScreenshotDialog(ScreenshotList *list, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::ScreenshotDialog),
|
||||
m_list(list)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->listView->setModel(m_list);
|
||||
}
|
||||
|
||||
ScreenshotDialog::~ScreenshotDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QList<ScreenShot*> ScreenshotDialog::selected()
|
||||
{
|
||||
QList<ScreenShot*> list;
|
||||
QList<ScreenShot*> first = m_list->screenshots();
|
||||
for (QModelIndex index : ui->listView->selectionModel()->selectedIndexes())
|
||||
{
|
||||
list.append(first.at(index.row()));
|
||||
}
|
||||
return list;
|
||||
}
|
29
gui/dialogs/ScreenshotDialog.h
Normal file
29
gui/dialogs/ScreenshotDialog.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include "logic/lists/ScreenshotList.h"
|
||||
|
||||
class BaseInstance;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class ScreenshotDialog;
|
||||
}
|
||||
|
||||
class ScreenshotDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ScreenshotDialog(ScreenshotList *list, QWidget *parent = 0);
|
||||
~ScreenshotDialog();
|
||||
|
||||
QList<ScreenShot *> selected();
|
||||
|
||||
private
|
||||
slots:
|
||||
|
||||
private:
|
||||
Ui::ScreenshotDialog *ui;
|
||||
ScreenshotList *m_list;
|
||||
};
|
93
gui/dialogs/ScreenshotDialog.ui
Normal file
93
gui/dialogs/ScreenshotDialog.ui
Normal file
@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ScreenshotDialog</class>
|
||||
<widget class="QDialog" name="ScreenshotDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>470</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>260</y>
|
||||
<width>441</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QListView" name="listView">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>439</width>
|
||||
<height>241</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::MultiSelection</enum>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>480</width>
|
||||
<height>360</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="flow">
|
||||
<enum>QListView::LeftToRight</enum>
|
||||
</property>
|
||||
<property name="isWrapping" stdset="0">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="viewMode">
|
||||
<enum>QListView::ListMode</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ScreenshotDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ScreenshotDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
81
logic/lists/ScreenshotList.cpp
Normal file
81
logic/lists/ScreenshotList.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include "ScreenshotList.h"
|
||||
#include "QDir"
|
||||
#include "QPixmap"
|
||||
|
||||
ScreenshotList::ScreenshotList(BaseInstance *instance, QObject *parent)
|
||||
: QAbstractListModel(parent), m_instance(instance)
|
||||
{
|
||||
}
|
||||
|
||||
int ScreenshotList::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return m_screenshots.size();
|
||||
}
|
||||
|
||||
QVariant ScreenshotList::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
switch (role)
|
||||
{
|
||||
case Qt::DecorationRole:
|
||||
{
|
||||
QPixmap map;
|
||||
map.loadFromData(m_screenshots.at(index.row())->file);
|
||||
return map;
|
||||
}
|
||||
case Qt::DisplayRole:
|
||||
return m_screenshots.at(index.row())->timestamp;
|
||||
case Qt::ToolTipRole:
|
||||
return m_screenshots.at(index.row())->timestamp;
|
||||
case Qt::TextAlignmentRole:
|
||||
return (int)(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant ScreenshotList::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Qt::ItemFlags ScreenshotList::flags(const QModelIndex &index) const
|
||||
{
|
||||
return Qt::NoItemFlags;
|
||||
}
|
||||
|
||||
Task *ScreenshotList::load()
|
||||
{
|
||||
return new ScreenshotLoadTask(this);
|
||||
}
|
||||
|
||||
ScreenshotLoadTask::ScreenshotLoadTask(ScreenshotList *list) : m_list(list)
|
||||
{
|
||||
}
|
||||
|
||||
ScreenshotLoadTask::~ScreenshotLoadTask()
|
||||
{
|
||||
}
|
||||
|
||||
void ScreenshotLoadTask::executeTask()
|
||||
{
|
||||
auto dir = QDir(m_list->instance()->minecraftRoot());
|
||||
if (!dir.cd("screenshots"))
|
||||
{
|
||||
emitFailed("Selected instance does not have any screenshots!");
|
||||
return;
|
||||
}
|
||||
dir.setNameFilters(QStringList() << "*.png");
|
||||
this->m_results = QList<ScreenShot *>();
|
||||
for (auto file : dir.entryList())
|
||||
{
|
||||
ScreenShot *shot = new ScreenShot();
|
||||
shot->timestamp = file.left(file.length() - 4);
|
||||
shot->file = QFile(file).readAll();
|
||||
m_results.append(shot);
|
||||
}
|
||||
m_list->loadShots(m_results);
|
||||
emitSucceeded();
|
||||
}
|
75
logic/lists/ScreenshotList.h
Normal file
75
logic/lists/ScreenshotList.h
Normal file
@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include "logic/BaseInstance.h"
|
||||
#include "logic/tasks/Task.h"
|
||||
|
||||
class ScreenShot
|
||||
{
|
||||
public:
|
||||
QString timestamp;
|
||||
QByteArray file;
|
||||
int imgurIndex;
|
||||
QString url;
|
||||
};
|
||||
|
||||
class ScreenshotList : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ScreenshotList(BaseInstance *instance, QObject *parent = 0);
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||
|
||||
int rowCount(const QModelIndex &parent) const;
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
|
||||
Task *load();
|
||||
|
||||
void loadShots(QList<ScreenShot *> shots)
|
||||
{
|
||||
m_screenshots = shots;
|
||||
}
|
||||
|
||||
QList<ScreenShot *> screenshots() const
|
||||
{
|
||||
return m_screenshots;
|
||||
}
|
||||
|
||||
BaseInstance *instance() const
|
||||
{
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
signals:
|
||||
|
||||
public
|
||||
slots:
|
||||
|
||||
private:
|
||||
QList<ScreenShot *> m_screenshots;
|
||||
BaseInstance *m_instance;
|
||||
};
|
||||
|
||||
class ScreenshotLoadTask : public Task
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ScreenshotLoadTask(ScreenshotList *list);
|
||||
~ScreenshotLoadTask();
|
||||
|
||||
QList<ScreenShot *> screenShots() const
|
||||
{
|
||||
return m_results;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void executeTask();
|
||||
|
||||
private:
|
||||
ScreenshotList *m_list;
|
||||
QList<ScreenShot *> m_results;
|
||||
};
|
144
logic/net/ScreenshotUploader.cpp
Normal file
144
logic/net/ScreenshotUploader.cpp
Normal file
@ -0,0 +1,144 @@
|
||||
#include "ScreenshotUploader.h"
|
||||
#include "logic/lists/ScreenshotList.h"
|
||||
#include <QNetworkRequest>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include "URLConstants.h"
|
||||
#include "MultiMC.h"
|
||||
|
||||
ScreenShotUpload::ScreenShotUpload(ScreenShot *shot) : m_shot(shot)
|
||||
{
|
||||
m_status = Job_NotStarted;
|
||||
}
|
||||
|
||||
void ScreenShotUpload::start()
|
||||
{
|
||||
m_status = Job_InProgress;
|
||||
QNetworkRequest request(URLConstants::IMGUR_UPLOAD_URL);
|
||||
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)");
|
||||
request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3");
|
||||
|
||||
QJsonObject object;
|
||||
object.insert("image", QJsonValue::fromVariant(m_shot->file.toBase64()));
|
||||
object.insert("type", QJsonValue::fromVariant("base64"));
|
||||
object.insert("name", QJsonValue::fromVariant(m_shot->timestamp));
|
||||
QJsonDocument doc;
|
||||
doc.setObject(object);
|
||||
|
||||
auto worker = MMC->qnam();
|
||||
QNetworkReply *rep = worker->post(request, doc.toJson());
|
||||
|
||||
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
||||
connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
|
||||
SLOT(downloadProgress(qint64, qint64)));
|
||||
connect(rep, SIGNAL(finished()), SLOT(downloadFinished()));
|
||||
connect(rep, SIGNAL(error(QNetworkReply::NetworkError)),
|
||||
SLOT(downloadError(QNetworkReply::NetworkError)));
|
||||
connect(rep, SIGNAL(readyRead()), SLOT(downloadReadyRead()));
|
||||
}
|
||||
void ScreenShotUpload::downloadError(QNetworkReply::NetworkError error)
|
||||
{
|
||||
m_status = Job_Failed;
|
||||
}
|
||||
void ScreenShotUpload::downloadFinished()
|
||||
{
|
||||
if (m_status != Job_Failed)
|
||||
{
|
||||
QByteArray data = m_reply->readAll();
|
||||
m_reply.reset();
|
||||
QJsonParseError jsonError;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError);
|
||||
if (jsonError.error != QJsonParseError::NoError)
|
||||
{
|
||||
emit failed(m_index_within_job);
|
||||
return;
|
||||
}
|
||||
auto object = doc.object();
|
||||
if (!object.value("success").toBool())
|
||||
{
|
||||
emit failed(m_index_within_job);
|
||||
return;
|
||||
}
|
||||
m_shot->imgurIndex = object.value("data").toVariant().toInt();
|
||||
m_status = Job_Finished;
|
||||
emit succeeded(m_index_within_job);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_reply.reset();
|
||||
emit failed(m_index_within_job);
|
||||
return;
|
||||
}
|
||||
}
|
||||
void ScreenShotUpload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
|
||||
{
|
||||
m_total_progress = bytesTotal;
|
||||
m_progress = bytesReceived;
|
||||
emit progress(m_index_within_job, bytesReceived, bytesTotal);
|
||||
}
|
||||
void ScreenShotUpload::downloadReadyRead()
|
||||
{
|
||||
// noop
|
||||
}
|
||||
ScreenShotGet::ScreenShotGet(ScreenShot *shot) : m_shot(shot)
|
||||
{
|
||||
m_status = Job_NotStarted;
|
||||
}
|
||||
void ScreenShotGet::start()
|
||||
{
|
||||
m_status = Job_InProgress;
|
||||
QNetworkRequest request(URLConstants::IMGUR_GET_BASE + m_shot->imgurIndex + ".json");
|
||||
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)");
|
||||
request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3");
|
||||
|
||||
auto worker = MMC->qnam();
|
||||
QNetworkReply *rep = worker->get(request);
|
||||
|
||||
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
||||
connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
|
||||
SLOT(downloadProgress(qint64, qint64)));
|
||||
connect(rep, SIGNAL(finished()), SLOT(downloadFinished()));
|
||||
connect(rep, SIGNAL(error(QNetworkReply::NetworkError)),
|
||||
SLOT(downloadError(QNetworkReply::NetworkError)));
|
||||
connect(rep, SIGNAL(readyRead()), SLOT(downloadReadyRead()));
|
||||
}
|
||||
void ScreenShotGet::downloadError(QNetworkReply::NetworkError error)
|
||||
{
|
||||
m_status = Job_Failed;
|
||||
}
|
||||
void ScreenShotGet::downloadFinished()
|
||||
{
|
||||
}
|
||||
void ScreenShotGet::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
|
||||
{
|
||||
m_total_progress = bytesTotal;
|
||||
m_progress = bytesReceived;
|
||||
emit progress(m_index_within_job, bytesReceived, bytesTotal);
|
||||
}
|
||||
void ScreenShotGet::downloadReadyRead()
|
||||
{
|
||||
if (m_status != Job_Failed)
|
||||
{
|
||||
QByteArray data = m_reply->readAll();
|
||||
m_reply.reset();
|
||||
QJsonParseError jsonError;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError);
|
||||
if (jsonError.error != QJsonParseError::NoError)
|
||||
{
|
||||
emit failed(m_index_within_job);
|
||||
return;
|
||||
}
|
||||
auto object = doc.object();
|
||||
m_shot->url = object.value("link").toString();
|
||||
m_status = Job_Finished;
|
||||
emit succeeded(m_index_within_job);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_reply.reset();
|
||||
emit failed(m_index_within_job);
|
||||
return;
|
||||
}
|
||||
}
|
52
logic/net/ScreenshotUploader.h
Normal file
52
logic/net/ScreenshotUploader.h
Normal file
@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
#include "NetAction.h"
|
||||
|
||||
class ScreenShot;
|
||||
typedef std::shared_ptr<class ScreenShotUpload> ScreenShotUploadPtr;
|
||||
typedef std::shared_ptr<class ScreenShotGet> ScreenShotGetPtr;
|
||||
class ScreenShotUpload : public NetAction
|
||||
{
|
||||
public:
|
||||
explicit ScreenShotUpload(ScreenShot *shot);
|
||||
static ScreenShotUploadPtr make(ScreenShot *shot)
|
||||
{
|
||||
return ScreenShotUploadPtr(new ScreenShotUpload(shot));
|
||||
}
|
||||
|
||||
protected
|
||||
slots:
|
||||
virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
|
||||
virtual void downloadError(QNetworkReply::NetworkError error);
|
||||
virtual void downloadFinished();
|
||||
virtual void downloadReadyRead();
|
||||
|
||||
public
|
||||
slots:
|
||||
virtual void start();
|
||||
|
||||
private:
|
||||
ScreenShot *m_shot;
|
||||
};
|
||||
class ScreenShotGet : public NetAction
|
||||
{
|
||||
public:
|
||||
explicit ScreenShotGet(ScreenShot *shot);
|
||||
static ScreenShotGetPtr make(ScreenShot *shot)
|
||||
{
|
||||
return ScreenShotGetPtr(new ScreenShotGet(shot));
|
||||
}
|
||||
|
||||
protected
|
||||
slots:
|
||||
virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
|
||||
virtual void downloadError(QNetworkReply::NetworkError error);
|
||||
virtual void downloadFinished();
|
||||
virtual void downloadReadyRead();
|
||||
|
||||
public
|
||||
slots:
|
||||
virtual void start();
|
||||
|
||||
private:
|
||||
ScreenShot *m_shot;
|
||||
};
|
@ -33,4 +33,6 @@ const QString FORGE_LEGACY_URL("http://files.minecraftforge.net/minecraftforge/j
|
||||
const QString FORGE_GRADLE_URL("http://files.minecraftforge.net/maven/net/minecraftforge/forge/json");
|
||||
const QString MOJANG_STATUS_URL("http://status.mojang.com/check");
|
||||
const QString MOJANG_STATUS_NEWS_URL("http://status.mojang.com/news");
|
||||
const QString IMGUR_UPLOAD_URL("https://api.imgur.com/3/image.json");
|
||||
const QString IMGUR_GET_BASE("https://api.imgur.com/3/image/");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user