From 4a77524b059c12165e20b38de6c0d4ed08e56419 Mon Sep 17 00:00:00 2001 From: robotbrain Date: Sun, 23 Feb 2014 16:14:24 -0500 Subject: [PATCH 1/9] Initial stuff. It doesnt work. --- CMakeLists.txt | 293 ++++++++++++++++--------------- gui/MainWindow.cpp | 71 +++++++- gui/MainWindow.h | 14 +- gui/MainWindow.ui | 13 +- gui/dialogs/ScreenshotDialog.cpp | 28 +++ gui/dialogs/ScreenshotDialog.h | 29 +++ gui/dialogs/ScreenshotDialog.ui | 93 ++++++++++ logic/lists/ScreenshotList.cpp | 81 +++++++++ logic/lists/ScreenshotList.h | 75 ++++++++ logic/net/ScreenshotUploader.cpp | 144 +++++++++++++++ logic/net/ScreenshotUploader.h | 52 ++++++ logic/net/URLConstants.h | 2 + 12 files changed, 744 insertions(+), 151 deletions(-) create mode 100644 gui/dialogs/ScreenshotDialog.cpp create mode 100644 gui/dialogs/ScreenshotDialog.h create mode 100644 gui/dialogs/ScreenshotDialog.ui create mode 100644 logic/lists/ScreenshotList.cpp create mode 100644 logic/lists/ScreenshotList.h create mode 100644 logic/net/ScreenshotUploader.cpp create mode 100644 logic/net/ScreenshotUploader.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e7dea671..048a466a6 100644 --- a/CMakeLists.txt +++ b/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() diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 29f7c8e87..5a22f6782 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -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 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 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 screenshots) +{ + + QStringList urls; + for (ScreenShot *shot : screenshots) + { + urls << QString("url + "\">Image %s") + .arg(QString::number(shot->imgurIndex)); + } + CustomMessageBox::selectable(this, tr("Done uploading!"), urls.join("\n"), + QMessageBox::Information)->exec(); +} diff --git a/gui/MainWindow.h b/gui/MainWindow.h index 4d9e165d9..b57afcf56 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -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 screenshots); + + void screenShotsGotten(QList 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; diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui index 8cf26d181..67625ac89 100644 --- a/gui/MainWindow.ui +++ b/gui/MainWindow.ui @@ -112,6 +112,8 @@ + + @@ -528,12 +530,19 @@ Launch the selected instance. + + + Upload Screenshots + + + <html><head/><body><p>View and upload screenshots for this instance</p></body></html> + + - - + diff --git a/gui/dialogs/ScreenshotDialog.cpp b/gui/dialogs/ScreenshotDialog.cpp new file mode 100644 index 000000000..662c9e840 --- /dev/null +++ b/gui/dialogs/ScreenshotDialog.cpp @@ -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 ScreenshotDialog::selected() +{ + QList list; + QList first = m_list->screenshots(); + for (QModelIndex index : ui->listView->selectionModel()->selectedIndexes()) + { + list.append(first.at(index.row())); + } + return list; +} diff --git a/gui/dialogs/ScreenshotDialog.h b/gui/dialogs/ScreenshotDialog.h new file mode 100644 index 000000000..d3f629e72 --- /dev/null +++ b/gui/dialogs/ScreenshotDialog.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#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 selected(); + +private +slots: + +private: + Ui::ScreenshotDialog *ui; + ScreenshotList *m_list; +}; diff --git a/gui/dialogs/ScreenshotDialog.ui b/gui/dialogs/ScreenshotDialog.ui new file mode 100644 index 000000000..c912dffee --- /dev/null +++ b/gui/dialogs/ScreenshotDialog.ui @@ -0,0 +1,93 @@ + + + ScreenshotDialog + + + + 0 + 0 + 470 + 300 + + + + Dialog + + + + + 10 + 260 + 441 + 31 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 10 + 10 + 439 + 241 + + + + QAbstractItemView::MultiSelection + + + + 480 + 360 + + + + QListView::LeftToRight + + + true + + + QListView::ListMode + + + + + + + buttonBox + accepted() + ScreenshotDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ScreenshotDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/logic/lists/ScreenshotList.cpp b/logic/lists/ScreenshotList.cpp new file mode 100644 index 000000000..ff37a0927 --- /dev/null +++ b/logic/lists/ScreenshotList.cpp @@ -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(); + 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(); +} diff --git a/logic/lists/ScreenshotList.h b/logic/lists/ScreenshotList.h new file mode 100644 index 000000000..4011c1bd5 --- /dev/null +++ b/logic/lists/ScreenshotList.h @@ -0,0 +1,75 @@ +#pragma once + +#include +#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 shots) + { + m_screenshots = shots; + } + + QList screenshots() const + { + return m_screenshots; + } + + BaseInstance *instance() const + { + return m_instance; + } + +signals: + +public +slots: + +private: + QList m_screenshots; + BaseInstance *m_instance; +}; + +class ScreenshotLoadTask : public Task +{ + Q_OBJECT + +public: + explicit ScreenshotLoadTask(ScreenshotList *list); + ~ScreenshotLoadTask(); + + QList screenShots() const + { + return m_results; + } + +protected: + virtual void executeTask(); + +private: + ScreenshotList *m_list; + QList m_results; +}; diff --git a/logic/net/ScreenshotUploader.cpp b/logic/net/ScreenshotUploader.cpp new file mode 100644 index 000000000..03ea1cb46 --- /dev/null +++ b/logic/net/ScreenshotUploader.cpp @@ -0,0 +1,144 @@ +#include "ScreenshotUploader.h" +#include "logic/lists/ScreenshotList.h" +#include +#include +#include +#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(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(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; + } +} diff --git a/logic/net/ScreenshotUploader.h b/logic/net/ScreenshotUploader.h new file mode 100644 index 000000000..09e586777 --- /dev/null +++ b/logic/net/ScreenshotUploader.h @@ -0,0 +1,52 @@ +#pragma once +#include "NetAction.h" + +class ScreenShot; +typedef std::shared_ptr ScreenShotUploadPtr; +typedef std::shared_ptr 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; +}; diff --git a/logic/net/URLConstants.h b/logic/net/URLConstants.h index 8cb1f3fda..3e21d21e9 100644 --- a/logic/net/URLConstants.h +++ b/logic/net/URLConstants.h @@ -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/"); } From 5e33da258c3b5159dba854eb4792d0852a1ca363 Mon Sep 17 00:00:00 2001 From: robotbrain Date: Sun, 23 Feb 2014 19:45:59 -0500 Subject: [PATCH 2/9] Close to finished. Need to fix the upload part. Viewing works (in grayscale) --- gui/MainWindow.cpp | 19 ------ gui/MainWindow.h | 2 - gui/dialogs/ScreenshotDialog.cpp | 2 +- gui/dialogs/ScreenshotDialog.ui | 21 +++++-- logic/lists/ScreenshotList.cpp | 12 ++-- logic/lists/ScreenshotList.h | 4 +- logic/net/ScreenshotUploader.cpp | 101 +++++++++---------------------- logic/net/ScreenshotUploader.h | 23 ------- logic/net/URLConstants.h | 3 +- 9 files changed, 53 insertions(+), 134 deletions(-) diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 5a22f6782..87c656016 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -1538,25 +1538,6 @@ void MainWindow::on_actionScreenshots_triggered() void MainWindow::screenshotsUploaded(QList 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 screenshots) -{ - QStringList urls; for (ScreenShot *shot : screenshots) { diff --git a/gui/MainWindow.h b/gui/MainWindow.h index b57afcf56..0a474ef1d 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -172,8 +172,6 @@ slots: void screenshotsUploaded(QList screenshots); - void screenShotsGotten(QList screenshots); - /*! * Runs the DownloadUpdateTask and installs updates. */ diff --git a/gui/dialogs/ScreenshotDialog.cpp b/gui/dialogs/ScreenshotDialog.cpp index 662c9e840..8900f15b0 100644 --- a/gui/dialogs/ScreenshotDialog.cpp +++ b/gui/dialogs/ScreenshotDialog.cpp @@ -20,7 +20,7 @@ QList ScreenshotDialog::selected() { QList list; QList first = m_list->screenshots(); - for (QModelIndex index : ui->listView->selectionModel()->selectedIndexes()) + for (QModelIndex index : ui->listView->selectionModel()->selectedRows()) { list.append(first.at(index.row())); } diff --git a/gui/dialogs/ScreenshotDialog.ui b/gui/dialogs/ScreenshotDialog.ui index c912dffee..af73e5ec4 100644 --- a/gui/dialogs/ScreenshotDialog.ui +++ b/gui/dialogs/ScreenshotDialog.ui @@ -11,7 +11,11 @@ - Dialog + Screenshots + + + + :/icons/multimc/scalable/apps/multimc.svg:/icons/multimc/scalable/apps/multimc.svg @@ -36,12 +40,15 @@ - QAbstractItemView::MultiSelection + QAbstractItemView::ExtendedSelection + + + QAbstractItemView::SelectItems - 480 - 360 + 120 + 90 @@ -51,11 +58,13 @@ true - QListView::ListMode + QListView::IconMode - + + + buttonBox diff --git a/logic/lists/ScreenshotList.cpp b/logic/lists/ScreenshotList.cpp index ff37a0927..e955f1214 100644 --- a/logic/lists/ScreenshotList.cpp +++ b/logic/lists/ScreenshotList.cpp @@ -1,6 +1,6 @@ #include "ScreenshotList.h" #include "QDir" -#include "QPixmap" +#include "QIcon" ScreenshotList::ScreenshotList(BaseInstance *instance, QObject *parent) : QAbstractListModel(parent), m_instance(instance) @@ -20,11 +20,7 @@ QVariant ScreenshotList::data(const QModelIndex &index, int role) const switch (role) { case Qt::DecorationRole: - { - QPixmap map; - map.loadFromData(m_screenshots.at(index.row())->file); - return map; - } + return QIcon(m_screenshots.at(index.row())->file); case Qt::DisplayRole: return m_screenshots.at(index.row())->timestamp; case Qt::ToolTipRole: @@ -43,7 +39,7 @@ QVariant ScreenshotList::headerData(int section, Qt::Orientation orientation, in Qt::ItemFlags ScreenshotList::flags(const QModelIndex &index) const { - return Qt::NoItemFlags; + return Qt::ItemIsSelectable; } Task *ScreenshotList::load() @@ -73,7 +69,7 @@ void ScreenshotLoadTask::executeTask() { ScreenShot *shot = new ScreenShot(); shot->timestamp = file.left(file.length() - 4); - shot->file = QFile(file).readAll(); + shot->file = dir.absoluteFilePath(file); m_results.append(shot); } m_list->loadShots(m_results); diff --git a/logic/lists/ScreenshotList.h b/logic/lists/ScreenshotList.h index 4011c1bd5..08c968f12 100644 --- a/logic/lists/ScreenshotList.h +++ b/logic/lists/ScreenshotList.h @@ -8,9 +8,9 @@ class ScreenShot { public: QString timestamp; - QByteArray file; - int imgurIndex; + QString file; QString url; + int imgurIndex; }; class ScreenshotList : public QAbstractListModel diff --git a/logic/net/ScreenshotUploader.cpp b/logic/net/ScreenshotUploader.cpp index 03ea1cb46..c1f622438 100644 --- a/logic/net/ScreenshotUploader.cpp +++ b/logic/net/ScreenshotUploader.cpp @@ -1,32 +1,48 @@ #include "ScreenshotUploader.h" #include "logic/lists/ScreenshotList.h" #include -#include +#include #include +#include +#include +#include +#include #include "URLConstants.h" #include "MultiMC.h" +#include "logger/QsLog.h" ScreenShotUpload::ScreenShotUpload(ScreenShot *shot) : m_shot(shot) { + m_url = URLConstants::IMGUR_UPLOAD_URL; m_status = Job_NotStarted; } void ScreenShotUpload::start() { m_status = Job_InProgress; - QNetworkRequest request(URLConstants::IMGUR_UPLOAD_URL); + QNetworkRequest request(m_url); request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3"); + request.setRawHeader("Accept", "application/json"); - 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); + QHttpMultiPart *multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType); + QHttpPart filePart; + filePart.setBody(QFile(m_shot->file).readAll().toBase64()); + filePart.setHeader(QNetworkRequest::ContentTypeHeader, "image/png"); + filePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"image\""); + multipart->append(filePart); + QHttpPart typePart; + typePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"type\""); + typePart.setBody("base64"); + multipart->append(typePart); + QHttpPart namePart; + namePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"name\""); + namePart.setBody(m_shot->timestamp.toUtf8()); + multipart->append(namePart); auto worker = MMC->qnam(); - QNetworkReply *rep = worker->post(request, doc.toJson()); + QNetworkReply *rep = worker->post(request, multipart); m_reply = std::shared_ptr(rep); connect(rep, SIGNAL(downloadProgress(qint64, qint64)), @@ -38,6 +54,7 @@ void ScreenShotUpload::start() } void ScreenShotUpload::downloadError(QNetworkReply::NetworkError error) { + QLOG_DEBUG() << m_reply->errorString(); m_status = Job_Failed; } void ScreenShotUpload::downloadFinished() @@ -50,16 +67,19 @@ void ScreenShotUpload::downloadFinished() QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError); if (jsonError.error != QJsonParseError::NoError) { + QLOG_DEBUG() << jsonError.errorString(); emit failed(m_index_within_job); return; } auto object = doc.object(); if (!object.value("success").toBool()) { + QLOG_DEBUG() << doc.toJson(); emit failed(m_index_within_job); return; } - m_shot->imgurIndex = object.value("data").toVariant().toInt(); + m_shot->imgurIndex = object.value("data").toObject().value("id").toVariant().toInt(); + m_shot->url = "https://imgur.com/gallery/" + QString::number(m_shot->imgurIndex); m_status = Job_Finished; emit succeeded(m_index_within_job); return; @@ -81,64 +101,3 @@ 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(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; - } -} diff --git a/logic/net/ScreenshotUploader.h b/logic/net/ScreenshotUploader.h index 09e586777..d5d1cef32 100644 --- a/logic/net/ScreenshotUploader.h +++ b/logic/net/ScreenshotUploader.h @@ -27,26 +27,3 @@ slots: 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; -}; diff --git a/logic/net/URLConstants.h b/logic/net/URLConstants.h index 3e21d21e9..f2a943bfa 100644 --- a/logic/net/URLConstants.h +++ b/logic/net/URLConstants.h @@ -33,6 +33,5 @@ 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/"); +const QString IMGUR_UPLOAD_URL("https://api.imgur.com/3/upload.json"); } From 226c1bdae5ec615381965b6731f6496dffa3299e Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Mon, 24 Feb 2014 09:34:21 +0100 Subject: [PATCH 3/9] Screenshot fixes, move some code around, fix some stuff --- gui/ConsoleWindow.cpp | 3 +++ gui/ConsoleWindow.h | 1 + gui/ConsoleWindow.ui | 7 ++++++ gui/MainWindow.cpp | 36 +++++++-------------------- gui/MainWindow.h | 2 -- gui/dialogs/ScreenshotDialog.cpp | 42 ++++++++++++++++++++++++++++++-- gui/dialogs/ScreenshotDialog.h | 11 ++++++++- gui/dialogs/ScreenshotDialog.ui | 16 ------------ logic/lists/ScreenshotList.cpp | 6 ++--- logic/net/ScreenshotUploader.cpp | 26 +++++++++++--------- logic/net/ScreenshotUploader.h | 4 ++- 11 files changed, 91 insertions(+), 63 deletions(-) diff --git a/gui/ConsoleWindow.cpp b/gui/ConsoleWindow.cpp index ccc037f2a..d11e8aff9 100644 --- a/gui/ConsoleWindow.cpp +++ b/gui/ConsoleWindow.cpp @@ -42,6 +42,8 @@ ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent) connect(mcproc, SIGNAL(launch_failed(BaseInstance *)), this, SLOT(onLaunchFailed(BaseInstance *))); + connect(ui->btnScreenshots, &QPushButton::clicked, this, &ConsoleWindow::uploadScreenshots); + restoreState( QByteArray::fromBase64(MMC->settings()->get("ConsoleWindowState").toByteArray())); restoreGeometry( @@ -52,6 +54,7 @@ ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent) auto icon = MMC->icons()->getIcon(iconKey); setWindowIcon(icon); m_trayIcon = new QSystemTrayIcon(icon, this); + // TODO add screenshot upload as a menu item in the tray icon QString consoleTitle = tr("Console window for ") + name; m_trayIcon->setToolTip(consoleTitle); setWindowTitle(consoleTitle); diff --git a/gui/ConsoleWindow.h b/gui/ConsoleWindow.h index 7fe90c521..e21da33c2 100644 --- a/gui/ConsoleWindow.h +++ b/gui/ConsoleWindow.h @@ -51,6 +51,7 @@ private: signals: void isClosing(); + void uploadScreenshots(); public slots: diff --git a/gui/ConsoleWindow.ui b/gui/ConsoleWindow.ui index c2307ecc5..e50fb5204 100644 --- a/gui/ConsoleWindow.ui +++ b/gui/ConsoleWindow.ui @@ -49,6 +49,13 @@ + + + + Upload Screenshots + + + diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 87c656016..f79b981a5 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -1235,6 +1235,7 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session) console = new ConsoleWindow(proc); connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded())); + connect(console, &ConsoleWindow::uploadScreenshots, this, &MainWindow::on_actionScreenshots_triggered); proc->setLogin(session); proc->launch(); @@ -1516,34 +1517,15 @@ void MainWindow::on_actionScreenshots_triggered() return; } ScreenshotDialog dialog(list, this); - if (dialog.exec() == QDialog::Accepted) + if (dialog.exec() == ScreenshotDialog::Accepted) { - QList 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] + QStringList urls; + for (ScreenShot *shot : dialog.uploaded()) { - CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"), - tr("Unknown error"), QMessageBox::Warning)->exec(); - }); - connect(job, &NetJob::succeeded, [this, screenshots] - { screenshotsUploaded(screenshots); }); + urls << QString("url + "\">Image %s") + .arg(QString::number(shot->imgurIndex)); + } + CustomMessageBox::selectable(this, tr("Done uploading!"), urls.join("\n"), + QMessageBox::Information)->exec(); } } - -void MainWindow::screenshotsUploaded(QList screenshots) -{ - QStringList urls; - for (ScreenShot *shot : screenshots) - { - urls << QString("url + "\">Image %s") - .arg(QString::number(shot->imgurIndex)); - } - CustomMessageBox::selectable(this, tr("Done uploading!"), urls.join("\n"), - QMessageBox::Information)->exec(); -} diff --git a/gui/MainWindow.h b/gui/MainWindow.h index 0a474ef1d..5911d1759 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -170,8 +170,6 @@ slots: void reloadStatus(); - void screenshotsUploaded(QList screenshots); - /*! * Runs the DownloadUpdateTask and installs updates. */ diff --git a/gui/dialogs/ScreenshotDialog.cpp b/gui/dialogs/ScreenshotDialog.cpp index 8900f15b0..02764fa38 100644 --- a/gui/dialogs/ScreenshotDialog.cpp +++ b/gui/dialogs/ScreenshotDialog.cpp @@ -1,6 +1,13 @@ #include "ScreenshotDialog.h" #include "ui_ScreenshotDialog.h" -#include "QModelIndex" + +#include +#include + +#include "ProgressDialog.h" +#include "CustomMessageBox.h" +#include "logic/net/NetJob.h" +#include "logic/net/ScreenshotUploader.h" ScreenshotDialog::ScreenshotDialog(ScreenshotList *list, QWidget *parent) : QDialog(parent), @@ -16,7 +23,12 @@ ScreenshotDialog::~ScreenshotDialog() delete ui; } -QList ScreenshotDialog::selected() +QList ScreenshotDialog::uploaded() const +{ + return m_uploaded; +} + +QList ScreenshotDialog::selected() const { QList list; QList first = m_list->screenshots(); @@ -26,3 +38,29 @@ QList ScreenshotDialog::selected() } return list; } + +void ScreenshotDialog::on_buttonBox_accepted() +{ + QList screenshots = selected(); + if (screenshots.isEmpty()) + { + done(NothingDone); + return; + } + NetJob *job = new NetJob("Screenshot Upload"); + for (ScreenShot *shot : screenshots) + { + qDebug() << shot->file; + job->addNetAction(ScreenShotUpload::make(shot)); + } + ProgressDialog prog(this); + prog.exec(job); + connect(job, &NetJob::failed, [this] + { + CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"), + tr("Unknown error"), QMessageBox::Warning)->exec(); + reject(); + }); + m_uploaded = screenshots; + connect(job, &NetJob::succeeded, this, &ScreenshotDialog::accept); +} diff --git a/gui/dialogs/ScreenshotDialog.h b/gui/dialogs/ScreenshotDialog.h index d3f629e72..1ca27bdd7 100644 --- a/gui/dialogs/ScreenshotDialog.h +++ b/gui/dialogs/ScreenshotDialog.h @@ -18,12 +18,21 @@ public: explicit ScreenshotDialog(ScreenshotList *list, QWidget *parent = 0); ~ScreenshotDialog(); - QList selected(); + enum + { + NothingDone = 0x42 + }; + + QList uploaded() const; private slots: + void on_buttonBox_accepted(); private: Ui::ScreenshotDialog *ui; ScreenshotList *m_list; + QList m_uploaded; + + QList selected() const; }; diff --git a/gui/dialogs/ScreenshotDialog.ui b/gui/dialogs/ScreenshotDialog.ui index af73e5ec4..7eeab859c 100644 --- a/gui/dialogs/ScreenshotDialog.ui +++ b/gui/dialogs/ScreenshotDialog.ui @@ -66,22 +66,6 @@ - - buttonBox - accepted() - ScreenshotDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - buttonBox rejected() diff --git a/logic/lists/ScreenshotList.cpp b/logic/lists/ScreenshotList.cpp index e955f1214..0565d0a46 100644 --- a/logic/lists/ScreenshotList.cpp +++ b/logic/lists/ScreenshotList.cpp @@ -1,6 +1,6 @@ #include "ScreenshotList.h" -#include "QDir" -#include "QIcon" +#include +#include ScreenshotList::ScreenshotList(BaseInstance *instance, QObject *parent) : QAbstractListModel(parent), m_instance(instance) @@ -39,7 +39,7 @@ QVariant ScreenshotList::headerData(int section, Qt::Orientation orientation, in Qt::ItemFlags ScreenshotList::flags(const QModelIndex &index) const { - return Qt::ItemIsSelectable; + return Qt::ItemIsSelectable | Qt::ItemIsEnabled; } Task *ScreenshotList::load() diff --git a/logic/net/ScreenshotUploader.cpp b/logic/net/ScreenshotUploader.cpp index c1f622438..829a08152 100644 --- a/logic/net/ScreenshotUploader.cpp +++ b/logic/net/ScreenshotUploader.cpp @@ -1,5 +1,5 @@ #include "ScreenshotUploader.h" -#include "logic/lists/ScreenshotList.h" + #include #include #include @@ -7,11 +7,13 @@ #include #include #include + +#include "logic/lists/ScreenshotList.h" #include "URLConstants.h" #include "MultiMC.h" #include "logger/QsLog.h" -ScreenShotUpload::ScreenShotUpload(ScreenShot *shot) : m_shot(shot) +ScreenShotUpload::ScreenShotUpload(ScreenShot *shot) : NetAction(), m_shot(shot) { m_url = URLConstants::IMGUR_UPLOAD_URL; m_status = Job_NotStarted; @@ -26,9 +28,16 @@ void ScreenShotUpload::start() request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3"); request.setRawHeader("Accept", "application/json"); + QFile f(m_shot->file); + if (!f.open(QFile::ReadOnly)) + { + emit failed(m_index_within_job); + return; + } + QHttpMultiPart *multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType); QHttpPart filePart; - filePart.setBody(QFile(m_shot->file).readAll().toBase64()); + filePart.setBody(f.readAll().toBase64()); filePart.setHeader(QNetworkRequest::ContentTypeHeader, "image/png"); filePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"image\""); multipart->append(filePart); @@ -45,12 +54,10 @@ void ScreenShotUpload::start() QNetworkReply *rep = worker->post(request, multipart); m_reply = std::shared_ptr(rep); - connect(rep, SIGNAL(downloadProgress(qint64, qint64)), - SLOT(downloadProgress(qint64, qint64))); - connect(rep, SIGNAL(finished()), SLOT(downloadFinished())); + connect(rep, &QNetworkReply::uploadProgress, this, &ScreenShotUpload::downloadProgress); + connect(rep, &QNetworkReply::finished, this, &ScreenShotUpload::downloadFinished); connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(downloadError(QNetworkReply::NetworkError))); - connect(rep, SIGNAL(readyRead()), SLOT(downloadReadyRead())); } void ScreenShotUpload::downloadError(QNetworkReply::NetworkError error) { @@ -86,6 +93,7 @@ void ScreenShotUpload::downloadFinished() } else { + QLOG_DEBUG() << m_reply->readAll(); m_reply.reset(); emit failed(m_index_within_job); return; @@ -97,7 +105,3 @@ void ScreenShotUpload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) m_progress = bytesReceived; emit progress(m_index_within_job, bytesReceived, bytesTotal); } -void ScreenShotUpload::downloadReadyRead() -{ - // noop -} diff --git a/logic/net/ScreenshotUploader.h b/logic/net/ScreenshotUploader.h index d5d1cef32..c1c9db6f2 100644 --- a/logic/net/ScreenshotUploader.h +++ b/logic/net/ScreenshotUploader.h @@ -18,7 +18,9 @@ slots: virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); virtual void downloadError(QNetworkReply::NetworkError error); virtual void downloadFinished(); - virtual void downloadReadyRead(); + virtual void downloadReadyRead() + { + } public slots: From a8811a27f78698f1ab2acad47e90f3b16274e221 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Mon, 24 Feb 2014 10:34:51 +0100 Subject: [PATCH 4/9] Working screenshot upload --- gui/MainWindow.cpp | 4 +- gui/dialogs/ScreenshotDialog.cpp | 15 ++-- gui/dialogs/ScreenshotDialog.h | 2 +- gui/dialogs/ScreenshotDialog.ui | 114 +++++++++++++++++-------------- logic/lists/ScreenshotList.cpp | 7 +- logic/lists/ScreenshotList.h | 4 +- logic/net/ScreenshotUploader.cpp | 7 +- 7 files changed, 84 insertions(+), 69 deletions(-) diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index f79b981a5..93608a0e8 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -1522,8 +1522,8 @@ void MainWindow::on_actionScreenshots_triggered() QStringList urls; for (ScreenShot *shot : dialog.uploaded()) { - urls << QString("url + "\">Image %s") - .arg(QString::number(shot->imgurIndex)); + urls << QString("url + "\">Image %1") + .arg(shot->timestamp.toString()); } CustomMessageBox::selectable(this, tr("Done uploading!"), urls.join("\n"), QMessageBox::Information)->exec(); diff --git a/gui/dialogs/ScreenshotDialog.cpp b/gui/dialogs/ScreenshotDialog.cpp index 02764fa38..33e931629 100644 --- a/gui/dialogs/ScreenshotDialog.cpp +++ b/gui/dialogs/ScreenshotDialog.cpp @@ -39,7 +39,7 @@ QList ScreenshotDialog::selected() const return list; } -void ScreenshotDialog::on_buttonBox_accepted() +void ScreenshotDialog::on_uploadBtn_clicked() { QList screenshots = selected(); if (screenshots.isEmpty()) @@ -50,17 +50,18 @@ void ScreenshotDialog::on_buttonBox_accepted() NetJob *job = new NetJob("Screenshot Upload"); for (ScreenShot *shot : screenshots) { - qDebug() << shot->file; job->addNetAction(ScreenShotUpload::make(shot)); } + m_uploaded = screenshots; ProgressDialog prog(this); - prog.exec(job); - connect(job, &NetJob::failed, [this] + if (prog.exec(job) == QDialog::Accepted) + { + accept(); + } + else { CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"), tr("Unknown error"), QMessageBox::Warning)->exec(); reject(); - }); - m_uploaded = screenshots; - connect(job, &NetJob::succeeded, this, &ScreenshotDialog::accept); + } } diff --git a/gui/dialogs/ScreenshotDialog.h b/gui/dialogs/ScreenshotDialog.h index 1ca27bdd7..104814f16 100644 --- a/gui/dialogs/ScreenshotDialog.h +++ b/gui/dialogs/ScreenshotDialog.h @@ -27,7 +27,7 @@ public: private slots: - void on_buttonBox_accepted(); + void on_uploadBtn_clicked(); private: Ui::ScreenshotDialog *ui; diff --git a/gui/dialogs/ScreenshotDialog.ui b/gui/dialogs/ScreenshotDialog.ui index 7eeab859c..9e4bd6f02 100644 --- a/gui/dialogs/ScreenshotDialog.ui +++ b/gui/dialogs/ScreenshotDialog.ui @@ -17,68 +17,82 @@ :/icons/multimc/scalable/apps/multimc.svg:/icons/multimc/scalable/apps/multimc.svg - - - - 10 - 260 - 441 - 31 - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - 10 - 10 - 439 - 241 - - - - QAbstractItemView::ExtendedSelection - - - QAbstractItemView::SelectItems - - - - 120 - 90 - - - - QListView::LeftToRight - - - true - - - QListView::IconMode - - + + + + + QAbstractItemView::ExtendedSelection + + + QAbstractItemView::SelectItems + + + + 120 + 90 + + + + QListView::LeftToRight + + + true + + + QListView::IconMode + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Close + + + + + + + Upload + + + + + + - buttonBox - rejected() + closeBtn + clicked() ScreenshotDialog reject() - 316 - 260 + 315 + 272 - 286 - 274 + 271 + 258 diff --git a/logic/lists/ScreenshotList.cpp b/logic/lists/ScreenshotList.cpp index 0565d0a46..6969549c6 100644 --- a/logic/lists/ScreenshotList.cpp +++ b/logic/lists/ScreenshotList.cpp @@ -1,4 +1,5 @@ #include "ScreenshotList.h" + #include #include @@ -22,9 +23,9 @@ QVariant ScreenshotList::data(const QModelIndex &index, int role) const case Qt::DecorationRole: return QIcon(m_screenshots.at(index.row())->file); case Qt::DisplayRole: - return m_screenshots.at(index.row())->timestamp; + return m_screenshots.at(index.row())->timestamp.toString("yyyy-MM-dd HH:mm:ss"); case Qt::ToolTipRole: - return m_screenshots.at(index.row())->timestamp; + return m_screenshots.at(index.row())->timestamp.toString("yyyy-MM-dd HH:mm:ss"); case Qt::TextAlignmentRole: return (int)(Qt::AlignHCenter | Qt::AlignVCenter); default: @@ -68,7 +69,7 @@ void ScreenshotLoadTask::executeTask() for (auto file : dir.entryList()) { ScreenShot *shot = new ScreenShot(); - shot->timestamp = file.left(file.length() - 4); + shot->timestamp = QDateTime::fromString(file, "yyyy-MM-dd_HH.mm.ss.png"); shot->file = dir.absoluteFilePath(file); m_results.append(shot); } diff --git a/logic/lists/ScreenshotList.h b/logic/lists/ScreenshotList.h index 08c968f12..dee74807b 100644 --- a/logic/lists/ScreenshotList.h +++ b/logic/lists/ScreenshotList.h @@ -7,10 +7,10 @@ class ScreenShot { public: - QString timestamp; + QDateTime timestamp; QString file; QString url; - int imgurIndex; + QString imgurIndex; }; class ScreenshotList : public QAbstractListModel diff --git a/logic/net/ScreenshotUploader.cpp b/logic/net/ScreenshotUploader.cpp index 829a08152..490c74b3f 100644 --- a/logic/net/ScreenshotUploader.cpp +++ b/logic/net/ScreenshotUploader.cpp @@ -24,7 +24,6 @@ void ScreenShotUpload::start() m_status = Job_InProgress; QNetworkRequest request(m_url); request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); - request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3"); request.setRawHeader("Accept", "application/json"); @@ -47,7 +46,7 @@ void ScreenShotUpload::start() multipart->append(typePart); QHttpPart namePart; namePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"name\""); - namePart.setBody(m_shot->timestamp.toUtf8()); + namePart.setBody(m_shot->timestamp.toString(Qt::ISODate).toUtf8()); multipart->append(namePart); auto worker = MMC->qnam(); @@ -85,8 +84,8 @@ void ScreenShotUpload::downloadFinished() emit failed(m_index_within_job); return; } - m_shot->imgurIndex = object.value("data").toObject().value("id").toVariant().toInt(); - m_shot->url = "https://imgur.com/gallery/" + QString::number(m_shot->imgurIndex); + m_shot->imgurIndex = object.value("data").toObject().value("id").toString(); + m_shot->url = object.value("data").toObject().value("link").toString(); m_status = Job_Finished; emit succeeded(m_index_within_job); return; From da33fa4090b4510267d06b3fd3ec439ff563b80e Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Mon, 24 Feb 2014 11:30:27 +0100 Subject: [PATCH 5/9] Imgur album creation --- CMakeLists.txt | 6 +- gui/MainWindow.cpp | 9 +- gui/dialogs/CustomMessageBox.cpp | 1 + gui/dialogs/ScreenshotDialog.cpp | 38 ++++---- gui/dialogs/ScreenshotDialog.h | 5 +- logic/lists/ScreenshotList.h | 2 +- logic/net/ImgurAlbumCreation.cpp | 90 +++++++++++++++++++ logic/net/ImgurAlbumCreation.h | 42 +++++++++ ...ScreenshotUploader.cpp => ImgurUpload.cpp} | 20 ++--- .../{ScreenshotUploader.h => ImgurUpload.h} | 11 ++- logic/net/URLConstants.h | 2 +- logic/tasks/SequentialTask.cpp | 15 +++- logic/tasks/SequentialTask.h | 4 +- 13 files changed, 193 insertions(+), 52 deletions(-) create mode 100644 logic/net/ImgurAlbumCreation.cpp create mode 100644 logic/net/ImgurAlbumCreation.h rename logic/net/{ScreenshotUploader.cpp => ImgurUpload.cpp} (80%) rename logic/net/{ScreenshotUploader.h => ImgurUpload.h} (53%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 048a466a6..12a673e3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -372,8 +372,10 @@ logic/net/HttpMetaCache.cpp logic/net/PasteUpload.h logic/net/PasteUpload.cpp logic/net/URLConstants.h -logic/net/ScreenshotUploader.h -logic/net/ScreenshotUploader.cpp +logic/net/ImgurUpload.h +logic/net/ImgurUpload.cpp +logic/net/ImgurAlbumCreation.h +logic/net/ImgurAlbumCreation.cpp # Yggdrasil login stuff logic/auth/AuthSession.h diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 93608a0e8..559c2f48c 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -81,7 +81,6 @@ #include "logic/net/URLConstants.h" #include "logic/net/NetJob.h" -#include "logic/net/ScreenshotUploader.h" #include "logic/BaseInstance.h" #include "logic/InstanceFactory.h" @@ -1519,13 +1518,7 @@ void MainWindow::on_actionScreenshots_triggered() ScreenshotDialog dialog(list, this); if (dialog.exec() == ScreenshotDialog::Accepted) { - QStringList urls; - for (ScreenShot *shot : dialog.uploaded()) - { - urls << QString("url + "\">Image %1") - .arg(shot->timestamp.toString()); - } - CustomMessageBox::selectable(this, tr("Done uploading!"), urls.join("\n"), + CustomMessageBox::selectable(this, tr("Done uploading!"), dialog.message(), QMessageBox::Information)->exec(); } } diff --git a/gui/dialogs/CustomMessageBox.cpp b/gui/dialogs/CustomMessageBox.cpp index 1d2ab58a4..4013db601 100644 --- a/gui/dialogs/CustomMessageBox.cpp +++ b/gui/dialogs/CustomMessageBox.cpp @@ -28,6 +28,7 @@ QMessageBox *selectable(QWidget *parent, const QString &title, const QString &te messageBox->setDefaultButton(defaultButton); messageBox->setTextInteractionFlags(Qt::TextSelectableByMouse); messageBox->setIcon(icon); + messageBox->setTextInteractionFlags(Qt::TextBrowserInteraction); return messageBox; } diff --git a/gui/dialogs/ScreenshotDialog.cpp b/gui/dialogs/ScreenshotDialog.cpp index 33e931629..3b4af5e59 100644 --- a/gui/dialogs/ScreenshotDialog.cpp +++ b/gui/dialogs/ScreenshotDialog.cpp @@ -7,12 +7,12 @@ #include "ProgressDialog.h" #include "CustomMessageBox.h" #include "logic/net/NetJob.h" -#include "logic/net/ScreenshotUploader.h" +#include "logic/net/ImgurUpload.h" +#include "logic/net/ImgurAlbumCreation.h" +#include "logic/tasks/SequentialTask.h" -ScreenshotDialog::ScreenshotDialog(ScreenshotList *list, QWidget *parent) : - QDialog(parent), - ui(new Ui::ScreenshotDialog), - m_list(list) +ScreenshotDialog::ScreenshotDialog(ScreenshotList *list, QWidget *parent) + : QDialog(parent), ui(new Ui::ScreenshotDialog), m_list(list) { ui->setupUi(this); ui->listView->setModel(m_list); @@ -23,15 +23,17 @@ ScreenshotDialog::~ScreenshotDialog() delete ui; } -QList ScreenshotDialog::uploaded() const +QString ScreenshotDialog::message() const { - return m_uploaded; + return tr("Visit album
Delete hash: %2 (save " + "this if you want to be able to edit/delete the album)") + .arg(m_imgurAlbum->id(), m_imgurAlbum->deleteHash()); } -QList ScreenshotDialog::selected() const +QList ScreenshotDialog::selected() const { - QList list; - QList first = m_list->screenshots(); + QList list; + QList first = m_list->screenshots(); for (QModelIndex index : ui->listView->selectionModel()->selectedRows()) { list.append(first.at(index.row())); @@ -41,20 +43,24 @@ QList ScreenshotDialog::selected() const void ScreenshotDialog::on_uploadBtn_clicked() { - QList screenshots = selected(); - if (screenshots.isEmpty()) + m_uploaded = selected(); + if (m_uploaded.isEmpty()) { done(NothingDone); return; } + SequentialTask *task = new SequentialTask(this); NetJob *job = new NetJob("Screenshot Upload"); - for (ScreenShot *shot : screenshots) + for (ScreenShot *shot : m_uploaded) { - job->addNetAction(ScreenShotUpload::make(shot)); + job->addNetAction(ImgurUpload::make(shot)); } - m_uploaded = screenshots; + NetJob *albumTask = new NetJob("Imgur Album Creation"); + albumTask->addNetAction(m_imgurAlbum = ImgurAlbumCreation::make(m_uploaded)); + task->addTask(std::shared_ptr(job)); + task->addTask(std::shared_ptr(albumTask)); ProgressDialog prog(this); - if (prog.exec(job) == QDialog::Accepted) + if (prog.exec(task) == QDialog::Accepted) { accept(); } diff --git a/gui/dialogs/ScreenshotDialog.h b/gui/dialogs/ScreenshotDialog.h index 104814f16..ac1494d6e 100644 --- a/gui/dialogs/ScreenshotDialog.h +++ b/gui/dialogs/ScreenshotDialog.h @@ -3,7 +3,7 @@ #include #include "logic/lists/ScreenshotList.h" -class BaseInstance; +class ImgurAlbumCreation; namespace Ui { @@ -23,7 +23,7 @@ public: NothingDone = 0x42 }; - QList uploaded() const; + QString message() const; private slots: @@ -33,6 +33,7 @@ private: Ui::ScreenshotDialog *ui; ScreenshotList *m_list; QList m_uploaded; + std::shared_ptr m_imgurAlbum; QList selected() const; }; diff --git a/logic/lists/ScreenshotList.h b/logic/lists/ScreenshotList.h index dee74807b..1d3e73ca5 100644 --- a/logic/lists/ScreenshotList.h +++ b/logic/lists/ScreenshotList.h @@ -10,7 +10,7 @@ public: QDateTime timestamp; QString file; QString url; - QString imgurIndex; + QString imgurId; }; class ScreenshotList : public QAbstractListModel diff --git a/logic/net/ImgurAlbumCreation.cpp b/logic/net/ImgurAlbumCreation.cpp new file mode 100644 index 000000000..0d8c4dc13 --- /dev/null +++ b/logic/net/ImgurAlbumCreation.cpp @@ -0,0 +1,90 @@ +#include "ImgurAlbumCreation.h" + +#include +#include +#include +#include + +#include "logic/lists/ScreenshotList.h" +#include "URLConstants.h" +#include "MultiMC.h" +#include "logger/QsLog.h" + +ImgurAlbumCreation::ImgurAlbumCreation(QList screenshots) : NetAction(), m_screenshots(screenshots) +{ + m_url = URLConstants::IMGUR_BASE_URL + "album.json"; + m_status = Job_NotStarted; +} + +void ImgurAlbumCreation::start() +{ + m_status = Job_InProgress; + QNetworkRequest request(m_url); + request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3"); + request.setRawHeader("Accept", "application/json"); + + QStringList ids; + for (auto shot : m_screenshots) + { + ids.append(shot->imgurId); + } + + const QByteArray data = "ids=" + ids.join(',').toUtf8() + "&title=Minecraft%20Screenshots&privacy=hidden"; + + auto worker = MMC->qnam(); + QNetworkReply *rep = worker->post(request, data); + + m_reply = std::shared_ptr(rep); + connect(rep, &QNetworkReply::uploadProgress, this, &ImgurAlbumCreation::downloadProgress); + connect(rep, &QNetworkReply::finished, this, &ImgurAlbumCreation::downloadFinished); + connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), + SLOT(downloadError(QNetworkReply::NetworkError))); +} +void ImgurAlbumCreation::downloadError(QNetworkReply::NetworkError error) +{ + QLOG_DEBUG() << m_reply->errorString(); + m_status = Job_Failed; +} +void ImgurAlbumCreation::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) + { + QLOG_DEBUG() << jsonError.errorString(); + emit failed(m_index_within_job); + return; + } + auto object = doc.object(); + if (!object.value("success").toBool()) + { + QLOG_DEBUG() << doc.toJson(); + emit failed(m_index_within_job); + return; + } + m_deleteHash = object.value("data").toObject().value("deletehash").toString(); + m_id = object.value("data").toObject().value("id").toString(); + m_status = Job_Finished; + emit succeeded(m_index_within_job); + return; + } + else + { + QLOG_DEBUG() << m_reply->readAll(); + m_reply.reset(); + emit failed(m_index_within_job); + return; + } +} +void ImgurAlbumCreation::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) +{ + m_total_progress = bytesTotal; + m_progress = bytesReceived; + emit progress(m_index_within_job, bytesReceived, bytesTotal); +} diff --git a/logic/net/ImgurAlbumCreation.h b/logic/net/ImgurAlbumCreation.h new file mode 100644 index 000000000..7be255dfb --- /dev/null +++ b/logic/net/ImgurAlbumCreation.h @@ -0,0 +1,42 @@ +#pragma once +#include "NetAction.h" + +class ScreenShot; +typedef std::shared_ptr ImgurAlbumCreationPtr; +class ImgurAlbumCreation : public NetAction +{ +public: + explicit ImgurAlbumCreation(QList screenshots); + static ImgurAlbumCreationPtr make(QList screenshots) + { + return ImgurAlbumCreationPtr(new ImgurAlbumCreation(screenshots)); + } + + QString deleteHash() const + { + return m_deleteHash; + } + QString id() const + { + return m_id; + } + +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: + QList m_screenshots; + + QString m_deleteHash; + QString m_id; +}; diff --git a/logic/net/ScreenshotUploader.cpp b/logic/net/ImgurUpload.cpp similarity index 80% rename from logic/net/ScreenshotUploader.cpp rename to logic/net/ImgurUpload.cpp index 490c74b3f..4992ee654 100644 --- a/logic/net/ScreenshotUploader.cpp +++ b/logic/net/ImgurUpload.cpp @@ -1,4 +1,4 @@ -#include "ScreenshotUploader.h" +#include "ImgurUpload.h" #include #include @@ -13,13 +13,13 @@ #include "MultiMC.h" #include "logger/QsLog.h" -ScreenShotUpload::ScreenShotUpload(ScreenShot *shot) : NetAction(), m_shot(shot) +ImgurUpload::ImgurUpload(ScreenShot *shot) : NetAction(), m_shot(shot) { - m_url = URLConstants::IMGUR_UPLOAD_URL; + m_url = URLConstants::IMGUR_BASE_URL + "upload.json"; m_status = Job_NotStarted; } -void ScreenShotUpload::start() +void ImgurUpload::start() { m_status = Job_InProgress; QNetworkRequest request(m_url); @@ -53,17 +53,17 @@ void ScreenShotUpload::start() QNetworkReply *rep = worker->post(request, multipart); m_reply = std::shared_ptr(rep); - connect(rep, &QNetworkReply::uploadProgress, this, &ScreenShotUpload::downloadProgress); - connect(rep, &QNetworkReply::finished, this, &ScreenShotUpload::downloadFinished); + connect(rep, &QNetworkReply::uploadProgress, this, &ImgurUpload::downloadProgress); + connect(rep, &QNetworkReply::finished, this, &ImgurUpload::downloadFinished); connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(downloadError(QNetworkReply::NetworkError))); } -void ScreenShotUpload::downloadError(QNetworkReply::NetworkError error) +void ImgurUpload::downloadError(QNetworkReply::NetworkError error) { QLOG_DEBUG() << m_reply->errorString(); m_status = Job_Failed; } -void ScreenShotUpload::downloadFinished() +void ImgurUpload::downloadFinished() { if (m_status != Job_Failed) { @@ -84,7 +84,7 @@ void ScreenShotUpload::downloadFinished() emit failed(m_index_within_job); return; } - m_shot->imgurIndex = object.value("data").toObject().value("id").toString(); + m_shot->imgurId = object.value("data").toObject().value("id").toString(); m_shot->url = object.value("data").toObject().value("link").toString(); m_status = Job_Finished; emit succeeded(m_index_within_job); @@ -98,7 +98,7 @@ void ScreenShotUpload::downloadFinished() return; } } -void ScreenShotUpload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) +void ImgurUpload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) { m_total_progress = bytesTotal; m_progress = bytesReceived; diff --git a/logic/net/ScreenshotUploader.h b/logic/net/ImgurUpload.h similarity index 53% rename from logic/net/ScreenshotUploader.h rename to logic/net/ImgurUpload.h index c1c9db6f2..e5e795877 100644 --- a/logic/net/ScreenshotUploader.h +++ b/logic/net/ImgurUpload.h @@ -2,15 +2,14 @@ #include "NetAction.h" class ScreenShot; -typedef std::shared_ptr ScreenShotUploadPtr; -typedef std::shared_ptr ScreenShotGetPtr; -class ScreenShotUpload : public NetAction +typedef std::shared_ptr ImgurUploadPtr; +class ImgurUpload : public NetAction { public: - explicit ScreenShotUpload(ScreenShot *shot); - static ScreenShotUploadPtr make(ScreenShot *shot) + explicit ImgurUpload(ScreenShot *shot); + static ImgurUploadPtr make(ScreenShot *shot) { - return ScreenShotUploadPtr(new ScreenShotUpload(shot)); + return ImgurUploadPtr(new ImgurUpload(shot)); } protected diff --git a/logic/net/URLConstants.h b/logic/net/URLConstants.h index f2a943bfa..55c8d527f 100644 --- a/logic/net/URLConstants.h +++ b/logic/net/URLConstants.h @@ -33,5 +33,5 @@ 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/upload.json"); +const QString IMGUR_BASE_URL("https://api.imgur.com/3/"); } diff --git a/logic/tasks/SequentialTask.cpp b/logic/tasks/SequentialTask.cpp index 63025eee8..e0f8fcdd7 100644 --- a/logic/tasks/SequentialTask.cpp +++ b/logic/tasks/SequentialTask.cpp @@ -28,7 +28,7 @@ void SequentialTask::getProgress(qint64 ¤t, qint64 &total) } } -void SequentialTask::addTask(std::shared_ptr task) +void SequentialTask::addTask(std::shared_ptr task) { m_queue.append(task); } @@ -43,7 +43,7 @@ void SequentialTask::startNext() { if (m_currentIndex != -1) { - std::shared_ptr previous = m_queue[m_currentIndex]; + std::shared_ptr previous = m_queue[m_currentIndex]; disconnect(previous.get(), 0, this, 0); } m_currentIndex++; @@ -52,7 +52,7 @@ void SequentialTask::startNext() emitSucceeded(); return; } - std::shared_ptr next = m_queue[m_currentIndex]; + std::shared_ptr next = m_queue[m_currentIndex]; connect(next.get(), SIGNAL(failed(QString)), this, SLOT(subTaskFailed(QString))); connect(next.get(), SIGNAL(status(QString)), this, SLOT(subTaskStatus(QString))); connect(next.get(), SIGNAL(progress(qint64,qint64)), this, SLOT(subTaskProgress())); @@ -73,5 +73,12 @@ void SequentialTask::subTaskProgress() { qint64 current, total; getProgress(current, total); - setProgress(100 * current / total); + if (total == 0) + { + setProgress(0); + } + else + { + setProgress(100 * current / total); + } } diff --git a/logic/tasks/SequentialTask.h b/logic/tasks/SequentialTask.h index 7f0469289..c405dca37 100644 --- a/logic/tasks/SequentialTask.h +++ b/logic/tasks/SequentialTask.h @@ -14,7 +14,7 @@ public: virtual QString getStatus() const; virtual void getProgress(qint64 ¤t, qint64 &total); - void addTask(std::shared_ptr task); + void addTask(std::shared_ptr task); protected: void executeTask(); @@ -27,6 +27,6 @@ slots: void subTaskProgress(); private: - QQueue > m_queue; + QQueue > m_queue; int m_currentIndex; }; From 55e21737dd7d30c1922615c575384b41cc77985f Mon Sep 17 00:00:00 2001 From: robotbrain Date: Mon, 24 Feb 2014 17:40:05 -0500 Subject: [PATCH 6/9] Deleting screenshots. Needs fixing. --- gui/ConsoleWindow.ui | 2 +- gui/MainWindow.ui | 2 +- gui/dialogs/ScreenshotDialog.cpp | 7 ++++++- gui/dialogs/ScreenshotDialog.h | 5 +++-- gui/dialogs/ScreenshotDialog.ui | 9 +++++++- logic/lists/ScreenshotList.cpp | 36 +++++++++++++++++++++++++++++++- logic/lists/ScreenshotList.h | 2 ++ 7 files changed, 56 insertions(+), 7 deletions(-) diff --git a/gui/ConsoleWindow.ui b/gui/ConsoleWindow.ui index e50fb5204..344cf74d8 100644 --- a/gui/ConsoleWindow.ui +++ b/gui/ConsoleWindow.ui @@ -52,7 +52,7 @@ - Upload Screenshots + Manage Screenshots diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui index 67625ac89..2bd8ec226 100644 --- a/gui/MainWindow.ui +++ b/gui/MainWindow.ui @@ -532,7 +532,7 @@ - Upload Screenshots + Manage Screenshots <html><head/><body><p>View and upload screenshots for this instance</p></body></html> diff --git a/gui/dialogs/ScreenshotDialog.cpp b/gui/dialogs/ScreenshotDialog.cpp index 3b4af5e59..c62e1d529 100644 --- a/gui/dialogs/ScreenshotDialog.cpp +++ b/gui/dialogs/ScreenshotDialog.cpp @@ -2,7 +2,7 @@ #include "ui_ScreenshotDialog.h" #include -#include +#include #include "ProgressDialog.h" #include "CustomMessageBox.h" @@ -71,3 +71,8 @@ void ScreenshotDialog::on_uploadBtn_clicked() reject(); } } + +void ScreenshotDialog::on_deleteBtn_clicked() +{ + m_list->deleteSelected(this); +} diff --git a/gui/dialogs/ScreenshotDialog.h b/gui/dialogs/ScreenshotDialog.h index ac1494d6e..a406d1fe2 100644 --- a/gui/dialogs/ScreenshotDialog.h +++ b/gui/dialogs/ScreenshotDialog.h @@ -24,16 +24,17 @@ public: }; QString message() const; + QList selected() const; private slots: void on_uploadBtn_clicked(); + void on_deleteBtn_clicked(); + private: Ui::ScreenshotDialog *ui; ScreenshotList *m_list; QList m_uploaded; std::shared_ptr m_imgurAlbum; - - QList selected() const; }; diff --git a/gui/dialogs/ScreenshotDialog.ui b/gui/dialogs/ScreenshotDialog.ui index 9e4bd6f02..4e42a5489 100644 --- a/gui/dialogs/ScreenshotDialog.ui +++ b/gui/dialogs/ScreenshotDialog.ui @@ -11,7 +11,7 @@ - Screenshots + Screenshot Manager @@ -72,6 +72,13 @@ + + + + Delete + + + diff --git a/logic/lists/ScreenshotList.cpp b/logic/lists/ScreenshotList.cpp index 6969549c6..9f4ce6b50 100644 --- a/logic/lists/ScreenshotList.cpp +++ b/logic/lists/ScreenshotList.cpp @@ -1,7 +1,11 @@ #include "ScreenshotList.h" +#include "gui/dialogs/ScreenshotDialog.h" #include #include +#include +#include "gui/dialogs/ProgressDialog.h" +#include "gui/dialogs/CustomMessageBox.h" ScreenshotList::ScreenshotList(BaseInstance *instance, QObject *parent) : QAbstractListModel(parent), m_instance(instance) @@ -15,7 +19,7 @@ int ScreenshotList::rowCount(const QModelIndex &) const QVariant ScreenshotList::data(const QModelIndex &index, int role) const { - if (!index.isValid()) + if (index.row() >= m_screenshots.size() || index.row() < 0) return QVariant(); switch (role) @@ -76,3 +80,33 @@ void ScreenshotLoadTask::executeTask() m_list->loadShots(m_results); emitSucceeded(); } +void ScreenshotList::deleteSelected(ScreenshotDialog *dialog) +{ + auto screens = dialog->selected(); + if (screens.isEmpty()) + { + return; + } + beginResetModel(); + QList::const_iterator it; + for (it = screens.cbegin(); it != screens.cend(); it++) + { + ScreenShot *shot = *it; + if (!QFile(shot->file).remove()) + { + CustomMessageBox::selectable(dialog, tr("Error!"), + tr("Failed to delete screenshots!"), + QMessageBox::Warning)->exec(); + break; + } + } + ProgressDialog refresh(dialog); + Task *t = load(); + if (refresh.exec(t) != QDialog::Accepted) + { + CustomMessageBox::selectable(dialog, tr("Error!"), + tr("Unable to refresh list: %1").arg(t->failReason()), + QMessageBox::Warning)->exec(); + } + endResetModel(); +} diff --git a/logic/lists/ScreenshotList.h b/logic/lists/ScreenshotList.h index 1d3e73ca5..8e512ace1 100644 --- a/logic/lists/ScreenshotList.h +++ b/logic/lists/ScreenshotList.h @@ -43,6 +43,8 @@ public: return m_instance; } + void deleteSelected(class ScreenshotDialog *dialog); + signals: public From b1cddb4600db2aa54c9d274466b393fc1e03eba9 Mon Sep 17 00:00:00 2001 From: robotbrain Date: Mon, 24 Feb 2014 17:49:18 -0500 Subject: [PATCH 7/9] Fix memory leak in system --- gui/dialogs/ScreenshotDialog.cpp | 6 +++--- gui/dialogs/ScreenshotDialog.h | 4 ++-- logic/lists/ScreenshotList.cpp | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gui/dialogs/ScreenshotDialog.cpp b/gui/dialogs/ScreenshotDialog.cpp index c62e1d529..76f872835 100644 --- a/gui/dialogs/ScreenshotDialog.cpp +++ b/gui/dialogs/ScreenshotDialog.cpp @@ -32,8 +32,8 @@ QString ScreenshotDialog::message() const QList ScreenshotDialog::selected() const { - QList list; - QList first = m_list->screenshots(); + QList> list; + QList> first = m_list->screenshots(); for (QModelIndex index : ui->listView->selectionModel()->selectedRows()) { list.append(first.at(index.row())); @@ -51,7 +51,7 @@ void ScreenshotDialog::on_uploadBtn_clicked() } SequentialTask *task = new SequentialTask(this); NetJob *job = new NetJob("Screenshot Upload"); - for (ScreenShot *shot : m_uploaded) + for (std::shared_ptr shot : m_uploaded) { job->addNetAction(ImgurUpload::make(shot)); } diff --git a/gui/dialogs/ScreenshotDialog.h b/gui/dialogs/ScreenshotDialog.h index a406d1fe2..ac95b4f05 100644 --- a/gui/dialogs/ScreenshotDialog.h +++ b/gui/dialogs/ScreenshotDialog.h @@ -24,7 +24,7 @@ public: }; QString message() const; - QList selected() const; + QList> selected() const; private slots: @@ -35,6 +35,6 @@ slots: private: Ui::ScreenshotDialog *ui; ScreenshotList *m_list; - QList m_uploaded; + QList> m_uploaded; std::shared_ptr m_imgurAlbum; }; diff --git a/logic/lists/ScreenshotList.cpp b/logic/lists/ScreenshotList.cpp index 9f4ce6b50..eda57a037 100644 --- a/logic/lists/ScreenshotList.cpp +++ b/logic/lists/ScreenshotList.cpp @@ -88,10 +88,10 @@ void ScreenshotList::deleteSelected(ScreenshotDialog *dialog) return; } beginResetModel(); - QList::const_iterator it; + QList>::const_iterator it; for (it = screens.cbegin(); it != screens.cend(); it++) { - ScreenShot *shot = *it; + std::shared_ptr = *it; if (!QFile(shot->file).remove()) { CustomMessageBox::selectable(dialog, tr("Error!"), From cb5cfe724208beb7d506868fc4e50d9f13e28a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 25 Feb 2014 00:51:24 +0100 Subject: [PATCH 8/9] Reorganize all the screenshot files --- CMakeLists.txt | 15 +++++++++------ gui/dialogs/ScreenshotDialog.cpp | 16 ++++++++-------- gui/dialogs/ScreenshotDialog.h | 6 +++--- .../ImgurAlbumCreation.cpp | 6 +++--- .../{net => screenshots}/ImgurAlbumCreation.h | 10 +++++----- logic/{net => screenshots}/ImgurUpload.cpp | 6 +++--- logic/{net => screenshots}/ImgurUpload.h | 10 +++++----- logic/screenshots/Screenshot.h | 15 +++++++++++++++ .../{lists => screenshots}/ScreenshotList.cpp | 6 +++--- logic/{lists => screenshots}/ScreenshotList.h | 19 ++++++------------- 10 files changed, 60 insertions(+), 49 deletions(-) rename logic/{net => screenshots}/ImgurAlbumCreation.cpp (92%) rename logic/{net => screenshots}/ImgurAlbumCreation.h (73%) rename logic/{net => screenshots}/ImgurUpload.cpp (95%) rename logic/{net => screenshots}/ImgurUpload.h (72%) create mode 100644 logic/screenshots/Screenshot.h rename logic/{lists => screenshots}/ScreenshotList.cpp (96%) rename logic/{lists => screenshots}/ScreenshotList.h (77%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 12a673e3f..da7b0e0bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -372,10 +372,6 @@ logic/net/HttpMetaCache.cpp logic/net/PasteUpload.h logic/net/PasteUpload.cpp logic/net/URLConstants.h -logic/net/ImgurUpload.h -logic/net/ImgurUpload.cpp -logic/net/ImgurAlbumCreation.h -logic/net/ImgurAlbumCreation.cpp # Yggdrasil login stuff logic/auth/AuthSession.h @@ -466,8 +462,15 @@ logic/lists/ForgeVersionList.h logic/lists/ForgeVersionList.cpp logic/lists/JavaVersionList.h logic/lists/JavaVersionList.cpp -logic/lists/ScreenshotList.h -logic/lists/ScreenshotList.cpp + +# the screenshots feature +logic/screenshots/Screenshot.h +logic/screenshots/ScreenshotList.h +logic/screenshots/ScreenshotList.cpp +logic/screenshots/ImgurUpload.h +logic/screenshots/ImgurUpload.cpp +logic/screenshots/ImgurAlbumCreation.h +logic/screenshots/ImgurAlbumCreation.cpp # Icons logic/icons/MMCIcon.h diff --git a/gui/dialogs/ScreenshotDialog.cpp b/gui/dialogs/ScreenshotDialog.cpp index 76f872835..a88c8dfd4 100644 --- a/gui/dialogs/ScreenshotDialog.cpp +++ b/gui/dialogs/ScreenshotDialog.cpp @@ -7,8 +7,8 @@ #include "ProgressDialog.h" #include "CustomMessageBox.h" #include "logic/net/NetJob.h" -#include "logic/net/ImgurUpload.h" -#include "logic/net/ImgurAlbumCreation.h" +#include "logic/screenshots/ImgurUpload.h" +#include "logic/screenshots/ImgurAlbumCreation.h" #include "logic/tasks/SequentialTask.h" ScreenshotDialog::ScreenshotDialog(ScreenshotList *list, QWidget *parent) @@ -30,10 +30,10 @@ QString ScreenshotDialog::message() const .arg(m_imgurAlbum->id(), m_imgurAlbum->deleteHash()); } -QList ScreenshotDialog::selected() const +QList ScreenshotDialog::selected() const { - QList> list; - QList> first = m_list->screenshots(); + QList list; + QList first = m_list->screenshots(); for (QModelIndex index : ui->listView->selectionModel()->selectedRows()) { list.append(first.at(index.row())); @@ -51,14 +51,14 @@ void ScreenshotDialog::on_uploadBtn_clicked() } SequentialTask *task = new SequentialTask(this); NetJob *job = new NetJob("Screenshot Upload"); - for (std::shared_ptr shot : m_uploaded) + for (auto shot : m_uploaded) { job->addNetAction(ImgurUpload::make(shot)); } NetJob *albumTask = new NetJob("Imgur Album Creation"); albumTask->addNetAction(m_imgurAlbum = ImgurAlbumCreation::make(m_uploaded)); - task->addTask(std::shared_ptr(job)); - task->addTask(std::shared_ptr(albumTask)); + task->addTask(NetJobPtr(job)); + task->addTask(NetJobPtr(albumTask)); ProgressDialog prog(this); if (prog.exec(task) == QDialog::Accepted) { diff --git a/gui/dialogs/ScreenshotDialog.h b/gui/dialogs/ScreenshotDialog.h index ac95b4f05..29dd67655 100644 --- a/gui/dialogs/ScreenshotDialog.h +++ b/gui/dialogs/ScreenshotDialog.h @@ -1,7 +1,7 @@ #pragma once #include -#include "logic/lists/ScreenshotList.h" +#include "logic/screenshots/ScreenshotList.h" class ImgurAlbumCreation; @@ -24,7 +24,7 @@ public: }; QString message() const; - QList> selected() const; + QList selected() const; private slots: @@ -35,6 +35,6 @@ slots: private: Ui::ScreenshotDialog *ui; ScreenshotList *m_list; - QList> m_uploaded; + QList m_uploaded; std::shared_ptr m_imgurAlbum; }; diff --git a/logic/net/ImgurAlbumCreation.cpp b/logic/screenshots/ImgurAlbumCreation.cpp similarity index 92% rename from logic/net/ImgurAlbumCreation.cpp rename to logic/screenshots/ImgurAlbumCreation.cpp index 0d8c4dc13..e473952e0 100644 --- a/logic/net/ImgurAlbumCreation.cpp +++ b/logic/screenshots/ImgurAlbumCreation.cpp @@ -5,12 +5,12 @@ #include #include -#include "logic/lists/ScreenshotList.h" -#include "URLConstants.h" +#include "logic/screenshots//ScreenshotList.h" +#include "logic/net/URLConstants.h" #include "MultiMC.h" #include "logger/QsLog.h" -ImgurAlbumCreation::ImgurAlbumCreation(QList screenshots) : NetAction(), m_screenshots(screenshots) +ImgurAlbumCreation::ImgurAlbumCreation(QList screenshots) : NetAction(), m_screenshots(screenshots) { m_url = URLConstants::IMGUR_BASE_URL + "album.json"; m_status = Job_NotStarted; diff --git a/logic/net/ImgurAlbumCreation.h b/logic/screenshots/ImgurAlbumCreation.h similarity index 73% rename from logic/net/ImgurAlbumCreation.h rename to logic/screenshots/ImgurAlbumCreation.h index 7be255dfb..6e8fbe94c 100644 --- a/logic/net/ImgurAlbumCreation.h +++ b/logic/screenshots/ImgurAlbumCreation.h @@ -1,13 +1,13 @@ #pragma once -#include "NetAction.h" +#include "logic/net/NetAction.h" +#include "Screenshot.h" -class ScreenShot; typedef std::shared_ptr ImgurAlbumCreationPtr; class ImgurAlbumCreation : public NetAction { public: - explicit ImgurAlbumCreation(QList screenshots); - static ImgurAlbumCreationPtr make(QList screenshots) + explicit ImgurAlbumCreation(QList screenshots); + static ImgurAlbumCreationPtr make(QList screenshots) { return ImgurAlbumCreationPtr(new ImgurAlbumCreation(screenshots)); } @@ -35,7 +35,7 @@ slots: virtual void start(); private: - QList m_screenshots; + QList m_screenshots; QString m_deleteHash; QString m_id; diff --git a/logic/net/ImgurUpload.cpp b/logic/screenshots/ImgurUpload.cpp similarity index 95% rename from logic/net/ImgurUpload.cpp rename to logic/screenshots/ImgurUpload.cpp index 4992ee654..62033ef58 100644 --- a/logic/net/ImgurUpload.cpp +++ b/logic/screenshots/ImgurUpload.cpp @@ -8,12 +8,12 @@ #include #include -#include "logic/lists/ScreenshotList.h" -#include "URLConstants.h" +#include "logic/screenshots/ScreenshotList.h" +#include "logic/net/URLConstants.h" #include "MultiMC.h" #include "logger/QsLog.h" -ImgurUpload::ImgurUpload(ScreenShot *shot) : NetAction(), m_shot(shot) +ImgurUpload::ImgurUpload(ScreenshotPtr shot) : NetAction(), m_shot(shot) { m_url = URLConstants::IMGUR_BASE_URL + "upload.json"; m_status = Job_NotStarted; diff --git a/logic/net/ImgurUpload.h b/logic/screenshots/ImgurUpload.h similarity index 72% rename from logic/net/ImgurUpload.h rename to logic/screenshots/ImgurUpload.h index e5e795877..1111a8d03 100644 --- a/logic/net/ImgurUpload.h +++ b/logic/screenshots/ImgurUpload.h @@ -1,13 +1,13 @@ #pragma once -#include "NetAction.h" +#include "logic/net/NetAction.h" +#include "Screenshot.h" -class ScreenShot; typedef std::shared_ptr ImgurUploadPtr; class ImgurUpload : public NetAction { public: - explicit ImgurUpload(ScreenShot *shot); - static ImgurUploadPtr make(ScreenShot *shot) + explicit ImgurUpload(ScreenshotPtr shot); + static ImgurUploadPtr make(ScreenshotPtr shot) { return ImgurUploadPtr(new ImgurUpload(shot)); } @@ -26,5 +26,5 @@ slots: virtual void start(); private: - ScreenShot *m_shot; + ScreenshotPtr m_shot; }; diff --git a/logic/screenshots/Screenshot.h b/logic/screenshots/Screenshot.h new file mode 100644 index 000000000..194e70e5d --- /dev/null +++ b/logic/screenshots/Screenshot.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include +#include + +struct ScreenShot +{ + QDateTime timestamp; + QString file; + QString url; + QString imgurId; +}; + +typedef std::shared_ptr ScreenshotPtr; diff --git a/logic/lists/ScreenshotList.cpp b/logic/screenshots/ScreenshotList.cpp similarity index 96% rename from logic/lists/ScreenshotList.cpp rename to logic/screenshots/ScreenshotList.cpp index eda57a037..def1bdf7a 100644 --- a/logic/lists/ScreenshotList.cpp +++ b/logic/screenshots/ScreenshotList.cpp @@ -69,13 +69,13 @@ void ScreenshotLoadTask::executeTask() return; } dir.setNameFilters(QStringList() << "*.png"); - this->m_results = QList(); + this->m_results.clear(); for (auto file : dir.entryList()) { ScreenShot *shot = new ScreenShot(); shot->timestamp = QDateTime::fromString(file, "yyyy-MM-dd_HH.mm.ss.png"); shot->file = dir.absoluteFilePath(file); - m_results.append(shot); + m_results.append(ScreenshotPtr(shot)); } m_list->loadShots(m_results); emitSucceeded(); @@ -91,7 +91,7 @@ void ScreenshotList::deleteSelected(ScreenshotDialog *dialog) QList>::const_iterator it; for (it = screens.cbegin(); it != screens.cend(); it++) { - std::shared_ptr = *it; + auto shot = *it; if (!QFile(shot->file).remove()) { CustomMessageBox::selectable(dialog, tr("Error!"), diff --git a/logic/lists/ScreenshotList.h b/logic/screenshots/ScreenshotList.h similarity index 77% rename from logic/lists/ScreenshotList.h rename to logic/screenshots/ScreenshotList.h index 8e512ace1..ca6314e96 100644 --- a/logic/lists/ScreenshotList.h +++ b/logic/screenshots/ScreenshotList.h @@ -4,14 +4,7 @@ #include "logic/BaseInstance.h" #include "logic/tasks/Task.h" -class ScreenShot -{ -public: - QDateTime timestamp; - QString file; - QString url; - QString imgurId; -}; +#include "Screenshot.h" class ScreenshotList : public QAbstractListModel { @@ -28,12 +21,12 @@ public: Task *load(); - void loadShots(QList shots) + void loadShots(QList shots) { m_screenshots = shots; } - QList screenshots() const + QList screenshots() const { return m_screenshots; } @@ -51,7 +44,7 @@ public slots: private: - QList m_screenshots; + QList m_screenshots; BaseInstance *m_instance; }; @@ -63,7 +56,7 @@ public: explicit ScreenshotLoadTask(ScreenshotList *list); ~ScreenshotLoadTask(); - QList screenShots() const + QList screenShots() const { return m_results; } @@ -73,5 +66,5 @@ protected: private: ScreenshotList *m_list; - QList m_results; + QList m_results; }; From 9d4e840a6e1a7169a2863fa1ff1812f8fe19e615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 25 Feb 2014 01:21:46 +0100 Subject: [PATCH 9/9] Screenshots: Optimize image loading and memory use, fix list and button layout. --- CMakeLists.txt | 1 + gui/dialogs/ScreenshotDialog.ui | 31 +++++++++++++++------------- logic/screenshots/Screenshot.cpp | 14 +++++++++++++ logic/screenshots/Screenshot.h | 4 ++++ logic/screenshots/ScreenshotList.cpp | 3 ++- 5 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 logic/screenshots/Screenshot.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index da7b0e0bd..ee836cd26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -465,6 +465,7 @@ logic/lists/JavaVersionList.cpp # the screenshots feature logic/screenshots/Screenshot.h +logic/screenshots/Screenshot.cpp logic/screenshots/ScreenshotList.h logic/screenshots/ScreenshotList.cpp logic/screenshots/ImgurUpload.h diff --git a/gui/dialogs/ScreenshotDialog.ui b/gui/dialogs/ScreenshotDialog.ui index 4e42a5489..eb3dafba5 100644 --- a/gui/dialogs/ScreenshotDialog.ui +++ b/gui/dialogs/ScreenshotDialog.ui @@ -38,6 +38,9 @@ true + + QListView::Adjust + QListView::IconMode @@ -45,6 +48,20 @@ + + + + Upload + + + + + + + Delete + + + @@ -65,20 +82,6 @@ - - - - Upload - - - - - - - Delete - - - diff --git a/logic/screenshots/Screenshot.cpp b/logic/screenshots/Screenshot.cpp new file mode 100644 index 000000000..882e491ff --- /dev/null +++ b/logic/screenshots/Screenshot.cpp @@ -0,0 +1,14 @@ +#include "Screenshot.h" +#include +#include +QIcon ScreenShot::getImage() +{ + if(!imageloaded) + { + QImage image(file); + QImage thumbnail = image.scaledToWidth(256, Qt::SmoothTransformation); + m_image = QIcon(QPixmap::fromImage(thumbnail)); + imageloaded = true; + } + return m_image; +} diff --git a/logic/screenshots/Screenshot.h b/logic/screenshots/Screenshot.h index 194e70e5d..815c0d47b 100644 --- a/logic/screenshots/Screenshot.h +++ b/logic/screenshots/Screenshot.h @@ -3,9 +3,13 @@ #include #include #include +#include struct ScreenShot { + QIcon getImage(); + QIcon m_image; + bool imageloaded = false; QDateTime timestamp; QString file; QString url; diff --git a/logic/screenshots/ScreenshotList.cpp b/logic/screenshots/ScreenshotList.cpp index def1bdf7a..8a64dc36d 100644 --- a/logic/screenshots/ScreenshotList.cpp +++ b/logic/screenshots/ScreenshotList.cpp @@ -25,7 +25,7 @@ QVariant ScreenshotList::data(const QModelIndex &index, int role) const switch (role) { case Qt::DecorationRole: - return QIcon(m_screenshots.at(index.row())->file); + return m_screenshots.at(index.row())->getImage(); case Qt::DisplayRole: return m_screenshots.at(index.row())->timestamp.toString("yyyy-MM-dd HH:mm:ss"); case Qt::ToolTipRole: @@ -80,6 +80,7 @@ void ScreenshotLoadTask::executeTask() m_list->loadShots(m_results); emitSucceeded(); } + void ScreenshotList::deleteSelected(ScreenshotDialog *dialog) { auto screens = dialog->selected();