Merge pull request #126 from ctrlaltca/cmake_qt5

Qt5 support
This commit is contained in:
Gavin Bisesi 2014-07-10 13:13:51 -04:00
commit f83d58309b
44 changed files with 703 additions and 159 deletions

View file

@ -7,13 +7,21 @@
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 2.6)
set(PROJECT_NAME "Cockatrice") if(POLICY CMP0020)
set(PROJECT_VERSION_MAJOR 0) cmake_policy(SET CMP0020 OLD)
set(PROJECT_VERSION_MINOR 0) endif()
set(PROJECT_VERSION_PATCH 1)
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} )
# Defualt to "Release" build type if(POLICY CMP0043)
cmake_policy(SET CMP0043 OLD)
endif()
if(POLICY CMP0048)
cmake_policy(SET CMP0048 OLD)
endif()
set(PROJECT_NAME "Cockatrice")
# Default to "Release" build type
# User-provided value for CMAKE_BUILD_TYPE must be checked before the PROJECT() call # User-provided value for CMAKE_BUILD_TYPE must be checked before the PROJECT() call
IF(DEFINED CMAKE_BUILD_TYPE) IF(DEFINED CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Type of build") SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Type of build")
@ -24,9 +32,19 @@ ENDIF()
# A project name is needed for CPack # A project name is needed for CPack
PROJECT("${PROJECT_NAME}") PROJECT("${PROJECT_NAME}")
# Set conventional loops # Set conventional loops
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
# Search path for cmake modules
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
# Retrieve git version hash
include(getversion)
# Create a header and a cpp file containing the version hash
include(createversionfile)
# Define a proper install path # Define a proper install path
if(UNIX) if(UNIX)
if(APPLE) if(APPLE)
@ -71,8 +89,33 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
ADD_DEFINITIONS("-DSFMT_MEXP=19937") ADD_DEFINITIONS("-DSFMT_MEXP=19937")
ENDIF() ENDIF()
#Find Qt4 and enable the needed features # Find Qt and enable the needed features
FIND_PACKAGE(Qt4 REQUIRED) # Default is Qt5 unless WITH_QT4 option is enabled
option(WITH_QT4 "Force thr use of Qt4 libraries" OFF)
IF(NOT WITH_QT4)
FIND_PACKAGE(Qt5Widgets)
ENDIF()
IF(Qt5Widgets_FOUND)
MESSAGE(STATUS "Found Qt ${Qt5Widgets_VERSION_STRING}")
if(UNIX AND NOT APPLE AND "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
# FIX: Qt was built with -reduce-relocations
add_definitions(-fPIC)
endif()
ELSE()
FIND_PACKAGE(Qt4 4.8.0 REQUIRED)
IF(QT4_FOUND)
# Old FindQt4.cmake modules used the same flag with different case
SET(Qt4_FOUND TRUE)
ENDIF()
IF(Qt4_FOUND)
MESSAGE(STATUS "Found Qt ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}")
ELSE()
MESSAGE(FATAL_ERROR "No Qt4 or Qt5 found!")
ENDIF()
ENDIF()
set(CMAKE_AUTOMOC TRUE) set(CMAKE_AUTOMOC TRUE)
@ -83,8 +126,8 @@ FIND_PACKAGE(Protobuf REQUIRED)
set(CPACK_PACKAGE_CONTACT "Daenyth+github@gmail.com") set(CPACK_PACKAGE_CONTACT "Daenyth+github@gmail.com")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_NAME}) set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_NAME})
set(CPACK_PACKAGE_VENDOR "Cockatrice Development Team") set(CPACK_PACKAGE_VENDOR "Cockatrice Development Team")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md") set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING") set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING")
set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}") set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}") set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
@ -96,7 +139,7 @@ if(UNIX)
set(CPACK_DMG_FORMAT "UDBZ") set(CPACK_DMG_FORMAT "UDBZ")
set(CPACK_DMG_VOLUME_NAME "${PROJECT_NAME}") set(CPACK_DMG_VOLUME_NAME "${PROJECT_NAME}")
set(CPACK_SYSTEM_NAME "OSX") set(CPACK_SYSTEM_NAME "OSX")
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}") set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-osx_git-${PROJECT_VERSION}")
set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/cockatrice/resources/appicon.icns") set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/cockatrice/resources/appicon.icns")
else() else()
# linux # linux
@ -107,13 +150,13 @@ if(UNIX)
endif() endif()
elseif(WIN32) elseif(WIN32)
set(CPACK_GENERATOR NSIS ${CPACK_GENERATOR}) set(CPACK_GENERATOR NSIS ${CPACK_GENERATOR})
set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}\\\\${PROJECT_VERSION}") set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}_win32_git-${PROJECT_VERSION}")
set(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\${PROJECT_NAME}.exe")
set(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${PROJECT_NAME}") # Configure file with custom definitions for NSIS.
set(CPACK_NSIS_HELP_LINK "https://github.com/Daenyth/Cockatrice") configure_file(
set(CPACK_NSIS_URL_INFO_ABOUT "https://github.com/Daenyth/Cockatrice") ${CMAKE_MODULE_PATH}/NSIS.definitions.nsh.in
set(CPACK_NSIS_CONTACT "Daenyth+github@gmail.com") ${PROJECT_BINARY_DIR}/NSIS.definitions.nsh
set(CPACK_NSIS_MODIFY_PATH ON) )
endif() endif()
include(CPack) include(CPack)

View file

@ -0,0 +1,3 @@
!define NSIS_PROJECT_NAME "@PROJECT_NAME@"
!define NSIS_SOURCE_PATH "@PROJECT_SOURCE_DIR@"
!define NSIS_BINARY_PATH "@PROJECT_BINARY_DIR@"

View file

@ -1,30 +1,25 @@
!include ..\..\..\NSIS.definitions.nsh
!include "MUI2.nsh" !include "MUI2.nsh"
!include "FileFunc.nsh" !include "FileFunc.nsh"
!define /date TIMESTAMP "%Y%m%d" Name "${NSIS_PROJECT_NAME}"
!searchparse /file ../build/cockatrice/version_string.cpp '= "' VERSION '";' OutFile "@CPACK_TOPLEVEL_DIRECTORY@/@CPACK_OUTPUT_FILE_NAME@"
Name "Cockatrice"
OutFile "cockatrice_win32_${TIMESTAMP}_git-${VERSION}.exe"
SetCompressor /SOLID lzma SetCompressor /SOLID lzma
InstallDir "$PROGRAMFILES\Cockatrice" InstallDir "$PROGRAMFILES\Cockatrice"
; set the Qt install dir here (and make sure you use the latest 4.8 version for packaging)
!define QTDIR "C:\Qt\4.8.6"
!define MUI_ABORTWARNING !define MUI_ABORTWARNING
!define MUI_WELCOMEFINISHPAGE_BITMAP "leftimage.bmp" !define MUI_WELCOMEFINISHPAGE_BITMAP "${NSIS_SOURCE_PATH}\cmake\leftimage.bmp"
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "leftimage.bmp" !define MUI_UNWELCOMEFINISHPAGE_BITMAP "${NSIS_SOURCE_PATH}\cmake\leftimage.bmp"
!define MUI_HEADERIMAGE !define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "headerimage.bmp" !define MUI_HEADERIMAGE_BITMAP "${NSIS_SOURCE_PATH}\cmake\headerimage.bmp"
!define MUI_HEADERIMAGE_UNBITMAP "headerimage.bmp" !define MUI_HEADERIMAGE_UNBITMAP "${NSIS_SOURCE_PATH}\cmake\headerimage.bmp"
!define MUI_WELCOMEPAGE_TEXT "This wizard will guide you through the installation of Cockatrice.$\r$\n$\r$\nClick Next to continue." !define MUI_WELCOMEPAGE_TEXT "This wizard will guide you through the installation of Cockatrice.$\r$\n$\r$\nClick Next to continue."
!define MUI_FINISHPAGE_RUN "$INSTDIR/oracle.exe" !define MUI_FINISHPAGE_RUN "$INSTDIR/oracle.exe"
!define MUI_FINISHPAGE_RUN_TEXT "Run card database downloader now" !define MUI_FINISHPAGE_RUN_TEXT "Run card database downloader now"
!define MUI_FINISHPAGE_RUN_PARAMETERS "-dlsets" !define MUI_FINISHPAGE_RUN_PARAMETERS "-dlsets"
!insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "..\COPYING" !insertmacro MUI_PAGE_LICENSE "${NSIS_SOURCE_PATH}\COPYING"
!insertmacro MUI_PAGE_COMPONENTS !insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_INSTFILES
@ -39,37 +34,8 @@ InstallDir "$PROGRAMFILES\Cockatrice"
Section "Application" SecApplication Section "Application" SecApplication
SetShellVarContext all SetShellVarContext all
SetOutPath "$INSTDIR" SetOutPath "$INSTDIR"
File ..\build\cockatrice\Release\cockatrice.exe
File ..\build\oracle\Release\oracle.exe
File ..\doc\usermanual\Usermanual.pdf
File ..\build\protobuf-2.5.0\protobuf-2.5.0\vsprojects\Release\libprotobuf.lib
File "${QTDIR}\bin\QtCore4.dll"
File "${QTDIR}\bin\QtGui4.dll"
File "${QTDIR}\bin\QtNetwork4.dll"
File "${QTDIR}\bin\QtSvg4.dll"
File "${QTDIR}\bin\QtXml4.dll"
File "${QTDIR}\bin\QtMultimedia4.dll"
SetOutPath "$INSTDIR\zonebg" File /r "${NSIS_BINARY_PATH}\Release\*.*"
File /r ..\zonebg\*.*
SetOutPath "$INSTDIR\plugins"
SetOutPath "$INSTDIR\plugins\codecs"
File "${QTDIR}\plugins\codecs\qcncodecs4.dll"
File "${QTDIR}\plugins\codecs\qjpcodecs4.dll"
File "${QTDIR}\plugins\codecs\qkrcodecs4.dll"
File "${QTDIR}\plugins\codecs\qtwcodecs4.dll"
SetOutPath "$INSTDIR\plugins\iconengines"
File "${QTDIR}\plugins\iconengines\qsvgicon4.dll"
SetOutPath "$INSTDIR\plugins\imageformats"
File "${QTDIR}\plugins\imageformats\qjpeg4.dll"
File "${QTDIR}\plugins\imageformats\qsvg4.dll"
SetOutPath "$INSTDIR\sounds"
File /r ..\sounds\*.*
SetOutPath "$INSTDIR\translations"
File /r ..\build\cockatrice\*.qm
WriteUninstaller "$INSTDIR\uninstall.exe" WriteUninstaller "$INSTDIR\uninstall.exe"
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2 ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
@ -107,12 +73,10 @@ SetShellVarContext all
Delete "$INSTDIR\oracle.exe" Delete "$INSTDIR\oracle.exe"
Delete "$INSTDIR\Usermanual.pdf" Delete "$INSTDIR\Usermanual.pdf"
Delete "$INSTDIR\libprotobuf.lib" Delete "$INSTDIR\libprotobuf.lib"
Delete "$INSTDIR\QtCore4.dll" Delete "$INSTDIR\Qt*.dll"
Delete "$INSTDIR\QtGui4.dll" Delete "$INSTDIR\icu*.dll"
Delete "$INSTDIR\QtNetwork4.dll" Delete "$INSTDIR\qt.conf"
Delete "$INSTDIR\QtSvg4.dll" Delete "$INSTDIR\qdebug.txt"
Delete "$INSTDIR\QtXml4.dll"
Delete "$INSTDIR\QtMultimedia4.dll"
RMDir "$INSTDIR" RMDir "$INSTDIR"
RMDir "$SMPROGRAMS\Cockatrice" RMDir "$SMPROGRAMS\Cockatrice"

View file

@ -0,0 +1,17 @@
set(VERSION_STRING_CPP "${PROJECT_BINARY_DIR}/version_string.cpp")
set(VERSION_STRING_H "${PROJECT_BINARY_DIR}/version_string.h")
INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})
set( hstring "extern const char *VERSION_STRING\;\n" )
set( cppstring "const char * VERSION_STRING = \"${PROJECT_VERSION}\"\;\n")
file(WRITE ${PROJECT_BINARY_DIR}/version_string.cpp.txt ${cppstring} )
file(WRITE ${PROJECT_BINARY_DIR}/version_string.h.txt ${hstring} )
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_BINARY_DIR}/version_string.h.txt ${VERSION_STRING_H}
)
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_BINARY_DIR}/version_string.cpp.txt ${VERSION_STRING_CPP}
)

View file

@ -15,15 +15,5 @@ else()
message( WARNING "Git not found. Build will not contain git revision info." ) message( WARNING "Git not found. Build will not contain git revision info." )
endif() endif()
set( hstring "extern const char *VERSION_STRING\;\n" ) set(PROJECT_VERSION_MAJOR ${GIT_COMMIT_ID})
set( cppstring "const char * VERSION_STRING = \"${GIT_COMMIT_ID}\"\;\n") set(PROJECT_VERSION ${GIT_COMMIT_ID} )
file(WRITE version_string.cpp.txt ${cppstring} )
file(WRITE version_string.h.txt ${hstring} )
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different version_string.h.txt ${CMAKE_CURRENT_BINARY_DIR}/version_string.h
)
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different version_string.cpp.txt ${CMAKE_CURRENT_BINARY_DIR}/version_string.cpp
)

View file

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

View file

Before

Width:  |  Height:  |  Size: 201 KiB

After

Width:  |  Height:  |  Size: 201 KiB

View file

@ -90,7 +90,7 @@ SET(cockatrice_SOURCES
src/qt-json/json.cpp src/qt-json/json.cpp
src/soundengine.cpp src/soundengine.cpp
src/pending_command.cpp src/pending_command.cpp
${CMAKE_CURRENT_BINARY_DIR}/version_string.cpp ${VERSION_STRING_CPP}
) )
if (UNIX AND NOT APPLE) if (UNIX AND NOT APPLE)
@ -125,41 +125,119 @@ if(APPLE)
set(cockatrice_SOURCES ${cockatrice_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/resources/appicon.icns) set(cockatrice_SOURCES ${cockatrice_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/resources/appicon.icns)
ENDIF(APPLE) ENDIF(APPLE)
if (NOT QT_QTMULTIMEDIA_FOUND) set(COCKATRICE_LIBS)
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
FIND_PACKAGE(QtMobility REQUIRED)
endif (NOT QT_QTMULTIMEDIA_FOUND)
SET(QT_USE_QTNETWORK TRUE) # Qt4 stuff
SET(QT_USE_QTMULTIMEDIA TRUE) if(Qt4_FOUND)
SET(QT_USE_QTXML TRUE) if (NOT QT_QTMULTIMEDIA_FOUND)
SET(QT_USE_QTSVG TRUE) FIND_PACKAGE(QtMobility REQUIRED)
endif()
SET(QT_USE_QTNETWORK TRUE)
SET(QT_USE_QTMULTIMEDIA TRUE)
SET(QT_USE_QTXML TRUE)
SET(QT_USE_QTSVG TRUE)
# Include directories
INCLUDE(${QT_USE_FILE})
INCLUDE_DIRECTORIES(${QT_INCLUDES})
INCLUDE_DIRECTORIES(${QT_MOBILITY_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${QT_MOBILITY_MULTIMEDIAKIT_INCLUDE_DIR})
LIST(APPEND COCKATRICE_LIBS ${QT_LIBRARIES})
LIST(APPEND COCKATRICE_LIBS ${QT_QTMAIN_LIBRARY})
LIST(APPEND COCKATRICE_LIBS ${QT_MOBILITY_MULTIMEDIAKIT_LIBRARY})
# Let cmake chew Qt4's translations and resource files
# Note: header files are MOC-ed automatically by cmake
QT4_ADD_TRANSLATION(cockatrice_QM ${cockatrice_TS})
QT4_ADD_RESOURCES(cockatrice_RESOURCES_RCC ${cockatrice_RESOURCES})
endif()
# qt5 stuff
if(Qt5Widgets_FOUND)
include_directories(${Qt5Widgets_INCLUDE_DIRS})
list(APPEND COCKATRICE_LIBS Widgets)
# QtNetwork
find_package(Qt5Network)
if(Qt5Network_FOUND)
include_directories(${Qt5Network_INCLUDE_DIRS})
list(APPEND COCKATRICE_LIBS Network)
endif()
# QtMultimedia
find_package(Qt5Multimedia)
if(Qt5Multimedia_FOUND)
include_directories(${Qt5Multimedia_INCLUDE_DIRS})
list(APPEND COCKATRICE_LIBS Multimedia)
endif()
# QtPrinter
find_package(Qt5PrintSupport)
if(Qt5PrintSupport_FOUND)
include_directories(${Qt5PrintSupport_INCLUDE_DIRS})
list(APPEND COCKATRICE_LIBS PrintSupport)
endif()
# QtXml
find_package(Qt5Xml)
if(Qt5Xml_FOUND)
include_directories(${Qt5Xml_INCLUDE_DIRS})
list(APPEND COCKATRICE_LIBS Xml)
endif()
# QtSvg
find_package(Qt5Svg)
if(Qt5Svg_FOUND)
include_directories(${Qt5Svg_INCLUDE_DIRS})
list(APPEND COCKATRICE_LIBS Svg)
endif()
# Qt5LinguistTools
find_package(Qt5LinguistTools)
if(Qt5LinguistTools_FOUND)
include_directories(${Qt5LinguistTools_INCLUDE_DIRS})
list(APPEND COCKATRICE_LIBS LinguistTools)
endif()
# Let cmake chew Qt5's translations and resource files
# Note: header files are MOC-ed automatically by cmake
QT5_ADD_TRANSLATION(cockatrice_QM ${cockatrice_TS})
QT5_ADD_RESOURCES(cockatrice_RESOURCES_RCC ${cockatrice_RESOURCES})
# guess plugins and libraries directory
set(QT_PLUGINS_DIR "${Qt5Widgets_DIR}/../../../plugins")
get_target_property(QT_LIBRARY_DIR Qt5::Core LOCATION)
get_filename_component(QT_LIBRARY_DIR ${QT_LIBRARY_DIR} PATH)
endif()
# Declare path variables # Declare path variables
set(ICONDIR share/icons CACHE STRING "icon dir") set(ICONDIR share/icons CACHE STRING "icon dir")
set(DESKTOPDIR share/applications CACHE STRING "desktop file destination") set(DESKTOPDIR share/applications CACHE STRING "desktop file destination")
# Let cmake chew Qt4's translations and resource files
# Note: header files are MOC-ed automatically by cmake
QT4_ADD_TRANSLATION(cockatrice_QM ${cockatrice_TS})
QT4_ADD_RESOURCES(cockatrice_RESOURCES_RCC ${cockatrice_RESOURCES})
# Include directories # Include directories
INCLUDE(${QT_USE_FILE})
INCLUDE_DIRECTORIES(../common) INCLUDE_DIRECTORIES(../common)
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR}) INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/common) INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/common)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
INCLUDE_DIRECTORIES(${QT_MOBILITY_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${QT_MOBILITY_MULTIMEDIAKIT_INCLUDE_DIR})
# Build cockatrice binary and link it # Build cockatrice binary and link it
ADD_EXECUTABLE(cockatrice WIN32 MACOSX_BUNDLE ${cockatrice_SOURCES} ${cockatrice_QM} ${cockatrice_RESOURCES_RCC} ${cockatrice_MOC_SRCS}) ADD_EXECUTABLE(cockatrice WIN32 MACOSX_BUNDLE ${cockatrice_SOURCES} ${cockatrice_QM} ${cockatrice_RESOURCES_RCC} ${cockatrice_MOC_SRCS})
TARGET_LINK_LIBRARIES(cockatrice cockatrice_common ${QT_QTMAIN_LIBRARY} ${QT_LIBRARIES} ${QT_MOBILITY_MULTIMEDIAKIT_LIBRARY})
if(MSVC) if(Qt4_FOUND)
set_target_properties(cockatrice PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS") if(MSVC)
endif(MSVC) set(QT_USE_QTMAIN true)
endif()
TARGET_LINK_LIBRARIES(cockatrice cockatrice_common ${COCKATRICE_LIBS})
endif()
if(Qt5Widgets_FOUND)
if(MSVC)
TARGET_LINK_LIBRARIES(cockatrice cockatrice_common Qt5::WinMain)
else()
TARGET_LINK_LIBRARIES(cockatrice cockatrice_common)
endif()
qt5_use_modules(cockatrice ${COCKATRICE_LIBS})
endif()
if(UNIX) if(UNIX)
if(APPLE) if(APPLE)
@ -178,11 +256,6 @@ elseif(WIN32)
INSTALL(FILES ${cockatrice_QM} DESTINATION ./translations) INSTALL(FILES ${cockatrice_QM} DESTINATION ./translations)
endif() endif()
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version_string.cpp ${CMAKE_CURRENT_BINARY_DIR}/version_string.h
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/../common/getversion.cmake
)
if(APPLE) if(APPLE)
# these needs to be relative to CMAKE_INSTALL_PREFIX # these needs to be relative to CMAKE_INSTALL_PREFIX
set(plugin_dest_dir cockatrice.app/Contents/Plugins) set(plugin_dest_dir cockatrice.app/Contents/Plugins)
@ -215,3 +288,36 @@ Data = Resources\")
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/cockatrice.app\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\") fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/cockatrice.app\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\")
" COMPONENT Runtime) " COMPONENT Runtime)
endif() endif()
if(WIN32)
# these needs to be relative to CMAKE_INSTALL_PREFIX
set(plugin_dest_dir Plugins)
set(qtconf_dest_dir .)
# note: no codecs in qt5
# note: phonon_backend => mediaservice
# note: needs platform on osx
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime
FILES_MATCHING REGEX "(codecs|iconengines|imageformats|mediaservice|phonon_backend|platforms)/.*d\\.dll")
else()
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime
FILES_MATCHING REGEX "(codecs|iconengines|imageformats|mediaservice|phonon_backend|platforms)/.*[^d]\\.dll")
endif()
install(CODE "
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths]
Plugins = Plugins
Translations = Resources/translations
Data = Resources\")
" COMPONENT Runtime)
install(CODE "
file(GLOB_RECURSE QTPLUGINS
\"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*.dll\")
set(BU_CHMOD_BUNDLE_ITEMS ON)
include(BundleUtilities)
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/cockatrice.exe\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\")
" COMPONENT Runtime)
endif()

View file

@ -11,8 +11,12 @@
AbstractCounter::AbstractCounter(Player *_player, int _id, const QString &_name, bool _shownInCounterArea, int _value, QGraphicsItem *parent) AbstractCounter::AbstractCounter(Player *_player, int _id, const QString &_name, bool _shownInCounterArea, int _value, QGraphicsItem *parent)
: QGraphicsItem(parent), player(_player), id(_id), name(_name), value(_value), hovered(false), aDec(0), aInc(0), dialogSemaphore(false), deleteAfterDialog(false), shownInCounterArea(_shownInCounterArea) : QGraphicsItem(parent), player(_player), id(_id), name(_name), value(_value), hovered(false), aDec(0), aInc(0), dialogSemaphore(false), deleteAfterDialog(false), shownInCounterArea(_shownInCounterArea)
{ {
#if QT_VERSION < 0x050000
setAcceptsHoverEvents(true); setAcceptsHoverEvents(true);
#else
setAcceptHoverEvents(true);
#endif
if (player->getLocal()) { if (player->getLocal()) {
menu = new QMenu(name); menu = new QMenu(name);
aSet = new QAction(this); aSet = new QAction(this);
@ -129,7 +133,13 @@ void AbstractCounter::setCounter()
{ {
bool ok; bool ok;
dialogSemaphore = true; dialogSemaphore = true;
int newValue = QInputDialog::getInteger(0, tr("Set counter"), tr("New value for counter '%1':").arg(name), value, -2000000000, 2000000000, 1, &ok); int newValue =
#if QT_VERSION < 0x050000
QInputDialog::getInteger(
#else
QInputDialog::getInt(
#endif
0, tr("Set counter"), tr("New value for counter '%1':").arg(name), value, -2000000000, 2000000000, 1, &ok);
if (deleteAfterDialog) { if (deleteAfterDialog) {
deleteLater(); deleteLater();
return; return;

View file

@ -68,6 +68,8 @@ QVariant CardDatabaseModel::headerData(int section, Qt::Orientation orientation,
void CardDatabaseModel::updateCardList() void CardDatabaseModel::updateCardList()
{ {
beginResetModel();
for (int i = 0; i < cardList.size(); ++i) for (int i = 0; i < cardList.size(); ++i)
disconnect(cardList[i], 0, this, 0); disconnect(cardList[i], 0, this, 0);
@ -75,7 +77,7 @@ void CardDatabaseModel::updateCardList()
for (int i = 0; i < cardList.size(); ++i) for (int i = 0; i < cardList.size(); ++i)
connect(cardList[i], SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *))); connect(cardList[i], SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *)));
reset(); endResetModel();
} }
void CardDatabaseModel::cardInfoChanged(CardInfo *card) void CardDatabaseModel::cardInfoChanged(CardInfo *card)

View file

@ -30,6 +30,8 @@ DeckListModel::~DeckListModel()
void DeckListModel::rebuildTree() void DeckListModel::rebuildTree()
{ {
beginResetModel();
root->clearTree(); root->clearTree();
InnerDecklistNode *listRoot = deckList->getRoot(); InnerDecklistNode *listRoot = deckList->getRoot();
for (int i = 0; i < listRoot->size(); i++) { for (int i = 0; i < listRoot->size(); i++) {
@ -55,7 +57,7 @@ void DeckListModel::rebuildTree()
} }
} }
reset(); endResetModel();
} }
int DeckListModel::rowCount(const QModelIndex &parent) const int DeckListModel::rowCount(const QModelIndex &parent) const

View file

@ -7,6 +7,10 @@
#include <QMessageBox> #include <QMessageBox>
#include <QDesktopServices> #include <QDesktopServices>
#if QT_VERSION >= 0x050000
#include <QUrlQuery>
#endif
DeckStatsInterface::DeckStatsInterface(QObject *parent) DeckStatsInterface::DeckStatsInterface(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
@ -39,12 +43,29 @@ void DeckStatsInterface::queryFinished(QNetworkReply *reply)
deleteLater(); deleteLater();
} }
void DeckStatsInterface::analyzeDeck(DeckList *deck) #if QT_VERSION < 0x050000
void DeckStatsInterface::getAnalyzeRequestData(DeckList *deck, QByteArray *data)
{ {
QUrl params; QUrl params;
params.addQueryItem("deck", deck->writeToString_Plain()); params.addQueryItem("deck", deck->writeToString_Plain());
data->append(params.encodedQuery());
}
#else
void DeckStatsInterface::getAnalyzeRequestData(DeckList *deck, QByteArray *data)
{
QUrl params;
QUrlQuery urlQuery;
urlQuery.addQueryItem("deck", deck->writeToString_Plain());
params.setQuery(urlQuery);
data->append(params.query(QUrl::EncodeReserved));
}
#endif
void DeckStatsInterface::analyzeDeck(DeckList *deck)
{
QByteArray data; QByteArray data;
data.append(params.encodedQuery()); getAnalyzeRequestData(deck, &data);
QNetworkRequest request(QUrl("http://deckstats.net/index.php")); QNetworkRequest request(QUrl("http://deckstats.net/index.php"));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

View file

@ -3,6 +3,7 @@
#include <QObject> #include <QObject>
class QByteArray;
class QNetworkAccessManager; class QNetworkAccessManager;
class QNetworkReply; class QNetworkReply;
class DeckList; class DeckList;
@ -13,6 +14,7 @@ private:
QNetworkAccessManager *manager; QNetworkAccessManager *manager;
private slots: private slots:
void queryFinished(QNetworkReply *reply); void queryFinished(QNetworkReply *reply);
void getAnalyzeRequestData(DeckList *deck, QByteArray *data);
public: public:
DeckStatsInterface(QObject *parent = 0); DeckStatsInterface(QObject *parent = 0);
void analyzeDeck(DeckList *deck); void analyzeDeck(DeckList *deck);

View file

@ -64,7 +64,11 @@ void DeckViewCardDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
DeckViewCard::DeckViewCard(const QString &_name, const QString &_originZone, QGraphicsItem *parent) DeckViewCard::DeckViewCard(const QString &_name, const QString &_originZone, QGraphicsItem *parent)
: AbstractCardItem(_name, 0, -1, parent), originZone(_originZone), dragItem(0) : AbstractCardItem(_name, 0, -1, parent), originZone(_originZone), dragItem(0)
{ {
#if QT_VERSION < 0x050000
setAcceptsHoverEvents(true); setAcceptsHoverEvents(true);
#else
setAcceptHoverEvents(true);
#endif
} }
DeckViewCard::~DeckViewCard() DeckViewCard::~DeckViewCard()

View file

@ -79,8 +79,13 @@ DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *pa
chooseTokenView->header()->setStretchLastSection(false); chooseTokenView->header()->setStretchLastSection(false);
chooseTokenView->header()->hideSection(1); chooseTokenView->header()->hideSection(1);
chooseTokenView->header()->hideSection(2); chooseTokenView->header()->hideSection(2);
#if QT_VERSION < 0x050000
chooseTokenView->header()->setResizeMode(3, QHeaderView::ResizeToContents); chooseTokenView->header()->setResizeMode(3, QHeaderView::ResizeToContents);
chooseTokenView->header()->setResizeMode(4, QHeaderView::ResizeToContents); chooseTokenView->header()->setResizeMode(4, QHeaderView::ResizeToContents);
#else
chooseTokenView->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
chooseTokenView->header()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
#endif
connect(chooseTokenView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this, SLOT(tokenSelectionChanged(QModelIndex, QModelIndex))); connect(chooseTokenView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this, SLOT(tokenSelectionChanged(QModelIndex, QModelIndex)));
if (predefinedTokens.isEmpty()) if (predefinedTokens.isEmpty())

View file

@ -73,8 +73,13 @@ DlgEditTokens::DlgEditTokens(CardDatabaseModel *_cardDatabaseModel, QWidget *par
chooseTokenView->header()->setStretchLastSection(false); chooseTokenView->header()->setStretchLastSection(false);
chooseTokenView->header()->hideSection(1); chooseTokenView->header()->hideSection(1);
chooseTokenView->header()->hideSection(2); chooseTokenView->header()->hideSection(2);
#if QT_VERSION < 0x050000
chooseTokenView->header()->setResizeMode(3, QHeaderView::ResizeToContents); chooseTokenView->header()->setResizeMode(3, QHeaderView::ResizeToContents);
chooseTokenView->header()->setResizeMode(4, QHeaderView::ResizeToContents); chooseTokenView->header()->setResizeMode(4, QHeaderView::ResizeToContents);
#else
chooseTokenView->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
chooseTokenView->header()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
#endif
connect(chooseTokenView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this, SLOT(tokenSelectionChanged(QModelIndex, QModelIndex))); connect(chooseTokenView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this, SLOT(tokenSelectionChanged(QModelIndex, QModelIndex)));
QAction *aAddToken = new QAction(tr("Add token"), this); QAction *aAddToken = new QAction(tr("Add token"), this);

View file

@ -33,8 +33,11 @@ GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSup
gameListView->header()->hideSection(1); gameListView->header()->hideSection(1);
else else
gameListProxyModel->setUnavailableGamesVisible(true); gameListProxyModel->setUnavailableGamesVisible(true);
#if QT_VERSION < 0x050000
gameListView->header()->setResizeMode(1, QHeaderView::ResizeToContents); gameListView->header()->setResizeMode(1, QHeaderView::ResizeToContents);
#else
gameListView->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
#endif
filterButton = new QPushButton; filterButton = new QPushButton;
filterButton->setIcon(QIcon(":/resources/icon_search.svg")); filterButton->setIcon(QIcon(":/resources/icon_search.svg"));
connect(filterButton, SIGNAL(clicked()), this, SLOT(actSetFilter())); connect(filterButton, SIGNAL(clicked()), this, SLOT(actSetFilter()));

View file

@ -55,6 +55,7 @@ QString translationPath = TRANSLATION_PATH;
QString translationPath = QString(); QString translationPath = QString();
#endif #endif
#if QT_VERSION < 0x050000
static void myMessageOutput(QtMsgType /*type*/, const char *msg) static void myMessageOutput(QtMsgType /*type*/, const char *msg)
{ {
QFile file("qdebug.txt"); QFile file("qdebug.txt");
@ -63,6 +64,16 @@ static void myMessageOutput(QtMsgType /*type*/, const char *msg)
out << msg << endl; out << msg << endl;
file.close(); file.close();
} }
#else
static void myMessageOutput(QtMsgType /*type*/, const QMessageLogContext &, const QString &msg)
{
QFile file("qdebug.txt");
file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
QTextStream out(&file);
out << msg << endl;
file.close();
}
#endif
void installNewTranslator() void installNewTranslator()
{ {
@ -87,11 +98,21 @@ int main(int argc, char *argv[])
QApplication app(argc, argv); QApplication app(argc, argv);
if (app.arguments().contains("--debug-output")) if (app.arguments().contains("--debug-output"))
{
#if QT_VERSION < 0x050000
qInstallMsgHandler(myMessageOutput); qInstallMsgHandler(myMessageOutput);
#else
qInstallMessageHandler(myMessageOutput);
#endif
}
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
app.addLibraryPath(app.applicationDirPath() + "/plugins"); app.addLibraryPath(app.applicationDirPath() + "/plugins");
#endif #endif
#if QT_VERSION < 0x050000
// gone in Qt5, all source files _MUST_ be utf8-encoded
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
QCoreApplication::setOrganizationName("Cockatrice"); QCoreApplication::setOrganizationName("Cockatrice");
QCoreApplication::setOrganizationDomain("cockatrice.de"); QCoreApplication::setOrganizationDomain("cockatrice.de");
@ -114,8 +135,13 @@ int main(int argc, char *argv[])
installNewTranslator(); installNewTranslator();
qsrand(QDateTime::currentDateTime().toTime_t()); qsrand(QDateTime::currentDateTime().toTime_t());
bool startMainProgram = true;
#if QT_VERSION < 0x050000
const QString dataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); const QString dataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
#else
const QString dataDir = QStandardPaths::standardLocations(QStandardPaths::DataLocation).first();
#endif
if (!db->getLoadSuccess()) if (!db->getLoadSuccess())
if (db->loadCardDatabase(dataDir + "/cards.xml")) if (db->loadCardDatabase(dataDir + "/cards.xml"))
settingsCache->setCardDatabasePath(dataDir + "/cards.xml"); settingsCache->setCardDatabasePath(dataDir + "/cards.xml");

View file

@ -13,7 +13,11 @@ PileZone::PileZone(Player *_p, const QString &_name, bool _isShufflable, bool _c
: CardZone(_p, _name, false, _isShufflable, _contentsKnown, parent) : CardZone(_p, _name, false, _isShufflable, _contentsKnown, parent)
{ {
setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor! setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor!
#if QT_VERSION < 0x050000
setAcceptsHoverEvents(true); setAcceptsHoverEvents(true);
#else
setAcceptHoverEvents(true);
#endif
setCursor(Qt::OpenHandCursor); setCursor(Qt::OpenHandCursor);
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(90).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2)); setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(90).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));

View file

@ -774,7 +774,13 @@ void Player::actViewLibrary()
void Player::actViewTopCards() void Player::actViewTopCards()
{ {
bool ok; bool ok;
int number = QInputDialog::getInteger(0, tr("View top cards of library"), tr("Number of cards:"), defaultNumberTopCards, 1, 2000000000, 1, &ok); int number =
#if QT_VERSION < 0x050000
QInputDialog::getInteger(
#else
QInputDialog::getInt(
#endif
0, tr("View top cards of library"), tr("Number of cards:"), defaultNumberTopCards, 1, 2000000000, 1, &ok);
if (ok) { if (ok) {
defaultNumberTopCards = number; defaultNumberTopCards = number;
static_cast<GameScene *>(scene())->toggleZoneView(this, "deck", number); static_cast<GameScene *>(scene())->toggleZoneView(this, "deck", number);
@ -829,7 +835,13 @@ void Player::actMulligan()
void Player::actDrawCards() void Player::actDrawCards()
{ {
int number = QInputDialog::getInteger(0, tr("Draw cards"), tr("Number:")); int number =
#if QT_VERSION < 0x050000
QInputDialog::getInteger(
#else
QInputDialog::getInt(
#endif
0, tr("Draw cards"), tr("Number:"));
if (number) { if (number) {
Command_DrawCards cmd; Command_DrawCards cmd;
cmd.set_number(number); cmd.set_number(number);
@ -844,8 +856,14 @@ void Player::actUndoDraw()
void Player::actMoveTopCardsToGrave() void Player::actMoveTopCardsToGrave()
{ {
int number = QInputDialog::getInteger(0, tr("Move top cards to grave"), tr("Number:")); int number =
if (!number) #if QT_VERSION < 0x050000
QInputDialog::getInteger(
#else
QInputDialog::getInt(
#endif
0, tr("Move top cards to grave"), tr("Number:"));
if (!number)
return; return;
const int maxCards = zones.value("deck")->getCards().size(); const int maxCards = zones.value("deck")->getCards().size();
@ -867,8 +885,14 @@ void Player::actMoveTopCardsToGrave()
void Player::actMoveTopCardsToExile() void Player::actMoveTopCardsToExile()
{ {
int number = QInputDialog::getInteger(0, tr("Move top cards to exile"), tr("Number:")); int number =
if (!number) #if QT_VERSION < 0x050000
QInputDialog::getInteger(
#else
QInputDialog::getInt(
#endif
0, tr("Move top cards to exile"), tr("Number:"));
if (!number)
return; return;
const int maxCards = zones.value("deck")->getCards().size(); const int maxCards = zones.value("deck")->getCards().size();
@ -914,7 +938,13 @@ void Player::actUntapAll()
void Player::actRollDie() void Player::actRollDie()
{ {
bool ok; bool ok;
int sides = QInputDialog::getInteger(0, tr("Roll die"), tr("Number of sides:"), 20, 2, 1000, 1, &ok); int sides =
#if QT_VERSION < 0x050000
QInputDialog::getInteger(
#else
QInputDialog::getInt(
#endif
0, tr("Roll die"), tr("Number of sides:"), 20, 2, 1000, 1, &ok);
if (ok) { if (ok) {
Command_RollDie cmd; Command_RollDie cmd;
cmd.set_sides(sides); cmd.set_sides(sides);
@ -2022,7 +2052,13 @@ void Player::actCardCounterTrigger()
case 11: { case 11: {
bool ok; bool ok;
dialogSemaphore = true; dialogSemaphore = true;
int number = QInputDialog::getInteger(0, tr("Set counters"), tr("Number:"), 0, 0, MAX_COUNTERS_ON_CARD, 1, &ok); int number =
#if QT_VERSION < 0x050000
QInputDialog::getInteger(
#else
QInputDialog::getInt(
#endif
0, tr("Set counters"), tr("Number:"), 0, 0, MAX_COUNTERS_ON_CARD, 1, &ok);
dialogSemaphore = false; dialogSemaphore = false;
if (clearCardsToDelete()) if (clearCardsToDelete())
return; return;

View file

@ -72,7 +72,11 @@ PlayerListWidget::PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient
setColumnCount(6); setColumnCount(6);
setHeaderHidden(true); setHeaderHidden(true);
setRootIsDecorated(false); setRootIsDecorated(false);
#if QT_VERSION < 0x050000
header()->setResizeMode(QHeaderView::ResizeToContents); header()->setResizeMode(QHeaderView::ResizeToContents);
#else
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
#endif
retranslateUi(); retranslateUi();
} }

View file

@ -553,7 +553,7 @@ int Json::nextToken(const QString &json, int &index)
QChar c = json[index]; QChar c = json[index];
index++; index++;
switch(c.toAscii()) switch(c.toLatin1())
{ {
case '{': return JsonTokenCurlyOpen; case '{': return JsonTokenCurlyOpen;
case '}': return JsonTokenCurlyClose; case '}': return JsonTokenCurlyClose;

View file

@ -258,8 +258,11 @@ void RemoteDeckList_TreeModel::deckListFinished(const Response &r)
{ {
const Response_DeckList &resp = r.GetExtension(Response_DeckList::ext); const Response_DeckList &resp = r.GetExtension(Response_DeckList::ext);
beginResetModel();
root->clearTree(); root->clearTree();
reset();
endResetModel();
ServerInfo_DeckStorage_TreeItem tempRoot; ServerInfo_DeckStorage_TreeItem tempRoot;
tempRoot.set_id(0); tempRoot.set_id(0);
@ -280,7 +283,11 @@ RemoteDeckList_TreeWidget::RemoteDeckList_TreeWidget(AbstractClient *_client, QW
setModel(proxyModel); setModel(proxyModel);
connect(treeModel, SIGNAL(treeRefreshed()), this, SLOT(expandAll())); connect(treeModel, SIGNAL(treeRefreshed()), this, SLOT(expandAll()));
#if QT_VERSION < 0x050000
header()->setResizeMode(QHeaderView::ResizeToContents); header()->setResizeMode(QHeaderView::ResizeToContents);
#else
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
#endif
setUniformRowHeights(true); setUniformRowHeights(true);
setSortingEnabled(true); setSortingEnabled(true);
proxyModel->sort(0, Qt::AscendingOrder); proxyModel->sort(0, Qt::AscendingOrder);

View file

@ -278,7 +278,11 @@ RemoteReplayList_TreeWidget::RemoteReplayList_TreeWidget(AbstractClient *_client
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
setModel(proxyModel); setModel(proxyModel);
#if QT_VERSION < 0x050000
header()->setResizeMode(QHeaderView::ResizeToContents); header()->setResizeMode(QHeaderView::ResizeToContents);
#else
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
#endif
header()->setStretchLastSection(false); header()->setStretchLastSection(false);
setUniformRowHeights(true); setUniformRowHeights(true);
setSortingEnabled(true); setSortingEnabled(true);

View file

@ -33,8 +33,13 @@ void SoundEngine::soundEnabledChanged()
if (settingsCache->getSoundEnabled()) { if (settingsCache->getSoundEnabled()) {
qDebug("SoundEngine: enabling sound"); qDebug("SoundEngine: enabling sound");
QAudioFormat format; QAudioFormat format;
#if QT_VERSION < 0x050000
format.setFrequency(44100); format.setFrequency(44100);
format.setChannels(1); format.setChannels(1);
#else
format.setSampleRate(44100);
format.setChannelCount(1);
#endif
format.setSampleSize(16); format.setSampleSize(16);
format.setCodec("audio/pcm"); format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian); format.setByteOrder(QAudioFormat::LittleEndian);

View file

@ -134,7 +134,11 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
deckView->setUniformRowHeights(true); deckView->setUniformRowHeights(true);
deckView->setSortingEnabled(true); deckView->setSortingEnabled(true);
deckView->sortByColumn(1, Qt::AscendingOrder); deckView->sortByColumn(1, Qt::AscendingOrder);
#if QT_VERSION < 0x050000
deckView->header()->setResizeMode(QHeaderView::ResizeToContents); deckView->header()->setResizeMode(QHeaderView::ResizeToContents);
#else
deckView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
#endif
deckView->installEventFilter(&deckViewKeySignals); deckView->installEventFilter(&deckViewKeySignals);
connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoRight(const QModelIndex &, const QModelIndex &))); connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoRight(const QModelIndex &, const QModelIndex &)));
connect(&deckViewKeySignals, SIGNAL(onEnter()), this, SLOT(actIncrement())); connect(&deckViewKeySignals, SIGNAL(onEnter()), this, SLOT(actIncrement()));

View file

@ -38,7 +38,11 @@ TabDeckStorage::TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_c
localDirView->setColumnHidden(1, true); localDirView->setColumnHidden(1, true);
localDirView->setRootIndex(localDirModel->index(localDirModel->rootPath(), 0)); localDirView->setRootIndex(localDirModel->index(localDirModel->rootPath(), 0));
localDirView->setSortingEnabled(true); localDirView->setSortingEnabled(true);
#if QT_VERSION < 0x050000
localDirView->header()->setResizeMode(QHeaderView::ResizeToContents); localDirView->header()->setResizeMode(QHeaderView::ResizeToContents);
#else
localDirView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
#endif
localDirView->header()->setSortIndicator(0, Qt::AscendingOrder); localDirView->header()->setSortIndicator(0, Qt::AscendingOrder);
leftToolBar = new QToolBar; leftToolBar = new QToolBar;

View file

@ -36,7 +36,11 @@ TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client)
localDirView->setColumnHidden(1, true); localDirView->setColumnHidden(1, true);
localDirView->setRootIndex(localDirModel->index(localDirModel->rootPath(), 0)); localDirView->setRootIndex(localDirModel->index(localDirModel->rootPath(), 0));
localDirView->setSortingEnabled(true); localDirView->setSortingEnabled(true);
#if QT_VERSION < 0x050000
localDirView->header()->setResizeMode(QHeaderView::ResizeToContents); localDirView->header()->setResizeMode(QHeaderView::ResizeToContents);
#else
localDirView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
#endif
localDirView->header()->setSortIndicator(0, Qt::AscendingOrder); localDirView->header()->setSortIndicator(0, Qt::AscendingOrder);
leftToolBar = new QToolBar; leftToolBar = new QToolBar;

View file

@ -28,11 +28,17 @@ RoomSelector::RoomSelector(AbstractClient *_client, QWidget *parent)
roomList->setRootIsDecorated(false); roomList->setRootIsDecorated(false);
roomList->setColumnCount(4); roomList->setColumnCount(4);
roomList->header()->setStretchLastSection(false); roomList->header()->setStretchLastSection(false);
#if QT_VERSION < 0x050000
roomList->header()->setResizeMode(0, QHeaderView::ResizeToContents); roomList->header()->setResizeMode(0, QHeaderView::ResizeToContents);
roomList->header()->setResizeMode(1, QHeaderView::Stretch); roomList->header()->setResizeMode(1, QHeaderView::Stretch);
roomList->header()->setResizeMode(2, QHeaderView::ResizeToContents); roomList->header()->setResizeMode(2, QHeaderView::ResizeToContents);
roomList->header()->setResizeMode(3, QHeaderView::ResizeToContents); roomList->header()->setResizeMode(3, QHeaderView::ResizeToContents);
#else
roomList->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
roomList->header()->setSectionResizeMode(1, QHeaderView::Stretch);
roomList->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
roomList->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
#endif
joinButton = new QPushButton; joinButton = new QPushButton;
connect(joinButton, SIGNAL(clicked()), this, SLOT(joinClicked())); connect(joinButton, SIGNAL(clicked()), this, SLOT(joinClicked()));
QHBoxLayout *buttonLayout = new QHBoxLayout; QHBoxLayout *buttonLayout = new QHBoxLayout;

View file

@ -28,7 +28,11 @@ TableZone::TableZone(Player *_p, QGraphicsItem *parent)
currentMinimumWidth = minWidth; currentMinimumWidth = minWidth;
setCacheMode(DeviceCoordinateCache); setCacheMode(DeviceCoordinateCache);
#if QT_VERSION < 0x050000
setAcceptsHoverEvents(true); setAcceptsHoverEvents(true);
#else
setAcceptHoverEvents(true);
#endif
} }
void TableZone::updateBgPixmap() void TableZone::updateBgPixmap()

View file

@ -216,7 +216,11 @@ UserList::UserList(TabSupervisor *_tabSupervisor, AbstractClient *_client, UserL
userTree = new QTreeWidget; userTree = new QTreeWidget;
userTree->setColumnCount(3); userTree->setColumnCount(3);
#if QT_VERSION < 0x050000
userTree->header()->setResizeMode(QHeaderView::ResizeToContents); userTree->header()->setResizeMode(QHeaderView::ResizeToContents);
#else
userTree->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
#endif
userTree->setHeaderHidden(true); userTree->setHeaderHidden(true);
userTree->setRootIsDecorated(false); userTree->setRootIsDecorated(false);
userTree->setIconSize(QSize(20, 12)); userTree->setIconSize(QSize(20, 12));

View file

@ -28,7 +28,20 @@ SET(common_SOURCES
sfmt/SFMT.c sfmt/SFMT.c
) )
INCLUDE(${QT_USE_FILE}) set(ORACLE_LIBS)
# Qt4 stuff
if(Qt4_FOUND)
# Include directories
INCLUDE(${QT_USE_FILE})
include_directories(${QT_INCLUDES})
endif()
# qt5 stuff
if(Qt5Widgets_FOUND)
include_directories(${Qt5Widgets_INCLUDE_DIRS})
endif()
INCLUDE_DIRECTORIES(pb) INCLUDE_DIRECTORIES(pb)
INCLUDE_DIRECTORIES(sfmt) INCLUDE_DIRECTORIES(sfmt)
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR}) INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR})

View file

@ -2,6 +2,7 @@
#define SERVER_RESPONSE_CONTAINERS_H #define SERVER_RESPONSE_CONTAINERS_H
#include <QPair> #include <QPair>
#include <QList>
#include "pb/server_message.pb.h" #include "pb/server_message.pb.h"
namespace google { namespace protobuf { class Message; } } namespace google { namespace protobuf { class Message; } }

View file

@ -16,21 +16,77 @@ SET(oracle_SOURCES
../cockatrice/src/qt-json/json.cpp ../cockatrice/src/qt-json/json.cpp
) )
SET(QT_USE_QTNETWORK TRUE) set(ORACLE_LIBS)
SET(QT_USE_QTXML TRUE)
SET(QT_USE_QTSVG TRUE) # Qt4 stuff
if(Qt4_FOUND)
SET(QT_USE_QTNETWORK TRUE)
SET(QT_USE_QTXML TRUE)
SET(QT_USE_QTSVG TRUE)
# Include directories
INCLUDE(${QT_USE_FILE})
include_directories(${QT_INCLUDES})
LIST(APPEND ORACLE_LIBS ${QT_QTMAIN_LIBRARY})
LIST(APPEND ORACLE_LIBS ${QT_LIBRARIES})
endif()
# qt5 stuff
if(Qt5Widgets_FOUND)
include_directories(${Qt5Widgets_INCLUDE_DIRS})
list(APPEND ORACLE_LIBS Widgets)
# QtConcurrent
find_package(Qt5Concurrent)
if(Qt5Concurrent_FOUND)
include_directories(${Qt5Concurrent_INCLUDE_DIRS})
list(APPEND ORACLE_LIBS Concurrent)
endif()
# QtNetwork
find_package(Qt5Network)
if(Qt5Network_FOUND)
include_directories(${Qt5Network_INCLUDE_DIRS})
list(APPEND ORACLE_LIBS Network)
endif()
# QtXml
find_package(Qt5Xml)
if(Qt5Xml_FOUND)
include_directories(${Qt5Xml_INCLUDE_DIRS})
list(APPEND ORACLE_LIBS Xml)
endif()
# QtSvg
find_package(Qt5Svg)
if(Qt5Svg_FOUND)
include_directories(${Qt5Svg_INCLUDE_DIRS})
list(APPEND ORACLE_LIBS Svg)
endif()
# guess plugins and libraries directory
set(QT_PLUGINS_DIR "${Qt5Widgets_DIR}/../../../plugins")
get_target_property(QT_LIBRARY_DIR Qt5::Core LOCATION)
get_filename_component(QT_LIBRARY_DIR ${QT_LIBRARY_DIR} PATH)
endif()
# Include directories
INCLUDE(${QT_USE_FILE})
INCLUDE_DIRECTORIES(../cockatrice/src) INCLUDE_DIRECTORIES(../cockatrice/src)
# Build oracle binary and link it # Build oracle binary and link it
ADD_EXECUTABLE(oracle WIN32 MACOSX_BUNDLE ${oracle_SOURCES} ${oracle_MOC_SRCS}) ADD_EXECUTABLE(oracle WIN32 MACOSX_BUNDLE ${oracle_SOURCES} ${oracle_MOC_SRCS})
TARGET_LINK_LIBRARIES(oracle ${QT_QTMAIN_LIBRARY} ${QT_LIBRARIES})
if(MSVC) if(Qt4_FOUND)
set_target_properties(oracle PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS") if(MSVC)
endif(MSVC) set(QT_USE_QTMAIN true)
endif()
TARGET_LINK_LIBRARIES(oracle ${ORACLE_LIBS})
endif()
if(Qt5Widgets_FOUND)
if(MSVC)
TARGET_LINK_LIBRARIES(oracle Qt5::WinMain)
endif()
qt5_use_modules(oracle ${ORACLE_LIBS})
endif()
if(UNIX) if(UNIX)
if(APPLE) if(APPLE)
@ -78,3 +134,35 @@ Translations = Resources/translations\")
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/oracle.app\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\") fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/oracle.app\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\")
" COMPONENT Runtime) " COMPONENT Runtime)
endif() endif()
IF(WIN32)
# these needs to be relative to CMAKE_INSTALL_PREFIX
set(plugin_dest_dir Plugins)
set(qtconf_dest_dir .)
# note: no codecs in qt5
# note: phonon_backend => mediaservice
# note: needs platform on osx
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime
FILES_MATCHING REGEX "(codecs|iconengines|imageformats|mediaservice|phonon_backend|platforms)/.*d\\.dll")
else()
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime
FILES_MATCHING REGEX "(codecs|iconengines|imageformats|mediaservice|phonon_backend|platforms)/.*[^d]\\.dll")
endif()
install(CODE "
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths]
Plugins = Plugins
Translations = Resources/translations\")
" COMPONENT Runtime)
install(CODE "
file(GLOB_RECURSE QTPLUGINS
\"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*.dll\")
set(BU_CHMOD_BUNDLE_ITEMS ON)
include(BundleUtilities)
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/oracle.exe\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\")
" COMPONENT Runtime)
endif()

View file

@ -8,9 +8,12 @@ SettingsCache *settingsCache;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication app(argc, argv); QApplication app(argc, argv);
#if QT_VERSION < 0x050000
// gone in Qt5, all source files _MUST_ be utf8-encoded
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
QCoreApplication::setOrganizationName("Cockatrice"); QCoreApplication::setOrganizationName("Cockatrice");
QCoreApplication::setOrganizationDomain("cockatrice"); QCoreApplication::setOrganizationDomain("cockatrice");
// this can't be changed, as it influences the default savepath for cards.xml // this can't be changed, as it influences the default savepath for cards.xml

View file

@ -1,5 +1,9 @@
#include "oracleimporter.h" #include "oracleimporter.h"
#include <QtGui> #if QT_VERSION < 0x050000
#include <QtGui>
#else
#include <QtWidgets>
#endif
#include <QDebug> #include <QDebug>
#include "qt-json/json.h" #include "qt-json/json.h"

View file

@ -1,8 +1,25 @@
#include <QtGui> #include <QtGui>
#if QT_VERSION < 0x050000
#include <QDesktopServices>
#else
#include <QStandardPaths>
#include <QtConcurrent>
#endif
#include <QAbstractButton>
#include <QCheckBox>
#include <QFileDialog>
#include <QGridLayout> #include <QGridLayout>
#include <QDesktopServices> #include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkReply> #include <QNetworkReply>
#include <QProgressBar>
#include <QPushButton>
#include <QRadioButton>
#include <QScrollArea>
#include <QScrollBar>
#include <QTextEdit>
#include "oraclewizard.h" #include "oraclewizard.h"
#include "oracleimporter.h" #include "oracleimporter.h"
@ -13,7 +30,14 @@ OracleWizard::OracleWizard(QWidget *parent)
: QWizard(parent) : QWizard(parent)
{ {
settings = new QSettings(this); settings = new QSettings(this);
importer = new OracleImporter(QDesktopServices::storageLocation(QDesktopServices::DataLocation), this);
importer = new OracleImporter(
#if QT_VERSION < 0x050000
QDesktopServices::storageLocation(QDesktopServices::DataLocation)
#else
QStandardPaths::standardLocations(QStandardPaths::DataLocation).first()
#endif
, this);
addPage(new IntroPage); addPage(new IntroPage);
addPage(new LoadSetsPage); addPage(new LoadSetsPage);
@ -372,7 +396,12 @@ void SaveSetsPage::updateTotalProgress(int cardsImported, int setIndex, const QS
bool SaveSetsPage::validatePage() bool SaveSetsPage::validatePage()
{ {
bool ok = false; bool ok = false;
const QString dataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); const QString dataDir =
#if QT_VERSION < 0x050000
QDesktopServices::storageLocation(QDesktopServices::DataLocation);
#else
QStandardPaths::standardLocations(QStandardPaths::DataLocation).first();
#endif
QDir dir(dataDir); QDir dir(dataDir);
if (!dir.exists()) if (!dir.exists())
dir.mkpath(dataDir); dir.mkpath(dataDir);

View file

@ -4,8 +4,6 @@
PROJECT(servatrice) PROJECT(servatrice)
# cmake module for libgcrypt is included in current directory
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
FIND_PACKAGE(Libgcrypt REQUIRED) FIND_PACKAGE(Libgcrypt REQUIRED)
SET(servatrice_SOURCES SET(servatrice_SOURCES
@ -17,15 +15,50 @@ SET(servatrice_SOURCES
src/server_logger.cpp src/server_logger.cpp
src/serversocketinterface.cpp src/serversocketinterface.cpp
src/isl_interface.cpp src/isl_interface.cpp
${CMAKE_CURRENT_BINARY_DIR}/version_string.cpp ${VERSION_STRING_CPP}
) )
SET(QT_DONTUSE_QTGUI) set(SERVATRICE_LIBS)
SET(QT_USE_QTNETWORK TRUE)
SET(QT_USE_QTSQL TRUE) # Qt4 stuff
if(Qt4_FOUND)
SET(QT_USE_QTNETWORK TRUE)
SET(QT_USE_QTSQL TRUE)
# Include directories
INCLUDE(${QT_USE_FILE})
include_directories(${QT_INCLUDES})
LIST(APPEND SERVATRICE_LIBS ${QT_LIBRARIES})
endif()
# qt5 stuff
if(Qt5Widgets_FOUND)
include_directories(${Qt5Widgets_INCLUDE_DIRS})
list(APPEND SERVATRICE_LIBS Widgets)
# QtNetwork
find_package(Qt5Network)
if(Qt5Network_FOUND)
include_directories(${Qt5Network_INCLUDE_DIRS})
list(APPEND SERVATRICE_LIBS Network)
endif()
# QtSql
find_package(Qt5Sql)
if(Qt5Sql_FOUND)
include_directories(${Qt5Sql_INCLUDE_DIRS})
list(APPEND SERVATRICE_LIBS Sql)
endif()
# guess plugins and libraries directory
set(QT_PLUGINS_DIR "${Qt5Widgets_DIR}/../../../plugins")
get_target_property(QT_LIBRARY_DIR Qt5::Core LOCATION)
get_filename_component(QT_LIBRARY_DIR ${QT_LIBRARY_DIR} PATH)
endif()
SET(QT_DONT_USE_QTGUI TRUE)
# Include directories # Include directories
INCLUDE(${QT_USE_FILE})
INCLUDE_DIRECTORIES(../common) INCLUDE_DIRECTORIES(../common)
INCLUDE_DIRECTORIES(${LIBGCRYPT_INCLUDE_DIR}) INCLUDE_DIRECTORIES(${LIBGCRYPT_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR}) INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR})
@ -34,13 +67,21 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
# Build servatrice binary and link it # Build servatrice binary and link it
ADD_EXECUTABLE(servatrice MACOSX_BUNDLE ${servatrice_SOURCES} ${servatrice_MOC_SRCS}) ADD_EXECUTABLE(servatrice MACOSX_BUNDLE ${servatrice_SOURCES} ${servatrice_MOC_SRCS})
TARGET_LINK_LIBRARIES(servatrice cockatrice_common ${QT_LIBRARIES} ${LIBGCRYPT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
#add_custom_target(versionheader ALL DEPENDS version_header) if(Qt4_FOUND)
add_custom_command( if(MSVC)
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version_string.h ${CMAKE_CURRENT_BINARY_DIR}/version_string.cpp set(QT_USE_QTMAIN true)
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/../common/getversion.cmake endif()
) TARGET_LINK_LIBRARIES(servatrice cockatrice_common ${SERVATRICE_LIBS} ${LIBGCRYPT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
endif()
if(Qt5Widgets_FOUND)
if(MSVC)
TARGET_LINK_LIBRARIES(servatrice cockatrice_common ${LIBGCRYPT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} Qt5::WinMain)
else()
TARGET_LINK_LIBRARIES(servatrice cockatrice_common ${LIBGCRYPT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
endif()
qt5_use_modules(servatrice ${SERVATRICE_LIBS})
endif()
# install rules # install rules
if(UNIX) if(UNIX)
@ -85,3 +126,35 @@ Translations = Resources/translations\")
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/servatrice.app\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\") fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/servatrice.app\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\")
" COMPONENT Runtime) " COMPONENT Runtime)
endif() endif()
if(WIN32)
# these needs to be relative to CMAKE_INSTALL_PREFIX
set(plugin_dest_dir Plugins)
set(qtconf_dest_dir .)
# note: no codecs in qt5
# note: phonon_backend => mediaservice
# note: needs platform on osx
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime
FILES_MATCHING REGEX "(codecs|iconengines|imageformats|mediaservice|phonon_backend|platforms)/.*d\\.dll")
else()
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime
FILES_MATCHING REGEX "(codecs|iconengines|imageformats|mediaservice|phonon_backend|platforms)/.*[^d]\\.dll")
endif()
install(CODE "
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths]
Plugins = Plugins
Translations = Resources/translations\")
" COMPONENT Runtime)
install(CODE "
file(GLOB_RECURSE QTPLUGINS
\"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*.dll\")
set(BU_CHMOD_BUNDLE_ITEMS ON)
include(BundleUtilities)
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/servatrice.exe\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\")
" COMPONENT Runtime)
endif()

View file

@ -82,6 +82,7 @@ void testHash()
std::cerr << startTime.secsTo(endTime) << "secs" << std::endl; std::cerr << startTime.secsTo(endTime) << "secs" << std::endl;
} }
#if QT_VERSION < 0x050000
void myMessageOutput(QtMsgType /*type*/, const char *msg) void myMessageOutput(QtMsgType /*type*/, const char *msg)
{ {
logger->logMessage(msg); logger->logMessage(msg);
@ -92,6 +93,18 @@ void myMessageOutput2(QtMsgType /*type*/, const char *msg)
logger->logMessage(msg); logger->logMessage(msg);
std::cerr << msg << std::endl; std::cerr << msg << std::endl;
} }
#else
void myMessageOutput(QtMsgType /*type*/, const QMessageLogContext &, const QString &msg)
{
logger->logMessage(msg);
}
void myMessageOutput2(QtMsgType /*type*/, const QMessageLogContext &, const QString &msg)
{
logger->logMessage(msg);
std::cerr << msg.toStdString() << std::endl;
}
#endif
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
void sigSegvHandler(int sig) void sigSegvHandler(int sig)
@ -121,9 +134,12 @@ int main(int argc, char *argv[])
bool logToConsole = args.contains("--log-to-console"); bool logToConsole = args.contains("--log-to-console");
qRegisterMetaType<QList<int> >("QList<int>"); qRegisterMetaType<QList<int> >("QList<int>");
#if QT_VERSION < 0x050000
// gone in Qt5, all source files _MUST_ be utf8-encoded
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
QSettings *settings = new QSettings("servatrice.ini", QSettings::IniFormat); QSettings *settings = new QSettings("servatrice.ini", QSettings::IniFormat);
loggerThread = new QThread; loggerThread = new QThread;
@ -133,11 +149,19 @@ int main(int argc, char *argv[])
loggerThread->start(); loggerThread->start();
QMetaObject::invokeMethod(logger, "startLog", Qt::BlockingQueuedConnection, Q_ARG(QString, settings->value("server/logfile").toString())); QMetaObject::invokeMethod(logger, "startLog", Qt::BlockingQueuedConnection, Q_ARG(QString, settings->value("server/logfile").toString()));
#if QT_VERSION < 0x050000
if (logToConsole) if (logToConsole)
qInstallMsgHandler(myMessageOutput); qInstallMsgHandler(myMessageOutput);
else else
qInstallMsgHandler(myMessageOutput2); qInstallMsgHandler(myMessageOutput2);
#else
if (logToConsole)
qInstallMessageHandler(myMessageOutput);
else
qInstallMessageHandler(myMessageOutput2);
#endif
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
struct sigaction hup; struct sigaction hup;
hup.sa_handler = ServerLogger::hupSignalHandler; hup.sa_handler = ServerLogger::hupSignalHandler;
@ -173,8 +197,12 @@ int main(int argc, char *argv[])
if (server->initServer()) { if (server->initServer()) {
std::cerr << "-------------------------" << std::endl; std::cerr << "-------------------------" << std::endl;
std::cerr << "Server initialized." << std::endl; std::cerr << "Server initialized." << std::endl;
#if QT_VERSION < 0x050000
qInstallMsgHandler(myMessageOutput); qInstallMsgHandler(myMessageOutput);
#else
qInstallMessageHandler(myMessageOutput);
#endif
retval = app.exec(); retval = app.exec();
std::cerr << "Server quit." << std::endl; std::cerr << "Server quit." << std::endl;

View file

@ -16,7 +16,7 @@ QString PasswordHasher::computeHash(const QString &password, const QString &salt
const int algo = GCRY_MD_SHA512; const int algo = GCRY_MD_SHA512;
const int rounds = 1000; const int rounds = 1000;
QByteArray passwordBuffer = (salt + password).toAscii(); QByteArray passwordBuffer = (salt + password).toUtf8();
int hashLen = gcry_md_get_algo_dlen(algo); int hashLen = gcry_md_get_algo_dlen(algo);
char hash[hashLen], tmp[hashLen]; char hash[hashLen], tmp[hashLen];
gcry_md_hash_buffer(algo, hash, passwordBuffer.data(), passwordBuffer.size()); gcry_md_hash_buffer(algo, hash, passwordBuffer.data(), passwordBuffer.size());

View file

@ -78,7 +78,11 @@ Servatrice_GameServer::~Servatrice_GameServer()
} }
} }
#if QT_VERSION < 0x050000
void Servatrice_GameServer::incomingConnection(int socketDescriptor) void Servatrice_GameServer::incomingConnection(int socketDescriptor)
#else
void Servatrice_GameServer::incomingConnection(qintptr socketDescriptor)
#endif
{ {
// Determine connection pool with smallest client count // Determine connection pool with smallest client count
int minClientCount = -1; int minClientCount = -1;
@ -234,8 +238,16 @@ bool Servatrice::initServer()
if (!certFile.open(QIODevice::ReadOnly)) if (!certFile.open(QIODevice::ReadOnly))
throw QString("Error opening certificate file: %1").arg(certFileName); throw QString("Error opening certificate file: %1").arg(certFileName);
QSslCertificate cert(&certFile); QSslCertificate cert(&certFile);
#if QT_VERSION < 0x050000
if (!cert.isValid()) if (!cert.isValid())
throw(QString("Invalid certificate.")); throw(QString("Invalid certificate."));
#else
const QDateTime currentTime = QDateTime::currentDateTime();
if(currentTime < cert.effectiveDate() ||
currentTime > cert.expiryDate() ||
cert.isBlacklisted())
throw(QString("Invalid certificate."));
#endif
qDebug() << "Loading private key..."; qDebug() << "Loading private key...";
QFile keyFile(keyFileName); QFile keyFile(keyFileName);
if (!keyFile.open(QIODevice::ReadOnly)) if (!keyFile.open(QIODevice::ReadOnly))
@ -319,7 +331,7 @@ void Servatrice::updateServerList()
query.prepare("select id, ssl_cert, hostname, address, game_port, control_port from " + dbPrefix + "_servers order by id asc"); query.prepare("select id, ssl_cert, hostname, address, game_port, control_port from " + dbPrefix + "_servers order by id asc");
servatriceDatabaseInterface->execSqlQuery(query); servatriceDatabaseInterface->execSqlQuery(query);
while (query.next()) { while (query.next()) {
ServerProperties prop(query.value(0).toInt(), QSslCertificate(query.value(1).toString().toAscii()), query.value(2).toString(), QHostAddress(query.value(3).toString()), query.value(4).toInt(), query.value(5).toInt()); ServerProperties prop(query.value(0).toInt(), QSslCertificate(query.value(1).toString().toUtf8()), query.value(2).toString(), QHostAddress(query.value(3).toString()), query.value(4).toInt(), query.value(5).toInt());
serverList.append(prop); serverList.append(prop);
qDebug() << QString("#%1 CERT=%2 NAME=%3 IP=%4:%5 CPORT=%6").arg(prop.id).arg(QString(prop.cert.digest().toHex())).arg(prop.hostname).arg(prop.address.toString()).arg(prop.gamePort).arg(prop.controlPort); qDebug() << QString("#%1 CERT=%2 NAME=%3 IP=%4:%5 CPORT=%6").arg(prop.id).arg(QString(prop.cert.digest().toHex())).arg(prop.hostname).arg(prop.address.toString()).arg(prop.gamePort).arg(prop.controlPort);
} }

View file

@ -52,7 +52,11 @@ public:
Servatrice_GameServer(Servatrice *_server, int _numberPools, const QSqlDatabase &_sqlDatabase, QObject *parent = 0); Servatrice_GameServer(Servatrice *_server, int _numberPools, const QSqlDatabase &_sqlDatabase, QObject *parent = 0);
~Servatrice_GameServer(); ~Servatrice_GameServer();
protected: protected:
#if QT_VERSION < 0x050000
void incomingConnection(int socketDescriptor); void incomingConnection(int socketDescriptor);
#else
void incomingConnection(qintptr socketDescriptor);
#endif
}; };
class Servatrice_IslServer : public QTcpServer { class Servatrice_IslServer : public QTcpServer {