diff options
49 files changed, 7899 insertions, 0 deletions
diff --git a/qnetchess/CHANGES b/qnetchess/CHANGES new file mode 100644 index 00000000..61644a3b --- /dev/null +++ b/qnetchess/CHANGES @@ -0,0 +1,2 @@ +2005.03.26 + Fixed the mate checker. (big thanks to knyaz@RusNet) diff --git a/qnetchess/CMakeLists.txt b/qnetchess/CMakeLists.txt new file mode 100644 index 00000000..569c30a7 --- /dev/null +++ b/qnetchess/CMakeLists.txt @@ -0,0 +1,60 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +project( qnetchess ) + +set( TQT_MAJOR_VERSION 14 ) +set( TQT_MINOR_VERSION 0 ) +set( TQT_MICRO_VERSION 0 ) +set( TQT_VERSION "${TQT_MAJOR_VERSION}.${TQT_MINOR_VERSION}.${TQT_MICRO_VERSION}" ) + + +##### cmake setup ############################### + +cmake_minimum_required( VERSION 2.8 ) + +include( CheckCXXSourceCompiles ) +include( GNUInstallDirs OPTIONAL ) + + +##### include our cmake modules ################# + +set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules" ) +include( TDEMacros ) +include( FindPkgConfig ) + + +##### install paths setup ####################### + +tde_setup_install_path( EXEC_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" ) +tde_setup_install_path( BIN_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/bin" ) + + +##### optional stuff ############################ + +option( WITH_ALL_OPTIONS "Enable all optional support" OFF ) + + +##### user requested modules #################### + +option( BUILD_ALL "Build all" OFF ) + + +##### configure checks ########################## + +include( ConfigureChecks.cmake ) + + +set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TQT_CXX_FLAGS}" ) + +##### q15 sources ###################### + +add_subdirectory( src ) diff --git a/qnetchess/ConfigureChecks.cmake b/qnetchess/ConfigureChecks.cmake new file mode 100644 index 00000000..d061bf44 --- /dev/null +++ b/qnetchess/ConfigureChecks.cmake @@ -0,0 +1,47 @@ +################################################# +# +# (C) 2011 Timothy Pearson +# kb9vqf (AT) pearsoncomputing.net +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + + +# required stuff + +#tde_setup_architecture_flags( ) + +#include(TestBigEndian) +#test_big_endian(WORDS_BIGENDIAN) + +#tde_setup_largefiles( ) + +find_package( TQt ) +#find_package( TDE ) + + +##### check for gcc visibility support ######### + +#if( WITH_GCC_VISIBILITY ) +# tde_setup_gcc_visibility( ) +#endif( ) + + +#if( BUILD_TRANSLATIONS AND NOT DEFINED MSGFMT_EXECUTABLE ) +# find_program( MSGFMT_EXECUTABLE msgfmt ) +# if( NOT MSGFMT_EXECUTABLE ) +# tde_message_fatal( "msgfmt program is required, but was not found on your system" ) +# endif( ) +#endif( ) + +#check_type_size( "int" SIZEOF_INT BUILTIN_TYPES_ONLY ) +#check_type_size( "long" SIZEOF_LONG BUILTIN_TYPES_ONLY ) + +#check_include_file( stdint.h HAVE_STDINT_H ) +#check_include_file( systems.h HAVE_SYSTEMS_H ) +#check_include_file( linux/inotify.h HAVE_INOTIFY ) + +#check_function_exists( statvfs HAVE_STATVFS ) diff --git a/qnetchess/Makefile b/qnetchess/Makefile new file mode 120000 index 00000000..51aac0ef --- /dev/null +++ b/qnetchess/Makefile @@ -0,0 +1 @@ +Makefile.FreeBSD
\ No newline at end of file diff --git a/qnetchess/Makefile.FreeBSD b/qnetchess/Makefile.FreeBSD new file mode 100644 index 00000000..bf8df640 --- /dev/null +++ b/qnetchess/Makefile.FreeBSD @@ -0,0 +1,14 @@ +# $Id: Makefile.FreeBSD,v 0.1 2004/08/21 12:11:49 denis Exp $ + +PROG= QNetChess +NO_MAN= noman +SRCS= main.cpp mainwindow.cpp gamesocket.cpp gameboard.cpp +MOCS= mainwindow.h gamesocket.h gameboard.h +LOCALE_FILE= ${PROG}_ru +DFLAGS= -DLOCALE_FILE=\"${LOCALE_FILE}\" +CFLAGS+= -W -Wall -Werror ${DFLAGS} +LDADD+= -L${X11BASE}/lib + + +.include "qt.FreeBSD.mk" +.include <bsd.prog.mk> diff --git a/qnetchess/Makefile.gnu b/qnetchess/Makefile.gnu new file mode 100644 index 00000000..07cc0a21 --- /dev/null +++ b/qnetchess/Makefile.gnu @@ -0,0 +1,51 @@ +# $Id: Makefile.gnu,v 0.1 2005/01/15 10:22:49 denis Exp $ + +TARGET= QNetChess +OBJS= main.o mainwindow.o gamesocket.o gameboard.o mainwindow.mo gamesocket.mo\ + gameboard.mo +LOCALE_FILE= $(TARGET)_ru +DFLAGS= -DLOCALE_FILE=\"$(LOCALE_FILE)\" +X11BASE= /usr/X11R6 +RM= rm -f +CC= gcc +CXX= g++ + +MOC= $(QTDIR)/bin/moc +QT_INC= -I$(QTDIR)/include +QT_LIB= -L$(QTDIR)/lib -lqt + +CFLAGS+= -O2 -W -Wall -Werror $(DFLAGS) -I$(X11BASE)/include $(QT_INC) +LDFLAGS+= -L$(X11BASE)/lib $(QT_LIB) + + +.SUFFIXES: .h .cxx .mo .o .cpp + +.h.cxx: + $(MOC) $< -o $@ + +.cpp.o: + $(CXX) $(CFLAGS) -c $< -o $@ + +.cxx.mo: + $(CXX) $(CFLAGS) -c $< -o $@ + + +all: $(OBJS) + $(CXX) $(LDFLAGS) -o $(TARGET) $(OBJS) + +clean: + $(RM) $(OBJS) *.cxx + +distclean: clean + $(RM) $(TARGET) + +main.o: main.cpp +mainwindow.o: mainwindow.cpp +mainwindow.cpp: mainwindow.h +mainwindow.mo: mainwindow.cxx +gamesocket.o: gamesocket.cpp +gamesocket.cpp: gamesocket.h +gamesocket.mo: gamesocket.cxx +gameboard.o: gameboard.cpp +gameboard.cpp: gameboard.h +gameboard.mo: gameboard.cxx diff --git a/qnetchess/Makefile.win32 b/qnetchess/Makefile.win32 new file mode 100644 index 00000000..9179cc83 --- /dev/null +++ b/qnetchess/Makefile.win32 @@ -0,0 +1,64 @@ +# $Id: Makefile.win32,v 1.0 2005/01/16 13:45:54 denis Exp $ + +PROG= QNetChess +CC= cl +CXX= cl +LOCALE_FILE= $(PROG)_ru +CXXFLAGS= -GX -nologo -W3 -MD -O1 -DQT_DLL -DQT_THREAD_SUPPORT -DNO_DEBUG\ + -DLOCALE_FILE=\""$(LOCALE_FILE)"\" +INCPATH= -I"$(QTDIR)\include" +LINK= link +LDFLAGS= /NOLOGO /SUBSYSTEM:windows /OPT:REF +LIBS= $(QTDIR)\lib\qt-mteval321.lib $(QTDIR)\lib\qtmain.lib \ + opengl32.lib glu32.lib kernel32.lib user32.lib gdi32.lib \ + comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib \ + uuid.lib imm32.lib winmm.lib wsock32.lib +MOC= $(QTDIR)\bin\moc + +OBJS= main.obj mainwindow.obj gameboard.obj gamesocket.obj\ + mainwindow.moc gameboard.moc gamesocket.moc +TARGET= $(PROG).exe + + +.SUFFIXES: .h .cxx .cpp .obj .moc + +.cpp.obj: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fo$@ $< + +.cxx.moc: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fo$@ $< + +.h.cxx: + $(MOC) -o $@ $< + +all: $(OBJS) + $(LINK) $(LDFLAGS) /OUT:$(TARGET) @<< + $(OBJS) $(LIBS) +<< + +clean: + -del main.obj + -del mainwindow.obj + -del gameboard.obj + -del gamesocket.obj + -del mainwindow.moc + -del gameboard.moc + -del gamesocket.moc + -del mainwindow.cxx + -del gameboard.cxx + -del gamesocket.cxx + +distclean: clean + -del $(TARGET) + + +main.obj: main.cpp +mainwindow.obj: mainwindow.cpp +gameboard.obj: gameboard.cpp +gamesocket.obj: gamesocket.cpp +mainwindow.moc: mainwindow.cxx +gameboard.moc: gameboard.cxx +gamesocket.moc: gamesocket.cxx +mainwindow.cxx: mainwindow.h +gameboard.cxx: gameboard.h +gamesocket.cxx: gamesocket.h diff --git a/qnetchess/QNetChess_ru.qm b/qnetchess/QNetChess_ru.qm Binary files differnew file mode 100644 index 00000000..6981cb4c --- /dev/null +++ b/qnetchess/QNetChess_ru.qm diff --git a/qnetchess/QNetChess_ru.ts b/qnetchess/QNetChess_ru.ts new file mode 100644 index 00000000..50a71158 --- /dev/null +++ b/qnetchess/QNetChess_ru.ts @@ -0,0 +1,274 @@ +<!DOCTYPE TS><TS> +<context> + <name>Drawer</name> + <message> + <source>Error moving</source> + <translation>Не правильный ход</translation> + </message> + <message> + <source>Yes</source> + <translation>Да</translation> + </message> + <message> + <source>No</source> + <translation>Нет</translation> + </message> + <message> + <source>You cannot move this figure because the king is in check</source> + <translation>Вы не можете двигать эту фигуру потому, что вашему королю объявлен шах</translation> + </message> + <message> + <source>To castle</source> + <translation>Рокировка</translation> + </message> + <message> + <source>Do you want to castle?</source> + <translation>Вы хотите сделать рокировку?</translation> + </message> +</context> +<context> + <name>FigureDialog</name> + <message> + <source>What figure should I set?</source> + <translation>Какую фигуру следует поставить?</translation> + </message> +</context> +<context> + <name>GameBoard</name> + <message> + <source>White</source> + <translation>Белыми</translation> + </message> + <message> + <source>Black</source> + <translation>Чёрными</translation> + </message> + <message> + <source>game with</source> + <translation>игра с</translation> + </message> + <message> + <source>Game chat</source> + <translation>Игровой чат</translation> + </message> + <message> + <source>History</source> + <translation>История</translation> + </message> + <message> + <source>Looking up the host</source> + <translation>Поиск хоста</translation> + </message> + <message> + <source>Accepted a new connection</source> + <translation>Принято новое соединение</translation> + </message> + <message> + <source>The host found</source> + <translation>Хост найден</translation> + </message> + <message> + <source>Socket Error...</source> + <translation>Ошибка сокета...</translation> + </message> + <message> + <source>You have a socket error number</source> + <translation>Возникла ошибка сокета номер</translation> + </message> + <message> + <source>game from</source> + <translation>игра с</translation> + </message> + <message> + <source>Accepted the</source> + <translation>Принята</translation> + </message> + <message> + <source>Your move...</source> + <translation>Ваш ход...</translation> + </message> + <message> + <source>Waiting a move...</source> + <translation>Ожидание хода...</translation> + </message> + <message> + <source>End the game</source> + <translation>Конец игры</translation> + </message> + <message> + <source>Want you to end the game? +You will lose it</source> + <translation>Желаете закончить игру? +Вы проиграете</translation> + </message> + <message> + <source>Yes, end</source> + <translation>Да, закончить</translation> + </message> + <message> + <source>No, continue</source> + <translation>Нет, продолжить</translation> + </message> + <message> + <source>B</source> + <translation>С</translation> + </message> + <message> + <source>K</source> + <translation>К</translation> + </message> + <message> + <source>C</source> + <translation>Л</translation> + </message> + <message> + <source>Q</source> + <translation>Ф</translation> + </message> + <message> + <source>Error!</source> + <translation>Ошибка!</translation> + </message> + <message> + <source>The host</source> + <translation>Хост</translation> + </message> + <message> + <source>not found.</source> + <translation>не найден.</translation> + </message> + <message> + <source>Save image</source> + <translation>Сохранить картинку</translation> + </message> + <message> + <source>Do you want to save the image?</source> + <translation>Вы желаете сохранить картинку?</translation> + </message> + <message> + <source>Yes, save</source> + <translation>Да, сохранить</translation> + </message> + <message> + <source>No, don't save</source> + <translation>Нет, не сохранять</translation> + </message> + <message> + <source>You scored the game</source> + <translation>Вы выиграли игру</translation> + </message> + <message> + <source>You have a mate. +You lost the game.</source> + <translation>Вам поставили мат. +Вы проиграли эту игру.</translation> + </message> + <message> + <source>You have a stalemate</source> + <translation>У вас пат</translation> + </message> + <message> + <source>Game over</source> + <translation>Конец игры</translation> + </message> + <message> + <source>Connected to the host</source> + <translation>Соединились с хостом</translation> + </message> + <message> + <source>Lookup Error</source> + <translation>Ошибка DNS</translation> + </message> +</context> +<context> + <name>MainWindow</name> + <message> + <source>New</source> + <translation>Новая</translation> + </message> + <message> + <source>Save image</source> + <translation>Сохранить картинку</translation> + </message> + <message> + <source>Quit</source> + <translation>Выход</translation> + </message> + <message> + <source>About the game</source> + <translation>Об Игре</translation> + </message> + <message> + <source>Game</source> + <translation>Игра</translation> + </message> + <message> + <source>Help</source> + <translation>Помощь</translation> + </message> + <message> + <source>Ready</source> + <translation>Готов</translation> + </message> + <message> + <source>About</source> + <translation>Об Игре</translation> + </message> + <message> + <source>is a network game chess for two players. +It has a client and a server in the same program. +You can modify and redistribute the source code +because it is under GPL. + +Russia, Tambov, 2005 (denis@silversoft.net)</source> + <translation>это сетевая игра в шахматы на два игрока. +Она содержит клиента и сервер в одной программе. +Вы можете модифицировать и распространять исходный код +потому, что он идёт под лицензией GPL. + +Россия, Тамбов, 2005 год (denis@silversoft.net)</translation> + </message> +</context> +<context> + <name>QObject</name> + <message> + <source>Socket Error</source> + <translation>Ошиба сокета</translation> + </message> + <message> + <source>Cannot create a server socket!</source> + <translation>Не могу создать серверный сокет!</translation> + </message> +</context> +<context> + <name>SelectGame</name> + <message> + <source>New game with...</source> + <translation>Новая игра с...</translation> + </message> + <message> + <source>To play with </source> + <translation>Играем с</translation> + </message> + <message> + <source>Choose your game</source> + <translation>Выбирете игру</translation> + </message> + <message> + <source>White game</source> + <translation>Игра белыми</translation> + </message> + <message> + <source>Black game</source> + <translation>Игра чёрными</translation> + </message> + <message> + <source>Play!</source> + <translation>Играть!</translation> + </message> + <message> + <source>Cancel</source> + <translation>Отмена</translation> + </message> +</context> +</TS> diff --git a/qnetchess/README b/qnetchess/README new file mode 100644 index 00000000..5c982c71 --- /dev/null +++ b/qnetchess/README @@ -0,0 +1,22 @@ +Network Chess Game +~~~~~~~~~~~~~~~~~~ + +This software is distributed under GNU GPL. +Use it at own risk. NO WARRANTY. + +To compile the game you need Qt library version 3.2 or newer. +Also you need to set QTDIR environvent variable. +Read Qt manual for more info. +Then just type make -f Makefile.gnu and wait for a few time. +If you use FreeBSD you may type Makefile.FreeBSD. + + +The game uses TCP port 1345, you may change it at gamesocket.h + + +Maybe I'll write HTTP-proxy support... maybe! + +Denis, Tambov +(aka denk@RusNet) + +2005/29/01 diff --git a/qnetchess/README.rus b/qnetchess/README.rus new file mode 100644 index 00000000..6ad273bb --- /dev/null +++ b/qnetchess/README.rus @@ -0,0 +1,29 @@ +, ... + + , , , ;-) + Qt-3, +ģ , FreeBSD, +, ӣ /usr/local/qt, +QTDIR , . +, , qt.FreeBSD.mk. + + , ... + 1345 :) + gamesocket.h + + HTTP-proxy , +... + +, configure ;-) + , ɣ . + QTDIR, - Qt. + ң - .. , configure ;-) + , ;-) + + ӣ, , +, +(aka denk@RusNet) + +P.S. + , ң ;-) + ! ;-) diff --git a/qnetchess/cmake/generate_apidox b/qnetchess/cmake/generate_apidox new file mode 100755 index 00000000..3a4e79cf --- /dev/null +++ b/qnetchess/cmake/generate_apidox @@ -0,0 +1,17 @@ +#!/bin/bash + +top_srcdir=${1} +top_builddir=${2} +kde_libs_htmldir=${3} +export TQTDOCDIR=${4} + +if [[ ! -d "${top_srcdir}/doc/common/" ]]; then + export DOXDATA=${kde_libs_htmldir}/en/common +fi + +abs_top_srcdir=$(cd ${top_srcdir} && pwd) + +rm -rf ${top_builddir}/${kde_libs_htmldir}/en +mkdir -p ${top_builddir}/${kde_libs_htmldir}/en +cd ${top_builddir}/${kde_libs_htmldir}/en +${abs_top_srcdir}/admin/doxygen.sh --modulename --installdir=${top_builddir}/${kde_libs_htmldir}/en ${abs_top_srcdir} diff --git a/qnetchess/cmake/install_apidox b/qnetchess/cmake/install_apidox new file mode 100755 index 00000000..b757f797 --- /dev/null +++ b/qnetchess/cmake/install_apidox @@ -0,0 +1,12 @@ +#!/bin/bash + +top_srcdir=${1} +top_builddir=${2} +kde_libs_htmldir=${3} +installdir=${DESTDIR} + +abs_top_srcdir=$(cd ${top_srcdir} && pwd) + +cd ${top_builddir} +mkdir -p ${installdir}/${kde_libs_htmldir}/en +cp -Rp ${top_builddir}/${kde_libs_htmldir}/en ${installdir}/${kde_libs_htmldir}/ diff --git a/qnetchess/cmake/modules/FindTDE.cmake b/qnetchess/cmake/modules/FindTDE.cmake new file mode 100644 index 00000000..01e6f462 --- /dev/null +++ b/qnetchess/cmake/modules/FindTDE.cmake @@ -0,0 +1,104 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +if( NOT TDE_FOUND ) + + message( STATUS "checking for 'TDE'") + + pkg_search_module( TDE tqt ) + + if( NOT TDE_FOUND ) + tde_message_fatal( "Unable to find tdelibs!\n Try adding the directory in which the tdelibs.pc file is located\nto the PKG_CONFIG_PATH variable." ) + endif( ) + + # if the path is not already defined by user, + # find tde-config executable + if( NOT DEFINED KDECONFIG_EXECUTABLE ) + find_program( KDECONFIG_EXECUTABLE + NAMES tde-config + HINTS "${TDE_PREFIX}/bin" ${BIN_INSTALL_DIR} ) + if( NOT KDECONFIG_EXECUTABLE ) + tde_message_fatal( "tde-config are NOT found." ) + endif( NOT KDECONFIG_EXECUTABLE ) + endif( NOT DEFINED KDECONFIG_EXECUTABLE ) + + set( ENV{LD_LIBRARY_PATH} "${TDE_LIBDIR}:$ENV{LD_LIBRARY_PATH}" ) + # check for installed trinity version + tde_execute_process( + COMMAND ${KDECONFIG_EXECUTABLE} --version + OUTPUT_VARIABLE _version + RESULT_VARIABLE _result + OUTPUT_STRIP_TRAILING_WHITESPACE + MESSAGE "Unable to run tde-config!\n TDELIBS are correctly installed?\n Path to tde-config are corect?" ) + + # parse tde-config output, to extract TDE version + string( REGEX MATCH "TDE: R([0-9\\.]+).*" __dummy "${_version}" ) + set( TDE_VERSION "${CMAKE_MATCH_1}" ) + + # ask tde-config for few paths + macro( __internal_get_path __type __var ) + tde_execute_process( + COMMAND ${KDECONFIG_EXECUTABLE} --expandvars --install ${__type} + OUTPUT_VARIABLE ${__var} + CACHE INTERNAL "TDE ${__type} path" FORCE + OUTPUT_STRIP_TRAILING_WHITESPACE ) + endmacro( __internal_get_path ) + + __internal_get_path( include TDE_INCLUDE_DIR ) + __internal_get_path( lib TDE_LIB_DIR ) + __internal_get_path( exe TDE_BIN_DIR ) + __internal_get_path( data TDE_DATA_DIR ) + __internal_get_path( config TDE_CONFIG_DIR ) + __internal_get_path( html TDE_HTML_DIR ) + __internal_get_path( cmake TDE_CMAKE_DIR ) + __internal_get_path( tqtplugins TDE_TQTPLUGINS_DIR ) + + # find kde tools + macro( __internal_find_program __prog __var ) + find_program( ${__var} + NAMES ${__prog} + HINTS "${TDE_PREFIX}/bin" ${BIN_INSTALL_DIR} + OUTPUT_STRIP_TRAILING_WHITESPACE ) + if( NOT ${__var} ) + tde_message_fatal( "${__prog} is NOT found.\n TDELIBS are correctly installed?" ) + endif( NOT ${__var} ) + set( ${__var} ${${__var}} CACHE INTERNAL "${__prog} executable" FORCE ) + endmacro( __internal_find_program ) + + __internal_find_program( dcopidl KDE3_DCOPIDL_EXECUTABLE ) + __internal_find_program( dcopidlng KDE3_DCOPIDLNG_EXECUTABLE ) + __internal_find_program( dcopidl2cpp KDE3_DCOPIDL2CPP_EXECUTABLE ) + __internal_find_program( meinproc KDE3_MEINPROC_EXECUTABLE ) + __internal_find_program( tdeconfig_compiler KDE3_KCFGC_EXECUTABLE ) + __internal_find_program( maketdewidgets KDE3_MAKETDEWIDGETS_EXECUTABLE ) + # Don't use __internal_find_program due to it's not mandatory + find_program( TDELFEDITOR_EXECUTABLE NAMES tdelfeditor + HINTS "${TDE_PREFIX}/bin" ${BIN_INSTALL_DIR} OUTPUT_STRIP_TRAILING_WHITESPACE ) + + # dcopidlng is a bash script which using tde-config; + # if PATH to tde-config is not set, dcopidlng will fail; + # for this reason we set KDECONFIG environment variable before running dcopidlng + set( KDE3_DCOPIDLNG_EXECUTABLE env KDECONFIG=${KDECONFIG_EXECUTABLE} ${KDE3_DCOPIDLNG_EXECUTABLE} + CACHE INTERNAL "dcopidlng executable" FORCE ) + + # look for SCM data if present + if( EXISTS "${CMAKE_SOURCE_DIR}/.tdescmmodule" ) + file( STRINGS "${CMAKE_SOURCE_DIR}/.tdescmmodule" TDE_SCM_MODULE_NAME ) + endif( EXISTS "${CMAKE_SOURCE_DIR}/.tdescmmodule" ) + if( EXISTS "${CMAKE_SOURCE_DIR}/.tdescmrevision" ) + file( STRINGS "${CMAKE_SOURCE_DIR}/.tdescmrevision" TDE_SCM_MODULE_REVISION ) + endif( EXISTS "${CMAKE_SOURCE_DIR}/.tdescmrevision" ) + + message( STATUS " found 'TDE', version ${TDE_VERSION}" ) + +endif( NOT TDE_FOUND ) + +include( "${TDE_CMAKE_DIR}/tdelibs.cmake" ) diff --git a/qnetchess/cmake/modules/FindTQt.cmake b/qnetchess/cmake/modules/FindTQt.cmake new file mode 100644 index 00000000..6194bb26 --- /dev/null +++ b/qnetchess/cmake/modules/FindTQt.cmake @@ -0,0 +1,107 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +macro( tqt_message ) + message( STATUS "${ARGN}" ) +endmacro( ) + +pkg_search_module( TQT tqt ) + +if( NOT TQT_FOUND ) + tde_message_fatal( "Unable to find tqt!\n Try adding the directory in which the tqt.pc file is located\nto the PKG_CONFIG_PATH variable." ) +endif( ) + +mark_as_advanced( + TMOC_EXECUTABLE + MOC_EXECUTABLE + UIC_EXECUTABLE +) + +# tmoc_executable +tde_execute_process( + COMMAND pkg-config tqt --variable=tmoc_executable + OUTPUT_VARIABLE TMOC_EXECUTABLE + CACHE FILEPATH "TQt tmoc executable path" + OUTPUT_STRIP_TRAILING_WHITESPACE ) + +if( NOT EXISTS ${TMOC_EXECUTABLE} ) + tde_message_fatal( "tmoc is not found!\n tqt is correctly installed?" ) +endif( ) + +tqt_message( " tmoc path: ${TMOC_EXECUTABLE}" ) + + +# moc_executable +tde_execute_process( + COMMAND pkg-config tqt --variable=moc_executable + OUTPUT_VARIABLE MOC_EXECUTABLE + CACHE FILEPATH "TQt moc executable path" + OUTPUT_STRIP_TRAILING_WHITESPACE ) + +if( NOT EXISTS ${MOC_EXECUTABLE} ) + tde_message_fatal( "Path to moc is not set.\n tqt is correctly installed?" ) +endif( ) + +tqt_message( " moc path: ${MOC_EXECUTABLE}" ) + + +# uic_executable +tde_execute_process( + COMMAND pkg-config tqt --variable=uic_executable + OUTPUT_VARIABLE UIC_EXECUTABLE + CACHE FILEPATH "TQt uic executable path" + OUTPUT_STRIP_TRAILING_WHITESPACE ) + +if( NOT EXISTS ${UIC_EXECUTABLE} ) + tde_message_fatal( "uic not found!\n tqt is correctly installed?" ) +endif( ) + +tqt_message( " uic path: ${UIC_EXECUTABLE}" ) + + +# tqt-replace script +set( TQT_REPLACE_SCRIPT "${TQT_PREFIX}/bin/tqt-replace" ) + +if( NOT EXISTS ${TQT_REPLACE_SCRIPT} ) + tde_message_fatal( "tqt-replace not found!\n Check tqt installation." ) +endif( ) + +tqt_message( " tqt-replace path: ${TQT_REPLACE_SCRIPT}" ) + + +# check if tqt is usable +tde_save( CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_LIBRARIES ) +set( CMAKE_REQUIRED_INCLUDES ${TQT_INCLUDE_DIRS} ) +foreach( _dirs ${TQT_LIBRARY_DIRS} ) + list( APPEND CMAKE_REQUIRED_LIBRARIES "-L${_dirs}" ) +endforeach() +list( APPEND CMAKE_REQUIRED_LIBRARIES ${TQT_LIBRARIES} ) + +check_cxx_source_compiles(" + #include <tqapplication.h> + int main(int argc, char **argv) { TQApplication app(argc, argv); return 0; } " + HAVE_USABLE_TQT ) + +if( NOT HAVE_USABLE_TQT ) + tde_message_fatal( "Unable to build a simple tqt test." ) +endif( ) + +tde_restore( CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_LIBRARIES ) + + +# TQT_CXX_FLAGS +foreach( _flag ${TQT_CFLAGS} ${TQT_CFLAGS_OTHER} ) + set( TQT_CXX_FLAGS "${TQT_CXX_FLAGS} ${_flag}" ) +endforeach() + +# Set compiler flags according to build type +set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-DNDEBUG" ) +set( CMAKE_C_FLAGS_RELWITHDEBINFO "-DNDEBUG" ) diff --git a/qnetchess/cmake/modules/FindTQtQUI.cmake b/qnetchess/cmake/modules/FindTQtQUI.cmake new file mode 100644 index 00000000..32dd245e --- /dev/null +++ b/qnetchess/cmake/modules/FindTQtQUI.cmake @@ -0,0 +1,45 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +macro( tqtqui_message ) + message( STATUS "${ARGN}" ) +endmacro( ) + +pkg_search_module( TQTQUI tqtqui ) + +if( NOT TQTQUI_FOUND ) + tde_message_fatal( "Unable to find tqtqui!\n Try adding the directory in which the tqtqui.pc file is located\nto the PKG_CONFIG_PATH variable." ) +endif( ) + +# check if tqtqui is usable +tde_save( CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_LIBRARIES ) +set( CMAKE_REQUIRED_INCLUDES ${TQTQUI_INCLUDE_DIRS} ) +foreach( _dirs ${TQTQUI_LIBRARY_DIRS} ) + list( APPEND CMAKE_REQUIRED_LIBRARIES "-L${_dirs}" ) +endforeach() +list( APPEND CMAKE_REQUIRED_LIBRARIES ${TQTQUI_LIBRARIES} ) + +check_cxx_source_compiles(" + #include <tqapplication.h> + int main(int argc, char **argv) { TQApplication app(argc, argv); return 0; } " + HAVE_USABLE_TQTQUI ) + +if( NOT HAVE_USABLE_TQTQUI ) + tde_message_fatal( "Unable to build a simple tqtqui test." ) +endif( ) + +tde_restore( CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_LIBRARIES ) + + +# TQTQUI_CXX_FLAGS +foreach( _flag ${TQTQUI_CFLAGS_OTHER} ) + set( TQTQUI_CXX_FLAGS "${TQTQUI_CXX_FLAGS} ${_flag}" ) +endforeach() diff --git a/qnetchess/cmake/modules/TDEL10n.cmake b/qnetchess/cmake/modules/TDEL10n.cmake new file mode 100644 index 00000000..62aad3a3 --- /dev/null +++ b/qnetchess/cmake/modules/TDEL10n.cmake @@ -0,0 +1,1151 @@ +################################################# +# +# (C) 2018-2019 Slávek Banko +# slavek (DOT) banko (AT) axis.cz +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + + +##### include essential TDE macros ############## + +set( MASTER_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" ) +include( TDEMacros ) + + +##### verify required programs ################## + +if( NOT DEFINED TDE_PREFIX AND IS_DIRECTORY /opt/trinity ) + set( TDE_PREFIX "/opt/trinity" ) +else( ) + set( TDE_PREFIX "/usr" ) +endif( ) + +if( NOT DEFINED KDE_XGETTEXT_EXECUTABLE ) + find_program( KDE_XGETTEXT_EXECUTABLE + NAMES kde-xgettext + HINTS "${TDE_PREFIX}/bin" + ) + if( "${KDE_XGETTEXT_EXECUTABLE}" STREQUAL "KDE_XGETTEXT_EXECUTABLE-NOTFOUND" ) + tde_message_fatal( "kde-xgettext is required but not found" ) + endif( ) +endif( ) + +if( NOT DEFINED XGETTEXT_EXECUTABLE ) + find_program( XGETTEXT_EXECUTABLE + NAMES xgettext + HINTS "${TDE_PREFIX}/bin" + ) + if( "${XGETTEXT_EXECUTABLE}" STREQUAL "XGETTEXT_EXECUTABLE-NOTFOUND" ) + tde_message_fatal( "xgettext is required but not found" ) + endif( ) + execute_process( + COMMAND ${XGETTEXT_EXECUTABLE} --version + OUTPUT_VARIABLE _xgettext_version + ERROR_VARIABLE _xgettext_version + ) + string( REGEX REPLACE "^xgettext[^\n]* ([^ ]*)\n.*" "\\1" _xgettext_version ${_xgettext_version} ) + if( "${_xgettext_version}" VERSION_LESS "0.19" ) + tde_message_fatal( "xgettext version >= 0.19 is required but found only ${_xgettext_version}" ) + endif( ) +endif( ) + +if( NOT DEFINED MSGUNIQ_EXECUTABLE ) + find_program( MSGUNIQ_EXECUTABLE + NAMES msguniq + HINTS "${TDE_PREFIX}/bin" + ) + if( "${MSGUNIQ_EXECUTABLE}" STREQUAL "MSGUNIQ_EXECUTABLE-NOTFOUND" ) + tde_message_fatal( "msguniq is required but not found" ) + endif( ) +endif( ) + +if( NOT DEFINED MSGCAT_EXECUTABLE ) + find_program( MSGCAT_EXECUTABLE + NAMES msgcat + HINTS "${TDE_PREFIX}/bin" + ) + if( "${MSGCAT_EXECUTABLE}" STREQUAL "MSGCAT_EXECUTABLE-NOTFOUND" ) + tde_message_fatal( "msgcat is required but not found" ) + endif( ) +endif( ) + +if( NOT DEFINED PO4A_GETTEXTIZE_EXECUTABLE ) + find_program( PO4A_GETTEXTIZE_EXECUTABLE + NAMES po4a-gettextize + HINTS "${TDE_PREFIX}/bin" + ) + if( "${PO4A_GETTEXTIZE_EXECUTABLE}" STREQUAL "PO4A_GETTEXTIZE_EXECUTABLE-NOTFOUND" ) + tde_message_fatal( "po4a-gettextize is required but not found" ) + endif( ) + execute_process( + COMMAND ${PO4A_GETTEXTIZE_EXECUTABLE} --version + OUTPUT_VARIABLE _po4a_version + ERROR_VARIABLE _po4a_version + ) + string( REGEX REPLACE "^po4a-gettextize[^\n]* ([^ ]*)\n.*" "\\1" _po4a_version ${_po4a_version} ) + if( "${_po4a_version}" VERSION_LESS "0.45" ) + tde_message_fatal( "po4a version >= 0.45 is required but found only ${_po4_version}" ) + endif( ) +endif( ) + +if( NOT DEFINED TDE_COMMON_TEXTS_POT ) + get_filename_component( TDE_SOURCE_BASE "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE ) + while( (NOT EXISTS "${TDE_SOURCE_BASE}/tdelibs" + OR NOT IS_DIRECTORY "${TDE_SOURCE_BASE}/tdelibs" ) + AND NOT "${TDE_SOURCE_BASE}" STREQUAL "/" ) + get_filename_component( TDE_SOURCE_BASE "${TDE_SOURCE_BASE}" PATH ) + endwhile( ) + find_file( TDE_COMMON_TEXTS_POT + NAMES tde.pot + HINTS "${TDE_SOURCE_BASE}/tdelibs" "${TDE_PREFIX}/include" "${TDE_PREFIX}/include/tde" + ) + if( "${TDE_COMMON_TEXTS_POT}" STREQUAL "TDE_COMMON_TEXTS_POT-NOTFOUND" ) + tde_message_fatal( "translation template with common texts not found" ) + endif( ) +endif( ) + + +################################################# +##### +##### tde_l10n_add_subdirectory +##### +##### The function simulates the add_subdirectory() behavior, but +##### the CMakeL10n.txt file is used instead of CMakeLists.txt. +##### + +function( tde_l10n_add_subdirectory _dir ) + set( CMAKE_CURRENT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${_dir}" ) + set( CMAKE_CURRENT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/${_dir}" ) + include( ${CMAKE_CURRENT_SOURCE_DIR}/CMakeL10n.txt ) +endfunction( ) + + +################################################# +##### +##### tde_l10n_auto_add_subdirectories +##### +##### The function is equivalent to tde_auto_add_subdirectories, but +##### the CMakeL10n.txt file is used instead of CMakeLists.txt. +##### + +function( tde_l10n_auto_add_subdirectories ) + file( GLOB _dirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/*" ) + foreach( _dir ${_dirs} ) + if( IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${_dir} + AND NOT ${_dir} STREQUAL ".svn" + AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_dir}/CMakeL10n.txt ) + tde_l10n_add_subdirectory( ${_dir} ) + endif( ) + endforeach( ) +endfunction( ) + + +################################################# +##### +##### tde_l10n_create_template +##### +##### Macro is used to generate a translation template - POT file. +##### +##### Syntax: +##### tde_l10n_create_template( +##### [CATALOG] file_name +##### [SOURCES source_spec [source_spec]] +##### [COMMENT tag] +##### [EXCLUDES regex [regex]] +##### [KEYWORDS keyword [keyword]] +##### [ATTRIBUTES attrib_spec [attrib_spec]] +##### [X-POT common_texts.pot] +##### [DESTINATION directory] +##### ) +##### +##### Where: +##### CATALOG determines the target file name (without pot suffix). +##### SOURCES can be specified by several options: +##### a) Do not specify anything +##### - all usual source files will be automatically searched. +##### b) Enter the directory name - for example, '.' or 'src' +##### - all the usual source files in the specified directory +##### and subdirectories will be searched. +##### c) Enter the mask - for example '*.cpp' +##### - all files with the specified mask will be searched. +##### d) Specify the name of the individual file. +##### The methods from b) to d) can be combined. +##### EXCLUDES determines which files are to be excluded from processing +##### COMMENT determines additional comment to extract by xgettext. +##### KEYWORDS determines additional keywords for xgettext. +##### Use "-" if is needed to disable default keywords. +##### ATTRIBUTES determines files and specification for extractattr: +##### source_spec:element,attribute[,context][[:element,attribute[,context]]...] +##### X-POT entries from common_texts.pot are not extracted +##### By default, "tde.pot" is searched for and used. +##### Use "-" to skip this. +##### DESTINATION determines directory to save translation template. +##### The destination directory is determined as follows: +##### a) Directory is specified as an argument. +##### b) The variable POT_SOURCE_DIR is set. +##### c) There is a 'translations' directory. +##### d) There is a 'po' directory. +##### +##### Note: +##### Editing the _files list inside foreach( ${_files} ) below in the +##### code is safe, because in CMake foreach parameters are evaluated +##### before the loop starts. Therefore, the changes in the list inside +##### the loop do not have an unwanted impact on the loop processing. +##### + +macro( tde_l10n_create_template ) + + unset( _catalog ) + unset( _sources ) + unset( _excludes ) + unset( _files ) + unset( _desktops ) + unset( _pots ) + unset( _dest ) + unset( _keywords_add ) + unset( _comment ) + unset( _attributes ) + unset( _exclude_pot ) + unset( _pot ) + unset( _directive ) + set( _var _catalog ) + set( _keywords_c_default "i18n" "i18n:1,2" "tr2i18n" "tr2i18n:1,2" "I18N_NOOP" "I18N_NOOP2" ) + set( _keywords_desktop_default "Description" "ExtraNames" "X-TDE-Submenu" ) + + foreach( _arg ${ARGN} ) + + # found directive "CATALOG" + if( "+${_arg}" STREQUAL "+CATALOG" ) + unset( _catalog ) + set( _var _catalog ) + set( _directive 1 ) + endif( ) + + # found directive "SOURCES" + if( "+${_arg}" STREQUAL "+SOURCES" ) + unset( _sources ) + set( _var _sources ) + set( _directive 1 ) + endif( ) + + # found directive "EXCLUDES" + if( "+${_arg}" STREQUAL "+EXCLUDES" ) + unset( _excludes ) + set( _var _excludes ) + set( _directive 1 ) + endif( ) + + # found directive "DESTINATION" + if( "+${_arg}" STREQUAL "+DESTINATION" ) + unset( _dest ) + set( _var _dest ) + set( _directive 1 ) + endif( ) + + # found directive "COMMENT" + if( "+${_arg}" STREQUAL "+COMMENT" ) + unset( _comment ) + set( _var _comment ) + set( _directive 1 ) + endif( ) + + # found directive "KEYWORDS" + if( "+${_arg}" STREQUAL "+KEYWORDS" ) + unset( _keywords_add ) + set( _var _keywords_add ) + set( _directive 1 ) + endif( ) + + # found directive "ATTRIBUTES" + if( "+${_arg}" STREQUAL "+ATTRIBUTES" ) + unset( _attributes ) + set( _var _attributes ) + set( _directive 1 ) + endif( ) + + # found directive "X-POT" + if( "+${_arg}" STREQUAL "+X-POT" ) + unset( _exclude_pot ) + set( _var _exclude_pot ) + set( _directive 1 ) + endif( ) + + # collect data + if( _directive ) + unset( _directive ) + elseif( _var ) + list( APPEND ${_var} ${_arg} ) + endif( ) + + endforeach( ) + + # verify catalog + if( NOT _catalog ) + tde_message_fatal( "the name of the translation catalog is not defined" ) + endif( ) + + # determine the destination directory + if( NOT _dest ) + if( POT_SOURCE_DIR ) + set( _dest ${POT_SOURCE_DIR} ) + elseif( EXISTS "${MASTER_SOURCE_DIR}/translations" ) + set( _dest "${MASTER_SOURCE_DIR}/translations/" ) + elseif( EXISTS "${MASTER_SOURCE_DIR}/po" ) + set( _dest "${MASTER_SOURCE_DIR}/po/" ) + else( ) + tde_message_fatal( "cannot determine destination directory" ) + endif( ) + endif( ) + if( ${_dest} MATCHES "[^/]$" ) + set( _dest "${_dest}/" ) + endif( ) + if( ${_dest} MATCHES "^[^/]" ) + set( _dest "${CMAKE_CURRENT_SOURCE_DIR}/${_dest}" ) + endif( ) + + get_filename_component( _potFilename "${_dest}${_catalog}.pot" ABSOLUTE ) + file( RELATIVE_PATH _potFilename ${CMAKE_SOURCE_DIR} ${_potFilename} ) + message( STATUS "Create translation template ${_potFilename}" ) + + # verify sources + if( NOT _sources AND NOT _attributes ) + # add current directory + list( APPEND _sources "." ) + endif( ) + foreach( _src ${_sources} ) + + # add all source files from directory + if( IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${_src} ) + if( ${_src} STREQUAL "." ) + set( _dir "${CMAKE_CURRENT_SOURCE_DIR}" ) + else( ) + set( _dir "${CMAKE_CURRENT_SOURCE_DIR}/${_src}" ) + endif( ) + file( GLOB_RECURSE _add_files + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + ${_dir}/*.c + ${_dir}/*.cc + ${_dir}/*.cpp + ${_dir}/*.h + ${_dir}/*.kcfg + ${_dir}/*.rc + ${_dir}/*.ui + ) + list( SORT _add_files ) + list( APPEND _files ${_add_files} ) + + # add files by the specified mask + elseif( ${_src} MATCHES "(\\*|\\?)" ) + file( GLOB_RECURSE _add_files + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/${_src} + ) + list( SORT _add_files ) + list( APPEND _files ${_add_files} ) + + # add a individual file + elseif( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_src} ) + list( APPEND _files ${_src} ) + endif( ) + + endforeach( ) + + # filter files by excludes + if( _excludes ) + foreach( _src ${_files} ) + foreach( _exclude ${_excludes} ) + if( ${_src} MATCHES ${_exclude} ) + list( REMOVE_ITEM _files ${_src} ) + endif( ) + endforeach( ) + endforeach( ) + endif( ) + if( NOT _files AND NOT _attributes ) + tde_message_fatal( "no source files found" ) + endif( ) + + # prepare x-pot + if( NOT _exclude_pot ) + set( _exclude_pot "${TDE_COMMON_TEXTS_POT}" ) + endif( ) + if( "${_exclude_pot}" STREQUAL "-" ) + unset( _exclude_pot ) + else( ) + if( ${_exclude_pot} MATCHES "^[^/]" ) + set( _exclude_pot "${CMAKE_CURRENT_SOURCE_DIR}/${_exclude_pot}" ) + endif( ) + set( _exclude_pot "-x${_exclude_pot}" ) + endif( ) + + # prepare comment + if( NOT "${_comment}" STREQUAL "" ) + if( "${_comment}" STREQUAL "-" OR "${_comment}" STREQUAL "all" ) + set( _comment "-c" ) + else( ) + set( _comment "-c${_comment}" ) + endif( ) + endif( ) + + # prepare keywords + unset( _keywords_c ) + unset( _keywords_desktop ) + foreach( _keyword ${_keywords_c_default} ${_keywords_add} ) + if( "${_keyword}" STREQUAL "-" ) + unset( _keywords_c ) + unset( _keyword ) + endif( ) + list( APPEND _keywords_c "-k${_keyword}" ) + endforeach( ) + foreach( _keyword ${_keywords_desktop_default} ${_keywords_add} ) + if( "${_keyword}" STREQUAL "-" ) + unset( _keywords_desktop ) + unset( _keyword ) + endif( ) + list( APPEND _keywords_desktop "-k${_keyword}" ) + endforeach( ) + + # prepare resource files *.kcfg, *.rc and *.ui + foreach( _src ${_files} ) + if( ${_src} MATCHES "\\.(kcfg|rc|ui)(\\.cmake)?$" ) + set( _src_index 0 ) + set( _src_l10n "${_src}.tde_l10n" ) + list( FIND _files "${_src_l10n}" _src_file_index ) + while( "${_src_file_index}" GREATER -1 ) + set( _src_l10n "${_src}.tde_l10n${_src_index}" ) + list( FIND _files "${_src_l10n}" _src_file_index ) + math( EXPR _src_index "${_src_index}+1" ) + endwhile( ) + tde_l10n_prepare_xml( SOURCE ${_src} TARGET ${_src_l10n} ) + list( REMOVE_ITEM _files ${_src} ) + list( APPEND _files "${_src_l10n}" ) + endif( ) + endforeach( ) + + # prepare attributes + if( _attributes ) + foreach( _attrib ${_attributes} ) + if( ${_attrib} MATCHES "^([^:]+):(.+)$" ) + string( REGEX REPLACE "^([^:]+):(.+)$" "\\1" _attrib_glob ${_attrib} ) + string( REGEX REPLACE "^([^:]+):(.+)$" "\\2" _attrib_spec ${_attrib} ) + file( GLOB_RECURSE _attrib_files + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/${_attrib_glob} + ) + if( _excludes ) + foreach( _src ${_attrib_files} ) + foreach( _exclude ${_excludes} ) + if( ${_src} MATCHES ${_exclude} ) + list( REMOVE_ITEM _attrib_files ${_src} ) + endif( ) + endforeach( ) + endforeach( ) + endif( ) + if( _attrib_files ) + list( SORT _attrib_files ) + string( REGEX MATCHALL "[^:]+" _attrib_spec "${_attrib_spec}" ) + foreach( _src ${_attrib_files} ) + set( _src_index 0 ) + set( _src_l10n "${_src}.tde_l10n" ) + list( FIND _files "${_src_l10n}" _src_file_index ) + while( "${_src_file_index}" GREATER -1 ) + set( _src_l10n "${_src}.tde_l10n${_src_index}" ) + list( FIND _files "${_src_l10n}" _src_file_index ) + math( EXPR _src_index "${_src_index}+1" ) + endwhile( ) + tde_l10n_prepare_xmlattr( + SOURCE ${_src} + TARGET ${_src_l10n} + ATTRIBUTES ${_attrib_spec} + ) + list( APPEND _files "${_src_l10n}" ) + endforeach( ) + endif( ) + endif( ) + endforeach( ) + endif( ) + + # prepare tips + foreach( _src ${_files} ) + if( ${_src} MATCHES "(^|/)tips$" ) + tde_l10n_preparetips( ${_src} ) + list( REMOVE_ITEM _files ${_src} ) + list( APPEND _files "${_src}.tde_l10n" ) + endif( ) + endforeach( ) + + # prepare documentation + foreach( _src ${_files} ) + if( ${_src} MATCHES "\\.(ad|adoc|docbook|[1-8])(\\.cmake)?$" ) + if( ${_src} MATCHES "\\.(ad|adoc)(\\.cmake)?$" ) + set( _doc_format "asciidoc" ) + elseif( ${_src} MATCHES "\\.(docbook)(\\.cmake)?$" ) + set( _doc_format "docbook" ) + elseif( ${_src} MATCHES "\\.([1-8])(\\.cmake)?$" ) + set( _doc_format "man" ) + else( ) + set( _doc_format "text" ) + endif( ) + execute_process( + COMMAND ${PO4A_GETTEXTIZE_EXECUTABLE} + -f ${_doc_format} -m ${_src} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE _potDoc + ) + if( _potDoc ) + string( REPLACE "Content-Type: text/plain; charset=CHARSET" "Content-Type: text/plain; charset=UTF-8" _potDoc "${_potDoc}" ) + string( REPLACE "Content-Transfer-Encoding: ENCODING" "Content-Transfer-Encoding: 8bit" _potDoc "${_potDoc}" ) + file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/${_src}.tde_l10n "${_potDoc}" ) + list( APPEND _pots ${_src}.tde_l10n ) + endif( ) + list( REMOVE_ITEM _files ${_src} ) + endif( ) + endforeach( ) + + # pick desktop files *.desktop and *.protocol + foreach( _src ${_files} ) + if( ${_src} MATCHES "\\.(desktop|protocol)(\\.cmake)?$" ) + list( APPEND _desktops ${_src} ) + list( REMOVE_ITEM _files ${_src} ) + endif( ) + endforeach( ) + + # pick pot files *.pot + foreach( _src ${_files} ) + if( ${_src} MATCHES "\\.pot(\\.cmake)?(\\.tde_l10n)?$" ) + list( APPEND _pots ${_src} ) + list( REMOVE_ITEM _files ${_src} ) + endif( ) + endforeach( ) + + # add common translator info + if( _files ) + list( FIND _excludes "_translatorinfo" _translatorinfo_index ) + if( "${_translatorinfo_index}" LESS 0 ) + set( _translatorinfo + "i18n(\"NAME OF TRANSLATORS\", \"Your names\")\n" + "i18n(\"EMAIL OF TRANSLATORS\", \"Your emails\")\n" + ) + file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/_translatorinfo.tde_l10n ${_translatorinfo} ) + list( INSERT _files 0 "_translatorinfo.tde_l10n" ) + endif( ) + endif( ) + + # create translation template + if( _files ) + execute_process( + COMMAND ${KDE_XGETTEXT_EXECUTABLE} --foreign-user -C + ${_comment} ${_keywords_c} ${_exclude_pot} -o - ${_files} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE _pot + ) + + # set charset and encoding headers + if( _pot ) + string( REPLACE "Content-Type: text/plain; charset=CHARSET" "Content-Type: text/plain; charset=UTF-8" _pot "${_pot}" ) + string( REPLACE "Content-Transfer-Encoding: ENCODING" "Content-Transfer-Encoding: 8bit" _pot "${_pot}" ) + endif( ) + endif( ) + + # process desktop files + if( _desktops ) + # create translation template for desktop files + if( _pot ) + set( _withPotHeader "--omit-header" ) + else( ) + set( _withPotHeader "--foreign-user" ) + endif( ) + execute_process( + COMMAND ${XGETTEXT_EXECUTABLE} ${_withPotHeader} -L Desktop + ${_keywords_desktop} -o - ${_desktops} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE _potDesktop + ) + + # merge translation templates + if( _potDesktop ) + if( _pot ) + file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-pot.tmp "${_pot}" ) + file( APPEND ${CMAKE_CURRENT_SOURCE_DIR}/extracted-pot.tmp "${_potDesktop}" ) + execute_process( + COMMAND ${MSGUNIQ_EXECUTABLE} --use-first + INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-pot.tmp + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE _pot + ) + file( REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-pot.tmp ) + else( ) + set( _pot "${_potDesktop}" ) + + # set charset and encoding headers + string( REPLACE "Content-Type: text/plain; charset=CHARSET" "Content-Type: text/plain; charset=UTF-8" _pot "${_pot}" ) + string( REPLACE "Content-Transfer-Encoding: ENCODING" "Content-Transfer-Encoding: 8bit" _pot "${_pot}" ) + endif( ) + endif( ) + endif( ) + + # merge additional pot files + if( _pots ) + file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-pot.tmp "${_pot}" ) + execute_process( + COMMAND ${MSGCAT_EXECUTABLE} --use-first extracted-pot.tmp ${_pots} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE _pot + ) + file( REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-pot.tmp ) + + # set charset and encoding headers + string( REPLACE "Content-Type: text/plain; charset=CHARSET" "Content-Type: text/plain; charset=UTF-8" _pot "${_pot}" ) + string( REPLACE "Content-Transfer-Encoding: ENCODING" "Content-Transfer-Encoding: 8bit" _pot "${_pot}" ) + endif( ) + + # finalize translation template + if( _pot ) + + # update references for resources to original files and line numbers + list( FIND _files "extracted-rc.tde_l10n" _extractedRC_index ) + if( "${_extractedRC_index}" GREATER -1 + AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/extracted-rc.tde_l10n ) + file( READ "${CMAKE_CURRENT_SOURCE_DIR}/extracted-rc.tde_l10n" _extractedRC ) + string( REGEX REPLACE "[^\n]" "" _extractedRC_len "${_extractedRC}" ) + string( LENGTH "+${_extractedRC_len}" _extractedRC_len ) + set( _rcPos 0 ) + while( _rcPos LESS ${_extractedRC_len} ) + string( REGEX REPLACE "^([^\n]*)\n(.*)" "\\1" _rcLine "${_extractedRC}" ) + string( REGEX REPLACE "^([^\n]*)\n(.*)" "\\2" _extractedRC "${_extractedRC}" ) + math( EXPR _rcPos "${_rcPos}+1" ) + if( "${_rcLine}" MATCHES "^//i18n: file .* line [0-9]*$" ) + string( REGEX REPLACE "^//i18n: file (.*) line ([0-9]*)$" "\\1:\\2" _rcOrig ${_rcLine} ) + endif( ) + if( "${_rcLine}" MATCHES "^i18n\\(" AND _rcOrig ) + string( REGEX REPLACE "(^|\n)(#:.*) extracted-rc.tde_l10n:${_rcPos}( |\n)" "\\1\\2 ${_rcOrig}\\3" _pot "${_pot}" ) + unset( _rcOrig ) + endif( ) + endwhile( ) + endif( ) + + # update references for modified source files (".tde_l10n" extension) + string( REGEX REPLACE "\\.tde_l10n[0-9]*(:[0-9]+)" "\\1" _pot "${_pot}" ) + + # save translation template + if( EXISTS "${_dest}${_catalog}.pot" ) + file( READ "${_dest}${_catalog}.pot" _potOrig ) + else( ) + unset( _potOrig ) + endif( ) + if( _potOrig ) + string( REGEX REPLACE "\n\"POT-Creation-Date: [^\"]*\"\n" "" _potOrig "${_potOrig}" ) + string( REGEX REPLACE "\n\"POT-Creation-Date: [^\"]*\"\n" "" _potNew "${_pot}" ) + endif( ) + if( NOT _potOrig OR NOT "${_potNew}" STREQUAL "${_potOrig}" ) + file( WRITE "${_dest}${_catalog}.pot" "${_pot}" ) + endif( ) + + endif( _pot ) + + # cleanup + foreach( _file ${_files} ${_desktops} ${_pots} ) + if( "${_file}" MATCHES "\\.tde_l10n[0-9]*$" ) + file( REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/${_file} ) + endif( ) + endforeach( ) + +endmacro( ) + + +################################################# +##### +##### tde_l10n_preparetips +##### +##### Macro is used to prepare tips file for xgettext +##### + +macro( tde_l10n_preparetips _tips ) + + tde_l10n_prepare_xml( + SOURCE ${_tips} + TAGS html + C_FORMAT + PRESERVE entities line-wrap spaces-leading spaces-trailing spaces-multi + ) + +endmacro( ) + + +################################################# +##### +##### tde_l10n_prepare_xml +##### +##### The function is used to prepare XML file for xgettext. +##### The default settings are identical to extractrc. +##### + +function( tde_l10n_prepare_xml ) + + unset( _source ) + unset( _target ) + unset( _context ) + set( _skip_properties "database|associations|populationText" ) + set( _tags "[tT][eE][xX][tT]|title|string|whatsthis|tooltip|label" ) + set( _preserve "line-wrap" "lines-leading" "lines-multi" "spaces-leading" "spaces-trailing" "spaces-multi" ) + set( _no_c_format 1 ) + unset( _directive ) + set( _var _source ) + + foreach( _arg ${ARGN} ) + + # found directive "SOURCE" + if( "+${_arg}" STREQUAL "+SOURCE" ) + unset( _source ) + set( _var _source ) + set( _directive 1 ) + endif( ) + + # found directive "TARGET" + if( "+${_arg}" STREQUAL "+TARGET" ) + unset( _target ) + set( _var _target ) + set( _directive 1 ) + endif( ) + + # found directive "CONTEXT" + if( "+${_arg}" STREQUAL "+CONTEXT" ) + unset( _context ) + set( _var _context ) + set( _directive 1 ) + endif( ) + + # found directive "SKIP-PROPERTIES" + if( "+${_arg}" STREQUAL "+SKIP-PROPERTIES" ) + unset( _skip_properties ) + set( _var _skip_properties ) + set( _directive 1 ) + endif( ) + + # found directive "TAGS" + if( "+${_arg}" STREQUAL "+TAGS" ) + unset( _tags ) + set( _var _tags ) + set( _directive 1 ) + endif( ) + + # found directive "PRESERVE" + if( "+${_arg}" STREQUAL "+PRESERVE" ) + unset( _preserve ) + set( _var _preserve ) + set( _directive 1 ) + endif( ) + + # found directive "C_FORMAT" + if( "+${_arg}" STREQUAL "+C_FORMAT" ) + unset( _no_c_format ) + set( _directive 1 ) + endif( ) + + # found directive "NO_C_FORMAT" + if( "+${_arg}" STREQUAL "+NO_C_FORMAT" ) + set( _no_c_format 1 ) + set( _directive 1 ) + endif( ) + + # collect data + if( _directive ) + unset( _directive ) + elseif( _var ) + list( APPEND ${_var} ${_arg} ) + endif( ) + + endforeach( ) + + # verify source + if( NOT _source ) + tde_message_fatal( "no source XML file" ) + endif( ) + if( NOT IS_ABSOLUTE "${_source}" ) + set( _source "${CMAKE_CURRENT_SOURCE_DIR}/${_source}" ) + endif( ) + if( NOT _target ) + set( _target "${_source}.tde_l10n" ) + endif( ) + if( NOT IS_ABSOLUTE "${_target}" ) + set( _target "${CMAKE_CURRENT_SOURCE_DIR}/${_target}" ) + endif( ) + + # prepare tags to regexp + string( REPLACE ";" "|" _tags "${_tags}" ) + if( "${_skip_properties}" STREQUAL "-" ) + unset( _skip_properties ) + endif( ) + if( DEFINED _skip_properties ) + string( REPLACE ";" "|" _skip_properties "${_skip_properties}" ) + set( _tags "property|${_tags}" ) + endif( ) + + # read file + file( READ ${_source} _xml_data ) + string( REGEX REPLACE "[^\n]" "" _xml_len ${_xml_data} ) + string( LENGTH "+${_xml_len}" _xml_len ) + + # process lines + set( _xml_pos 0 ) + unset( _xml_l10n ) + unset( _xml_inside ) + unset( _xml_tag_empty ) + unset( _xml_skipped_prop ) + while( _xml_pos LESS ${_xml_len} ) + # pick line + string( REGEX REPLACE "^([^\n]*)\n(.*)" "\\1" _xml_line "${_xml_data}" ) + string( REGEX REPLACE "^([^\n]*)\n(.*)" "\\2" _xml_data "${_xml_data}" ) + math( EXPR _xml_pos "${_xml_pos}+1" ) + set( _xml_newline 1 ) + + # process tags on line + while( _xml_newline OR NOT "${_xml_line}" STREQUAL "" ) + unset( _xml_newline ) + unset( _xml_line_prefix ) + unset( _xml_line_suffix ) + unset( _xml_line_rest ) + if( NOT _xml_inside ) + if( _xml_skipped_prop AND "${_xml_line}" MATCHES "</property>" ) + unset( _xml_skipped_prop ) + string( REGEX MATCH "</property>(.*)" _xml_line "${_xml_line}" ) + string( REGEX REPLACE "^</property>(.*)" "\\1" _xml_line "${_xml_line}" ) + endif( ) + if( NOT _xml_skipped_prop AND "${_xml_line}" MATCHES "<(${_tags})([ \t][^>]*)*>" ) + string( REGEX MATCH "<(${_tags})([ \t][^>]*)*>(.*)" _xml_line "${_xml_line}" ) + string( REGEX MATCH "^<(${_tags})([ \t][^>]*)*>" _xml_attr "${_xml_line}" ) + string( REGEX REPLACE "^<(${_tags})([ \t][^>]*)*>(.*)" "\\3" _xml_line "${_xml_line}" ) + if( "${_xml_attr}" MATCHES "^<property([ \t][^>]*)*>" AND DEFINED _skip_properties ) + if( "${_xml_attr}" MATCHES "[ \t]name=\"(${_skip_properties})\"" ) + set( _xml_skipped_prop 1 ) + endif( ) + set( _xml_line_rest "${_xml_line}" ) + set( _xml_line "" ) + else( ) + set( _xml_inside 1 ) + set( _xml_context "${_context}" ) + if( "${_xml_attr}" MATCHES "[ \t]context=\"([^\"]*)\"" ) + string( REGEX REPLACE ".* context=\"([^\"]*)\".*" "\\1" _xml_context "${_xml_attr}" ) + endif( ) + set( _xml_line_prefix "i18n(" ) + if( _no_c_format ) + set( _xml_line_prefix "${_xml_line_prefix}/* xgettext: no-c-format */" ) + endif( ) + if( _xml_context ) + set( _xml_line_prefix "${_xml_line_prefix}\"${_xml_context}\", " ) + endif( ) + set( _xml_tag_empty 1 ) + endif( ) + else( ) + set( _xml_line "" ) + endif( ) + endif( ) + + if( _xml_inside ) + if( "${_xml_line}" MATCHES "</(${_tags})>" ) + unset( _xml_inside ) + string( REGEX REPLACE "</(${_tags})>(.*)" "\\2" _xml_line_rest "${_xml_line}" ) + string( REGEX REPLACE "</(${_tags})>(.*)" "" _xml_line "${_xml_line}" ) + set( _xml_line_suffix ");" ) + endif( ) + + string( REGEX REPLACE "\\\\" "\\\\\\\\" _xml_line "${_xml_line}" ) + string( REGEX REPLACE "\\\"" "\\\\\"" _xml_line "${_xml_line}" ) + string( REGEX REPLACE "\t" "\\\\t" _xml_line "${_xml_line}" ) + if( NOT ";${_preserve};" MATCHES ";entities;" ) + string( REGEX REPLACE "<" "<" _xml_line "${_xml_line}" ) + string( REGEX REPLACE ">" ">" _xml_line "${_xml_line}" ) + string( REGEX REPLACE "&" "&" _xml_line "${_xml_line}" ) + endif( ) + if( NOT ";${_preserve};" MATCHES ";spaces-leading;" ) + string( REGEX REPLACE "^ +" "" _xml_line "${_xml_line}" ) + endif( ) + if( NOT ";${_preserve};" MATCHES ";spaces-trailing;" ) + string( REGEX REPLACE " +$" "" _xml_line "${_xml_line}" ) + endif( ) + if( NOT ";${_preserve};" MATCHES ";spaces-multi;" ) + string( REGEX REPLACE " +" " " _xml_line "${_xml_line}" ) + endif( ) + + if( _xml_inside ) + if( ";${_preserve};" MATCHES ";line-wrap;" ) + if( NOT "${_xml_line}" STREQUAL "" + OR ( ";${_preserve};" MATCHES ";lines-leading;" AND _xml_tag_empty ) + OR ( ";${_preserve};" MATCHES ";lines-multi;" AND NOT _xml_tag_empty ) ) + set( _xml_line "${_xml_line}\\n" ) + endif( ) + elseif( NOT "${_xml_line}" STREQUAL "" AND NOT _xml_tag_empty ) + set( _xml_line " ${_xml_line}" ) + endif( ) + endif( ) + if( NOT "${_xml_line}" STREQUAL "" ) + unset( _xml_tag_empty ) + endif( ) + endif( ) + + # drop empty tag on single line + if( _xml_line_prefix AND _xml_line_suffix AND _xml_tag_empty ) + # skip empty string for translation + + # add current tag to output + else( ) + set( _xml_l10n "${_xml_l10n}${_xml_line_prefix}" ) + if( NOT "${_xml_line}" STREQUAL "" OR ( _xml_line_suffix AND _xml_tag_empty ) ) + set( _xml_l10n "${_xml_l10n}\"${_xml_line}\"" ) + endif( ) + set( _xml_l10n "${_xml_l10n}${_xml_line_suffix}" ) + endif( ) + + # take the rest of the line for processing + set( _xml_line "${_xml_line_rest}" ) + endwhile( ) + set( _xml_l10n "${_xml_l10n}\n" ) + endwhile( ) + + # write file + file( WRITE ${_target} "${_xml_l10n}" ) + +endfunction( ) + + +################################################# +##### +##### tde_l10n_prepare_xmlattr +##### +##### The function is used to prepare attributes in XML file +##### for xgettext, comparable to extractattr. +##### + +function( tde_l10n_prepare_xmlattr ) + + unset( _source ) + unset( _target ) + unset( _context ) + unset( _attribs ) + unset( _directive ) + set( _preserve "line-wrap" "lines-leading" "spaces-leading" "spaces-trailing" "spaces-multi" ) + set( _var _source ) + + foreach( _arg ${ARGN} ) + + # found directive "SOURCE" + if( "+${_arg}" STREQUAL "+SOURCE" ) + unset( _source ) + set( _var _source ) + set( _directive 1 ) + endif( ) + + # found directive "TARGET" + if( "+${_arg}" STREQUAL "+TARGET" ) + unset( _target ) + set( _var _target ) + set( _directive 1 ) + endif( ) + + # found directive "CONTEXT" + if( "+${_arg}" STREQUAL "+CONTEXT" ) + unset( _context ) + set( _var _context ) + set( _directive 1 ) + endif( ) + + # found directive "ATTRIBUTES" + if( "+${_arg}" STREQUAL "+ATTRIBUTES" ) + unset( _attribs ) + set( _var _attribs ) + set( _directive 1 ) + endif( ) + + # found directive "PRESERVE" + if( "+${_arg}" STREQUAL "+PRESERVE" ) + unset( _preserve ) + set( _var _preserve ) + set( _directive 1 ) + endif( ) + + # collect data + if( _directive ) + unset( _directive ) + elseif( _var ) + list( APPEND ${_var} ${_arg} ) + endif( ) + + endforeach( ) + + # verify source + if( NOT _source ) + tde_message_fatal( "no source XML file" ) + endif( ) + if( NOT IS_ABSOLUTE "${_source}" ) + set( _source "${CMAKE_CURRENT_SOURCE_DIR}/${_source}" ) + endif( ) + if( NOT _target ) + set( _target "${_source}.tde_l10n" ) + endif( ) + if( NOT IS_ABSOLUTE "${_target}" ) + set( _target "${CMAKE_CURRENT_SOURCE_DIR}/${_target}" ) + endif( ) + + # prepare tags to regexp + if( NOT _attribs ) + tde_message_fatal( "no attributes specified" ) + endif( ) + unset( _tags ) + foreach( _attrib ${_attribs} ) + string( REGEX REPLACE "^([^,]+),.*" "\\1" _tag "${_attrib}" ) + list( APPEND _tags "${_tag}" ) + endforeach( ) + list( REMOVE_DUPLICATES _tags ) + string( REPLACE ";" "|" _tags "${_tags}" ) + + # read file + file( READ ${_source} _xml_data ) + string( REGEX REPLACE "[^\n]" "" _xml_len ${_xml_data} ) + string( LENGTH "+${_xml_len}" _xml_len ) + + # process lines + set( _xml_pos 0 ) + unset( _xml_l10n ) + unset( _xml_inside_tag ) + unset( _xml_inside_attrib ) + unset( _xml_attrib_empty ) + while( _xml_pos LESS ${_xml_len} ) + # pick line + string( REGEX REPLACE "^([^\n]*)\n(.*)" "\\1" _xml_line "${_xml_data}" ) + string( REGEX REPLACE "^([^\n]*)\n(.*)" "\\2" _xml_data "${_xml_data}" ) + math( EXPR _xml_pos "${_xml_pos}+1" ) + set( _xml_newline 1 ) + + # process tags on line + while( _xml_newline OR NOT "${_xml_line}" STREQUAL "" ) + unset( _xml_line_rest ) + if( NOT _xml_inside_tag ) + if( "${_xml_line}" MATCHES "<(${_tags})([ \t\n][^>]*|$)" ) + set( _xml_inside_tag 1 ) + string( REGEX MATCH "<(${_tags})([ \t\n][^>]*|$)(.*)" _xml_line "${_xml_line}" ) + string( REGEX REPLACE "^<(${_tags})[ \t\n]*.*" "\\1" _xml_tag "${_xml_line}" ) + string( REGEX REPLACE "^<(${_tags})[ \t\n]*" "" _xml_line "${_xml_line}" ) + unset( _tag_attribs ) + foreach( _attrib ${_attribs} ) + if( "${_attrib}" MATCHES "^${_xml_tag}," ) + string( REGEX REPLACE "^([^,]+),([^,]+),?(.*)" "\\2" _attrib "${_attrib}" ) + list( APPEND _tag_attribs "${_attrib}" ) + endif( ) + endforeach( ) + string( REPLACE ";" "|" _tag_attribs "${_tag_attribs}" ) + unset( _xml_inside_attrib ) + else( ) + set( _xml_line "" ) + endif( ) + endif( ) + + if( _xml_inside_tag ) + if( "${_xml_line}" MATCHES "^(([ \t]*[^>=]+=\"[^\"]*\")*)[ \t]*/?>" ) + unset( _xml_inside_tag ) + string( REGEX REPLACE "^(([ \t]*[^>=]+=\"[^\"]*\")*)[ \t]*/?>(.*)" "\\3" _xml_line_rest "${_xml_line}" ) + string( REGEX REPLACE "^(([ \t]*[^>=]+=\"[^\"]*\")*)[ \t]*/?>(.*)" "\\1" _xml_line "${_xml_line}" ) + endif( ) + + # process attribs on line + set( _xml_attrib_line "${_xml_line}" ) + while( _xml_newline OR NOT "${_xml_attrib_line}" STREQUAL "" ) + unset( _xml_newline ) + unset( _xml_line_prefix ) + unset( _xml_line_suffix ) + unset( _xml_attrib_line_rest ) + + if( NOT _xml_inside_attrib ) + if( "${_xml_attrib_line}" MATCHES "(^|[ \t]+)(${_tag_attribs})=\"" ) + set( _xml_inside_attrib 1 ) + string( REGEX MATCH "(^|[ \t]+)(${_tag_attribs})=\"(.*)" _xml_attrib_line "${_xml_attrib_line}" ) + string( REGEX REPLACE "^[ \t]*(${_tag_attribs})=\".*" "\\1" _xml_attrib "${_xml_attrib_line}" ) + string( REGEX REPLACE "^[ \t]*(${_tag_attribs})=\"" "" _xml_attrib_line "${_xml_attrib_line}" ) + set( _xml_context "${_context}" ) + foreach( _attrib ${_attribs} ) + if( "${_attrib}" MATCHES "^${_xml_tag},${_xml_attrib}," ) + string( REGEX REPLACE "^([^,]+),([^,]+),?(.*)" "\\3" _xml_context "${_attrib}" ) + endif( ) + endforeach( ) + set( _xml_line_prefix "i18n(" ) + if( _xml_context ) + set( _xml_line_prefix "${_xml_line_prefix}\"${_xml_context}\", " ) + endif( ) + set( _xml_attrib_empty 1 ) + else( ) + set( _xml_attrib_line "" ) + endif( ) + endif( ) + + if( _xml_inside_attrib ) + if( "${_xml_attrib_line}" MATCHES "\"" ) + unset( _xml_inside_attrib ) + string( REGEX REPLACE "\"(.*)" "\\1" _xml_attrib_line_rest "${_xml_attrib_line}" ) + string( REGEX REPLACE "\"(.*)" "" _xml_attrib_line "${_xml_attrib_line}" ) + set( _xml_line_suffix ");" ) + endif( ) + + string( REGEX REPLACE "\\\\" "\\\\\\\\" _xml_attrib_line "${_xml_attrib_line}" ) + string( REGEX REPLACE "\\\"" "\\\\\"" _xml_attrib_line "${_xml_attrib_line}" ) + string( REGEX REPLACE "\t" "\\\\t" _xml_attrib_line "${_xml_attrib_line}" ) + if( NOT ";${_preserve};" MATCHES ";entities;" ) + string( REGEX REPLACE "<" "<" _xml_attrib_line "${_xml_attrib_line}" ) + string( REGEX REPLACE ">" ">" _xml_attrib_line "${_xml_attrib_line}" ) + string( REGEX REPLACE "&" "&" _xml_attrib_line "${_xml_attrib_line}" ) + endif( ) + if( NOT ";${_preserve};" MATCHES ";spaces-leading;" ) + string( REGEX REPLACE "^ +" "" _xml_attrib_line "${_xml_attrib_line}" ) + endif( ) + if( NOT ";${_preserve};" MATCHES ";spaces-trailing;" ) + string( REGEX REPLACE " +$" "" _xml_attrib_line "${_xml_attrib_line}" ) + endif( ) + if( NOT ";${_preserve};" MATCHES ";spaces-multi;" ) + string( REGEX REPLACE " +" " " _xml_attrib_line "${_xml_attrib_line}" ) + endif( ) + + if( NOT "${_xml_inside_attrib}" STREQUAL "" ) + if( ";${_preserve};" MATCHES ";line-wrap;" ) + if( ";${_preserve};" MATCHES ";lines-leading;" + OR NOT "${_xml_attrib_line}" STREQUAL "" OR NOT _xml_attrib_empty ) + set( _xml_attrib_line "${_xml_attrib_line}\\n" ) + endif( ) + elseif( NOT "${_xml_attrib_line}" STREQUAL "" AND NOT _xml_attrib_empty ) + set( _xml_attrib_line " ${_xml_attrib_line}" ) + endif( ) + endif( ) + if( NOT "${_xml_attrib_line}" STREQUAL "" ) + unset( _xml_attrib_empty ) + endif( ) + endif( ) + + # drop empty attrib on single line + if( _xml_line_prefix AND _xml_line_suffix AND _xml_attrib_empty ) + # skip empty translation + + # add current attrib to output + else( ) + set( _xml_l10n "${_xml_l10n}${_xml_line_prefix}" ) + if( NOT "${_xml_attrib_line}" STREQUAL "" OR ( _xml_line_suffix AND _xml_attrib_empty ) ) + set( _xml_l10n "${_xml_l10n}\"${_xml_attrib_line}\"" ) + endif( ) + set( _xml_l10n "${_xml_l10n}${_xml_line_suffix}" ) + endif( ) + + # take the rest of the line for processing + set( _xml_attrib_line "${_xml_attrib_line_rest}" ) + endwhile( ) + endif( ) + + # take the rest of the line for processing + unset( _xml_newline ) + set( _xml_line "${_xml_line_rest}" ) + endwhile( ) + set( _xml_l10n "${_xml_l10n}\n" ) + endwhile( ) + + # write file + file( WRITE ${_target} "${_xml_l10n}" ) + +endfunction( ) diff --git a/qnetchess/cmake/modules/TDEMacros.cmake b/qnetchess/cmake/modules/TDEMacros.cmake new file mode 100644 index 00000000..13fa54a0 --- /dev/null +++ b/qnetchess/cmake/modules/TDEMacros.cmake @@ -0,0 +1,2172 @@ +################################################# +# +# (C) 2010-2012 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# (C) 2011-2012 Timothy Pearson +# kb9vqf (AT) pearsoncomputing.net +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include( KDE3Macros ) # we will need this module for a while +include( CheckCXXCompilerFlag ) + + +################################################# +##### +##### tde_message_fatal + +macro( tde_message_fatal ) + message( FATAL_ERROR + "#################################################\n" + " ${ARGV}\n" + "#################################################" ) +endmacro( tde_message_fatal ) + + +################################################# +##### +##### tde_get_arg( <ARG_NAME> <COUNT> <RETURN> <REST> <ARGS...> ) +##### ARG_NAME(string): name of an argument to find in ARGS +##### COUNT(number): argument dimension, a number of items returned in RETURN +##### RETURN(list ref): items returned for argument as they found in ARGS +##### REST(list ref): rest of items except argument name and items returned in RETURN +##### ARGS(list): source list of arguments + +macro( tde_get_arg ARG_NAME COUNT RETURN REST ) + unset( ${RETURN} ) + unset( ${REST} ) + list( APPEND ${REST} ${ARGN} ) + list( FIND ${REST} ${ARG_NAME} _arg_idx) + if( NOT ${_arg_idx} EQUAL -1 ) + list( REMOVE_AT ${REST} ${_arg_idx} ) + set( _i 0 ) + while( ${_i} LESS ${COUNT} ) + list( GET ${REST} ${_arg_idx} _arg ) + list( REMOVE_AT ${REST} ${_arg_idx} ) + list( APPEND ${RETURN} ${_arg} ) + math( EXPR _i "${_i} + 1" ) + endwhile() + endif() +endmacro( tde_get_arg ) + + +################################################ +##### +##### tde_execute_process( <ARGS...> [MESSAGE <MSG>] ) +##### MSG: fatal error message (standard message will be written if not supplied) +##### ARGS: execute_process arguments + +macro( tde_execute_process ) + tde_get_arg( MESSAGE 1 _message _rest_args ${ARGV} ) + tde_get_arg( RESULT_VARIABLE 1 _result_variable _tmp ${_rest_args} ) + tde_get_arg( COMMAND 1 _command _tmp ${_rest_args} ) + tde_get_arg( OUTPUT_VARIABLE 1 _output_variable _tmp ${_rest_args} ) + tde_get_arg( CACHE 3 _cache _rest_args2 ${_rest_args} ) + + # handle optional FORCE parameter + if( DEFINED _cache ) + list( GET _cache 2 _tmp ) + if( _tmp STREQUAL FORCE ) + set( _rest_args ${_rest_args2} ) + else() + tde_get_arg( CACHE 2 _cache _rest_args ${_rest_args} ) + endif() + endif() + + if( NOT DEFINED _result_variable ) + list( APPEND _rest_args RESULT_VARIABLE _exec_result ) + set( _result_variable _exec_result ) + endif() + + execute_process( ${_rest_args} ) + + if( DEFINED _output_variable AND DEFINED _cache ) + set( ${_output_variable} ${${_output_variable}} CACHE ${_cache} ) + endif() + + if( ${_result_variable} ) + if( DEFINED _message ) + tde_message_fatal( ${_message} ) + else() + if( ${${_result_variable}} MATCHES "^[0-9]+$" ) + set( ${_result_variable} "status ${${_result_variable}} returned!" ) + endif() + tde_message_fatal( "Error executing '${_command}': ${${_result_variable}}" ) + endif() + endif() +endmacro( tde_execute_process ) + + +if( DEFINED MASTER_SOURCE_DIR ) + return( ) +endif( ) +########### slave part ends here ############### + + +################################################ +##### +##### tde_install_icons( <icons...> THEME <svgicons> DESTINATION <destdir> ) +##### default theme: hicolor +##### default destination: ${SHARE_INSTALL_DIR}/icons + +macro( tde_install_icons ) + tde_get_arg( DESTINATION 1 _dest _args ${ARGV} ) + tde_get_arg( THEME 1 _req_theme _icons ${_args} ) + + #defaults + if( NOT _icons ) + set( _icons "*" ) + endif( NOT _icons ) + if( NOT _dest ) + set( _dest "${ICON_INSTALL_DIR}" ) + endif( NOT _dest ) + + foreach( _icon ${_icons} ) + unset( _theme ) # clearing + + file(GLOB _icon_files *-${_icon}.png *-${_icon}.mng _icon_files *-${_icon}.svg* ) + foreach( _icon_file ${_icon_files} ) + # FIXME need a review + string( REGEX MATCH "^.*/([a-zA-Z][a-zA-Z])([0-9a-zA-Z]+)\\-([a-z]+)\\-([^/]+)$" _dummy "${_icon_file}" ) + set( _type "${CMAKE_MATCH_1}" ) + set( _size "${CMAKE_MATCH_2}" ) + set( _group "${CMAKE_MATCH_3}" ) + set( _name "${CMAKE_MATCH_4}" ) + + # we must ignore invalid icon names + if( _type AND _size AND _group AND _name ) + + # autodetect theme + if( NOT _req_theme ) + unset( _theme ) + if( "${_type}" STREQUAL "cr" ) + set( _theme crystalsvg ) + elseif( "${_type}" STREQUAL "lo" ) + set( _theme locolor ) + endif( "${_type}" STREQUAL "cr" ) + # defaulting + if( NOT _theme ) + set( _theme hicolor ) + endif( NOT _theme ) + else( NOT _req_theme ) + set( _theme ${_req_theme} ) + endif( NOT _req_theme ) + + # fix "group" name + if( "${_group}" STREQUAL "mime" ) + set( _group "mimetypes" ) + endif( "${_group}" STREQUAL "mime" ) + if( "${_group}" STREQUAL "filesys" ) + set( _group "places" ) + endif( "${_group}" STREQUAL "filesys" ) + if( "${_group}" STREQUAL "category" ) + set( _group "categories" ) + endif( "${_group}" STREQUAL "category" ) + if( "${_group}" STREQUAL "device" ) + set( _group "devices" ) + endif( "${_group}" STREQUAL "device" ) + if( "${_group}" STREQUAL "app" ) + set( _group "apps" ) + endif( "${_group}" STREQUAL "app" ) + if( "${_group}" STREQUAL "action" ) + set( _group "actions" ) + endif( "${_group}" STREQUAL "action" ) + + if( "${_size}" STREQUAL "sc" ) + install( FILES ${_icon_file} DESTINATION ${_dest}/${_theme}/scalable/${_group}/ RENAME ${_name} ) + else( "${_size}" STREQUAL "sc" ) + install( FILES ${_icon_file} DESTINATION ${_dest}/${_theme}/${_size}x${_size}/${_group}/ RENAME ${_name} ) + endif( "${_size}" STREQUAL "sc" ) + + endif( _type AND _size AND _group AND _name ) + + endforeach( _icon_file ) + endforeach( _icon ) + +endmacro( tde_install_icons ) + + +################################################# +##### +##### tde_add_lut( <source> <result> [depends] ) +##### default depends: source + +macro( tde_add_lut _src _lut _dep ) + set( create_hash_table ${CMAKE_SOURCE_DIR}/kjs/create_hash_table ) + if( NOT _dep ) + set( _dep ${_src} ) + endif( NOT _dep ) + add_custom_command( OUTPUT ${_lut} + COMMAND perl ARGS ${create_hash_table} ${CMAKE_CURRENT_SOURCE_DIR}/${_src} -i > ${_lut} + DEPENDS ${_src} ) + set_source_files_properties( ${_dep} PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_lut} ) + unset( _dep ) +endmacro( tde_add_lut ) + + +################################################# +##### +##### tde_add_luts( <sources...> ) + +macro( tde_add_luts ) + foreach( _src ${ARGV} ) + get_filename_component( _lut ${_src} NAME_WE ) + set( _lut "${_lut}.lut.h" ) + tde_add_lut( ${_src} ${_lut} ${_src} ) + endforeach( _src ) +endmacro( tde_add_luts ) + + +################################################# +##### +##### tde_file_to_cpp( <source> <destination> <variable> ) + +macro( tde_file_to_cpp _src _dst _var ) + if( IS_ABSOLUTE ${_dst} ) + set( dst ${_dst} ) + else( ) + set( dst "${CMAKE_CURRENT_BINARY_DIR}/${_dst}" ) + endif( ) + file( READ ${_src} text ) + string( REGEX REPLACE "\n" "\\\\n\"\n\"" text "${text}" ) + set( text "/* Generated by CMake */\n\nconst char *${_var} = \n\n\"${text}\";\n" ) + string( REGEX REPLACE "\n\"\";\n$" ";\n" text "${text}" ) + file( WRITE ${dst} "${text}" ) +endmacro( ) + + +################################################# +##### +##### tde_get_library_filename( <var> <target> ) + +function( tde_get_library_filename _filename _target ) + get_target_property( _type ${_target} TYPE ) + if( "${_type}" MATCHES "_LIBRARY" ) + get_target_property( _output_prefix ${_target} PREFIX ) + if( "${_output_prefix}" STREQUAL "_output_prefix-NOTFOUND" ) + if( "${_type}" MATCHES "STATIC_" ) + set( _output_prefix "${CMAKE_STATIC_LIBRARY_PREFIX}" ) + elseif( "${_type}" MATCHES "SHARED_" ) + set( _output_prefix "${CMAKE_SHARED_LIBRARY_PREFIX}" ) + elseif( "${_type}" MATCHES "MODULE_" ) + set( _output_prefix "${CMAKE_SHARED_MODULE_PREFIX}" ) + else( ) + set( _output_prefix "" ) + endif( ) + endif( ) + get_target_property( _output_suffix ${_target} SUFFIX ) + if( "${_output_suffix}" STREQUAL "_output_suffix-NOTFOUND" ) + if( "${_type}" MATCHES "STATIC_" ) + set( _output_suffix "${CMAKE_STATIC_LIBRARY_SUFFIX}" ) + elseif( "${_type}" MATCHES "SHARED_" ) + set( _output_suffix "${CMAKE_SHARED_LIBRARY_SUFFIX}" ) + elseif( "${_type}" MATCHES "MODULE_" ) + set( _output_suffix "${CMAKE_SHARED_MODULE_SUFFIX}" ) + else( ) + set( _output_suffix "" ) + endif( ) + endif( ) + get_target_property( _output ${_target} OUTPUT_NAME ) + set( ${_filename} "${_output_prefix}${_output}${_output_suffix}" PARENT_SCOPE ) + else( ) + set( ${_filename} "" PARENT_SCOPE ) + endif( ) +endfunction( ) + + +################################################# +##### +##### tde_install_la_file( <target> <destination> ) + +macro( tde_install_la_file _target _destination ) + + tde_get_library_filename( _soname ${_target} ) + get_target_property( _target_release ${_target} RELEASE ) + if( _target_release ) + string( REPLACE "-${_target_release}" "" _soname_base "${_soname}" ) + else( ) + set( _soname_base ${_soname} ) + endif( ) + string( REGEX REPLACE "\\.so(\\.[0-9]+)*$" "" _laname "${_soname_base}" ) + set( _laname ${CMAKE_CURRENT_BINARY_DIR}/${_laname}.la ) + + file( WRITE ${_laname} +"# ${_laname} - a libtool library file, generated by cmake +# The name that we can dlopen(3). +dlname='${_soname}' +# Names of this library +library_names='${_soname} ${_soname} ${_soname_base}' +# The name of the static archive +old_library='' +# Libraries that this one depends upon. +dependency_libs='' +# Version information.\ncurrent=0\nage=0\nrevision=0 +# Is this an already installed library?\ninstalled=yes +# Should we warn about portability when linking against -modules?\nshouldnotlink=yes +# Files to dlopen/dlpreopen\ndlopen=''\ndlpreopen='' +# Directory that this library needs to be installed in: +libdir='${_destination}' +" ) + + install( FILES ${_laname} DESTINATION ${_destination} ) + +endmacro( tde_install_la_file ) + + +################################################# +##### +##### tde_add_ui_files + +macro( tde_add_ui_files _sources ) + foreach( _ui_file ${ARGN} ) + + get_filename_component( _ui_basename ${_ui_file} NAME_WE ) + get_filename_component( _ui_absolute_path ${_ui_file} ABSOLUTE ) + + list( APPEND ${_sources} ${_ui_basename}.cpp ) + + add_custom_command( OUTPUT ${_ui_basename}.h ${_ui_basename}.cpp + COMMAND ${CMAKE_COMMAND} + -DUIC_EXECUTABLE:FILEPATH=${UIC_EXECUTABLE} + -DTQT_REPLACE_SCRIPT:FILEPATH=${TQT_REPLACE_SCRIPT} + -DTDE_TQTPLUGINS_DIR:FILEPATH=${TDE_TQTPLUGINS_DIR} + -DMOC_EXECUTABLE:FILEPATH=${MOC_EXECUTABLE} + -DUI_FILE:FILEPATH=${_ui_absolute_path} + -DMASTER_SOURCE_DIR:FILEPATH=${CMAKE_SOURCE_DIR} + -DMASTER_BINARY_DIR:FILEPATH=${CMAKE_BINARY_DIR} + -P ${CMAKE_MODULE_PATH}/tde_uic.cmake + DEPENDS ${_ui_absolute_path} ) + + endforeach( _ui_file ) +endmacro( tde_add_ui_files ) + + +################################################# +##### +##### tde_moc + +macro( tde_moc _sources ) + foreach( _input_file ${ARGN} ) + + get_filename_component( _input_file "${_input_file}" ABSOLUTE ) + get_filename_component( _basename ${_input_file} NAME_WE ) + set( _output_file "${_basename}.moc.cpp" ) + add_custom_command( OUTPUT ${_output_file} + COMMAND + ${TMOC_EXECUTABLE} ${_input_file} -o ${_output_file} + DEPENDS + ${_input_file} ) + list( APPEND ${_sources} ${_output_file} ) + + endforeach( ) +endmacro( ) + + +################################################# +##### +##### tde_automoc + +macro( tde_automoc ) + foreach( _src_file ${ARGN} ) + + get_filename_component( _src_file "${_src_file}" ABSOLUTE ) + + if( EXISTS "${_src_file}" ) + + # read source file and check if have moc include + file( READ "${_src_file}" _src_content ) + string( REGEX MATCHALL "#include +[^ ]+\\.moc[\">]" _moc_includes "${_src_content}" ) + + # found included moc(s)? + if( _moc_includes ) + foreach( _moc_file ${_moc_includes} ) + + # extracting moc filename + string( REGEX MATCH "[^ <\"]+\\.moc" _moc_file "${_moc_file}" ) + set( _moc_file "${CMAKE_CURRENT_BINARY_DIR}/${_moc_file}" ) + + # create header filename + get_filename_component( _src_path "${_src_file}" ABSOLUTE ) + get_filename_component( _src_path "${_src_path}" PATH ) + get_filename_component( _src_header "${_moc_file}" NAME_WE ) + set( _header_file "${_src_path}/${_src_header}.h" ) + + # if header doesn't exists, check in META_INCLUDES + if( NOT EXISTS "${_header_file}" ) + unset( _found ) + foreach( _src_path ${_meta_includes} ) + set( _header_file "${_src_path}/${_src_header}.h" ) + if( EXISTS "${_header_file}" ) + set( _found 1 ) + break( ) + endif( ) + endforeach( ) + if( NOT _found ) + get_filename_component( _moc_file "${_moc_file}" NAME ) + tde_message_fatal( "AUTOMOC error: '${_moc_file}' cannot be generated.\n Reason: '${_src_file}.h' not found." ) + endif( ) + endif( ) + + # moc-ing header + add_custom_command( OUTPUT ${_moc_file} + COMMAND ${TMOC_EXECUTABLE} ${_header_file} -o ${_moc_file} + DEPENDS ${_header_file} ) + + # create dependency between source file and moc file + set_property( SOURCE ${_src_file} APPEND PROPERTY OBJECT_DEPENDS ${_moc_file} ) + + endforeach( _moc_file ) + + endif( _moc_includes ) + + endif( EXISTS "${_src_file}" ) + + endforeach( _src_file ) +endmacro( tde_automoc ) + + +################################################# +##### +##### __tde_internal_process_sources + +macro( __tde_internal_process_sources _sources ) + + unset( ${_sources} ) + + foreach( _arg ${ARGN} ) + get_filename_component( _ext ${_arg} EXT ) + get_filename_component( _name ${_arg} NAME_WE ) + get_filename_component( _path ${_arg} PATH ) + + # if not path, set it to "." + if( NOT _path ) + set( _path "./" ) + endif( NOT _path ) + + # handle .ui files + if( ${_ext} STREQUAL ".ui" ) + tde_add_ui_files( ${_sources} ${_arg} ) + + # handle .skel files + elseif( ${_ext} STREQUAL ".skel" ) + kde3_add_dcop_skels( ${_sources} ${_path}/${_name}.h ) + + # handle .stub files + elseif( ${_ext} STREQUAL ".stub" ) + kde3_add_dcop_stubs( ${_sources} ${_path}/${_name}.h ) + + # handle .kcfgc files + elseif( ${_ext} STREQUAL ".kcfgc" ) + kde3_add_kcfg_files( ${_sources} ${_arg} ) + + # handle any other files + else( ${_ext} STREQUAL ".ui" ) + list(APPEND ${_sources} ${_arg} ) + endif( ${_ext} STREQUAL ".ui" ) + endforeach( _arg ) + +endmacro( __tde_internal_process_sources ) + + +################################################# +##### +##### tde_install_libtool_file + +macro( tde_install_libtool_file _target _destination ) + + # get .so name + tde_get_library_filename( _soname ${_target} ) + get_target_property( _target_release ${_target} RELEASE ) + if( _target_release ) + string( REPLACE "-${_target_release}" "" _soname_base "${_soname}" ) + else( ) + set( _soname_base ${_soname} ) + endif( ) + + # get .la name + string( REGEX REPLACE "\\.so(\\.[0-9]+)*$" "" _laname "${_soname_base}" ) + set( _laname ${_laname}.la ) + + # get version of target + get_target_property( _target_version ${_target} VERSION ) + get_target_property( _target_soversion ${_target} SOVERSION ) + + # we have so version + if( _target_version ) + set( _library_name_1 "${_soname}.${_target_version}" ) + set( _library_name_2 "${_soname}.${_target_soversion}" ) + set( _library_name_3 "${_soname_base}" ) + + string( REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$" _dummy "${_target_version}" ) + set( _version_current "${CMAKE_MATCH_1}" ) + set( _version_age "${CMAKE_MATCH_2}" ) + set( _version_revision "${CMAKE_MATCH_3}" ) + + # we have no so version (module?) + else( _target_version ) + set( _library_name_1 "${_soname}" ) + set( _library_name_2 "${_soname}" ) + set( _library_name_3 "${_soname_base}" ) + set( _version_current "0" ) + set( _version_age "0" ) + set( _version_revision "0" ) + endif( _target_version ) + + if( IS_ABSOLUTE ${_destination} ) + set( _libdir "${_destination}" ) + else( IS_ABSOLUTE ${_destination} ) + set( _libdir "${CMAKE_INSTALL_PREFIX}/${_destination}" ) + endif( IS_ABSOLUTE ${_destination} ) + + configure_file( ${CMAKE_SOURCE_DIR}/cmake/modules/template_libtool_file.cmake "${_laname}" @ONLY ) + + install( FILES "${CMAKE_CURRENT_BINARY_DIR}/${_laname}" DESTINATION ${_destination} ) + +endmacro( tde_install_libtool_file ) + + +################################################# +##### +##### tde_install_export / tde_import + +function( tde_install_export ) + file( GLOB export_files ${CMAKE_CURRENT_BINARY_DIR}/export-*.cmake ) + + set( mode "WRITE" ) + foreach( filename ${export_files} ) + file( READ ${filename} content ) + file( ${mode} "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.cmake" "${content}" ) + set( mode "APPEND" ) + endforeach( ) + + install( FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.cmake" DESTINATION ${CMAKE_INSTALL_DIR} ) +endfunction( ) + + +macro( tde_import _library ) + message( STATUS "checking for '${_library}'" ) + string( TOUPPER "BUILD_${_library}" _build ) + if( ${_build} ) + message( STATUS " ok, activated for build" ) + else() + if( EXISTS "${TDE_CMAKE_DIR}/${_library}.cmake" ) + include( "${TDE_CMAKE_DIR}/${_library}.cmake" ) + message( STATUS " ok, found import file" ) + else() + tde_message_fatal( "'${_library}' are required,\n but is not installed nor selected for build" ) + endif() + endif() +endmacro() + + +################################################# +##### +##### tde_add_library + +macro( tde_add_library _arg_target ) + + unset( _target ) + unset( _type ) + unset( _static_pic ) + unset( _automoc ) + unset( _meta_includes ) + unset( _no_libtool_file ) + unset( _no_export ) + unset( _version ) + unset( _release ) + unset( _sources ) + unset( _destination ) + unset( _embed ) + unset( _link ) + unset( _dependencies ) + unset( _storage ) + unset( _exclude_from_all ) + + set( _shouldnotlink no ) + + # metadata + unset( _description ) + unset( _license ) + unset( _copyright ) + unset( _authors ) + unset( _product ) + unset( _organization ) + unset( _version ) + unset( _datetime ) + unset( _notes ) + + # default metadata + set( _product "Trinity Desktop Environment" ) + tde_curdatetime( _datetime ) + + foreach( _arg ${ARGV} ) + + # this variable help us to skip + # storing unapropriate values (i.e. directives) + unset( _skip_store ) + + # found one of directives: "SHARED", "STATIC", "MODULE" + if( "+${_arg}" STREQUAL "+SHARED" OR "+${_arg}" STREQUAL "+STATIC" OR "+${_arg}" STREQUAL "+MODULE" ) + set( _skip_store 1 ) + set( _type "${_arg}" ) + endif( "+${_arg}" STREQUAL "+SHARED" OR "+${_arg}" STREQUAL "+STATIC" OR "+${_arg}" STREQUAL "+MODULE" ) + + # found directive "STATIC_PIC" + if( "+${_arg}" STREQUAL "+STATIC_PIC" ) + set( _skip_store 1 ) + set( _type "STATIC" ) + set( _static_pic 1 ) + endif( "+${_arg}" STREQUAL "+STATIC_PIC" ) + + # found directive "AUTOMOC" + if( "+${_arg}" STREQUAL "+AUTOMOC" ) + set( _skip_store 1 ) + set( _automoc 1 ) + endif( "+${_arg}" STREQUAL "+AUTOMOC" ) + + # found directive "META_INCLUDES" + if( "+${_arg}" STREQUAL "+META_INCLUDES" ) + set( _skip_store 1 ) + set( _storage "_meta_includes" ) + endif( ) + + # found directive "NO_LIBTOOL_FILE" + if( "+${_arg}" STREQUAL "+NO_LIBTOOL_FILE" ) + set( _skip_store 1 ) + set( _no_libtool_file 1 ) + endif( "+${_arg}" STREQUAL "+NO_LIBTOOL_FILE" ) + + # found directive "NO_EXPORT" + if( "+${_arg}" STREQUAL "+NO_EXPORT" ) + set( _skip_store 1 ) + set( _no_export 1 ) + endif( "+${_arg}" STREQUAL "+NO_EXPORT" ) + + # found directive "VERSION" + if( "+${_arg}" STREQUAL "+VERSION" ) + set( _skip_store 1 ) + set( _storage "_version" ) + endif( "+${_arg}" STREQUAL "+VERSION" ) + + # found directive "RELEASE" + if( "+${_arg}" STREQUAL "+RELEASE" ) + set( _skip_store 1 ) + set( _storage "_release" ) + endif( "+${_arg}" STREQUAL "+RELEASE" ) + + # found directive "SOURCES" + if( "+${_arg}" STREQUAL "+SOURCES" ) + set( _skip_store 1 ) + set( _storage "_sources" ) + endif( "+${_arg}" STREQUAL "+SOURCES" ) + + # found directive "EMBED" + if( "+${_arg}" STREQUAL "+EMBED" ) + set( _skip_store 1 ) + set( _storage "_embed" ) + endif( "+${_arg}" STREQUAL "+EMBED" ) + + # found directive "LINK" + if( "+${_arg}" STREQUAL "+LINK" ) + set( _skip_store 1 ) + set( _storage "_link" ) + endif( "+${_arg}" STREQUAL "+LINK" ) + + # found directive "DEPENDENCIES" + if( "+${_arg}" STREQUAL "+DEPENDENCIES" ) + set( _skip_store 1 ) + set( _storage "_dependencies" ) + endif( "+${_arg}" STREQUAL "+DEPENDENCIES" ) + + # found directive "DESTINATION" + if( "+${_arg}" STREQUAL "+DESTINATION" ) + set( _skip_store 1 ) + set( _storage "_destination" ) + unset( ${_storage} ) + endif( "+${_arg}" STREQUAL "+DESTINATION" ) + + # found directive "EXCLUDE_FROM_ALL" + if( "+${_arg}" STREQUAL "+EXCLUDE_FROM_ALL" ) + set( _skip_store 1 ) + set( _exclude_from_all "EXCLUDE_FROM_ALL" ) + endif( "+${_arg}" STREQUAL "+EXCLUDE_FROM_ALL" ) + + # metadata + if( "+${_arg}" STREQUAL "+DESCRIPTION" ) + set( _skip_store 1 ) + set( _storage "_description" ) + endif( ) + if( "+${_arg}" STREQUAL "+LICENSE" ) + set( _skip_store 1 ) + set( _storage "_license" ) + endif( ) + if( "+${_arg}" STREQUAL "+COPYRIGHT" ) + set( _skip_store 1 ) + set( _storage "_copyright" ) + endif( ) + if( "+${_arg}" STREQUAL "+AUTHORS" ) + set( _skip_store 1 ) + set( _storage "_authors" ) + endif( ) + if( "+${_arg}" STREQUAL "+PRODUCT" ) + set( _skip_store 1 ) + set( _storage "_product" ) + endif( ) + if( "+${_arg}" STREQUAL "+ORGANIZATION" ) + set( _skip_store 1 ) + set( _storage "_organization" ) + endif( ) + if( "+${_arg}" STREQUAL "+VERSION" ) + set( _skip_store 1 ) + set( _storage "_version" ) + endif( ) + if( "+${_arg}" STREQUAL "+DATETIME" ) + set( _skip_store 1 ) + set( _storage "_datetime" ) + endif( ) + if( "+${_arg}" STREQUAL "+NOTES" ) + set( _skip_store 1 ) + set( _storage "_notes" ) + endif( ) + + # storing value + if( _storage AND NOT _skip_store ) + list( APPEND ${_storage} ${_arg} ) + list( REMOVE_DUPLICATES ${_storage} ) + endif( _storage AND NOT _skip_store ) + + endforeach( _arg ) + + # if no type is set, we choose one + # based on BUILD_SHARED_LIBS + if( NOT _type ) + if( BUILD_SHARED_LIBS ) + set( _type "SHARED" ) + else( BUILD_SHARED_LIBS ) + set( _type "STATIC" ) + endif( BUILD_SHARED_LIBS ) + endif( NOT _type ) + + # change target name, based on type + string( TOLOWER "${_type}" _type_lower ) + set( _target "${_arg_target}-${_type_lower}" ) + + # create variables like "LIB_xxx" for convenience + if( ${_type} STREQUAL "SHARED" ) + string( TOUPPER "${_arg_target}" _tmp ) + set( LIB_${_tmp} ${_target} CACHE INTERNAL LIB_${tmp} FORCE ) + endif( ${_type} STREQUAL "SHARED" ) + + # disallow target without sources + if( NOT _sources ) + message( FATAL_ERROR "\nTarget [$_target] have no sources." ) + endif( NOT _sources ) + + # processing different types of sources + __tde_internal_process_sources( _sources ${_sources} ) + + # set automoc + if( _automoc ) + tde_automoc( ${_sources} ) + endif( _automoc ) + + # add target + add_library( ${_target} ${_type} ${_exclude_from_all} ${_sources} ) + + # we assume that modules have no prefix and no version + # also, should not link + if( ${_type} STREQUAL "MODULE" ) + set_target_properties( ${_target} PROPERTIES PREFIX "" ) + unset( _version ) + set( _shouldnotlink yes ) + endif( ${_type} STREQUAL "MODULE" ) + + # set real name of target + if( _release ) + # add release number to output name + set_target_properties( ${_target} PROPERTIES RELEASE ${_release} ) + set_target_properties( ${_target} PROPERTIES OUTPUT_NAME "${_arg_target}-${_release}" ) + else( _release ) + set_target_properties( ${_target} PROPERTIES OUTPUT_NAME ${_arg_target} ) + endif( _release ) + + # set -fPIC flag for static libraries + if( _static_pic ) + if( "${CMAKE_VERSION}" VERSION_LESS "2.8.9" ) + set_target_properties( ${_target} PROPERTIES COMPILE_FLAGS -fPIC ) + else( ) + set_target_properties( ${_target} PROPERTIES POSITION_INDEPENDENT_CODE ON ) + endif( ) + endif( _static_pic ) + + # set version + if( _version ) + if( ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" ) + # OpenBSD: _soversion and _version both contains only major and minor + string( REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$" _dummy "${_version}" ) + set( _version "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}" ) + set( _soversion "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}" ) + else( ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" ) + # General (Linux) case: _soversion contains only the major number of version + string( REGEX MATCH "^[0-9]+" _soversion ${_version} ) + endif( ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" ) + set_target_properties( ${_target} PROPERTIES VERSION ${_version} SOVERSION ${_soversion} ) + endif( _version ) + + # set interface libraries (only for shared) + unset( _shared_libs ) + if( NOT ${_type} STREQUAL "STATIC" ) + foreach( _lib ${_link} ) + #get_target_property( _lib_type ${_lib} TYPE ) + #if( NOT "STATIC_LIBRARY" STREQUAL "${_lib_type}" ) + if( NOT ${_lib} MATCHES ".+-static" ) + list( APPEND _shared_libs ${_lib} ) + endif( NOT ${_lib} MATCHES ".+-static" ) + #endif( NOT "STATIC_LIBRARY" STREQUAL "${_lib_type}" ) + endforeach( _lib ) + endif( NOT ${_type} STREQUAL "STATIC" ) + + # set embedded archives + if( _embed ) + list( INSERT _link 0 -Wl,-whole-archive ${_embed} -Wl,-no-whole-archive ) + endif( _embed ) + + # set link libraries + if( _link ) + if( _embed AND ${CMAKE_VERSION} VERSION_EQUAL "2.8.12.0" ) + # hack for broken CMake 2.8.12.0 + set_target_properties( ${_target} PROPERTIES LINK_LIBRARIES "${_link}" ) + else( _embed AND ${CMAKE_VERSION} VERSION_EQUAL "2.8.12.0" ) + target_link_libraries( ${_target} ${_link} ) + endif( _embed AND ${CMAKE_VERSION} VERSION_EQUAL "2.8.12.0" ) + endif( ) + if( _shared_libs ) + set_target_properties( ${_target} PROPERTIES + LINK_INTERFACE_LIBRARIES "${_shared_libs}" + INTERFACE_LINK_LIBRARIES "${_shared_libs}" ) + endif( _shared_libs ) + + # set dependencies + if( _dependencies ) + add_dependencies( ${_target} ${_dependencies} ) + endif( _dependencies ) + + # if destination directory is set + if( _destination ) + + # we export only shared libs (no static, no modules); + # also, do not export targets marked as "NO_EXPORT" (usually for tdeinit) + if( "SHARED" STREQUAL ${_type} AND NOT _no_export ) + + # get target properties: output name, version, soversion + tde_get_library_filename( _output ${_target} ) + get_target_property( _version ${_target} VERSION ) + get_target_property( _soversion ${_target} SOVERSION ) + + if( _version ) + set( _location "${_destination}/${_output}.${_version}" ) + set( _soname "${_output}.${_soversion}" ) + else( ) + set( _location "${_destination}/${_output}" ) + set( _soname "${_output}" ) + endif( ) + + configure_file( ${CMAKE_SOURCE_DIR}/cmake/modules/template_export_library.cmake "${PROJECT_BINARY_DIR}/export-${_target}.cmake" @ONLY ) + endif( ) + + # install target + install( TARGETS ${_target} DESTINATION ${_destination} ) + + # install base soname + if( _release AND NOT "STATIC" STREQUAL ${_type} ) + tde_get_library_filename( _soname ${_target} ) + string( REPLACE "-${_release}" "" _soname_base "${_soname}" ) + if( _version ) + get_target_property( _soversion ${_target} SOVERSION ) + set( _soname "${_soname}.${_soversion}" ) + endif( ) + add_custom_command( TARGET ${_target} POST_BUILD + COMMAND ln -s ${_soname} "${CMAKE_CURRENT_BINARY_DIR}/${_soname_base}" ) + install( FILES "${CMAKE_CURRENT_BINARY_DIR}/${_soname_base}" DESTINATION ${_destination} ) + endif( ) + + # install .la files for dynamic libraries + if( NOT "STATIC" STREQUAL ${_type} AND NOT _no_libtool_file ) + tde_install_libtool_file( ${_target} ${_destination} ) + endif( ) + + endif( _destination ) + + # embed name and metadata + set( ELF_EMBEDDING_METADATA "\"${_target}\" \"${_description}\" \"${_license}\" \"${_copyright}\" \"${_authors}\" \"${_product}\" \"${_organization}\" \"${_version}\" \"${_datetime}\" \"x-sharedlib\" \"${TDE_SCM_MODULE_NAME}\" \"${TDE_SCM_MODULE_REVISION}\" \"${_notes}\"" ) + separate_arguments( ELF_EMBEDDING_METADATA ) + if( TDELFEDITOR_EXECUTABLE AND _soname ) + if( _version ) + add_custom_command( + TARGET ${_target} + POST_BUILD + COMMAND ${TDELFEDITOR_EXECUTABLE} -m ${CMAKE_CURRENT_BINARY_DIR}/${_soname}.${_version} ${ELF_EMBEDDING_METADATA} || true + COMMAND ${TDELFEDITOR_EXECUTABLE} -e ${CMAKE_CURRENT_BINARY_DIR}/${_soname}.${_version} || true + ) + else( ) + add_custom_command( + TARGET ${_target} + POST_BUILD + COMMAND ${TDELFEDITOR_EXECUTABLE} -m ${CMAKE_CURRENT_BINARY_DIR}/${_soname} ${ELF_EMBEDDING_METADATA} || true + COMMAND ${TDELFEDITOR_EXECUTABLE} -e ${CMAKE_CURRENT_BINARY_DIR}/${_soname} || true + ) + endif( ) + endif( TDELFEDITOR_EXECUTABLE AND _soname ) + +endmacro( tde_add_library ) + + +################################################# +##### +##### tde_add_kpart + +macro( tde_add_kpart _target ) + tde_add_library( ${_target} ${ARGN} MODULE ) +endmacro( tde_add_kpart ) + + +################################################# +##### +##### tde_curdatetime +macro( tde_curdatetime result ) + tde_execute_process( COMMAND "date" "+%m/%d/%Y %H:%M:%S" OUTPUT_VARIABLE ${result} ) + string( REGEX REPLACE "(..)/(..)/(....) (........).*" "\\1/\\2/\\3 \\4" ${result} ${${result}} ) +endmacro( tde_curdatetime ) + + +################################################# +##### +##### tde_add_executable + +macro( tde_add_executable _arg_target ) + + unset( _target ) + unset( _automoc ) + unset( _meta_includes ) + unset( _setuid ) + unset( _sources ) + unset( _destination ) + unset( _link ) + unset( _dependencies ) + unset( _storage ) + + # metadata + unset( _description ) + unset( _license ) + unset( _copyright ) + unset( _authors ) + unset( _product ) + unset( _organization ) + unset( _version ) + unset( _datetime ) + unset( _notes ) + + # default metadata + set( _product "Trinity Desktop Environment" ) + set( _version "${TDE_VERSION}" ) + tde_curdatetime( _datetime ) + + foreach( _arg ${ARGV} ) + + # this variable help us to skip + # storing unapropriate values (i.e. directives) + unset( _skip_store ) + + # found directive "AUTOMOC" + if( "+${_arg}" STREQUAL "+AUTOMOC" ) + set( _skip_store 1 ) + set( _automoc 1 ) + endif( "+${_arg}" STREQUAL "+AUTOMOC" ) + + # found directive "META_INCLUDES" + if( "+${_arg}" STREQUAL "+META_INCLUDES" ) + set( _skip_store 1 ) + set( _storage "_meta_includes" ) + endif( ) + + # found directive "SETUID" + if( "+${_arg}" STREQUAL "+SETUID" ) + set( _skip_store 1 ) + set( _setuid 1 ) + endif( "+${_arg}" STREQUAL "+SETUID" ) + + # found directive "SOURCES" + if( "+${_arg}" STREQUAL "+SOURCES" ) + set( _skip_store 1 ) + set( _storage "_sources" ) + endif( "+${_arg}" STREQUAL "+SOURCES" ) + + # found directive "LINK" + if( "+${_arg}" STREQUAL "+LINK" ) + set( _skip_store 1 ) + set( _storage "_link" ) + endif( "+${_arg}" STREQUAL "+LINK" ) + + # found directive "DEPENDENCIES" + if( "+${_arg}" STREQUAL "+DEPENDENCIES" ) + set( _skip_store 1 ) + set( _storage "_dependencies" ) + endif( "+${_arg}" STREQUAL "+DEPENDENCIES" ) + + # found directive "DESTINATION" + if( "+${_arg}" STREQUAL "+DESTINATION" ) + set( _skip_store 1 ) + set( _storage "_destination" ) + unset( ${_storage} ) + endif( "+${_arg}" STREQUAL "+DESTINATION" ) + + # metadata + if( "+${_arg}" STREQUAL "+DESCRIPTION" ) + set( _skip_store 1 ) + set( _storage "_description" ) + endif( ) + if( "+${_arg}" STREQUAL "+LICENSE" ) + set( _skip_store 1 ) + set( _storage "_license" ) + endif( ) + if( "+${_arg}" STREQUAL "+COPYRIGHT" ) + set( _skip_store 1 ) + set( _storage "_copyright" ) + endif( ) + if( "+${_arg}" STREQUAL "+AUTHORS" ) + set( _skip_store 1 ) + set( _storage "_authors" ) + endif( ) + if( "+${_arg}" STREQUAL "+PRODUCT" ) + set( _skip_store 1 ) + set( _storage "_product" ) + endif( ) + if( "+${_arg}" STREQUAL "+ORGANIZATION" ) + set( _skip_store 1 ) + set( _storage "_organization" ) + endif( ) + if( "+${_arg}" STREQUAL "+VERSION" ) + set( _skip_store 1 ) + set( _storage "_version" ) + endif( ) + if( "+${_arg}" STREQUAL "+DATETIME" ) + set( _skip_store 1 ) + set( _storage "_datetime" ) + endif( ) + if( "+${_arg}" STREQUAL "+NOTES" ) + set( _skip_store 1 ) + set( _storage "_notes" ) + endif( ) + + # storing value + if( _storage AND NOT _skip_store ) + #set( ${_storage} "${${_storage}} ${_arg}" ) + list( APPEND ${_storage} ${_arg} ) + endif( _storage AND NOT _skip_store ) + + endforeach( _arg ) + + set( _target "${_arg_target}" ) + + # disallow target without sources + if( NOT _sources ) + message( FATAL_ERROR "\nTarget [$_target] have no sources." ) + endif( NOT _sources ) + + # processing different types of sources + __tde_internal_process_sources( _sources ${_sources} ) + + # set automoc + if( _automoc ) + tde_automoc( ${_sources} ) + endif( _automoc ) + + # add target + add_executable( ${_target} ${_sources} ) + + # set link libraries + if( _link ) + target_link_libraries( ${_target} ${_link} ) + endif( _link ) + + # set dependencies + if( _dependencies ) + add_dependencies( ${_target} ${_dependencies} ) + endif( _dependencies ) + + # set PIE flags for setuid binaries + if( _setuid ) + set_target_properties( ${_target} PROPERTIES COMPILE_FLAGS "${TDE_PIE_CFLAGS}" ) + set_target_properties( ${_target} PROPERTIES LINK_FLAGS "${TDE_PIE_LDFLAGS}" ) + endif( _setuid ) + + # set destination directory + if( _destination ) + if( _setuid ) + install( TARGETS ${_target} DESTINATION ${_destination} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE SETUID ) + else( _setuid ) + install( TARGETS ${_target} DESTINATION ${_destination} ) + endif( _setuid ) + endif( _destination ) + + # embed icon, name, and metadata + set( ELF_EMBEDDING_METADATA "\"${_target}\" \"${_description}\" \"${_license}\" \"${_copyright}\" \"${_authors}\" \"${_product}\" \"${_organization}\" \"${_version}\" \"${_datetime}\" \"${_target}\" \"${TDE_SCM_MODULE_NAME}\" \"${TDE_SCM_MODULE_REVISION}\" \"${_notes}\"" ) + separate_arguments( ELF_EMBEDDING_METADATA ) + if( TDELFEDITOR_EXECUTABLE ) + add_custom_command( + TARGET ${_target} + POST_BUILD + COMMAND ${TDELFEDITOR_EXECUTABLE} -m ${CMAKE_CURRENT_BINARY_DIR}/${_target} ${ELF_EMBEDDING_METADATA} || true + COMMAND ${TDELFEDITOR_EXECUTABLE} -e ${CMAKE_CURRENT_BINARY_DIR}/${_target} || true + COMMAND ${TDELFEDITOR_EXECUTABLE} -t ${CMAKE_CURRENT_BINARY_DIR}/${_target} ${_target} || true + ) + endif( TDELFEDITOR_EXECUTABLE ) + +endmacro( tde_add_executable ) + + +################################################# +##### +##### tde_add_check_executable + +macro( tde_add_check_executable _arg_target ) + + unset( _target ) + unset( _automoc ) + unset( _test ) + unset( _test_args ) + unset( _meta_includes ) + unset( _sources ) + unset( _destination ) + unset( _link ) + unset( _dependencies ) + unset( _storage ) + + foreach( _arg ${ARGV} ) + + # this variable help us to skip + # storing unapropriate values (i.e. directives) + unset( _skip_store ) + + # found directive "AUTOMOC" + if( "+${_arg}" STREQUAL "+AUTOMOC" ) + set( _skip_store 1 ) + set( _automoc 1 ) + endif( "+${_arg}" STREQUAL "+AUTOMOC" ) + + # found directive "TEST" + if( "+${_arg}" STREQUAL "+TEST" ) + set( _skip_store 1 ) + set( _test 1 ) + set( _storage "_test_args" ) + endif( "+${_arg}" STREQUAL "+TEST" ) + + # found directive "META_INCLUDES" + if( "+${_arg}" STREQUAL "+META_INCLUDES" ) + set( _skip_store 1 ) + set( _storage "_meta_includes" ) + endif( ) + + # found directive "SOURCES" + if( "+${_arg}" STREQUAL "+SOURCES" ) + set( _skip_store 1 ) + set( _storage "_sources" ) + endif( "+${_arg}" STREQUAL "+SOURCES" ) + + # found directive "LINK" + if( "+${_arg}" STREQUAL "+LINK" ) + set( _skip_store 1 ) + set( _storage "_link" ) + endif( "+${_arg}" STREQUAL "+LINK" ) + + # found directive "DEPENDENCIES" + if( "+${_arg}" STREQUAL "+DEPENDENCIES" ) + set( _skip_store 1 ) + set( _storage "_dependencies" ) + endif( "+${_arg}" STREQUAL "+DEPENDENCIES" ) + + # storing value + if( _storage AND NOT _skip_store ) + #set( ${_storage} "${${_storage}} ${_arg}" ) + list( APPEND ${_storage} ${_arg} ) + endif( _storage AND NOT _skip_store ) + + endforeach( _arg ) + + set( _target "${_arg_target}" ) + + # try to autodetect sources + if( NOT _sources ) + file( GLOB _sources "${_target}.cpp" "${_target}.cxx" "${_target}.c" ) + if( NOT _sources ) + message( FATAL_ERROR "\nNo sources found for test executable \"${_target}\"." ) + endif( ) + endif( NOT _sources ) + + # processing different types of sources + __tde_internal_process_sources( _sources ${_sources} ) + + # set automoc + if( _automoc ) + tde_automoc( ${_sources} ) + endif( _automoc ) + + # add target + add_executable( ${_target} EXCLUDE_FROM_ALL ${_sources} ) + + # set link libraries + if( _link ) + target_link_libraries( ${_target} ${_link} ) + endif( _link ) + + # set dependencies + if( _dependencies ) + add_dependencies( ${_target} ${_dependencies} ) + endif( _dependencies ) + + # create make check target + if(NOT TARGET check) + add_custom_target( check + COMMAND ${CMAKE_CTEST_COMMAND} + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" + COMMENT "Running tests..." ) + endif(NOT TARGET check) + + add_dependencies( check ${_target} ) + + # add test target + if( _test ) + # get relative path to current directory and strip end tests dir + file( RELATIVE_PATH _test_prefix ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ) + string( REGEX REPLACE "(^\\.+/?|(^|/)tests?$|/$)" "" _test_prefix "${_test_prefix}" ) + if( _test_prefix ) + set( _test_prefix "${_test_prefix}/" ) + endif( _test_prefix ) + add_test( NAME "${_test_prefix}${_target}" COMMAND "${_target}" ${_test_args} ) + endif( _test ) + +endmacro( tde_add_check_executable ) + + +################################################# +##### +##### tde_add_tdeinit_executable + +macro( tde_add_tdeinit_executable _target ) + + configure_file( ${CMAKE_SOURCE_DIR}/cmake/modules/template_tdeinit_executable.cmake ${_target}_tdeinit_executable.cpp COPYONLY ) + configure_file( ${CMAKE_SOURCE_DIR}/cmake/modules/template_tdeinit_module.cmake ${_target}_tdeinit_module.cpp COPYONLY ) + + unset( _sources ) + unset( _runtime_destination ) + unset( _library_destination ) + unset( _plugin_destination ) + + # default storage is _sources + set( _storage _sources ) + + # set default export to NO_EXPORT + set( _export "NO_EXPORT" ) + + foreach( _arg ${ARGN} ) + + # this variable help us to skip + # storing unapropriate values (i.e. directives) + unset( _skip_store ) + + # found directive "EXPORT" + if( "+${_arg}" STREQUAL "+EXPORT" ) + set( _skip_store 1 ) + unset( _export ) + endif( "+${_arg}" STREQUAL "+EXPORT" ) + + # found directive "RUNTIME_DESTINATION" + if( "+${_arg}" STREQUAL "+RUNTIME_DESTINATION" ) + set( _skip_store 1 ) + set( _storage "_runtime_destination" ) + unset( ${_storage} ) + endif( "+${_arg}" STREQUAL "+RUNTIME_DESTINATION" ) + + # found directive "LIBRARY_DESTINATION" + if( "+${_arg}" STREQUAL "+LIBRARY_DESTINATION" ) + set( _skip_store 1 ) + set( _storage "_library_destination" ) + unset( ${_storage} ) + endif( "+${_arg}" STREQUAL "+LIBRARY_DESTINATION" ) + + # found directive "PLUGIN_DESTINATION" + if( "+${_arg}" STREQUAL "+PLUGIN_DESTINATION" ) + set( _skip_store 1 ) + set( _storage "_plugin_destination" ) + unset( ${_storage} ) + endif( "+${_arg}" STREQUAL "+PLUGIN_DESTINATION" ) + + # storing value + if( _storage AND NOT _skip_store ) + list( APPEND ${_storage} ${_arg} ) + set( _storage "_sources" ) + endif( _storage AND NOT _skip_store ) + + endforeach( _arg ) + + # if destinations are not set, we using some defaults + # we assume that tdeinit executable MUST be installed + # (otherwise why we build it?) + if( NOT _runtime_destination ) + set( _runtime_destination ${BIN_INSTALL_DIR} ) + endif( NOT _runtime_destination ) + if( NOT _library_destination ) + set( _library_destination ${LIB_INSTALL_DIR} ) + endif( NOT _library_destination ) + if( NOT _plugin_destination ) + set( _plugin_destination ${PLUGIN_INSTALL_DIR} ) + endif( NOT _plugin_destination ) + + # create the library + tde_add_library( tdeinit_${_target} ${_sources} SHARED ${_export} + DESTINATION ${_library_destination} + ) + + # create the executable + tde_add_executable( ${_target} + SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${_target}_tdeinit_executable.cpp + LINK tdeinit_${_target}-shared + DESTINATION ${_runtime_destination} + ) + + # create the plugin + tde_add_kpart( ${_target} + SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${_target}_tdeinit_module.cpp + LINK tdeinit_${_target}-shared + DESTINATION ${_plugin_destination} + ) + +endmacro( tde_add_tdeinit_executable ) + + +################################################# +##### +##### tde_create_translation + +macro( tde_create_translation ) + + unset( _srcs ) + unset( _lang ) + unset( _dest ) + unset( _out_name ) + unset( _directive ) + unset( _var ) + + foreach( _arg ${ARGN} ) + + # found directive "FILES" + if( "+${_arg}" STREQUAL "+FILES" ) + unset( _srcs ) + set( _var _srcs ) + set( _directive 1 ) + endif( ) + + # found directive "LANG" + if( "+${_arg}" STREQUAL "+LANG" ) + unset( _lang ) + set( _var _lang ) + set( _directive 1 ) + endif( ) + + # found directive "DESTINATION" + if( "+${_arg}" STREQUAL "+DESTINATION" ) + unset( _dest ) + set( _var _dest ) + set( _directive 1 ) + endif( ) + + # found directive "OUTPUT_NAME" + if( "+${_arg}" STREQUAL "+OUTPUT_NAME" ) + unset( _out_name ) + set( _var _out_name ) + set( _directive 1 ) + endif( ) + + # collect data + if( _directive ) + unset( _directive ) + elseif( _var ) + list( APPEND ${_var} ${_arg} ) + endif() + + endforeach( ) + + if( NOT MSGFMT_EXECUTABLE ) + tde_setup_msgfmt( ) + endif( ) + if( NOT _lang ) + tde_message_fatal( "missing LANG directive" ) + endif( ) + + # if no file specified, include all *.po files + if( NOT _srcs ) + file( GLOB _srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.po ) + endif( ) + if( NOT _srcs ) + tde_message_fatal( "no source files" ) + endif( ) + + if( NOT _lang STREQUAL "auto") + set( _real_lang ${_lang} ) + + if( NOT _dest ) + set( _dest "${LOCALE_INSTALL_DIR}/${_lang}/LC_MESSAGES" ) + endif( ) + + # OUTPUT_NAME can only be used if we have only one file + list( LENGTH _srcs _srcs_num) + if( _out_name AND _srcs_num GREATER 1 ) + tde_message_fatal( "OUTPUT_NAME can be supplied only with single file or LANG=auto" ) + endif( ) + + elseif( NOT _out_name ) + tde_message_fatal( "LANG=auto reqires OUTPUT_NAME directive to be set" ) + elseif( _dest ) + tde_message_fatal( "DESTINATION cannot be used with LANG=auto" ) + endif( ) + + # generate *.mo files + foreach( _src ${_srcs} ) + + get_filename_component( _src ${_src} ABSOLUTE ) + + if( _out_name ) + set( _out ${_out_name} ) + if( _lang STREQUAL "auto" ) + get_filename_component( _real_lang ${_src} NAME_WE ) + set( _dest "${LOCALE_INSTALL_DIR}/${_real_lang}/LC_MESSAGES" ) + endif( ) + else( ) + get_filename_component( _out ${_src} NAME_WE ) + endif( ) + + string( REPLACE "@" "_" _target ${_real_lang} ) + set( _out_filename "${_out}-${_real_lang}.mo" ) + set( _install_filename "${_out}.mo" ) + + add_custom_command( + OUTPUT ${_out_filename} + COMMAND ${MSGFMT_EXECUTABLE} ${_src} -o ${_out_filename} + DEPENDS ${_src} ) + add_custom_target( "${_out}-${_target}-translation" ALL DEPENDS ${_out_filename} ) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${_out_filename} RENAME ${_install_filename} DESTINATION ${_dest} ) + + endforeach( ) + +endmacro( ) + + +################################################# +##### +##### tde_create_handbook + +macro( tde_create_handbook ) + + unset( _target ) + unset( _dest ) + unset( _noindex ) + unset( _srcs ) + unset( _extra ) + unset( _srcdir ) + + set( _lang en ) + set( _first_arg 1 ) + set( _var _target ) + + foreach( _arg ${ARGN} ) + + # found directive "NOINDEX" + if( "+${_arg}" STREQUAL "+NOINDEX" ) + set( _noindex 1 ) + set( _directive 1 ) + endif() + + # found directive "FILES" + if( "+${_arg}" STREQUAL "+FILES" ) + unset( _srcs ) + set( _var _srcs ) + set( _directive 1 ) + endif() + + # found directive "EXTRA" + if( "+${_arg}" STREQUAL "+EXTRA" ) + unset( _extra ) + set( _var _extra ) + set( _directive 1 ) + endif() + + # found directive "SRCDIR" + if( "+${_arg}" STREQUAL "+SRCDIR" ) + unset( _srcdir ) + set( _var _srcdir ) + set( _directive 1 ) + endif() + + # found directive DESTINATION + if( "+${_arg}" STREQUAL "+DESTINATION" ) + unset( _dest ) + set( _var _dest ) + set( _directive 1 ) + endif() + + # found directive "LANG" + if( "+${_arg}" STREQUAL "+LANG" ) + unset( _lang ) + set( _var _lang ) + set( _directive 1 ) + endif() + + # collect data + if( _directive ) + unset( _directive ) + elseif( _var ) + if( _first_arg ) + set( _target "${_arg}" ) + else() + list( APPEND ${_var} ${_arg} ) + endif() + endif() + + unset( _first_arg ) + + endforeach() + + # if no target specified, try to guess it from DESTINATION + if( NOT _target ) + if( NOT _dest ) + tde_message_fatal( "target name cannot be determined because DESTINATION is not set" ) + endif() + string( REPLACE "/" "-" _target "${_dest}" ) + endif() + + set( _target "${_target}-${_lang}-handbook" ) + + # if no file specified, include all docbooks, stylesheets and images + if( NOT _srcs ) + file( GLOB _srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.docbook *.css *.png ) + endif() + + # if no destination specified, defaulting to HTML_INSTALL_DIR + if( NOT _dest ) + set( _dest "${HTML_INSTALL_DIR}/${_lang}" ) + # if destination is NOT absolute path, + # we assume that is relative to HTML_INSTALL_DIR + elseif( NOT IS_ABSOLUTE ${_dest} ) + set( _dest "${HTML_INSTALL_DIR}/${_lang}/${_dest}" ) + endif() + + if( NOT _srcs ) + tde_message_fatal( "no source files" ) + endif() + + if( NOT _noindex ) + + # check for index.docbook + list( FIND _srcs "index.docbook" _find_index ) + if( -1 EQUAL _find_index ) + tde_message_fatal( "missing index.docbook file" ) + endif() + + # check for srcdir + if( _srcdir ) + set( _srcdir "--srcdir=${_srcdir}" ) + endif() + + add_custom_command( + OUTPUT index.cache.bz2 + COMMAND ${KDE3_MEINPROC_EXECUTABLE} ${_srcdir} --check --cache index.cache.bz2 ${CMAKE_CURRENT_SOURCE_DIR}/index.docbook + DEPENDS ${_srcs} ) + + add_custom_target( ${_target} ALL DEPENDS index.cache.bz2 ) + + list( APPEND _srcs ${CMAKE_CURRENT_BINARY_DIR}/index.cache.bz2 ) + + if( NOT TDE_HTML_DIR ) + set( TDE_HTML_DIR ${HTML_INSTALL_DIR} ) + endif( ) + + tde_install_empty_directory( ${_dest} ) + tde_install_symlink( ${TDE_HTML_DIR}/${_lang}/common ${_dest} ) + + endif() + + install( FILES ${_srcs} ${_extra} DESTINATION ${_dest} ) + +endmacro( ) + + +################################################# +##### +##### tde_create_tarball +##### +##### Macro is used to create tarball. +##### + +macro( tde_create_tarball ) + + unset( _target ) + unset( _files ) + unset( _destination ) + set( _sourcedir "${CMAKE_CURRENT_SOURCE_DIR}" ) + set( _compression "gzip" ) + set( _var _target ) + + foreach( _arg ${ARGN} ) + + # found directive "TARGET" + if( "+${_arg}" STREQUAL "+TARGET" ) + unset( _target ) + set( _var _target ) + set( _directive 1 ) + endif( ) + + # found directive "SOURCEDIR" + if( "+${_arg}" STREQUAL "+SOURCEDIR" ) + unset( _sourcedir ) + set( _var _sourcedir ) + set( _directive 1 ) + endif( ) + + # found directive "FILES" + if( "+${_arg}" STREQUAL "+FILES" ) + unset( _files ) + set( _var _files ) + set( _directive 1 ) + endif( ) + + # found directive "DESTINATION" + if( "+${_arg}" STREQUAL "+DESTINATION" ) + unset( _destination ) + set( _var _destination ) + set( _directive 1 ) + endif( ) + + # found directive "COMPRESSION" + if( "+${_arg}" STREQUAL "+COMPRESSION" ) + unset( _compression ) + set( _var _compression ) + set( _directive 1 ) + endif( ) + + # collect data + if( _directive ) + unset( _directive ) + elseif( _var ) + list( APPEND ${_var} ${_arg} ) + endif( ) + + endforeach( ) + + if( NOT _target ) + tde_message_fatal( "Target tarball name not specified." ) + endif( ) + + if( NOT _files ) + file( GLOB_RECURSE _files RELATIVE ${_sourcedir} "${_sourcedir}/*" ) + endif( ) + + unset( _files_deps ) + foreach( _file ${_files} ) + list( APPEND _files_deps "${_sourcedir}/${_file}" ) + endforeach( ) + + if( NOT DEFINED TAR_EXECUTABLE ) + find_program( TAR_EXECUTABLE NAMES tar ) + if( "${TAR_EXECUTABLE}" STREQUAL "TAR_EXECUTABLE-NOTFOUND" ) + tde_message_fatal( "tar executable is required but not found on your system" ) + endif( ) + endif( ) + + if( NOT DEFINED TAR_SETOWNER ) + execute_process( + COMMAND ${TAR_EXECUTABLE} --version + OUTPUT_VARIABLE TAR_VERSION + ) + string( REGEX REPLACE "^([^\n]*)\n.*" "\\1" TAR_VERSION "${TAR_VERSION}" ) + if( "${TAR_VERSION}" MATCHES "GNU *tar" ) + set( TAR_SETOWNER "--owner=root;--group=root" ) + elseif( "${TAR_VERSION}" MATCHES "bsd *tar" ) + set( TAR_SETOWNER "--uname=root;--gname=root" ) + else( ) + set( TAR_SETOWNER "" ) + endif( ) + endif( ) + + if( "${_compression}" STREQUAL "-" ) + unset( _compression ) + endif( ) + if( _compression ) + if( "${_compression}" STREQUAL "gzip" ) + set( _compression "-z" ) + else( ) + set( _compression "--use-compress-program=\"${_compression}\"" ) + endif( ) + endif( ) + + get_filename_component( _target_path "${CMAKE_CURRENT_BINARY_DIR}/${_target}" ABSOLUTE ) + file( RELATIVE_PATH _target_path "${CMAKE_BINARY_DIR}" "${_target_path}" ) + string( REPLACE "/" "+" _target_name "${_target_path}" ) + add_custom_target( "${_target_name}-tarball" ALL + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_target}" ) + + add_custom_command( + COMMAND ${TAR_EXECUTABLE} cf ${CMAKE_CURRENT_BINARY_DIR}/${_target} + ${_compression} ${TAR_SETOWNER} -- ${_files} + WORKING_DIRECTORY "${_sourcedir}" + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_target}" + DEPENDS ${_files_deps} + COMMENT "Create tarball ${_target_path}" + ) + + if( _destination ) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${_target} DESTINATION ${_destination} ) + endif( ) + +endmacro() + + +################################################# +##### +##### tde_include_tqt + +macro( tde_include_tqt ) + foreach( _cpp ${ARGN} ) + set_source_files_properties( ${_cpp} PROPERTIES COMPILE_FLAGS "-include tqt.h" ) + endforeach() +endmacro( ) + + +################################################# +##### +##### tde_install_symlink + +macro( tde_install_symlink _target _link ) + + # if path is relative, we must to prefix it with CMAKE_INSTALL_PREFIX + if( IS_ABSOLUTE "${_link}" ) + set( _destination "${_link}" ) + else( IS_ABSOLUTE "${_link}" ) + set( _destination "${CMAKE_INSTALL_PREFIX}/${_link}" ) + endif( IS_ABSOLUTE "${_link}" ) + + get_filename_component( _path "${_destination}" PATH ) + if( NOT IS_DIRECTORY "\$ENV{DESTDIR}${_path}" ) + install( CODE "file( MAKE_DIRECTORY \"\$ENV{DESTDIR}${_path}\" )" ) + endif( NOT IS_DIRECTORY "\$ENV{DESTDIR}${_path}" ) + + install( CODE "execute_process( COMMAND ln -s ${_target} \$ENV{DESTDIR}${_destination} )" ) + +endmacro( tde_install_symlink ) + + +################################################# +##### +##### tde_install_empty_directory + +macro( tde_install_empty_directory _path ) + + # if path is relative, we must to prefix it with CMAKE_INSTALL_PREFIX + if( IS_ABSOLUTE "${_path}" ) + set( _destination "${_path}" ) + else( IS_ABSOLUTE "${_path}" ) + set( _destination "${CMAKE_INSTALL_PREFIX}/${_path}" ) + endif( IS_ABSOLUTE "${_path}" ) + + install( CODE "file( MAKE_DIRECTORY \"\$ENV{DESTDIR}${_destination}\" )" ) + +endmacro( tde_install_empty_directory ) + + +################################################# +##### +##### tde_conditional_add_subdirectory + +macro( tde_conditional_add_subdirectory _cond _path ) + + if( ${_cond} ) + add_subdirectory( "${_path}" ) + endif( ${_cond} ) + +endmacro( tde_conditional_add_subdirectory ) + + +################################################# +##### +##### tde_auto_add_subdirectories + +macro( tde_auto_add_subdirectories ) + file( GLOB _dirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} * ) + foreach( _dir ${_dirs} ) + if( IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${_dir} ) + if( NOT ${_dir} STREQUAL ".svn" AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_dir}/CMakeLists.txt ) + add_subdirectory( ${_dir} ) + endif() + endif() + endforeach() +endmacro() + + +################################################# +##### +##### tde_save / tde_restore + +macro( tde_save ) + foreach( _var ${ARGN} ) + set( __bak_${_var} ${${_var}} ) + endforeach() +endmacro() + +macro( tde_save_and_set _var ) + set( __bak_${_var} ${${_var}} ) + set( ${_var} ${ARGN} ) +endmacro( ) + +macro( tde_restore ) + foreach( _var ${ARGN} ) + set( ${_var} ${__bak_${_var}} ) + unset( __bak_${_var} ) + endforeach() +endmacro() + + +################################################# +##### +##### tde_setup_install_path + +macro( tde_setup_install_path _path _default ) + if( DEFINED ${_path} ) + set( ${_path} "${${_path}}" CACHE INTERNAL "" FORCE ) + else( ) + set( ${_path} "${_default}" ) + endif( ) +endmacro( ) + + +################################################## + +if( ${CMAKE_SOURCE_DIR} MATCHES ${CMAKE_BINARY_DIR} ) + tde_message_fatal( "Please use out-of-source building, like this: + \n rm ${CMAKE_SOURCE_DIR}/CMakeCache.txt + mkdir /tmp/${PROJECT_NAME}.build + cd /tmp/${PROJECT_NAME}.build + cmake ${CMAKE_SOURCE_DIR} [arguments...]" ) +endif( ) + +################################################# +##### +##### tde_setup_architecture_flags + +macro( tde_setup_architecture_flags ) + message( STATUS "Detected ${CMAKE_SYSTEM_PROCESSOR} CPU architecture" ) + ## Immediate symbol binding is available only for gcc but not on ARM architectures + if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" AND NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES arm* AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" ) + set( LINKER_IMMEDIATE_BINDING_FLAGS "-z\ now" CACHE INTERNAL "" FORCE ) + else( ) + set( LINKER_IMMEDIATE_BINDING_FLAGS "" CACHE INTERNAL "" FORCE ) + endif( ) + + check_cxx_compiler_flag( -fPIE HAVE_PIE_SUPPORT ) + if( HAVE_PIE_SUPPORT ) + set( TDE_PIE_CFLAGS -fPIE ) + set( TDE_PIE_LDFLAGS -pie ) + endif( HAVE_PIE_SUPPORT ) +endmacro( ) + + +################################################# +##### +##### tde_setup_gcc_visibility + +macro( tde_setup_gcc_visibility ) + if( NOT DEFINED __KDE_HAVE_GCC_VISIBILITY ) + if( NOT UNIX ) + tde_message_fatal( "gcc visibility support was requested, but your system is not *NIX" ) + endif( NOT UNIX ) + + if( TQT_FOUND ) + find_library( TQT_LIBFILE tqt-mt HINTS "${TQT_LIBRARY_DIRS}" ) + if( NOT "${TQT_LIBFILE}" STREQUAL "TQT_LIBFILE-NOTFOUND" ) + message( STATUS "Performing Test HAVE_TQT_VISIBILITY" ) + execute_process( + COMMAND readelf --syms "${TQT_LIBFILE}" + OUTPUT_VARIABLE HAVE_TQT_VISIBILITY + ) + if( "${HAVE_TQT_VISIBILITY}" STREQUAL "" OR + "${HAVE_TQT_VISIBILITY}" MATCHES "GLOBAL[\t ]+DEFAULT[^\n]+QSettingsPrivate" ) + message( STATUS "Performing Test HAVE_TQT_VISIBILITY - Failed" ) + tde_message_fatal( "gcc visibility support was requested, but not supported in tqt library" ) + endif( ) + message( STATUS "Performing Test HAVE_TQT_VISIBILITY - Success" ) + endif( ) + endif( TQT_FOUND ) + + if( TDE_FOUND ) + find_file( TDEMACROS_H kdemacros.h HINTS "${TDE_INCLUDE_DIR}" ) + if( NOT "${TDEMACROS_H}" STREQUAL "TDEMACROS_H-NOTFOUND" ) + tde_save_and_set( CMAKE_REQUIRED_INCLUDES "${TDE_INCLUDE_DIR}" ) + check_cxx_source_compiles( " + #include <${TDEMACROS_H}> + #ifndef __KDE_HAVE_GCC_VISIBILITY + #error gcc visibility is not enabled in tdelibs + #endif + int main() { return 0; } " + HAVE_TDE_VISIBILITY + ) + tde_restore( CMAKE_REQUIRED_INCLUDES ) + if( NOT HAVE_TDE_VISIBILITY ) + tde_message_fatal( "gcc visibility support was requested, but not supported in tdelibs" ) + endif( NOT HAVE_TDE_VISIBILITY ) + endif( ) + endif( TDE_FOUND ) + + set( __KDE_HAVE_GCC_VISIBILITY 1 ) + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden") + endif( ) +endmacro( ) + + +################################################# +##### +##### tde_setup_msgfmt + +macro( tde_setup_msgfmt ) + if( NOT DEFINED MSGFMT_EXECUTABLE ) + include( FindGettext ) + if( GETTEXT_FOUND ) + set( MSGFMT_EXECUTABLE ${GETTEXT_MSGFMT_EXECUTABLE} + CACHE FILEPATH "path to msgfmt executable" ) + endif( GETTEXT_FOUND ) + + if( NOT MSGFMT_EXECUTABLE ) + tde_message_fatal( "msgfmt is required but was not found on your system." ) + endif( NOT MSGFMT_EXECUTABLE ) + endif( ) +endmacro( ) + + +################################################ +##### +##### tde_setup_largefiles + +macro( tde_setup_largefiles ) + if( NOT DEFINED HAVE_LARGEFILES ) + message( STATUS "Check support for large files" ) + unset( LARGEFILES_DEFINITIONS ) + + # check without special definitions + unset( HAVE_SIZEOF_T CACHE ) + check_type_size( off_t SIZEOF_OFF_T ) + if( SIZEOF_OFF_T GREATER 7 ) + set( HAVE_LARGEFILES 1 ) + endif( ) + + # check with definition _FILE_OFFSET_BITS=64 + if( NOT HAVE_LARGEFILES ) + unset( HAVE_SIZEOF_OFF_T CACHE ) + tde_save_and_set( CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_FILE_OFFSET_BITS=64" ) + check_type_size( off_t SIZEOF_OFF_T ) + tde_restore( CMAKE_REQUIRED_DEFINITIONS ) + if( SIZEOF_OFF_T GREATER 7 ) + set( LARGEFILES_DEFINITIONS "-D_FILE_OFFSET_BITS=64" ) + set( HAVE_LARGEFILES 1 ) + endif( ) + endif( ) + + # check with definition _LARGE_FILES + if( NOT HAVE_LARGEFILES ) + unset( HAVE_SIZEOF_OFF_T CACHE ) + tde_save_and_set( CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_LARGE_FILES" ) + check_type_size( off_t SIZEOF_OFF_T ) + tde_restore( CMAKE_REQUIRED_DEFINITIONS ) + if( SIZEOF_OFF_T GREATER 7 ) + set( LARGEFILES_DEFINITIONS "-D_LARGE_FILES" ) + set( HAVE_LARGEFILES 1 ) + endif( ) + endif( ) + + # check with definition _LARGEFILE_SOURCE + if( NOT HAVE_LARGEFILES ) + unset( HAVE_SIZEOF_OFF_T CACHE ) + tde_save_and_set( CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_LARGEFILE_SOURCE" ) + check_type_size( off_t SIZEOF_OFF_T ) + tde_restore( CMAKE_REQUIRED_DEFINITIONS ) + if( SIZEOF_OFF_T GREATER 7 ) + set( LARGEFILES_DEFINITIONS "-D_LARGEFILE_SOURCE" ) + set( HAVE_LARGEFILES 1 ) + endif( ) + endif( ) + + # check for fseeko/ftello + if( HAVE_LARGEFILES ) + tde_save_and_set( CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} ${LARGEFILES_DEFINITIONS}" ) + check_symbol_exists( "fseeko" "stdio.h" HAVE_FSEEKO ) + tde_restore( CMAKE_REQUIRED_DEFINITIONS ) + if( NOT HAVE_FSEEKO ) + tde_save_and_set( CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} ${LARGEFILES_DEFINITIONS} -D_LARGEFILE_SOURCE" ) + check_symbol_exists( "fseeko" "stdio.h" HAVE_FSEEKO ) + tde_restore( CMAKE_REQUIRED_DEFINITIONS ) + if( HAVE_FSEEKO ) + set( LARGEFILES_DEFINITIONS "${LARGEFILES_DEFINITIONS} -D_LARGEFILE_SOURCE" ) + else( ) + unset( HAVE_LARGEFILES ) + endif( ) + endif( ) + endif( ) + + # check results + if( HAVE_LARGEFILES ) + if( "${LARGEFILES_DEFINITIONS}" STREQUAL "" ) + message( STATUS "Check support for large files - Success" ) + else( ) + add_definitions( ${LARGEFILES_DEFINITIONS} ) + message( STATUS "Check support for large files - Success with ${LARGEFILES_DEFINITIONS}" ) + endif( ) + set( HAVE_LARGEFILES 1 CACHE INTERNAL "Support for large files enabled" ) + else( ) + message( STATUS "Check support for large files - Failed" ) + tde_message_fatal( "Cannot find a way to enable support for large files." ) + endif( ) + endif( ) +endmacro( ) + + +################################################# +##### +##### tde_setup_dbus + +macro( tde_setup_dbus ) + if( NOT DBUS_FOUND ) + pkg_search_module( DBUS dbus-1 ) + if( NOT DBUS_FOUND ) + tde_message_fatal( "dbus-1 is required, but not found on your system" ) + endif( ) + endif( ) + + if( NOT DEFINED DBUS_SYSTEM_CONF_DIRECTORY ) + execute_process( + COMMAND ${PKG_CONFIG_EXECUTABLE} + dbus-1 --variable=sysconfdir + OUTPUT_VARIABLE DBUS_SYSTEM_CONF_BASE + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if( DBUS_SYSTEM_CONF_BASE ) + set( DBUS_SYSTEM_CONF_DIRECTORY "${DBUS_SYSTEM_CONF_BASE}/dbus-1/system.d" ) + message( STATUS "Using " ${DBUS_SYSTEM_CONF_DIRECTORY} " for DBUS system configuration files" ) + else( ) + tde_message_fatal( "Can not find the base directory for the dbus-1 configuration" ) + endif( ) + endif( ) + + if( NOT DEFINED DBUS_SESSION_CONF_DIRECTORY ) + execute_process( + COMMAND ${PKG_CONFIG_EXECUTABLE} + dbus-1 --variable=sysconfdir + OUTPUT_VARIABLE DBUS_SYSTEM_CONF_BASE + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if( DBUS_SYSTEM_CONF_BASE ) + set( DBUS_SESSION_CONF_DIRECTORY "${DBUS_SYSTEM_CONF_BASE}/dbus-1/session.d" ) + message( STATUS "Using " ${DBUS_SESSION_CONF_DIRECTORY} " for DBUS session configuration files" ) + else( ) + tde_message_fatal( "Can not find the base directory for the dbus-1 configuration" ) + endif( ) + endif( ) + + if( NOT DEFINED DBUS_SESSION_DIRECTORY ) + execute_process( + COMMAND ${PKG_CONFIG_EXECUTABLE} + dbus-1 --variable=session_bus_services_dir + OUTPUT_VARIABLE DBUS_SESSION_DIRECTORY + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + message( STATUS "Using " ${DBUS_SESSION_DIRECTORY} " for DBUS session service files" ) + endif( ) + + if( NOT DEFINED DBUS_SERVICE_DIRECTORY ) + execute_process( + COMMAND ${PKG_CONFIG_EXECUTABLE} + dbus-1 --variable=system_bus_services_dir + OUTPUT_VARIABLE DBUS_SERVICE_DIRECTORY + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if( "${DBUS_SERVICE_DIRECTORY}" STREQUAL "" ) + if( "${DBUS_SESSION_DIRECTORY}" MATCHES "/services$" ) + string( REGEX REPLACE "/services$" "/system-services" + DBUS_SERVICE_DIRECTORY "${DBUS_SESSION_DIRECTORY}" ) + else( ) + tde_message_fatal( "Directory for DBUS system service files can not be determined." ) + endif( ) + endif( ) + message( STATUS "Using " ${DBUS_SERVICE_DIRECTORY} " for DBUS system service files" ) + endif( ) + + if( NOT "${ARGV}" STREQUAL "" AND NOT DBUS_TQT_FOUND ) + pkg_search_module( DBUS_TQT ${ARGV} ) + if( NOT DBUS_TQT_FOUND ) + tde_message_fatal( "${ARGV} is required, but not found on your system" ) + endif( ) + endif( ) + if( "${ARGV}" STREQUAL "dbus-1-tqt" AND NOT DEFINED DBUSXML2QT3_EXECUTABLE ) + find_program( DBUSXML2QT3_EXECUTABLE + NAMES dbusxml2qt3 + HINTS "${TDE_PREFIX}/bin" ${BIN_INSTALL_DIR} + ) + endif( ) + +endmacro( ) + + +################################################# +##### +##### tde_setup_polkit + +macro( tde_setup_polkit ) + if( NOT POLKIT_GOBJECT_FOUND ) + pkg_search_module( POLKIT_GOBJECT polkit-gobject-1 ) + if( NOT POLKIT_GOBJECT_FOUND ) + tde_message_fatal( "polkit-gobject-1 is required, but not found on your system" ) + endif( ) + endif( ) + + foreach( _arg ${ARGV} ) + if( NOT "${_arg}" MATCHES "^polkit-" ) + set( _arg "polkit-${_arg}" ) + endif( ) + string( TOUPPER "${_arg}" _polkit_module ) + if( "${_polkit_module}" MATCHES "-[0-9]+$" ) + string( REGEX REPLACE "-[0-9]+$" "" _polkit_module "${_polkit_module}" ) + endif( ) + string( REPLACE "-" "_" _polkit_module "${_polkit_module}" ) + if( NOT "${_arg}" MATCHES "-[0-9]+$" ) + set( _arg "${_arg}-1" ) + endif( ) + if( NOT ${_polkit_module}_FOUND ) + pkg_search_module( ${_polkit_module} ${_arg} ) + if( NOT ${_polkit_module}_FOUND ) + tde_message_fatal( "${_arg} is required, but not found on your system" ) + endif( ) + endif( ) + endforeach( ) + + if( NOT DEFINED POLKIT_ACTIONS_DIRECTORY ) + execute_process( + COMMAND ${PKG_CONFIG_EXECUTABLE} + polkit-gobject-1 --variable=actiondir + OUTPUT_VARIABLE POLKIT_ACTIONS_DIRECTORY + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + message( STATUS "Using " ${POLKIT_ACTIONS_DIRECTORY} " for PolicyKit action files" ) + endif( ) + +endmacro( ) diff --git a/qnetchess/cmake/modules/TDESetupPaths.cmake b/qnetchess/cmake/modules/TDESetupPaths.cmake new file mode 100644 index 00000000..465df7fc --- /dev/null +++ b/qnetchess/cmake/modules/TDESetupPaths.cmake @@ -0,0 +1,68 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +################################################# +##### +##### tde_internal_setup_path + +macro( _tde_internal_setup_path _path _default _comment ) + if( DEFINED ${_path} ) + set( ${_path} "${${_path}}" CACHE PATH "${_comment}" ) + else( DEFINED ${_path} ) + set( ${_path} "${_default}" ) + endif( DEFINED ${_path} ) +endmacro( _tde_internal_setup_path ) + + +################################################# +##### +##### tde_setup_paths + +macro( tde_setup_paths ) + + # install paths + _tde_internal_setup_path( EXEC_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" "Base directory for executables and libraries" ) + _tde_internal_setup_path( SHARE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/share" "Base directory for files which go to share/" ) + _tde_internal_setup_path( BIN_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/bin" "The install dir for executables (default ${EXEC_INSTALL_PREFIX}/bin)" ) + _tde_internal_setup_path( SBIN_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/sbin" "The install dir for system executables (default ${EXEC_INSTALL_PREFIX}/sbin)" ) + _tde_internal_setup_path( LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX}" "The subdirectory relative to the install prefix where libraries will be installed (default is ${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX})" ) + _tde_internal_setup_path( LIBEXEC_INSTALL_DIR "${LIB_INSTALL_DIR}/trinity/libexec" "The subdirectory relative to the install prefix where libraries will be installed (default is ${LIB_INSTALL_DIR}/trinity/libexec)" ) + _tde_internal_setup_path( PKGCONFIG_INSTALL_DIR "${LIB_INSTALL_DIR}/pkgconfig" "The install dir for pkg-config metadata files" ) + _tde_internal_setup_path( INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" "The subdirectory to the header prefix" ) + + _tde_internal_setup_path( CMAKE_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/cmake" "The install dir for cmake import modules" ) + _tde_internal_setup_path( PLUGIN_INSTALL_DIR "${LIB_INSTALL_DIR}/trinity" "The subdirectory relative to the install prefix where plugins will be installed (default is ${LIB_INSTALL_DIR}/trinity)" ) + _tde_internal_setup_path( CONFIG_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/config" "The config file install dir" ) + _tde_internal_setup_path( DATA_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/apps" "The parent directory where applications can install their data" ) + _tde_internal_setup_path( HTML_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/doc/tde/HTML" "The HTML install dir for documentation" ) + _tde_internal_setup_path( ICON_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/icons" "The icon install dir (default ${SHARE_INSTALL_PREFIX}/share/icons/)" ) + _tde_internal_setup_path( KCFG_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/config.kcfg" "The install dir for tdeconfig files" ) + _tde_internal_setup_path( LOCALE_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/locale" "The install dir for translations" ) + _tde_internal_setup_path( APPS_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/applnk" "The install dir for the application desktop files" ) + _tde_internal_setup_path( MIME_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/mimelnk" "The install dir for the mimetype desktop files" ) + _tde_internal_setup_path( SERVICES_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/services" "The install dir for service (desktop, protocol, ...) files" ) + _tde_internal_setup_path( SERVICETYPES_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/servicetypes" "The install dir for servicestypes desktop files" ) + _tde_internal_setup_path( SOUND_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/sounds" "The install dir for sound files" ) + _tde_internal_setup_path( TEMPLATES_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/templates" "The install dir for templates (Create new file...)" ) + _tde_internal_setup_path( WALLPAPER_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/wallpapers" "The install dir for wallpapers" ) + _tde_internal_setup_path( KCONF_UPDATE_INSTALL_DIR "${DATA_INSTALL_DIR}/tdeconf_update" "The tdeconf_update install dir" ) + _tde_internal_setup_path( AUTOSTART_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/autostart" "The install dir for autostart files" ) + + _tde_internal_setup_path( SYSCONF_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/etc" "The sysconfig install dir (default ${CMAKE_INSTALL_PREFIX}/etc)" ) + _tde_internal_setup_path( MAN_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/man" "The man install dir (default ${SHARE_INSTALL_PREFIX}/man/)" ) + _tde_internal_setup_path( INFO_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/info" "The info install dir (default ${SHARE_INSTALL_PREFIX}/info)" ) + + _tde_internal_setup_path( XDG_MENU_INSTALL_DIR "${SYSCONF_INSTALL_DIR}/xdg/menus" "The XDG menus dir" ) + _tde_internal_setup_path( XDG_APPS_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/applications/tde" "The XDG apps dir" ) + _tde_internal_setup_path( XDG_DIRECTORY_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/desktop-directories" "The XDG directory" ) + _tde_internal_setup_path( XDG_MIME_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/mime/packages" "The install dir for the xdg mimetypes" ) + +endmacro( tde_setup_paths ) diff --git a/qnetchess/cmake/modules/tde_uic.cmake b/qnetchess/cmake/modules/tde_uic.cmake new file mode 100644 index 00000000..36b921f2 --- /dev/null +++ b/qnetchess/cmake/modules/tde_uic.cmake @@ -0,0 +1,67 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +set( CMAKE_MODULE_PATH "${MASTER_SOURCE_DIR}/cmake/modules" ) +include( TDEMacros ) + +get_filename_component( _ui_basename ${UI_FILE} NAME_WE ) + +# FIXME this will working only on out-of-source mode +set( local_ui_file ${_ui_basename}.ui ) +configure_file( ${UI_FILE} ${local_ui_file} COPYONLY ) +tde_execute_process( COMMAND ${TQT_REPLACE_SCRIPT} ${local_ui_file} ) + +# ui.h extension file, if exists +if( EXISTS "${UI_FILE}.h" ) + configure_file( ${UI_FILE}.h ${local_ui_file}.h COPYONLY ) + tde_execute_process( COMMAND ${TQT_REPLACE_SCRIPT} ${local_ui_file}.h ) +endif( ) + +if( TDE_TQTPLUGINS_DIR ) + set( L -L ${TDE_TQTPLUGINS_DIR} ) +endif( ) + +tde_execute_process( COMMAND ${UIC_EXECUTABLE} + -nounload -tr tr2i18n + ${L} + ${local_ui_file} + OUTPUT_VARIABLE _ui_h_content ) + +if( _ui_h_content ) + string( REGEX REPLACE "#ifndef " "#ifndef UI_" _ui_h_content "${_ui_h_content}" ) + string( REGEX REPLACE "#define " "#define UI_" _ui_h_content "${_ui_h_content}" ) + string( REGEX REPLACE "public TQWizard" "public KWizard" _ui_h_content "${_ui_h_content}" ) + string( REGEX REPLACE "public QWizard" "public KWizard" _ui_h_content "${_ui_h_content}" ) + string( REGEX REPLACE "#include <ntqwizard.h>" "#include <kwizard.h>" _ui_h_content "${_ui_h_content}" ) + string( REGEX REPLACE "#include <qwizard.h>" "#include <kwizard.h>" _ui_h_content "${_ui_h_content}" ) + file( WRITE ${_ui_basename}.h "${_ui_h_content}" ) +endif( ) + +tde_execute_process( COMMAND ${UIC_EXECUTABLE} + -nounload -tr tr2i18n + ${L} + -impl ${_ui_basename}.h + ${local_ui_file} + OUTPUT_VARIABLE _ui_cpp_content ) + +if( _ui_cpp_content ) + string( REGEX REPLACE "tr2i18n\\(\"\"\\)" "QString::null" _ui_cpp_content "${_ui_cpp_content}" ) + string( REGEX REPLACE "tr2i18n\\(\"\", \"\"\\)" "QString::null" _ui_cpp_content "${_ui_cpp_content}" ) + string( REGEX REPLACE ": TQWizard\\(" ": KWizard(" _ui_cpp_content "${_ui_cpp_content}" ) + string( REGEX REPLACE ": QWizard\\(" ": KWizard(" _ui_cpp_content "${_ui_cpp_content}" ) + file( WRITE ${_ui_basename}.cpp "#include <kdialog.h>\n#include <tdelocale.h>\n\n${_ui_cpp_content}" ) + + tde_execute_process( COMMAND ${MOC_EXECUTABLE} + ${_ui_basename}.h + OUTPUT_VARIABLE _ui_h_moc_content ) + file( APPEND ${_ui_basename}.cpp "${_ui_h_moc_content}" ) + +endif( ) diff --git a/qnetchess/cmake/modules/template_dummy_cpp.cmake b/qnetchess/cmake/modules/template_dummy_cpp.cmake new file mode 100644 index 00000000..8e1f5ff5 --- /dev/null +++ b/qnetchess/cmake/modules/template_dummy_cpp.cmake @@ -0,0 +1,5 @@ +#ifdef _AIX + namespace { + void *not_empty_file; + } +#endif diff --git a/qnetchess/cmake/modules/template_export_library.cmake b/qnetchess/cmake/modules/template_export_library.cmake new file mode 100644 index 00000000..4d6cb3ff --- /dev/null +++ b/qnetchess/cmake/modules/template_export_library.cmake @@ -0,0 +1,7 @@ +add_library( @_target@ @_type@ IMPORTED ) + +set_target_properties( @_target@ PROPERTIES + IMPORTED_LINK_INTERFACE_LIBRARIES "@_shared_libs@" + IMPORTED_LOCATION "@_location@" + IMPORTED_SONAME "@_soname@" ) + diff --git a/qnetchess/cmake/modules/template_libtool_file.cmake b/qnetchess/cmake/modules/template_libtool_file.cmake new file mode 100644 index 00000000..fcd73d46 --- /dev/null +++ b/qnetchess/cmake/modules/template_libtool_file.cmake @@ -0,0 +1,35 @@ +# @_laname@ - a libtool library file +# Generated by CMake - GNU libtool +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# The name that we can dlopen(3). +dlname='@_library_name_2@' + +# Names of this library. +library_names='@_library_name_1@ @_library_name_2@ @_library_name_3@' + +# The name of the static archive. +old_library='' + +# Libraries that this one depends upon. +dependency_libs='' + +# Version information for @_name@. +current=@_version_current@ +age=@_version_age@ +revision=@_version_revision@ + +# Is this an already installed library? +installed=yes + +# Should we warn about portability when linking against -modules? +shouldnotlink=@_shouldnotlink@ + +# Files to dlopen/dlpreopen +dlopen='' +dlpreopen='' + +# Directory that this library needs to be installed in: +libdir='@_libdir@' diff --git a/qnetchess/cmake/modules/template_tdeinit_executable.cmake b/qnetchess/cmake/modules/template_tdeinit_executable.cmake new file mode 100644 index 00000000..3d480c44 --- /dev/null +++ b/qnetchess/cmake/modules/template_tdeinit_executable.cmake @@ -0,0 +1,2 @@ +extern "C" int kdemain(int argc, char* argv[]); +int main(int argc, char* argv[]) { return kdemain(argc,argv); } diff --git a/qnetchess/cmake/modules/template_tdeinit_module.cmake b/qnetchess/cmake/modules/template_tdeinit_module.cmake new file mode 100644 index 00000000..efd89d88 --- /dev/null +++ b/qnetchess/cmake/modules/template_tdeinit_module.cmake @@ -0,0 +1,3 @@ +#include <kdemacros.h> +extern "C" int kdemain(int argc, char* argv[]); +extern "C" KDE_EXPORT int tdeinitmain(int argc, char* argv[]) { return kdemain(argc,argv); } diff --git a/qnetchess/qt.FreeBSD.mk b/qnetchess/qt.FreeBSD.mk new file mode 100644 index 00000000..f9c913bb --- /dev/null +++ b/qnetchess/qt.FreeBSD.mk @@ -0,0 +1,29 @@ +# $Id: qt.FreeBSD.mk,v 1.0 2004/11/05 10:22:11 denis Exp $ + +QTDIR= ${X11BASE} +MOC= ${QTDIR}/bin/moc +LUPDATE= ${QTDIR}/bin/lupdate +LRELEASE= ${QTDIR}/bin/lrelease + +PTHREAD_CFLAGS?= -pthread +PTHREAD_LIBS?= -pthread + +QTCFLAGS= ${QTDIR}/include -DQT_NO_COMPAT ${PTHREAD_CFLAGS} +QTLFLAGS= -L${QTDIR}/lib -lqt-mt ${PTHREAD_LIBS} + +CFLAGS+= -I${QTCFLAGS} +CXXFLAGS= ${CFLAGS} +LDADD+= ${QTLFLAGS} + +SRCMOC= ${MOCS:M*.h:R:S/$/.cxx/g} +OBJMOC= ${MOCS:M*.h:R:S/$/.mo/g} +OBJS+= ${OBJMOC} +CLEANFILES+= ${SRCMOC} + +.SUFFIXES: .h .cxx .mo + +.h.cxx: + ${MOC} ${.IMPSRC} -o ${.TARGET} + +.cxx.mo: + ${CXX} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} diff --git a/qnetchess/src/CMakeLists.txt b/qnetchess/src/CMakeLists.txt new file mode 100644 index 00000000..4d5bac08 --- /dev/null +++ b/qnetchess/src/CMakeLists.txt @@ -0,0 +1,44 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# (C) 2011-2012 Timothy Pearson +# kb9vqf (AT) pearsoncomputing (DOT) net +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIR} +) + + +##### q15 ################################# + +install( PROGRAMS + ${CMAKE_CURRENT_BINARY_DIR}/qnetchess + DESTINATION ${BIN_INSTALL_DIR} ) + + +set( target qnetchess ) + +set( ${target}_SRCS + gameboard.cpp gamesocket.cpp main.cpp mainwindow.cpp +) + +tde_add_executable( ${target} AUTOMOC + SOURCES ${${target}_SRCS} + LINK tqt-mt + DESTINATION ${BIN_INSTALL_DIR} +) diff --git a/qnetchess/src/gameboard.cpp b/qnetchess/src/gameboard.cpp new file mode 100644 index 00000000..ca07e3b8 --- /dev/null +++ b/qnetchess/src/gameboard.cpp @@ -0,0 +1,1987 @@ +/* + * $Id: gameboard.cpp,v 1.1 2005/03/26 11:24:13 denis Exp $ + * + * Author: Denis Kozadaev (denis@tambov.ru) + * Description: + * + * See also: style(9) + * + * Hacked by: + * Fixed the mate checker (big thanks to knyaz@RusNet) + */ + +#include <ntqpainter.h> +#include <ntqfontmetrics.h> +#include <ntqmessagebox.h> +#include <ntqcursor.h> +#include <ntqfiledialog.h> +#include <stdlib.h> + +#include "gameboard.h" +#include "gamesocket.h" + +#include "xpm/black_bishop.xpm" +#include "xpm/black_castle.xpm" +#include "xpm/black_king.xpm" +#include "xpm/black_knight.xpm" +#include "xpm/black_pawn.xpm" +#include "xpm/black_queen.xpm" +#include "xpm/white_bishop.xpm" +#include "xpm/white_castle.xpm" +#include "xpm/white_king.xpm" +#include "xpm/white_knight.xpm" +#include "xpm/white_pawn.xpm" +#include "xpm/white_queen.xpm" + +const int + cell_size = 40, + XSize = 640, + YSize = 480; + +TQColor cb, cw; + +bool +Figure::hasMyFigure(GameBoard::GameType gt, GameBoard::FigureType *map, + int x, int y, bool mirror) +{ + int n; + bool res; + + n = map2map(gt, x, y, mirror); + + if (gt == GameBoard::WHITE) + switch (map[n]) { + case GameBoard::DUMMY: + case GameBoard::WHITE_PAWN: + case GameBoard::WHITE_CASTLE: + case GameBoard::WHITE_BISHOP: + case GameBoard::WHITE_KING: + case GameBoard::WHITE_QUEEN: + case GameBoard::WHITE_KNIGHT: + res = TRUE; + break; + default: + res = FALSE; + } + else if (gt == GameBoard::BLACK) + switch (map[n]) { + case GameBoard::DUMMY: + case GameBoard::BLACK_PAWN: + case GameBoard::BLACK_CASTLE: + case GameBoard::BLACK_BISHOP: + case GameBoard::BLACK_KING: + case GameBoard::BLACK_QUEEN: + case GameBoard::BLACK_KNIGHT: + res = TRUE; + break; + default: + res = FALSE; + } + else + res = FALSE; + + return (res); +} + + +int +Figure::hasEnemyFigure(GameBoard::GameType gt, GameBoard::FigureType *map, + int x, int y, bool mirror) +{ + int n; + int res; + + n = map2map(gt, x, y, mirror); + + if (gt == GameBoard::BLACK) + switch (map[n]) { + case GameBoard::WHITE_PAWN: + case GameBoard::WHITE_CASTLE: + case GameBoard::WHITE_BISHOP: + case GameBoard::WHITE_QUEEN: + case GameBoard::WHITE_KNIGHT: + res = 1; + break; + case GameBoard::WHITE_KING: + res = 2; + break; + case GameBoard::DUMMY: + default: + res = 0; + } + else if (gt == GameBoard::WHITE) + switch (map[n]) { + case GameBoard::BLACK_PAWN: + case GameBoard::BLACK_CASTLE: + case GameBoard::BLACK_BISHOP: + case GameBoard::BLACK_QUEEN: + case GameBoard::BLACK_KNIGHT: + res = 1; + break; + case GameBoard::BLACK_KING: + res = 2; + break; + case GameBoard::DUMMY: + default: + res = 0; + } + else + res = 0; + + return (res); +} + + +bool +Figure::hasFigure(GameBoard::GameType gt, GameBoard::FigureType *map, + int x, int y, bool mirror) +{ + int n; + + n = map2map(gt, x, y, mirror); + + return (map[n] != GameBoard::NONE); +} + + +int +Figure::map2map(GameBoard::GameType gt, int x, int y, bool mirror) +{ + int n = -1; + + if (gt == GameBoard::WHITE) + if (mirror) + n = (y - 1) * 8 + (8 - x); + else + n = (8 - y) * 8 + (x - 1); + else if (gt == GameBoard::BLACK) + if (mirror) + n = (8 - y) * 8 + (x - 1); + else + n = (y - 1) * 8 + (8 - x); + + return (n); +} + + +QString +Figure::map2str(int x, int y) +{ + QString s; + + s = TQString(TQChar('a' + x - 1)) + TQString::number(y); + return (s); +} + + +void +Figure::str2map(const TQString &coo, int *x, int *y) +{ + + *x = coo[0] - 'a' + 1; + *y = coo[1] - '0'; +} + + +int +Figure::validMove(GameBoard::GameType gt, GameBoard::FigureType *map, + int fx, int fy, int tx, int ty, bool mirror) +{ + TQPointArray vl; + int res, f, t; + + moveList(vl, gt, map, fx, fy, mirror); + res = hasPoint(vl, tx, ty); + f = map2map(gt, fx, fy, mirror); + switch (map[f]) { + case GameBoard::WHITE_PAWN: + if (res && (ty == 8)) + res++; + break; + case GameBoard::BLACK_PAWN: + if (res && (ty == 1)) + res++; + break; + default:; + } + if (res) { + t = map2map(gt, tx, ty, mirror); + map[t] = map[f]; + map[f] = GameBoard::NONE; + if (mirror) { + vl.resize(0); + t = checkKing(gt, map, mirror, vl, FALSE); + switch (t) { + case 1: + res |= 0x10; + break; + case 2: + res |= 0x20; + break; + case 3: + res |= 0x40; + break; + default:; + } + } + } + + return (res); +} + + +/* + * 0 - nothing + * 1 - check + * 2 - mate + * 3 - stalemate + */ +int +Figure::checkKing(GameBoard::GameType gt, GameBoard::FigureType *map, + bool mirror, TQPointArray &vl, bool co) +{ + TQPointArray tmp; + GameBoard::FigureType myking, map1[64]; + GameBoard::GameType mytype; + int res, x, y, p, xk, yk, pk; + bool hp; + + if (gt == GameBoard::WHITE) { + myking = GameBoard::BLACK_KING; + mytype = GameBoard::BLACK; + } else if (gt == GameBoard::BLACK) { + myking = GameBoard::WHITE_KING; + mytype = GameBoard::WHITE; + } else { + myking = GameBoard::NONE; + mytype = GameBoard::NOGAME; + } + xk = yk = -1; + res = 0; p = -1; + + for (y = 1; y < 9; ++y) + for (x = 1; x < 9; ++x) + /* check enemy figures */ + if (hasMyFigure(gt, map, x, y, mirror)) + moveList(vl, gt, map, x, y, mirror); + else if (p == -1) { + p = map2map(mytype, x, y, !mirror); + if (map[p] == myking) { + xk = x; + yk = y; + } else + p = -1; + } + + hp = hasPoint(vl, xk, yk); + if (hp) { + res++; + if (!co) { + vl.resize(0); + for (y = 1; y < 9; ++y) + for (x = 1; x < 9; ++x) + if (hasMyFigure(mytype, map, + x, y, !mirror)) + moveList(vl, mytype, map, + x, y, !mirror); + memmove(map1, map, sizeof(map1)); + pk = map2map(mytype, xk, yk, !mirror); + for (x = vl.size() - 1; x >= 0; --x) { + p = map2map(mytype, vl.point(x).x(), + vl.point(x).y(), !mirror); + if (p != pk) + map1[p] = GameBoard::DUMMY; + } + if (checkKing(gt, map1, mirror, vl, TRUE) != 0) { + vl.resize(0); + moveListKing(vl, mytype, map, xk, yk, !mirror); + memmove(map1, map, sizeof(map1)); + for (y = 0, x = vl.size() - 1; x >= 0; --x) { + p = map2map(mytype, vl.point(x).x(), + vl.point(x).y(), !mirror); + map1[p] = myking; + map1[pk] = GameBoard::NONE; + if (checkKing(gt, map1, mirror, + tmp, TRUE) == 1) + ++y; + map1[pk] = map[pk]; + map1[p] = map[p]; + } + if (y == (int)vl.size()) + res++; + } + } + } else if (!co) { + vl.resize(0); + for (y = 1; y < 9; ++y) + for (x = 1; x < 9; ++x) + if (hasMyFigure(mytype, map, x, y, !mirror)) + moveList(vl, mytype, map, x, y, + !mirror); + if (vl.size() == 0) + res = 3; + } + + return (res); +} + + +void +Figure::moveList(TQPointArray &vl, GameBoard::GameType gt, + GameBoard::FigureType *map, int x, int y, bool mirror) +{ + int n; + + n = map2map(gt, x, y, mirror); + switch (map[n]) { + case GameBoard::WHITE_PAWN: + moveListWhitePawn(vl, gt, map, x, y, mirror); + break; + + case GameBoard::WHITE_CASTLE: + case GameBoard::BLACK_CASTLE: + moveListCastle(vl, gt, map, x, y, mirror); + break; + + case GameBoard::WHITE_BISHOP: + case GameBoard::BLACK_BISHOP: + moveListBishop(vl, gt, map, x, y, mirror); + break; + + case GameBoard::WHITE_KING: + case GameBoard::BLACK_KING: + moveListKing(vl, gt, map, x, y, mirror); + break; + + case GameBoard::WHITE_QUEEN: + case GameBoard::BLACK_QUEEN: + moveListQueen(vl, gt, map, x, y, mirror); + break; + + case GameBoard::WHITE_KNIGHT: + case GameBoard::BLACK_KNIGHT: + moveListKnight(vl, gt, map, x, y, mirror); + break; + + case GameBoard::BLACK_PAWN: + moveListBlackPawn(vl, gt, map, x, y, mirror); + break; + + + default:; + } +} + + +void +Figure::moveListWhitePawn(TQPointArray &vl, GameBoard::GameType gt, + GameBoard::FigureType *map, int x, int y, bool mirror) +{ + + if (validPoint(gt, map, x, y + 1, mirror) && + !hasFigure(gt, map, x, y + 1, mirror)) { + vl.putPoints(vl.size(), 1, x, y + 1); + if ((y == 2) && validPoint(gt, map, x, y + 2, mirror)) + vl.putPoints(vl.size(), 1, x, y + 2); + } + if (validPoint(gt, map, x + 1, y + 1, mirror) && + hasEnemyFigure(gt, map, x + 1, y + 1, mirror)) + vl.putPoints(vl.size(), 1, x + 1, y + 1); + if (validPoint(gt, map, x - 1, y + 1, mirror) && + hasEnemyFigure(gt, map, x - 1, y + 1, mirror)) + vl.putPoints(vl.size(), 1, x - 1, y + 1); +} + + +void +Figure::moveListBlackPawn(TQPointArray &vl, GameBoard::GameType gt, + GameBoard::FigureType *map, int x, int y, bool mirror) +{ + + if (validPoint(gt, map, x, y - 1, mirror) && + !hasFigure(gt, map, x, y - 1, mirror)) { + vl.putPoints(vl.size(), 1, x, y - 1); + if ((y == 7) && validPoint(gt, map, x, y - 2, mirror)) + vl.putPoints(vl.size(), 1, x, y - 2); + } + if (validPoint(gt, map, x + 1, y - 1, mirror) && + hasEnemyFigure(gt, map, x + 1, y - 1, mirror)) + vl.putPoints(vl.size(), 1, x + 1, y - 1); + if (validPoint(gt, map, x - 1, y - 1, mirror) && + hasEnemyFigure(gt, map, x - 1, y - 1, mirror)) + vl.putPoints(vl.size(), 1, x - 1, y - 1); +} + + +void +Figure::moveListCastle(TQPointArray &vl, GameBoard::GameType gt, + GameBoard::FigureType *map, int x, int y, bool mirror) +{ + int i; + + for (i = x + 1; i < 9; i++) { + if (!hasFigure(gt, map, i, y, mirror)) { + vl.putPoints(vl.size(), 1, i, y); + continue; + } else if (hasEnemyFigure(gt, map, i, y, mirror)) + vl.putPoints(vl.size(), 1, i, y); + break; + } + for (i = x - 1; i > 0; i--) { + if (!hasFigure(gt, map, i, y, mirror)) { + vl.putPoints(vl.size(), 1, i, y); + continue; + } else if (hasEnemyFigure(gt, map, i, y, mirror)) + vl.putPoints(vl.size(), 1, i, y); + break; + } + for (i = y + 1; i < 9; i++) { + if (!hasFigure(gt, map, x, i, mirror)) { + vl.putPoints(vl.size(), 1, x, i); + continue; + } else if (hasEnemyFigure(gt, map, x, i, mirror)) + vl.putPoints(vl.size(), 1, x, i); + break; + } + for (i = y - 1; i > 0; i--) { + if (!hasFigure(gt, map, x, i, mirror)) { + vl.putPoints(vl.size(), 1, x, i); + continue; + } else if (hasEnemyFigure(gt, map, x, i, mirror)) + vl.putPoints(vl.size(), 1, x, i); + break; + } +} + + +void +Figure::moveListBishop(TQPointArray &vl, GameBoard::GameType gt, + GameBoard::FigureType *map, int x, int y, bool mirror) +{ + int i, j; + + for (i = x + 1, j = y + 1; (i < 9) && (j < 9); i++, j++) { + if (!hasFigure(gt, map, i, j, mirror)) { + vl.putPoints(vl.size(), 1, i, j); + continue; + } else if (hasEnemyFigure(gt, map, i, j, mirror)) + vl.putPoints(vl.size(), 1, i, j); + break; + } + for (i = x - 1, j = y + 1; (i > 0) && (j < 9); i--, j++) { + if (!hasFigure(gt, map, i, j, mirror)) { + vl.putPoints(vl.size(), 1, i, j); + continue; + } else if (hasEnemyFigure(gt, map, i, j, mirror)) + vl.putPoints(vl.size(), 1, i, j); + break; + } + for (i = x - 1, j = y - 1; (i > 0) && (j > 0); i--, j--) { + if (!hasFigure(gt, map, i, j, mirror)) { + vl.putPoints(vl.size(), 1, i, j); + continue; + } else if (hasEnemyFigure(gt, map, i, j, mirror)) + vl.putPoints(vl.size(), 1, i, j); + break; + } + for (i = x + 1, j = y - 1; (i < 9) && (j > 0); i++, j--) { + if (!hasFigure(gt, map, i, j, mirror)) { + vl.putPoints(vl.size(), 1, i, j); + continue; + } else if (hasEnemyFigure(gt, map, i, j, mirror)) + vl.putPoints(vl.size(), 1, i, j); + break; + } +} + + +void +Figure::moveListKing(TQPointArray &vl, GameBoard::GameType gt, + GameBoard::FigureType *map, int x, int y, bool mirror) +{ + int x1, x2, y1, y2; + + x1 = x - 1; x2 = x + 1; + y1 = y - 1; y2 = y + 1; + if (validPoint(gt, map, x1, y2, mirror) && + !hasKingsMeeting(gt, map, x1, y2, mirror)) + vl.putPoints(vl.size(), 1, x1, y2); + if (validPoint(gt, map, x, y2, mirror) && + !hasKingsMeeting(gt, map, x, y2, mirror)) + vl.putPoints(vl.size(), 1, x, y2); + if (validPoint(gt, map, x2, y2, mirror) && + !hasKingsMeeting(gt, map, x2, y2, mirror)) + vl.putPoints(vl.size(), 1, x2, y2); + if (validPoint(gt, map, x1, y, mirror) && + !hasKingsMeeting(gt, map, x1, y, mirror)) + vl.putPoints(vl.size(), 1, x1, y); + if (validPoint(gt, map, x2, y, mirror) && + !hasKingsMeeting(gt, map, x2, y, mirror)) + vl.putPoints(vl.size(), 1, x2, y); + if (validPoint(gt, map, x1, y1, mirror) && + !hasKingsMeeting(gt, map, x1, y1, mirror)) + vl.putPoints(vl.size(), 1, x1, y1); + if (validPoint(gt, map, x, y1, mirror) && + !hasKingsMeeting(gt, map, x, y1, mirror)) + vl.putPoints(vl.size(), 1, x, y1); + if (validPoint(gt, map, x2, y1, mirror) && + !hasKingsMeeting(gt, map, x2, y1, mirror)) + vl.putPoints(vl.size(), 1, x2, y1); +} + + +void +Figure::moveListQueen(TQPointArray &vl, GameBoard::GameType gt, + GameBoard::FigureType *map, int x, int y, bool mirror) +{ + + moveListBishop(vl, gt, map, x, y, mirror); + moveListCastle(vl, gt, map, x, y, mirror); +} + + +void +Figure::moveListKnight(TQPointArray &vl, GameBoard::GameType gt, + GameBoard::FigureType *map, int x, int y, bool mirror) +{ + int x1, x2, x3, x4, + y1, y2, y3, y4; + + x1 = x + 1; + x2 = x1 + 1; + x3 = x - 1; + x4 = x3 - 1; + y1 = y + 1; + y2 = y1 + 1; + y3 = y - 1; + y4 = y3 - 1; + if (validPoint(gt, map, x3, y2, mirror)) + vl.putPoints(vl.size(), 1, x3, y2); + if (validPoint(gt, map, x1, y2, mirror)) + vl.putPoints(vl.size(), 1, x1, y2); + if (validPoint(gt, map, x4, y1, mirror)) + vl.putPoints(vl.size(), 1, x4, y1); + if (validPoint(gt, map, x2, y1, mirror)) + vl.putPoints(vl.size(), 1, x2, y1); + if (validPoint(gt, map, x4, y3, mirror)) + vl.putPoints(vl.size(), 1, x4, y3); + if (validPoint(gt, map, x2, y3, mirror)) + vl.putPoints(vl.size(), 1, x2, y3); + if (validPoint(gt, map, x3, y4, mirror)) + vl.putPoints(vl.size(), 1, x3, y4); + if (validPoint(gt, map, x1, y4, mirror)) + vl.putPoints(vl.size(), 1, x1, y4); +} + + +bool +Figure::hasKingsMeeting(GameBoard::GameType gt, GameBoard::FigureType *map, + int x, int y, bool mirror) +{ + int x1, x2, y1, y2; + bool res; + + x1 = x - 1; x2 = x + 1; + y1 = y - 1; y2 = y + 1; + res = FALSE; + + if (validPoint(gt, map, x1, y2, mirror)) + res = (hasEnemyFigure(gt, map, x1, y2, mirror) == 2); + if (! res && validPoint(gt, map, x, y2, mirror)) + res = (hasEnemyFigure(gt, map, x, y2, mirror) == 2); + if (!res && validPoint(gt, map, x2, y2, mirror)) + res = (hasEnemyFigure(gt, map, x2, y2, mirror) == 2); + if (!res && validPoint(gt, map, x1, y, mirror)) + res = (hasEnemyFigure(gt, map, x1, y, mirror) == 2); + if (!res && validPoint(gt, map, x2, y, mirror)) + res = (hasEnemyFigure(gt, map, x2, y, mirror) == 2); + if (!res && validPoint(gt, map, x1, y1, mirror)) + res = (hasEnemyFigure(gt, map, x1, y1, mirror) == 2); + if (!res && validPoint(gt, map, x, y1, mirror)) + res = (hasEnemyFigure(gt, map, x, y1, mirror) == 2); + if (!res && validPoint(gt, map, x2, y1, mirror)) + res = (hasEnemyFigure(gt, map, x2, y1, mirror) == 2); + + return (res); +} + + +bool +Figure::hasPoint(const TQPointArray &vl, int x, int y) +{ + int i, xp, yp, cnt; + bool res = FALSE; + + cnt = vl.count(); + for (i = 0; i < cnt; ++i) { + vl.point(i, &xp, &yp); + if ((xp == x) && (yp == y)) { + res = TRUE; + break; + } + } + + return (res); +} + + +bool +Figure::validPoint(GameBoard::GameType gt, GameBoard::FigureType *map, + int x, int y, bool mirror) +{ + bool res; + + res = ((x >0) && (x < 9) && (y >0) && (y < 9)); + if (res) + res = !hasMyFigure(gt, map, x, y, mirror); + + return (res); +} + +//----------------------------------------------------------------------------- + +GameBoard::GameBoard(GameType g, const TQString &h, TQWidget *parent, + const char *name) + :TQWidget(parent, name, TQt::WResizeNoErase | + TQt::WRepaintNoErase | TQt::WDestructiveClose) +{ + TQString str; + + gt = g; hst = h; + setCursor(TQCursor(TQt::WaitCursor)); + if (gt == WHITE) + str = tr("White"); + else if (gt == BLACK) + str = tr("Black"); + str += ' ' + tr("game with") + ' '; + setCaption(str + hst); + setIcon(TQPixmap((const char **)white_knight)); + map = new FigureType[64]; + initMap(); + + sock = new TQSocket(this); + drw = new Drawer(map, >, this); + drw->setEnabled(FALSE); + drw->setFocusPolicy(NoFocus); + box = new TQGroupBox(tr("Game chat"), this); + lst = new TQListBox(box); + lst->setFocusPolicy(NoFocus); + lst->setVScrollBarMode(TQScrollView::AlwaysOff); + lst->setSelectionMode(TQListBox::NoSelection); + edt = new TQLineEdit(box); + edt->setEnabled(FALSE); + setFocusProxy(edt); + hist = new TQGroupBox(tr("History"), this); + hist->setAlignment(TQt::AlignHCenter); + hist->setFocusPolicy(NoFocus); + hw = new TQListBox(hist); + hw->setSelectionMode(TQListBox::NoSelection); + hw->setPaletteBackgroundColor(cw); + hb = new TQListBox(hist); + hb->setSelectionMode(TQListBox::NoSelection); + hb->setPaletteBackgroundColor(cb); + tmr = new TQTimer(this); + sock_tout = SOCK_WAIT; + my_stat = tr("Looking up the host") + ' ' + hst + "..."; + TQObject::connect(sock, SIGNAL(hostFound()), + this, SLOT(showHostFound())); + TQObject::connect(sock, SIGNAL(connected()), + this, SLOT(sockConnected())); + TQObject::connect(sock, SIGNAL(readyRead()), + this, SLOT(sockRead())); + TQObject::connect(sock, SIGNAL(connectionClosed()), + this, SLOT(sockClosed())); + TQObject::connect(sock, SIGNAL(error(int)), + this, SLOT(sockError(int))); + TQObject::connect(drw, SIGNAL(moved(const TQString&)), + this, SLOT(sendMove(const TQString&))); + TQObject::connect(drw, SIGNAL(newFigure(const TQString&, + GameBoard::FigureType)), + this, SLOT(sendFigure(const TQString&, GameBoard::FigureType))); + TQObject::connect(drw, SIGNAL(gameover(int)), + this, SLOT(gameover(int))); + TQObject::connect(edt, SIGNAL(returnPressed()), + this, SLOT(sendText())); + TQObject::connect(tmr, SIGNAL(timeout()), this, SLOT(sockTest())); + + resize(XSize, YSize); + setMinimumSize(size()); + setMaximumSize(size()); + sock->connectToHost(hst, GAME_PORT); + tmr->start(1000); +} + +GameBoard::GameBoard(int sfd, TQWidget *parent, const char *name) + :TQWidget(parent, name, TQt::WResizeNoErase | TQt::WRepaintNoErase | + TQt::WDestructiveClose) +{ + + gt = NOGAME; + setCursor(TQCursor(TQt::WaitCursor)); + setIcon(TQPixmap((const char **)white_knight)); + map = new FigureType[64]; + memset(map, NONE, 64 * sizeof(*map)); + + sock = new TQSocket(this); + drw = new Drawer(map, >, this); + drw->setEnabled(FALSE); + drw->setFocusPolicy(NoFocus); + box = new TQGroupBox(tr("Game chat"), this); + lst = new TQListBox(box); + lst->setFocusPolicy(NoFocus); + lst->setVScrollBarMode(TQScrollView::AlwaysOff); + lst->setSelectionMode(TQListBox::NoSelection); + edt = new TQLineEdit(box); + setFocusProxy(edt); + hist = new TQGroupBox(tr("History"), this); + hist->setAlignment(TQt::AlignHCenter); + hist->setFocusPolicy(NoFocus); + hw = new TQListBox(hist); + hw->setSelectionMode(TQListBox::NoSelection); + hw->setPaletteBackgroundColor(cw); + hb = new TQListBox(hist); + hb->setSelectionMode(TQListBox::NoSelection); + hb->setPaletteBackgroundColor(cb); + tmr = new TQTimer(this); + sock->setSocket(sfd); + sock_tout = SOCK_WAIT; + my_stat = tr("Accepted a new connection"); + TQObject::connect(sock, SIGNAL(hostFound()), + this, SLOT(showHostFound())); + TQObject::connect(sock, SIGNAL(connected()), + this, SLOT(sockConnected())); + TQObject::connect(sock, SIGNAL(readyRead()), + this, SLOT(sockRead())); + TQObject::connect(sock, SIGNAL(connectionClosed()), + this, SLOT(sockClosed())); + TQObject::connect(sock, SIGNAL(error(int)), + this, SLOT(sockError(int))); + TQObject::connect(drw, SIGNAL(moved(const TQString&)), + this, SLOT(sendMove(const TQString&))); + TQObject::connect(drw, SIGNAL(newFigure(const TQString&, + GameBoard::FigureType)), + this, SLOT(sendFigure(const TQString&, GameBoard::FigureType))); + TQObject::connect(drw, SIGNAL(gameover(int)), + this, SLOT(gameover(int))); + TQObject::connect(edt, SIGNAL(returnPressed()), + this, SLOT(sendText())); + TQObject::connect(tmr, SIGNAL(timeout()), this, SLOT(sockTest())); + resize(XSize, YSize); + setMinimumSize(size()); + setMaximumSize(size()); + tmr->start(1000); +} + +GameBoard::~GameBoard() +{ + + GameProtocol::sendQuit(sock); + delete tmr; + delete hb; + delete hw; + delete hist; + delete edt; + delete lst; + delete box; + delete drw; + delete sock; + delete map; +} + + +void +GameBoard::resizeEvent(TQResizeEvent *e) +{ + TQFontMetrics fm(font()); + int w = e->size().width(), + h = e->size().height(), + fh = fm.lineSpacing() + 4; + + TQWidget::resizeEvent(e); + drw->move(0, 0); + box->move(drw->x(), drw->y() + drw->height()); + box->resize(w, h - box->y()); + edt->move(2, box->height() - fh - 2); + edt->resize(box->width() - edt->x() * 2, fh); + lst->move(edt->x(), fm.lineSpacing()); + lst->resize(edt->width(), edt->y() - lst->y()); + hist->move(drw->x() + drw->width(), drw->y()); + hist->resize(w - hist->x(), box->y()); + hw->move(2, TQFontMetrics(hist->font()).lineSpacing()); + hw->resize((hist->width() - hw->x()) / 2, + hist->height() - hw->y() - 2); + hb->move(hw->x() + hw->width(), hw->y()); + hb->resize(hw->size()); +} + + +void +GameBoard::focusInEvent(TQFocusEvent *e) +{ + + TQWidget::focusInEvent(e); + emit showStatus(my_stat); +} + + +void +GameBoard::initMap() +{ + + memset(map, NONE, 64 * sizeof(*map)); + if (gt == WHITE) { + map[0] = BLACK_CASTLE; + map[1] = BLACK_KNIGHT; + map[2] = BLACK_BISHOP; + map[3] = BLACK_QUEEN; + map[4] = BLACK_KING; + map[5] = BLACK_BISHOP; + map[6] = BLACK_KNIGHT; + map[7] = BLACK_CASTLE; + map[8] = BLACK_PAWN; + map[9] = BLACK_PAWN; + map[10] = BLACK_PAWN; + map[11] = BLACK_PAWN; + map[12] = BLACK_PAWN; + map[13] = BLACK_PAWN; + map[14] = BLACK_PAWN; + map[15] = BLACK_PAWN; + map[48] = WHITE_PAWN; + map[49] = WHITE_PAWN; + map[50] = WHITE_PAWN; + map[51] = WHITE_PAWN; + map[52] = WHITE_PAWN; + map[53] = WHITE_PAWN; + map[54] = WHITE_PAWN; + map[55] = WHITE_PAWN; + map[56] = WHITE_CASTLE; + map[57] = WHITE_KNIGHT; + map[58] = WHITE_BISHOP; + map[59] = WHITE_QUEEN; + map[60] = WHITE_KING; + map[61] = WHITE_BISHOP; + map[62] = WHITE_KNIGHT; + map[63] = WHITE_CASTLE; + } else { + map[0] = WHITE_CASTLE; + map[1] = WHITE_KNIGHT; + map[2] = WHITE_BISHOP; + map[3] = WHITE_KING; + map[4] = WHITE_QUEEN; + map[5] = WHITE_BISHOP; + map[6] = WHITE_KNIGHT; + map[7] = WHITE_CASTLE; + map[8] = WHITE_PAWN; + map[9] = WHITE_PAWN; + map[10] = WHITE_PAWN; + map[11] = WHITE_PAWN; + map[12] = WHITE_PAWN; + map[13] = WHITE_PAWN; + map[14] = WHITE_PAWN; + map[15] = WHITE_PAWN; + map[48] = BLACK_PAWN; + map[49] = BLACK_PAWN; + map[50] = BLACK_PAWN; + map[51] = BLACK_PAWN; + map[52] = BLACK_PAWN; + map[53] = BLACK_PAWN; + map[54] = BLACK_PAWN; + map[55] = BLACK_PAWN; + map[56] = BLACK_CASTLE; + map[57] = BLACK_KNIGHT; + map[58] = BLACK_BISHOP; + map[59] = BLACK_KING; + map[60] = BLACK_QUEEN; + map[61] = BLACK_BISHOP; + map[62] = BLACK_KNIGHT; + map[63] = BLACK_CASTLE; + } +} + + +void +GameBoard::showHostFound() +{ + + my_stat = tr("The host found"); + emit showStatus(my_stat); +} + + +void +GameBoard::sockConnected() +{ + + my_stat = tr("Connected to the host"); + emit showStatus(my_stat); + GameProtocol::setGameType(sock, gt); + edt->setEnabled(TRUE); +} + + +void +GameBoard::sockRead() +{ + TQString str; + + if (sock->canReadLine()) { + str = sock->readLine(); + str.remove(EOL); + str.remove('\r'); + parseString(str); + sock_tout = SOCK_WAIT; + } +} + + +void +GameBoard::sockClosed() +{ + + close(); +} + + +void +GameBoard::sockError(int err) +{ + TQString e; + + TQMessageBox::critical(this, tr("Socket Error..."), + tr("You have a socket error number") + ' ' + + TQString::number(err)); +} + + +void +GameBoard::parseString(const TQString &str) +{ + TQStringList lst(TQStringList::split(SEP, str)); + TQString s(lst[0].lower()); + int id; + + if (s == "game") { + s = lst[1].lower(); + if (s == "mate") { + updateHistory(GAMEOVER_TXT, TRUE); + gt = NOGAME; + gameover(0); + close(); + } else if (s == "stalemate") { + gt = NOGAME; + gameover(3); + close(); + } else if (s != "accept") { + if (s == "white") { + gt = BLACK; + s = tr("White"); + } else if (s == "black") { + gt = WHITE; + s = tr("Black"); + drw->setEnabled(TRUE); + setCursor(TQCursor(TQt::ArrowCursor)); + } + s += ' ' + tr("game from") + ' '; + my_stat = tr("Accepted the") + ' ' + s; + hst = sock->peerName(); + if (hst.isEmpty()) + hst = sock->peerAddress().toString() + ':' + + TQString::number(sock->peerPort()); + initMap(); + drw->repaint(TRUE); + GameProtocol::acceptGame(sock); + setCaption(s + hst); + my_stat += hst; + emit showStatus(my_stat); + } else if (gt == WHITE) { + drw->setEnabled(TRUE); + setCursor(TQCursor(TQt::ArrowCursor)); + } + } else if (s == "move") { + if (!drw->isEnabled()) { + drw->setEnabled(TRUE); + s = lst[1].lower(); + updateHistory(s, TRUE); + drw->makeMove(s); + setCursor(TQCursor(TQt::ArrowCursor)); + my_stat = tr("Your move..."); + emit showStatus(my_stat); + } + } else if (s == "quit") { + gt = NOGAME; + sockClosed(); + } else if (s == "chat") { + s = str.right(str.length() - 5); + updateChat('>' + s); + } else if (s == "figure") { + s = lst[1].lower(); + id = lst[2].toInt(); + drw->newFigure(s, id); + updateHistory(id, TRUE); + } +} + + +void +GameBoard::sendMove(const TQString &str) +{ + + GameProtocol::sendMove(sock, str); + drw->setEnabled(FALSE); + setCursor(TQCursor(TQt::WaitCursor)); + updateHistory(str, FALSE); + sock_tout = SOCK_WAIT; + my_stat = tr("Waiting a move..."); + emit showStatus(my_stat); +} + + +void +GameBoard::closeEvent(TQCloseEvent *e) +{ + int res; + + if (gt != NOGAME) { + res = TQMessageBox::question(this, tr("End the game"), + tr("Want you to end the game?\nYou will lose it"), + tr("Yes, end"), tr("No, continue"), TQString::null, 1); + if (res == 0) + TQWidget::closeEvent(e); + } else + TQWidget::closeEvent(e); +} + + +void +GameBoard::sendText() +{ + TQString s; + + s = edt->text().utf8(); + if (!s.isEmpty()) { + updateChat(s); + GameProtocol::sendText(sock, s.ascii()); + } + edt->clear(); +} + + +void +GameBoard::updateChat(const TQString &s) +{ + int fh, h; + + lst->insertItem(TQString::fromUtf8(s.ascii())); + h = lst->height(); + fh = TQFontMetrics(lst->font()).lineSpacing(); + if ((int)lst->count() * fh >= lst->visibleHeight()) + lst->removeItem(0); +} + + +void +GameBoard::updateHistory(const TQString &st, bool t) +{ + TQString s; + + if (st.length() == 3) { + if (st[0] == '@') + s = "O-O"; + else + s = st; + } else + s = st.left(2) + " - " + st.right(2); + if (t) { + if (gt == WHITE) + hb->insertItem(s); + else if (gt == BLACK) + hw->insertItem(s); + } else { + if (gt == WHITE) + hw->insertItem(s); + else if (gt == BLACK) + hb->insertItem(s); + } +} + + +void +GameBoard::updateHistory(int id, bool t) +{ + TQString s("; "), s1; + + switch (id) { + case 3: + s += tr("B"); + break; + case 4: + s += tr("K"); + break; + case 5: + s += tr("C"); + break; + case 10: + s += tr("Q"); + break; + default: + s += tr("Error!"); + } + if (t) { + if (gt == WHITE) { + id = hb->count() - 1; + s1 = hb->text(id); + hb->changeItem(s1 + s, id); + } else if (gt == BLACK) { + id = hw->count() - 1; + s1 = hw->text(id); + hw->changeItem(s1 + s, id); + } + } else { + if (gt == WHITE) { + id = hw->count() - 1; + s1 = hw->text(id); + hw->changeItem(s1 + s, id); + } else if (gt == BLACK) { + id = hb->count() - 1; + s1 = hb->text(id); + hb->changeItem(s1 + s, id); + } + } +} + + +void +GameBoard::sendFigure(const TQString &coo, GameBoard::FigureType ft) +{ + int id = -1; + + switch (ft) { + case BLACK_CASTLE: + case WHITE_CASTLE: + id = 5; + break; + + case BLACK_BISHOP: + case WHITE_BISHOP: + id = 3; + break; + + case BLACK_KNIGHT: + case WHITE_KNIGHT: + id = 4; + break; + + case BLACK_QUEEN: + case WHITE_QUEEN: + id = 10; + break; + default: + id = -1; + } + if (id != -1) { + GameProtocol::sendFigure(sock, coo, id); + updateHistory(id, FALSE); + } +} + + +void +GameBoard::sockTest() +{ + + --sock_tout; + if (sock_tout < 0) { + tmr->stop(); + HAXEP: + gt = NOGAME; + sockClosed(); + } else if ((sock->state() == TQSocket::HostLookup) && + (sock_tout + 60 < SOCK_WAIT)) { + tmr->stop(); + TQMessageBox::critical(this, tr("Lookup Error"), + tr("The host") + ' ' + hst + ' ' + tr("not found.")); + goto HAXEP; + } + +} + + +void +GameBoard::saveImage() +{ + TQString fn; + + fn = TQFileDialog::getSaveFileName(TQString::null, "*.png", this, NULL, + tr("Save image")); + + if (!fn.isEmpty()) { + if (fn.findRev(".png") < (int)(fn.length() - 4)) + fn += ".png"; + TQPixmap::grabWidget(this).save(fn, "PNG"); + } +} + + +void +GameBoard::gameover(int type) +{ + bool save = FALSE; + + TQString s('\n' + tr("Do you want to save the image?")), + yes(tr("Yes, save")), + no(tr("No, don't save")), + go(tr("Game over")); + + if (type == 0) { + save = (TQMessageBox::question(this, go, + tr("You scored the game") + s, yes, no) == 0); + } else if (type == 2) { + updateHistory(GAMEOVER_TXT, FALSE); + GameProtocol::sendGameover(sock, "MATE"); + save = (TQMessageBox::question(this, go, + tr("You have a mate.\nYou lost the game.") + s, + yes, no) == 0); + } else if (type == 3) { + GameProtocol::sendGameover(sock, "STALEMATE"); + save = (TQMessageBox::question(this, go, + tr("You have a stalemate") + s, yes, no) == 0); + } + + if (save) + saveImage(); +} + +//----------------------------------------------------------------------------- + +Drawer::Drawer(GameBoard::FigureType *ft, GameBoard::GameType *g, + TQWidget *parent, const char *name) + :TQWidget(parent, name, TQt::WResizeNoErase | TQt::WRepaintNoErase) +{ + TQFontMetrics fm(font()); + int i; + + map = ft; gt = g; + kk = rcm = lcm = km = FALSE; + cs = cell_size * 8; + top_margin = 5; + for (left_margin = 0, i = 0; i < 8; i++) + left_margin = MAX(fm.width(QString::number(i)), left_margin); + left_margin += top_margin; + hl = fm.lineSpacing() + 2; + setPaletteBackgroundColor(TQt::white); + i = MAX(cs + left_margin + top_margin, cs + top_margin + hl); + resize(i, i); + x_brd = i - cs - 6; + y_brd = 4; + tfx = tfy = -1; + fig[0] = TQPixmap((const char **)black_bishop); + fig[1] = TQPixmap((const char **)black_castle); + fig[2] = TQPixmap((const char **)black_knight); + fig[3] = TQPixmap((const char **)black_pawn); + fig[4] = TQPixmap((const char **)black_king); + fig[5] = TQPixmap((const char **)black_queen); + fig[6] = TQPixmap((const char **)white_bishop); + fig[7] = TQPixmap((const char **)white_castle); + fig[8] = TQPixmap((const char **)white_knight); + fig[9] = TQPixmap((const char **)white_pawn); + fig[10] = TQPixmap((const char **)white_king); + fig[11] = TQPixmap((const char **)white_queen); +} + +Drawer::~Drawer() +{ +} + + +void +Drawer::paintEvent(TQPaintEvent *e) +{ + TQPainter *p; + int w, y; + + w = width(); + y = w - 4; + TQWidget::paintEvent(e); + p = new TQPainter(this); + p->setPen(TQt::black); + p->drawRect(0, 0, w, w); + p->drawRect(2, 2, y, y); + p->drawLine(2, y, x_brd, cs + 4); + drawBoard(p, x_brd, y_brd); + drawMap(p, x_brd, y_brd); + delete p; +} + + +void +Drawer::drawBoard(TQPainter *p, int x, int y) +{ + int i, j, cs, x1, r, k; + char c, st; + + cs = Drawer::cs + 2; + p->setPen(TQt::black); + p->drawRect(x, y, cs, cs); + c = 'a'; st = 1; + r = (*gt == GameBoard::BLACK); + if (r) { + c += 7; + st = -st; + k = 1; + r ^= 1; + } else + k = 8; + x1 = x + 1; + for (j = 0, y++; j < 8; j++, y += cell_size, r ^= 1) { + for (i = 0, x = x1; i < 8; i++, x += cell_size) { + r ^= 1; + if (r) { + p->setPen(cw); + p->setBrush(cw); + } else { + p->setPen(cb); + p->setBrush(cb); + } + p->drawRect(x, y, cell_size, cell_size); + if (j == 7) { + p->setPen(Qt::black); + p->drawText(x, cs + 2, cell_size, hl, + TQt::AlignCenter, TQChar(c)); + c += st; + } + } + p->setPen(TQt::black); + p->drawText(x1 - left_margin, y, left_margin, cell_size, + TQt::AlignCenter, TQString::number(k)); + k -= st; + } + if ((tfx != -1) && (tfy != -1)) { + map2win(tfx, tfy, x, y); + p->setPen(TQPen(TQt::red, 2)); + p->setBrush(TQt::NoBrush); + p->drawRect(x, y, cell_size, cell_size); + } +} + + +void +Drawer::drawMap(TQPainter *p, int x, int y) +{ + int i, j, x1, n; + TQPixmap *xpm; + + x1 = x + 1; y++; + for (n = j = 0; j < 8; j++, y += cell_size) { + for (i = 0, x = x1; i < 8; i++, x += cell_size) { + switch (map[n++]) { + case GameBoard::WHITE_PAWN: + xpm = &fig[9]; + break; + case GameBoard::WHITE_CASTLE: + xpm = &fig[7]; + break; + case GameBoard::WHITE_BISHOP: + xpm = &fig[6]; + break; + case GameBoard::WHITE_KING: + xpm = &fig[10]; + break; + case GameBoard::WHITE_QUEEN: + xpm = &fig[11]; + break; + case GameBoard::WHITE_KNIGHT: + xpm = &fig[8]; + break; + case GameBoard::BLACK_PAWN: + xpm = &fig[3]; + break; + case GameBoard::BLACK_CASTLE: + xpm = &fig[1]; + break; + case GameBoard::BLACK_BISHOP: + xpm = &fig[0]; + break; + case GameBoard::BLACK_KING: + xpm = &fig[4]; + break; + case GameBoard::BLACK_QUEEN: + xpm = &fig[5]; + break; + case GameBoard::BLACK_KNIGHT: + xpm = &fig[2]; + break; + default: + xpm = NULL; + } + if (xpm != NULL) + p->drawPixmap(x, y, *xpm); + } + } +} + + +void +Drawer::mousePressEvent(TQMouseEvent *e) +{ + int x = e->x() - x_brd, + y = e->y() - y_brd; + + if ((x >= 0) && (x <= cs) && (y >= 0) && (y <= cs)) { + win2map(x, y); + if (hasTakenFigure()) { + if ((tfx == x) && (tfy == y)) { + tfx = tfy = -1; + repaint(FALSE); + } else + makeMove(*gt, tfx, tfy, x, y, FALSE, FALSE); + } else if (canTake(x, y)) { + takeFigure(x, y); + emit touchFigure(x, y); + } + } +} + + +bool +Drawer::canTake(int x, int y) +{ + + return (Figure::hasMyFigure(*gt, map, x, y, FALSE)); +} + + +void +Drawer::win2map(int &x, int &y) +{ + + if (*gt == GameBoard::WHITE) { + x /= cell_size; + y = 8 - y / cell_size; + x++; + } else if (*gt == GameBoard::BLACK) { + x = 8 - x / cell_size; + y /= cell_size; + y++; + } +} + + +void +Drawer::map2win(int mx, int my, int &x, int &y) +{ + + if (*gt == GameBoard::WHITE) { + x = (mx - 1) * cell_size + x_brd + 1; + y = (8 - my) * cell_size + y_brd + 1; + } else if (*gt == GameBoard::BLACK) { + x = (8 - mx) * cell_size + x_brd + 1; + y = (my - 1) * cell_size + y_brd + 1; + } else { + x = mx; + y = my; + } +} + + +void +Drawer::takeFigure(int x, int y) +{ + + if ((tfx == x) && (tfy == y)) + tfx = tfy = -1; + else { + tfx = x; + tfy = y; + } + repaint(FALSE); +} + + +bool +Drawer::hasTakenFigure() +{ + + return ((tfx != -1) && (tfy != -1)); +} + + +void +Drawer::newFigure(const TQString &coo, int id) +{ + GameBoard::FigureType ft; + int x, y, n; + + ft = GameBoard::NONE; n = -1; + Figure::str2map(coo, &x, &y); + if (*gt == GameBoard::WHITE) { + n = Figure::map2map(GameBoard::BLACK, x, y, TRUE); + switch (id) { + case 3: + ft = GameBoard::BLACK_BISHOP; + break; + case 4: + ft = GameBoard::BLACK_KNIGHT; + break; + case 5: + ft = GameBoard::BLACK_CASTLE; + break; + case 10: + ft = GameBoard::BLACK_QUEEN; + break; + default: + ft = GameBoard::NONE; + } + } else if (*gt == GameBoard::BLACK) { + n = Figure::map2map(GameBoard::WHITE, x, y, TRUE); + switch (id) { + case 3: + ft = GameBoard::WHITE_BISHOP; + break; + case 4: + ft = GameBoard::WHITE_KNIGHT; + break; + case 5: + ft = GameBoard::WHITE_CASTLE; + break; + case 10: + ft = GameBoard::WHITE_QUEEN; + break; + default: + ft = GameBoard::NONE; + } + } + + if (ft != GameBoard::NONE) { + map[n] = ft; + repaint(FALSE); + } +} + + +void +Drawer::makeMove(const TQString &txt) +{ + int fx, fy, tx, ty; + GameBoard::GameType et; + + if (*gt == GameBoard::WHITE) + et = GameBoard::BLACK; + else if (*gt == GameBoard::BLACK) + et = GameBoard::WHITE; + else + et = GameBoard::NOGAME; + if (txt == LONG_XCHG) { + if (et == GameBoard::BLACK) + makeMove(et, 1, 8, 4, 8, TRUE, TRUE); + else if (et == GameBoard::WHITE) + makeMove(et, 1, 1, 4, 1, TRUE, TRUE); + } else if (txt == SHORT_XCHG) { + if (et == GameBoard::BLACK) + makeMove(et, 8, 8, 6, 8, TRUE, TRUE); + else if (et == GameBoard::WHITE) + makeMove(et, 8, 1, 6, 1, TRUE, TRUE); + } else { + Figure::str2map(txt.left(2), &fx, &fy); + Figure::str2map(txt.right(2), &tx, &ty); + makeMove(et, fx, fy, tx, ty, TRUE, FALSE); + } +} + + +void +Drawer::makeMove(GameBoard::GameType gt, int fx, int fy, int tx, int ty, + bool mirror, bool xc) +{ + GameBoard::GameType et; + GameBoard::FigureType fo, old; + int res, nf, nt; + FigureDialog *dlg; + bool x; + TQPointArray vl; + + et = GameBoard::NOGAME; + nf = Figure::map2map(gt, fx, fy, mirror); + fo = map[nf]; + nt = Figure::map2map(gt, tx, ty, mirror); + old = map[nt]; + res = Figure::validMove(gt, map, fx, fy, tx, ty, mirror); + if (res) { + if (!mirror) { + x = FALSE; + if (gt == GameBoard::WHITE) + et = GameBoard::BLACK; + else if (gt == GameBoard::BLACK) + et = GameBoard::WHITE; + if (Figure::checkKing(et, map, mirror, vl, TRUE) != + 0) { + map[nf] = map[nt]; + map[nt] = old; + tfx = tfy = -1; + TQMessageBox::information(this, + tr("Error moving"), tr("You cannot " + "move this figure because the king " + "is in check") + '.'); + goto HAXEP; + } else + kk = FALSE; + if (!km && (!lcm || !rcm) && !kk) + x = xchg(fo, map[nt], fx, fy, tx, ty); + else + x = TRUE; + if (x) + emit moved(Figure::map2str(fx, fy) + + Figure::map2str(tx, ty)); + if ((res & 0xF) == 2) { + dlg = new FigureDialog(fig, gt, this); + dlg->exec(); + fo = dlg->figure(); + delete dlg; + map[nt] = fo; + emit newFigure(Figure::map2str(tx, ty), fo); + } + tfx = tfy = -1; + } else if (xc) { + if (gt == GameBoard::BLACK) + checkBlackCastle(fx, fy, tx, ty, TRUE); + else if (gt == GameBoard::WHITE) + checkWhiteCastle(fx, fy, tx, ty, TRUE); + } + if (mirror && (res & 0x10)) { + kk = TRUE; + } else if (res & 0x20) { + repaint(FALSE); + emit gameover(2); + return; + } else if (res & 0x40) { + repaint(FALSE); + emit gameover(3); + return; + } + HAXEP: + repaint(FALSE); + } +} + + +bool +Drawer::xchg(GameBoard::FigureType o, GameBoard::FigureType n, + int fx, int fy, int tx, int ty) +{ + bool ret = TRUE; + + if (*gt == GameBoard::WHITE) { + km = ((o == n) && (o == GameBoard::WHITE_KING)); + if (!km && ((o == n) && (o == GameBoard::WHITE_CASTLE))) + ret = checkWhiteCastle(fx, fy, tx, ty, FALSE); + } else if (*gt == GameBoard::BLACK) { + km = ((o == n) && (o == GameBoard::BLACK_KING)); + if (!km && ((o == n) && (o == GameBoard::BLACK_CASTLE))) + ret = checkBlackCastle(fx, fy, tx, ty, FALSE); + } + + return (ret); +} + + +bool +Drawer::checkWhiteCastle(int fx, int fy, int tx, int ty, bool mirror) +{ + int n1, n2; + bool ret = TRUE; + + n1 = n2 = -1; + if ((fx == 1) && (fy == 1)) { + if ((tx == 4) && (ty == 1)) + if (mirror) { + n1 = Figure::map2map(*gt, 5, 1, FALSE); + n2 = Figure::map2map(*gt, 3, 1, FALSE); + } else if (!lcm) { + if (makeXchg()) { + n1 = Figure::map2map(*gt, 5, 1, FALSE); + n2 = Figure::map2map(*gt, 3, 1, FALSE); + emit moved(LONG_XCHG); + ret = FALSE; + rcm = TRUE; + } + lcm = TRUE; + } + } else if ((fx == 8) && (fy == 1)) { + if ((tx == 6) && (ty == 1)) + if (mirror) { + n1 = Figure::map2map(*gt, 5, 1, FALSE); + n2 = Figure::map2map(*gt, 7, 1, FALSE); + } else if (!rcm) { + if (makeXchg()) { + n1 = Figure::map2map(*gt, 5, 1, FALSE); + n2 = Figure::map2map(*gt, 7, 1, FALSE); + emit moved(SHORT_XCHG); + ret = FALSE; + lcm = TRUE; + } + rcm = TRUE; + } + } + if (n1 != n2) { + map[n2] = map[n1]; + map[n1] = GameBoard::NONE; + } + + return (ret); +} + + +bool +Drawer::checkBlackCastle(int fx, int fy, int tx, int ty, bool mirror) +{ + int n1, n2; + bool ret = TRUE; + + n1 = n2 = -1; + if ((fx == 1) && (fy == 8)) { + if ((tx == 4) && (ty == 8)) { + if (mirror) { + n1 = Figure::map2map(*gt, 5, 8, FALSE); + n2 = Figure::map2map(*gt, 3, 8, FALSE); + } else if (!rcm) { + if (makeXchg()) { + n1 = Figure::map2map(*gt, 5, 8, FALSE); + n2 = Figure::map2map(*gt, 3, 8, FALSE); + emit moved(LONG_XCHG); + ret = FALSE; + } + rcm = TRUE; + } + } + } else if ((fx == 8) && (fy == 8)) { + if ((tx == 6) && (ty == 8)) + if (mirror) { + n1 = Figure::map2map(*gt, 5, 8, FALSE); + n2 = Figure::map2map(*gt, 7, 8, FALSE); + } else if (!lcm) { + if (makeXchg()) { + n1 = Figure::map2map(*gt, 5, 8, FALSE); + n2 = Figure::map2map(*gt, 7, 8, FALSE); + emit moved(SHORT_XCHG); + ret = FALSE; + } + lcm = TRUE; + } + } + if (n1 != n2) { + map[n2] = map[n1]; + map[n1] = GameBoard::NONE; + } + + return (ret); +} + + +bool +Drawer::makeXchg() +{ + + return (TQMessageBox::question(this, tr("To castle"), + tr("Do you want to castle?"), tr("Yes"), tr("No")) == 0); +} + + +//----------------------------------------------------------------------------- + +FigureDialog::FigureDialog(const TQPixmap *f, const GameBoard::GameType g, + TQWidget *parent, const char *name):TQDialog(parent, name) +{ + TQFontMetrics fm(font()); + int w, h; + + gt = g; fig = f; + if (gt == GameBoard::WHITE) + fr = GameBoard::WHITE_QUEEN; + else if (gt == GameBoard::BLACK) + fr = GameBoard::BLACK_QUEEN; + str = tr("What figure should I set?"); + setCaption(str); + fh = fm.lineSpacing() + 2; + h = cell_size + fh; + w = MAX(cell_size * 4, fm.width(str)); + step = (w - cell_size * 4) / 2; + resize(w, h); + setMinimumSize(size()); + setMaximumSize(size()); +} + +FigureDialog::~FigureDialog() +{ +} + + +void +FigureDialog::paintEvent(TQPaintEvent *e) +{ + TQPainter *p; + int x, f = -1; + + TQDialog::paintEvent(e); + p = new TQPainter(this); + + p->setPen(TQt::black); + p->drawText(0, 0, width(), fh, TQt::AlignCenter, str); + x = step; + if (gt == GameBoard::BLACK) + f = 0; + else if (gt == GameBoard::WHITE) + f = 6; + p->drawPixmap(x, fh, fig[f]); x += cell_size; + p->drawPixmap(x, fh, fig[f + 1]); x += cell_size; + p->drawPixmap(x, fh, fig[f + 2]); x += cell_size; + p->drawPixmap(x, fh, fig[f + 5]); + + delete p; +} + + +void +FigureDialog::mousePressEvent(TQMouseEvent *e) +{ + int x = e->x(), + y = e->y(), + f = -1; + + if (e->button() == TQt::LeftButton) { + if ((x >= step) && (x <= width() - step) && (y >= fh) && + (y <= height())) + f = (x - step) / cell_size; + } + + if (f != -1) { + if (gt == GameBoard::WHITE) + switch (f) { + case 0: + fr = GameBoard::WHITE_BISHOP; + break; + case 1: + fr = GameBoard::WHITE_CASTLE; + break; + case 2: + fr = GameBoard::WHITE_KNIGHT; + break; + case 3: + default: + fr = GameBoard::WHITE_QUEEN; + } + else if (gt == GameBoard::BLACK) + switch (f) { + case 0: + fr = GameBoard::BLACK_BISHOP; + break; + case 1: + fr = GameBoard::BLACK_CASTLE; + break; + case 2: + fr = GameBoard::BLACK_KNIGHT; + break; + case 3: + default: + fr = GameBoard::BLACK_QUEEN; + } + accept(); + } +} + + +//----------------------------------------------------------------------------- + +void +GameProtocol::send(TQSocket *sock, const TQString &dat) +{ + TQString s(dat + EOL); + const char *buf; + + if (sock->state() == TQSocket::Connected) { + buf = s.ascii(); + sock->writeBlock(buf, s.length()); + sock->flush(); + } +} + + +void +GameProtocol::setGameType(TQSocket *sock, GameBoard::GameType gt) +{ + TQString d("GAME"); + + d += SEP; + if (gt == GameBoard::WHITE) + d += "WHITE"; + else if (gt == GameBoard::BLACK) + d += "BLACK"; + else + d += "NOGAME"; + send(sock, d); +} + + +void +GameProtocol::acceptGame(TQSocket *sock) +{ + TQString d("GAME"); + + d += SEP; + d += "ACCEPT"; + send(sock, d); +} + + +void +GameProtocol::sendMove(TQSocket *sock, const TQString &coo) +{ + TQString d("MOVE"); + + d += SEP; + d += coo; + send(sock, d); +} + + +void +GameProtocol::sendQuit(TQSocket *sock) +{ + + send(sock, "QUIT"); +} + + +void +GameProtocol::sendText(TQSocket *sock, const TQString &txt) +{ + TQString d("CHAT"); + + d += SEP; + d += txt; + send(sock, d); +} + + +void +GameProtocol::sendFigure(TQSocket *sock, const TQString &coo, int id) +{ + TQString d("FIGURE"); + + d += SEP; + d += coo; + d += SEP; + d += TQString::number(id); + send(sock, d); +} + + +void +GameProtocol::sendGameover(TQSocket *sock, const TQString &got) +{ + TQString d("GAME"); + + d += SEP; + d += got; + send(sock, d); +} + +#include "gameboard.moc" diff --git a/qnetchess/src/gameboard.h b/qnetchess/src/gameboard.h new file mode 100644 index 00000000..2db232ac --- /dev/null +++ b/qnetchess/src/gameboard.h @@ -0,0 +1,245 @@ +/* + * $Id: gameboard.h,v 0.1 2005/01/08 13:00:57 denis Exp $ + * + * Author: Denis Kozadaev (denis@tambov.ru) + * Description: + * + * See also: style(9) + * + * Hacked by: + */ + +#ifndef __GAME_BOARD_H__ +#define __GAME_BOARD_H__ + +#include <ntqwidget.h> +#include <ntqpainter.h> +#include <ntqpixmap.h> +#include <ntqpointarray.h> +#include <ntqdialog.h> +#include <ntqsocket.h> +#include <ntqgroupbox.h> +#include <ntqlineedit.h> +#include <ntqlistbox.h> +#include <ntqtimer.h> +#include <stdlib.h> + +#define MAX(a, b) (((a) > (b))?(a):(b)) +#define SEP ' ' +#define EOL '\n' +#define LONG_XCHG "@-@" +#define SHORT_XCHG "o-o" +#define SOCK_WAIT 900 +#define GAMEOVER_TXT "****" + +class GameBoard; +class Drawer; +class Figure; + +class GameBoard:public TQWidget +{ + Q_OBJECT +public: + enum GameType { + NOGAME = 0x0, + BLACK = 0x1, + WHITE = 0x2 + }; + + enum FigureType { + NONE = 0x00, + WHITE_PAWN = 0x01, + WHITE_CASTLE = 0x02, + WHITE_BISHOP = 0x03, + WHITE_KING = 0x04, + WHITE_QUEEN = 0x05, + WHITE_KNIGHT = 0x06, + BLACK_PAWN = 0x11, + BLACK_CASTLE = 0x12, + BLACK_BISHOP = 0x13, + BLACK_KING = 0x14, + BLACK_QUEEN = 0x15, + BLACK_KNIGHT = 0x16, + DUMMY = 0xFF + }; + + GameBoard(GameType, const TQString &, TQWidget *parent = NULL, + const char *name = NULL); + GameBoard(int, TQWidget *parent = NULL, const char *name = NULL); + ~GameBoard(); + + void saveImage(); + + GameType type()const{return (gt);} + TQString status()const{return (my_stat);} + +private: + Drawer *drw; + GameType gt; + FigureType *map; + TQString hst, my_stat; + TQSocket *sock; + TQGroupBox *box, *hist; + TQListBox *lst, *hw, *hb; + TQLineEdit *edt; + TQTimer *tmr; + int sock_tout; + + void initMap(); + void parseString(const TQString&); + void updateChat(const TQString&); + void updateHistory(const TQString&, bool); + void updateHistory(int, bool); + +protected: + void resizeEvent(TQResizeEvent *); + void closeEvent(TQCloseEvent *); + void focusInEvent(TQFocusEvent *); + +private slots: + void showHostFound(); + void sockConnected(); + void sockRead(); + void sockClosed(); + void sendMove(const TQString&); + void sendText(); + void sendFigure(const TQString&, GameBoard::FigureType); + void sockTest(); + void sockError(int); + void gameover(int); + +signals: + void showStatus(const TQString&); +}; + +//----------------------------------------------------------------------------- + +class Drawer:public TQWidget +{ + Q_OBJECT +public: + Drawer(GameBoard::FigureType *, GameBoard::GameType *, + TQWidget *parent = NULL, const char *name = NULL); + ~Drawer(); + + void makeMove(const TQString&); + void newFigure(const TQString&, int); + +private: + int top_margin, left_margin, hl; + int x_brd, y_brd, cs; + int tfx, tfy; + TQPixmap fig[12]; + GameBoard::FigureType *map; + GameBoard::GameType *gt; + bool km, lcm, rcm, kk; + + void drawBoard(TQPainter *, int, int); + void drawMap(TQPainter *, int, int); + void win2map(int&, int&); + void map2win(int, int, int&, int&); + void takeFigure(int, int); + void makeMove(GameBoard::GameType, int, int, int, int, bool, bool); + bool xchg(GameBoard::FigureType, GameBoard::FigureType, + int, int, int, int); + bool checkWhiteCastle(int, int, int, int, bool); + bool checkBlackCastle(int, int, int, int, bool); + + bool canTake(int, int); + bool hasTakenFigure(); + bool makeXchg(); + +protected: + void paintEvent(TQPaintEvent *); + void mousePressEvent(TQMouseEvent *); + +signals: + void touchFigure(int, int); + void moved(const TQString&); + void newFigure(const TQString&, GameBoard::FigureType); + void gameover(int); +}; + +//----------------------------------------------------------------------------- + +class FigureDialog:public TQDialog +{ + Q_OBJECT +public: + FigureDialog(const TQPixmap *, const GameBoard::GameType, + TQWidget *parent = NULL, const char *name = NULL); + ~FigureDialog(); + + GameBoard::FigureType figure()const{return (fr);} + +private: + GameBoard::GameType gt; + const TQPixmap *fig; + TQString str; + int step, fh; + GameBoard::FigureType fr; + +protected: + void paintEvent(TQPaintEvent *); + void mousePressEvent(TQMouseEvent *); +}; + +//----------------------------------------------------------------------------- + +class Figure +{ +public: + + static bool hasMyFigure(GameBoard::GameType, + GameBoard::FigureType *, int, int, bool); + static int hasEnemyFigure(GameBoard::GameType, + GameBoard::FigureType *, int, int, bool); + static bool hasFigure(GameBoard::GameType, + GameBoard::FigureType *, int, int, bool); + static int map2map(GameBoard::GameType, int, int, bool); + static int validMove(GameBoard::GameType, GameBoard::FigureType *, + int, int, int, int, bool); + + static void moveList(TQPointArray&, GameBoard::GameType, + GameBoard::FigureType *, int, int, bool); + static void moveListWhitePawn(TQPointArray&, GameBoard::GameType, + GameBoard::FigureType *, int, int, bool); + static void moveListBlackPawn(TQPointArray&, GameBoard::GameType, + GameBoard::FigureType *, int, int, bool); + static void moveListCastle(TQPointArray&, GameBoard::GameType, + GameBoard::FigureType *, int, int, bool); + static void moveListBishop(TQPointArray&, GameBoard::GameType, + GameBoard::FigureType *, int, int, bool); + static void moveListKing(TQPointArray&, GameBoard::GameType, + GameBoard::FigureType *, int, int, bool); + static void moveListQueen(TQPointArray&, GameBoard::GameType, + GameBoard::FigureType *, int, int, bool); + static void moveListKnight(TQPointArray&, GameBoard::GameType, + GameBoard::FigureType *, int, int, bool); + static bool hasPoint(const TQPointArray&, int, int); + static bool hasKingsMeeting(GameBoard::GameType, + GameBoard::FigureType *, int, int, bool); + static bool validPoint(GameBoard::GameType, + GameBoard::FigureType *, int, int, bool); + static TQString map2str(int, int); + static void str2map(const TQString&, int *, int *); + static int checkKing(GameBoard::GameType, GameBoard::FigureType *, + bool, TQPointArray&, bool); +}; + +//----------------------------------------------------------------------------- + +class GameProtocol +{ +public: + static void send(TQSocket *, const TQString&); + static void setGameType(TQSocket *, GameBoard::GameType); + static void acceptGame(TQSocket *); + static void sendMove(TQSocket *, const TQString&); + static void sendQuit(TQSocket *); + static void sendText(TQSocket *, const TQString&); + static void sendFigure(TQSocket *, const TQString&, int); + static void sendGameover(TQSocket *, const TQString&); +}; + +#endif /* __GAME_BOARD_H__ */ diff --git a/qnetchess/src/gamesocket.cpp b/qnetchess/src/gamesocket.cpp new file mode 100644 index 00000000..b3dc2fe5 --- /dev/null +++ b/qnetchess/src/gamesocket.cpp @@ -0,0 +1,33 @@ +/* + * $Id: gamesocket.cpp,v 0.1 2005/01/08 12:31:24 denis Exp $ + * + * Author: Denis Kozadaev (denis@tambov.ru) + * Description: + * + * See also: style(9) + * + * Hacked by: + */ + +#include <ntqsocket.h> + +#include "gamesocket.h" + +GameSocket::GameSocket(TQObject *parent, const char *name) + :TQServerSocket(GAME_PORT, GAME_BACKLOG, parent, name) +{ +} + +GameSocket::~GameSocket() +{ +} + + +void +GameSocket::newConnection(int sock) +{ + + emit acceptConnection(sock); +} + +#include "gamesocket.moc" diff --git a/qnetchess/src/gamesocket.h b/qnetchess/src/gamesocket.h new file mode 100644 index 00000000..63774721 --- /dev/null +++ b/qnetchess/src/gamesocket.h @@ -0,0 +1,37 @@ +/* + * $Id: gamesocket.h,v 0.1 2005/01/08 12:31:24 denis Exp $ + * + * Author: Denis Kozadaev (denis@tambov.ru) + * Description: + * + * See also: style(9) + * + * Hacked by: + */ + +#ifndef __GAME_SOCKET_H__ +#define __GAME_SOCKET_H__ + +#include <ntqserversocket.h> +#include <stdlib.h> + +#define GAME_PORT 1345 +#define GAME_BACKLOG 5 + +class GameSocket:public TQServerSocket +{ + Q_OBJECT +public: + GameSocket(TQObject *parent = NULL, const char *name = NULL); + ~GameSocket(); + +private: + +protected: + void newConnection(int); + +signals: + void acceptConnection(int); +}; + +#endif /* __GAME_SOCKET_H__ */ diff --git a/qnetchess/src/main.cpp b/qnetchess/src/main.cpp new file mode 100644 index 00000000..d58a6cce --- /dev/null +++ b/qnetchess/src/main.cpp @@ -0,0 +1,54 @@ +/* + * $Id: main.cpp,v 0.1 2005/01/08 12:19:58 denis Exp $ + * + * Author: Denis Kozadaev (denis@tambov.ru) + * Description: + * + * See also: style(9) + * + * Hacked by: + */ + +#include <ntqapplication.h> +#include <ntqmessagebox.h> +#include <ntqtextcodec.h> +#include <ntqtranslator.h> + +#include "mainwindow.h" + +const int + XSize = 800, + YSize = 600; + +int +main(int argc, const char *argv[]) +{ + TQApplication *app; + MainWindow *mw; +// TQTranslator *qt; + int result = 0; + + app = new TQApplication(argc, (char **)argv); +/* FIXME: how does TQTranslator() work in TQt? + qt = new TQTranslator(); + if (qt->load(LOCALE_FILE)) + app->installTranslator(qt);*/ + mw = new MainWindow(); + + if (mw->sockOk()) { + app->setMainWidget(mw); + mw->show(); + mw->resize(XSize, YSize); + mw->setMinimumSize(mw->size()); + result = app->exec(); + } else + TQMessageBox::critical(NULL, TQObject::tr("Socket Error"), + TQObject::tr("Cannot create a server socket!")); + + delete mw; +// delete qt; + delete app; + + return (result); +} + diff --git a/qnetchess/src/mainwindow.cpp b/qnetchess/src/mainwindow.cpp new file mode 100644 index 00000000..d490f85d --- /dev/null +++ b/qnetchess/src/mainwindow.cpp @@ -0,0 +1,294 @@ +/* + * $Id: mainwindow.cpp,v 0.1 2005/01/08 12:20:13 denis Exp $ + * + * Author: Denis Kozadaev (denis@tambov.ru) + * Description: + * + * See also: style(9) + * + * Hacked by: + */ + +#include <ntqapplication.h> +#include <ntqmenubar.h> +#include <ntqstatusbar.h> +#include <ntqpixmap.h> +#include <ntqvalidator.h> +#include <ntqmessagebox.h> + +#include "mainwindow.h" +#include "gameboard.h" + +#include "xpm/chess.xpm" +#include "xpm/quit.xpm" +#include "xpm/new_game.xpm" + +extern TQColor cw, cb; + +MainWindow::MainWindow(TQWidget *parent, const char *name) + :TQMainWindow(parent, name) +{ + TQPixmap xpm(chess_xpm); + + cw = TQColor(0x8F, 0xDF, 0xF0); + cb = TQColor(0x70, 0x9F, 0xDF); + setIcon(xpm); + wrk = new TQWorkspace(this); + sock = new GameSocket(this); + game = new TQPopupMenu(this); + game->insertItem(TQPixmap((const char **)new_game), tr("New"), + this, SLOT(newGame()), CTRL + Key_N); + id = game->insertItem(xpm, tr("Save image"), this, + SLOT(saveImage()), CTRL + Key_S); + game->setItemEnabled(id, FALSE); + game->insertSeparator(); + game->insertItem(TQPixmap((const char **)quit_xpm), tr("Quit"), tqApp, + SLOT(quit()), CTRL + Key_Q); + help = new TQPopupMenu(this); + help->insertItem(xpm, tr("About the game"), this, SLOT(about())); + + menuBar()->insertItem(tr("Game"), game); + menuBar()->insertSeparator(); + menuBar()->insertItem(tr("Help"), help); + + setCentralWidget(wrk); + ready_txt = tr("Ready"); + showStatus(ready_txt); + + TQObject::connect(sock, SIGNAL(acceptConnection(int)), + this, SLOT(newGame(int))); + TQObject::connect(wrk, SIGNAL(windowActivated(TQWidget *)), + this, SLOT(activated(TQWidget *))); +} + +MainWindow::~MainWindow() +{ + + delete help; + delete game; + delete sock; + delete wrk; +} + + +void +MainWindow::showStatus(const TQString &txt) +{ + + statusBar()->message(txt); +} + + +void +MainWindow::newGame() +{ + SelectGame *dlg; + GameBoard *brd; + TQString hst; + + dlg = new SelectGame(this); + dlg->setHosts(hosts); + if (dlg->exec()) { + hosts = dlg->hosts(); + hst = dlg->host(); + brd = new GameBoard(dlg->gameType(), hst, wrk); + showStatus(brd->status()); + TQObject::connect(brd, SIGNAL(showStatus(const TQString&)), + this, SLOT(showStatus(const TQString&))); + brd->show(); + } + delete dlg; +} + + +void +MainWindow::newGame(int sock) +{ + GameBoard *brd; + + brd = new GameBoard(sock, wrk); + showStatus(brd->status()); + TQObject::connect(brd, SIGNAL(showStatus(const TQString&)), + this, SLOT(showStatus(const TQString&))); + brd->show(); + game->setItemEnabled(id, TRUE); +} + + +void +MainWindow::about() +{ + + TQMessageBox::about(this, tr("About") + " QNetChess", "QNetChess " + tr( + "is a network game chess for two players.\n" + "It has a client and a server in the same program.\n" + "You can modify and redistribute the source code\n" + "because it is under GPL.\n\n" + "Russia, Tambov, 2005, 2020 (denis@tambov.ru)" + )); +} + + +void +MainWindow::activated(TQWidget *w) +{ + GameBoard *brd = (GameBoard *)w; + + game->setItemEnabled(id, brd != NULL); + if (brd != NULL) + showStatus(brd->status()); + else + showStatus(ready_txt); +} + + +void +MainWindow::saveImage() +{ + GameBoard *brd = (GameBoard *)wrk->activeWindow(); + + if (brd != NULL) + brd->saveImage(); +} + +//----------------------------------------------------------------------------- + +SelectGame::SelectGame(TQWidget *parent, const char *name) + :TQDialog(parent, name) +{ + + setCaption(tr("New game with...")); + l1 = new TQLabel(tr("To play with "), this); + hst = new TQComboBox(TRUE, this); + hst->setValidator(new TQRegExpValidator( + TQRegExp("([a-zA-Z0-9]*\\.)*[a-zA-Z]"), hst)); + btn = new TQButtonGroup(tr("Choose your game"), this); + wg = new TQRadioButton(tr("White game"), btn); + bg = new TQRadioButton(tr("Black game"), btn); + box = new TQGroupBox(this); + Ok = new TQPushButton(tr("Play!"), box); + Cancel = new TQPushButton(tr("Cancel"), box); + + resize(400, TQFontMetrics(font()).lineSpacing() * 7); + setMinimumSize(size()); + setMaximumSize(size()); + + TQObject::connect(Ok, SIGNAL(clicked()), this, SLOT(accept())); + TQObject::connect(Cancel, SIGNAL(clicked()), this, SLOT(reject())); + TQObject::connect(wg, SIGNAL(clicked()), this, SLOT(checkParams())); + TQObject::connect(bg, SIGNAL(clicked()), this, SLOT(checkParams())); + TQObject::connect(hst, SIGNAL(textChanged(const TQString&)), + this, SLOT(checkParams(const TQString&))); + + checkParams(); +} + +SelectGame::~SelectGame() +{ + + delete Cancel; + delete Ok; + delete box; + delete bg; + delete wg; + delete btn; + delete hst; + delete l1; +} + + +void +SelectGame::resizeEvent(TQResizeEvent *e) +{ + TQFontMetrics fm(font()); + int w = e->size().width(), + h = e->size().height(), + fh = fm.lineSpacing() + 2, + bl; + + TQDialog::resizeEvent(e); + l1->setGeometry(0, 0, fm.width(l1->text()) + 20, fh); + hst->move(l1->x() + l1->width(), l1->y()); + hst->resize(w - hst->x(), l1->height()); + btn->move(l1->x(), l1->y() + l1->height()); + btn->resize(w, l1->height() * 3 + 2); + wg->setGeometry(2, fh, btn->width() - 4, fh); + bg->setGeometry(wg->x(), wg->y() + wg->height(), + wg->width(), wg->height()); + box->move(btn->x(), btn->y() + btn->height()); + box->resize(w, h - box->y()); + bl = box->width() / 5; + Ok->move(bl, 4); + Ok->resize(bl, box->height() - Ok->y() * 2); + Cancel->setGeometry(Ok->x() + Ok->width() + bl, Ok->y(), + Ok->width(), Ok->height()); +} + + +void +SelectGame::checkParams() +{ + bool res; + + res = !hst->currentText().isEmpty() && + (bg->isChecked() || wg->isChecked()); + Ok->setEnabled(res); +} + + +void +SelectGame::checkParams(const TQString&) +{ + + checkParams(); +} + + +TQString +SelectGame::host() +{ + TQString h(hst->currentText()); + + return h.left(h.findRev(':')); +} + + +TQStringList +SelectGame::hosts() +{ + TQStringList lst; + int i, cnt; + + cnt = hst->count(); + lst += host(); + for (i = 0; i < cnt; i++) + lst += hst->text(i); + + return (lst); +} + + +void +SelectGame::setHosts(const TQStringList &h) +{ + + hst->insertStringList(h); +} + + +GameBoard::GameType +SelectGame::gameType() +{ + GameBoard::GameType gt; + + if (wg->isChecked()) + gt = GameBoard::WHITE; + else if (bg->isChecked()) + gt = GameBoard::BLACK; + else + gt = GameBoard::NOGAME; + + return (gt); +} + +#include "mainwindow.moc" diff --git a/qnetchess/src/mainwindow.h b/qnetchess/src/mainwindow.h new file mode 100644 index 00000000..45a7f563 --- /dev/null +++ b/qnetchess/src/mainwindow.h @@ -0,0 +1,87 @@ +/* + * $Id: mainwindow.h,v 0.1 2005/01/08 12:20:13 denis Exp $ + * + * Author: Denis Kozadaev (denis@tambov.ru) + * Description: + * + * See also: style(9) + * + * Hacked by: + */ + +#ifndef __MAIN_WINDOW_H__ +#define __MAIN_WINDOW_H__ + +#include <ntqmainwindow.h> +#include <ntqpopupmenu.h> +#include <ntqworkspace.h> +#include <ntqdialog.h> +#include <ntqlabel.h> +#include <ntqcombobox.h> +#include <ntqbuttongroup.h> +#include <ntqradiobutton.h> +#include <ntqgroupbox.h> +#include <ntqpushbutton.h> +#include <stdlib.h> + +#include "gamesocket.h" +#include "gameboard.h" + +class MainWindow:public TQMainWindow +{ + Q_OBJECT +public: + MainWindow(TQWidget *parent = NULL, const char *name = NULL); + ~MainWindow(); + + bool sockOk()const{return (sock->ok());} + +private: + int id; + TQString ready_txt; + TQPopupMenu *game, *help; + TQWorkspace *wrk; + GameSocket *sock; + TQStringList hosts; + +private slots: + void showStatus(const TQString&); + void newGame(); + void newGame(int); + void about(); + void activated(TQWidget *); + void saveImage(); +}; + +//----------------------------------------------------------------------------- + +class SelectGame:public TQDialog +{ + Q_OBJECT +public: + SelectGame(TQWidget *parent = NULL, const char *name = NULL); + ~SelectGame(); + + void setHosts(const TQStringList &); + + TQString host(); + TQStringList hosts(); + GameBoard::GameType gameType(); + +private: + TQLabel *l1; + TQComboBox *hst; + TQButtonGroup *btn; + TQRadioButton *wg, *bg; + TQGroupBox *box; + TQPushButton *Ok, *Cancel; + +protected: + void resizeEvent(TQResizeEvent *); + +private slots: + void checkParams(); + void checkParams(const TQString&); +}; + +#endif /* __MAIN_WINDOW_H__ */ diff --git a/qnetchess/src/xpm/black_bishop.xpm b/qnetchess/src/xpm/black_bishop.xpm new file mode 100644 index 00000000..f866a010 --- /dev/null +++ b/qnetchess/src/xpm/black_bishop.xpm @@ -0,0 +1,46 @@ +/* XPM */ +static const char *black_bishop[]={ +"40 40 3 1", +". c None", +"# c #000000", +"a c #ffffff", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"...................##...................", +"..................####..................", +".................######.................", +"..................####..................", +"..................####..................", +".................######.................", +"...............##########...............", +"..............############..............", +".............##############.............", +"............#######aa#######............", +"...........########aa########...........", +"...........########aa########...........", +"..........######aaaaaaaa######..........", +"..........######aaaaaaaa######..........", +"..........#########aa#########..........", +"...........########aa########...........", +"...........########aa########...........", +"............################............", +".............##############.............", +"..............############..............", +"...............aaaaaaaaaa...............", +"..............############..............", +".............##############.............", +"..............############..............", +"...............a########a...............", +"...............#aaaaaaaa#...............", +"..........####################..........", +".........######################.........", +"........###########..###########........", +"........##########....##########........", +".........########......########.........", +"........................................", +"........................................", +"........................................"}; diff --git a/qnetchess/src/xpm/black_castle.xpm b/qnetchess/src/xpm/black_castle.xpm new file mode 100644 index 00000000..c483d9e0 --- /dev/null +++ b/qnetchess/src/xpm/black_castle.xpm @@ -0,0 +1,46 @@ +/* XPM */ +static const char *black_castle[]={ +"40 40 3 1", +". c None", +"# c #000000", +"a c #ffffff", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"..........#####...####...#####..........", +"..........#####...####...#####..........", +"..........#####...####...#####..........", +"..........####################..........", +"..........####################..........", +"...........##################...........", +"............##aaaaaaaaaaaa##............", +".............##############.............", +"..............############..............", +"..............##aaaaaaaa##..............", +"..............############..............", +"..............############..............", +"..............############..............", +"..............############..............", +"..............############..............", +"..............############..............", +"..............############..............", +"..............############..............", +"..............############..............", +"..............############..............", +"..............##aaaaaaaa##..............", +"..............############..............", +".............##aaaaaaaaaa##.............", +"............################............", +"...........##################...........", +"..........##aaaaaaaaaaaaaaaa##..........", +"..........####################..........", +".........######################.........", +".........######################.........", +".........######################.........", +"........................................", +"........................................", +"........................................"}; diff --git a/qnetchess/src/xpm/black_king.xpm b/qnetchess/src/xpm/black_king.xpm new file mode 100644 index 00000000..216c2cfc --- /dev/null +++ b/qnetchess/src/xpm/black_king.xpm @@ -0,0 +1,46 @@ +/* XPM */ +static const char *black_king[]={ +"40 40 3 1", +". c None", +"# c #000000", +"a c #ffffff", +"........................................", +"........................................", +"........................................", +"........................................", +"...................##...................", +"...................##...................", +".................######.................", +".................######.................", +"...................##...................", +"...................##...................", +"........####.......##.......####........", +"......########....#aa#....########......", +".....##########..#a##a#..##########.....", +".....####aaaa####a####a####aaaa####.....", +"....####a####a###a####a###a####a####....", +"....###a######a###a##a###a######a###....", +"....###a#######a###aa###a#######a###....", +"....###a########a##aa##a########a###....", +".....##a#########a####a#########a##.....", +".....###a########a####a########a###.....", +".....###a#########a##a#########a###.....", +"......##a#########a##a#########a##......", +"......###a########a##a########a###......", +".......##a########a##a########a##.......", +".......###a#######a##a#######a###.......", +"........###a######a##a######a###........", +".........###a#####a##a#####a###.........", +"..........###aaaaaaaaaaaaaa###..........", +"..........aaa##############aaa..........", +"..........####################..........", +".........######aaaaaaaaaa######.........", +"........####aaa##########aaa####........", +"........aaaa################aaaa........", +"........########################........", +"........########################........", +"........########################........", +".........######################.........", +"........................................", +"........................................", +"........................................"}; diff --git a/qnetchess/src/xpm/black_knight.xpm b/qnetchess/src/xpm/black_knight.xpm new file mode 100644 index 00000000..9ed24184 --- /dev/null +++ b/qnetchess/src/xpm/black_knight.xpm @@ -0,0 +1,46 @@ +/* XPM */ +static const char *black_knight[]={ +"40 40 3 1", +". c None", +"# c #000000", +"a c #ffffff", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"................#...#...................", +"...............###.###..................", +"...............###.###..................", +"..............####a###..................", +".............###aa#####.................", +"............###a#########...............", +"...........###############..............", +"..........############a####.............", +".........####aaa#######a####............", +".........###aaa#########a####...........", +"........#################a####..........", +"........##################a###..........", +".......###################a####.........", +".......####################a###.........", +"......######################a###........", +".....################.#####a####........", +"....##aa###########...######a###........", +"....##############...########a###.......", +"....#####a#######...########a####.......", +"....####aa#####....##########a###.......", +".....#aaa####.....############a###......", +".......a####....#############a####......", +"......#####....###############a###......", +".......##.....###############a####......", +".............#################a###......", +"............#################a####......", +"...........###################a###......", +"...........#######################......", +"...........#######################......", +"...........#######################......", +"...........######################.......", +"........................................", +"........................................", +"........................................"}; diff --git a/qnetchess/src/xpm/black_pawn.xpm b/qnetchess/src/xpm/black_pawn.xpm new file mode 100644 index 00000000..7a6f7309 --- /dev/null +++ b/qnetchess/src/xpm/black_pawn.xpm @@ -0,0 +1,45 @@ +/* XPM */ +static const char *black_pawn[]={ +"40 40 2 1", +". c None", +"# c #000000", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"..................####..................", +".................######.................", +"................########................", +"...............##########...............", +"...............##########...............", +"...............##########...............", +"................########................", +"................########................", +"...............##########...............", +"..............############..............", +".............##############.............", +".............##############.............", +".............##############.............", +"..............############..............", +"...............##########...............", +"..............############..............", +".............##############.............", +"............################............", +"............################............", +"...........##################...........", +"...........##################...........", +"..........####################..........", +"..........####################..........", +"..........####################..........", +"..........####################..........", +"..........####################..........", +"........................................", +"........................................", +"........................................"}; diff --git a/qnetchess/src/xpm/black_queen.xpm b/qnetchess/src/xpm/black_queen.xpm new file mode 100644 index 00000000..00f02b9d --- /dev/null +++ b/qnetchess/src/xpm/black_queen.xpm @@ -0,0 +1,46 @@ +/* XPM */ +static const char *black_queen[]={ +"40 40 3 1", +". c None", +"# c #000000", +"a c #ffffff", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"...................##...................", +"...........##.....####.....##...........", +"..........####....####....####..........", +"..........####.....##.....####..........", +"...........##......##......##...........", +"...##......##......##......##......##...", +"..####.....##.....####.....##.....####..", +"..####.....###....####....###.....####..", +"...##......###....####....###......##...", +"....#......###....####....###......#....", +"....##.....####...####...####.....##....", +"....###....####...####...####....###....", +"....####...####...####...####...####....", +".....###...####..######..####...###.....", +".....####..#####.######.#####..####.....", +"......####.#####.######.#####.####......", +"......##########.######.##########......", +"......############################......", +".......##########################.......", +".......########aaaaaaaaaa########.......", +"........##aaaaa##########aaaaa##........", +"........#a####################a#........", +".........######################.........", +".........######aaaaaaaaaa######.........", +".........#aaaaa##########aaaaa#.........", +".........######################.........", +"........#######aaaaaaaaaa#######........", +"........#aaaaaa##########aaaaaa#........", +"........########################........", +"........########################........", +".........######################.........", +"........................................", +"........................................", +"........................................"}; diff --git a/qnetchess/src/xpm/chess.xpm b/qnetchess/src/xpm/chess.xpm new file mode 100644 index 00000000..4d6af4cf --- /dev/null +++ b/qnetchess/src/xpm/chess.xpm @@ -0,0 +1,46 @@ +/* XPM */ +static const char *chess_xpm[]={ +"40 40 3 1", +"# c #000000", +"a c #ffffff", +". c none", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"..........#####...####...#####..........", +"..........#aaa#...#aa#...#aaa#..........", +"..........#aaa#...#aa#...#aaa#..........", +"..........#aaaa###aaaa###aaaa#..........", +"..........#aaaaaaaaaaaaaaaaaa#..........", +"...........#aaaaaaaaaaaaaaaa#...........", +"............#a############a#............", +".............#aaaaaaaaaaaa#.............", +"..............#aaaaaaaaaa#..............", +"..............#.########.#..............", +"..............#.########.#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +".............#a##########a#.............", +"............#aaaaaaaaaaaaaa#............", +"...........#aaaaaaaaaaaaaaaa#...........", +"..........#a################a#..........", +"..........#aaaaaaaaaaaaaaaaaa#..........", +".........#aaaaaaaaaaaaaaaaaaaa#.........", +".........#aaaaaaaaaaaaaaaaaaaa#.........", +".........######################.........", +"........................................", +"........................................", +"........................................"}; diff --git a/qnetchess/src/xpm/new_game.xpm b/qnetchess/src/xpm/new_game.xpm new file mode 100644 index 00000000..e2c22dda --- /dev/null +++ b/qnetchess/src/xpm/new_game.xpm @@ -0,0 +1,65 @@ +/* XPM */ +static const char *new_game[] = { +/* width height num_colors chars_per_pixel */ +" 50 50 8 1", +/* colors */ +". c #040204", +"# c #8cdef4", +"a c #749edc", +"b c #84a6f4", +"c c #0c0a0c", +"d c #6c96fa", +"e c #040604", +"f c #0c0e0c", +/* pixels */ +"..................................................", +".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +"e######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +"e######bbbbba######abbbaa#######bbbaab######bbbbaa", +"e######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +"c######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +".######aaaaaa######aaaaaa#######aaaaaa######aaaaaa", +"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +".aaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######", +"eaaaaaa######aaaaaa######aaaaaaa######aaaaaa######" +}; diff --git a/qnetchess/src/xpm/quit.xpm b/qnetchess/src/xpm/quit.xpm new file mode 100644 index 00000000..a6e1f83a --- /dev/null +++ b/qnetchess/src/xpm/quit.xpm @@ -0,0 +1,68 @@ +/* XPM */ +static const char *quit_xpm[]={ +"22 22 43 1", +"e c #a4140a", +"# c #a41c0b", +"m c #a92415", +"x c #ac2a1c", +"d c #ac2f21", +"b c #b23628", +"c c #b33b2e", +"a c #b44234", +"o c #bc421c", +"p c #bc5732", +"C c #bc5e04", +"q c #c0603a", +"h c #c07e5c", +"s c #c46f4a", +"g c #c47852", +"J c #cc7350", +"i c #cc825c", +"j c #cc8a63", +"k c #cc8f66", +"r c #d4976b", +"l c #d49e77", +"O c #d8cecc", +"F c #d99979", +"K c #dca47c", +"N c #dca684", +"f c #ddab91", +"n c #e2b59a", +"t c #e4d2c4", +"M c #e7e5ea", +"G c #ebf3f9", +"I c #ececf2", +"v c #ecfafc", +"w c #efcbb7", +"D c #f1c5b4", +"z c #f4eef4", +"B c #f4f6fc", +"y c #f8d5c8", +"L c #f9e4d8", +"H c #fcece2", +"E c #fcf2e4", +"A c #fcfed0", +"u c #fcfefc", +". c None", +"...#aabcccdbdddddde...", +".bbfggghgghijjikkjlmm.", +".bbfggghgghijjikkjlmm.", +"ennoppppqqkrsssssghlle", +"chhpppstuuuuvvwiihhrrx", +"chhpppstuuuuvvwiihhrrx", +"bggpssuuyylnzzABBjhrrm", +"dhhCttufsswDggnuuwjkkm", +"chhguuysggEEgghEEujrrm", +"chhguuysggEEgghEEujrrm", +"dhhkuursssEEhhiDDvlrr#", +"bhhFuuFgggGEiiiwwufll#", +"djjhBBtgggHEhhkIIAlll#", +"djjhBBtgggHEhhkIIAlll#", +"diiJEEuKhhLtjjDuuMlll#", +"djjskkBuyynfLLBuullNN#", +"djjskkBuyynfLLBuullNN#", +"djjgggiLuuuuuuLlllfNN#", +"eKKhhhijkkfnrrlNNfOgge", +".mmKkkrkrrllllKKKfgee.", +".mmKkkrkrrllllKKKfgee.", +"...exxmm##m######ee..."}; diff --git a/qnetchess/src/xpm/white_bishop.xpm b/qnetchess/src/xpm/white_bishop.xpm new file mode 100644 index 00000000..31de757e --- /dev/null +++ b/qnetchess/src/xpm/white_bishop.xpm @@ -0,0 +1,46 @@ +/* XPM */ +static const char *white_bishop[]={ +"40 40 3 1", +". c None", +"# c #000000", +"a c #ffffff", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"...................##...................", +"..................#aa#..................", +".................#aaaa#.................", +"..................#aa#..................", +"..................####..................", +".................#aaaa#.................", +"...............##aaaaaa##...............", +"..............#aaaaaaaaaa#..............", +".............#aaaaaaaaaaaa#.............", +"............#aaaaaa##aaaaaa#............", +"...........#aaaaaaa##aaaaaaa#...........", +"...........#aaaaaaa##aaaaaaa#...........", +"..........#aaaaa########aaaaa#..........", +"..........#aaaaa########aaaaa#..........", +"..........#aaaaaaaa##aaaaaaaa#..........", +"...........#aaaaaaa##aaaaaaa#...........", +"...........#aaaaaaa##aaaaaaa#...........", +"............#aaaaaaaaaaaaaa#............", +".............#aaaaaaaaaaaa#.............", +"..............#aaaaaaaaaa#..............", +"...............##########...............", +"..............#aaaaaaaaaa#..............", +".............#aaaaaaaaaaaa#.............", +"..............#aaaaaaaaaa#..............", +"...............#aaaaaaaa#...............", +"...............##########...............", +"..........#####aaaaaaaaaa#####..........", +".........#aaaaaaaaa##aaaaaaaaa#.........", +"........#aaaaaaaaa#..#aaaaaaaaa#........", +"........#aaaaaaaa#....#aaaaaaaa#........", +".........########......########.........", +"........................................", +"........................................", +"........................................"}; diff --git a/qnetchess/src/xpm/white_castle.xpm b/qnetchess/src/xpm/white_castle.xpm new file mode 100644 index 00000000..ab8f499c --- /dev/null +++ b/qnetchess/src/xpm/white_castle.xpm @@ -0,0 +1,46 @@ +/* XPM */ +static const char *white_castle[]={ +"40 40 3 1", +". c None", +"# c #000000", +"a c #ffffff", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"..........#####...####...#####..........", +"..........#aaa#...#aa#...#aaa#..........", +"..........#aaa#...#aa#...#aaa#..........", +"..........#aaaa###aaaa###aaaa#..........", +"..........#aaaaaaaaaaaaaaaaaa#..........", +"...........#aaaaaaaaaaaaaaaa#...........", +"............#a############a#............", +".............#aaaaaaaaaaaa#.............", +"..............#aaaaaaaaaa#..............", +"..............#a########a#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +"..............#aaaaaaaaaa#..............", +"..............#a########a#..............", +"..............#aaaaaaaaaa#..............", +".............#a##########a#.............", +"............#aaaaaaaaaaaaaa#............", +"...........#aaaaaaaaaaaaaaaa#...........", +"..........#a################a#..........", +"..........#aaaaaaaaaaaaaaaaaa#..........", +".........#aaaaaaaaaaaaaaaaaaaa#.........", +".........#aaaaaaaaaaaaaaaaaaaa#.........", +".........######################.........", +"........................................", +"........................................", +"........................................"}; diff --git a/qnetchess/src/xpm/white_king.xpm b/qnetchess/src/xpm/white_king.xpm new file mode 100644 index 00000000..f3fb74fc --- /dev/null +++ b/qnetchess/src/xpm/white_king.xpm @@ -0,0 +1,46 @@ +/* XPM */ +static const char *white_king[]={ +"40 40 3 1", +". c None", +"# c #000000", +"a c #ffffff", +"........................................", +"........................................", +"........................................", +"........................................", +"...................##...................", +"...................##...................", +".................##aa##.................", +".................##aa##.................", +"...................##...................", +"...................##...................", +"........####.......##.......####........", +"......##aaaa##....####....##aaaa##......", +".....#aaaaaaaa#..##aa##..#aaaaaaaa#.....", +".....#aaa####aa###aaaa###aa####aaa#.....", +"....#aaa#aaaa#aa##aaaa##aa#aaaa#aaa#....", +"....#aa#aaaaaa#aa##aa##aa#aaaaaa#aa#....", +"....#aa#aaaaaaa#aa####aa#aaaaaaa#aa#....", +"....#aa#aaaaaaaa#aa##aa#aaaaaaaa#aa#....", +".....#a#aaaaaaaaa#aaaa#aaaaaaaaa#a#.....", +".....#aa#aaaaaaaa#aaaa#aaaaaaaa#aa#.....", +".....#aa#aaaaaaaaa#aa#aaaaaaaaa#aa#.....", +"......#a#aaaaaaaaa#aa#aaaaaaaaa#a#......", +"......#aa#aaaaaaaa#aa#aaaaaaaa#aa#......", +".......#a#aaaaaaaa#aa#aaaaaaaa#a#.......", +".......#aa#aaaaaaa#aa#aaaaaaa#aa#.......", +"........#aa#aaaaaa#aa#aaaaaa#aa#........", +".........#aa#aaaaa#aa#aaaaa#aa#.........", +"..........#aa##############aa#..........", +"..........###aaaaaaaaaaaaaa###..........", +"..........#aaaaaaaaaaaaaaaaaa#..........", +".........#aaaaa##########aaaaa#.........", +"........#aaa###aaaaaaaaaa###aaa#........", +"........####aaaaaaaaaaaaaaaa####........", +"........#aaaaaaaaaaaaaaaaaaaaaa#........", +"........#aaaaaaaaaaaaaaaaaaaaaa#........", +"........##aaaaaaaaaaaaaaaaaaaa##........", +".........######################.........", +"........................................", +"........................................", +"........................................"}; diff --git a/qnetchess/src/xpm/white_knight.xpm b/qnetchess/src/xpm/white_knight.xpm new file mode 100644 index 00000000..e2aae2e4 --- /dev/null +++ b/qnetchess/src/xpm/white_knight.xpm @@ -0,0 +1,46 @@ +/* XPM */ +static const char *white_knight[]={ +"40 40 3 1", +". c None", +"# c #000000", +"a c #ffffff", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"................#...#...................", +"...............#a#.#a#..................", +"...............#a#.#a#..................", +"..............#aaa#aa#..................", +".............#aa##aaa##.................", +"............#aa#aaaaaaa##...............", +"...........#aaaaaaaaaaaaa#..............", +"..........#aaaaaaaaaaa#aaa#.............", +".........#aaa###aaaaaaa#aaa#............", +".........#aa###aaaaaaaaa#aaa#...........", +"........#aaaaaaaaaaaaaaaa#aaa#..........", +"........#aaaaaaaaaaaaaaaaa#aa#..........", +".......#aaaaaaaaaaaaaaaaaa#aaa#.........", +".......#aaaaaaaaaaaaaa#aaaa#aa#.........", +"......#aaaaaaaaaaaaaa##aaaaa#aa#........", +".....#aaaaaaaaaaaaa##.#aaaa#aaa#........", +"....#a##aaaaaaaaaa#...#aaaaa#aa#........", +"....#aaaaaaaaaaaa#...#aaaaaaa#aa#.......", +"....#aaaa#aaaaa##...#aaaaaaa#aaa#.......", +"....#aaa##aaa##....#aaaaaaaaa#aa#.......", +".....####aaa#.....#aaaaaaaaaaa#aa#......", +".......#aaa#....##aaaaaaaaaaa#aaa#......", +"......#aa##....#aaaaaaaaaaaaaa#aa#......", +".......##.....#aaaaaaaaaaaaaa#aaa#......", +".............#aaaaaaaaaaaaaaaa#aa#......", +"............#aaaaaaaaaaaaaaaa#aaa#......", +"...........#aaaaaaaaaaaaaaaaaa#aa#......", +"...........#aaaaaaaaaaaaaaaaaaaaa#......", +"...........#aaaaaaaaaaaaaaaaaaaaa#......", +"...........#aaaaaaaaaaaaaaaaaaaaa#......", +"...........######################.......", +"........................................", +"........................................", +"........................................"}; diff --git a/qnetchess/src/xpm/white_pawn.xpm b/qnetchess/src/xpm/white_pawn.xpm new file mode 100644 index 00000000..541f9a40 --- /dev/null +++ b/qnetchess/src/xpm/white_pawn.xpm @@ -0,0 +1,46 @@ +/* XPM */ +static const char *white_pawn[]={ +"40 40 3 1", +". c None", +"# c #000000", +"a c #ffffff", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"..................####..................", +".................#aaaa#.................", +"................#aaaaaa#................", +"...............#aaaaaaaa#...............", +"...............#aaaaaaaa#...............", +"...............#aaaaaaaa#...............", +"................#aaaaaa#................", +"................##aaaa##................", +"...............#aaaaaaaa#...............", +"..............#aaaaaaaaaa#..............", +".............#aaaaaaaaaaaa#.............", +".............#aaaaaaaaaaaa#.............", +".............#aaaaaaaaaaaa#.............", +"..............#aaaaaaaaaa#..............", +"...............#aaaaaaaa#...............", +"..............#aaaaaaaaaa#..............", +".............#aaaaaaaaaaaa#.............", +"............#aaaaaaaaaaaaaa#............", +"............#aaaaaaaaaaaaaa#............", +"...........#aaaaaaaaaaaaaaaa#...........", +"...........#aaaaaaaaaaaaaaaa#...........", +"..........#aaaaaaaaaaaaaaaaaa#..........", +"..........#aaaaaaaaaaaaaaaaaa#..........", +"..........#aaaaaaaaaaaaaaaaaa#..........", +"..........#aaaaaaaaaaaaaaaaaa#..........", +"..........####################..........", +"........................................", +"........................................", +"........................................"}; diff --git a/qnetchess/src/xpm/white_queen.xpm b/qnetchess/src/xpm/white_queen.xpm new file mode 100644 index 00000000..dd01f7dc --- /dev/null +++ b/qnetchess/src/xpm/white_queen.xpm @@ -0,0 +1,46 @@ +/* XPM */ +static const char *white_queen[]={ +"40 40 3 1", +". c None", +"# c #000000", +"a c #ffffff", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"........................................", +"...................##...................", +"...........##.....#aa#.....##...........", +"..........#aa#....#aa#....#aa#..........", +"..........#aa#.....##.....#aa#..........", +"...........##......##......##...........", +"...##......##......##......##......##...", +"..#aa#.....##.....#aa#.....##.....#aa#..", +"..#aa#.....#a#....#aa#....#a#.....#aa#..", +"...##......#a#....#aa#....#a#......##...", +"....#......#a#....#aa#....#a#......#....", +"....##.....#aa#...#aa#...#aa#.....##....", +"....#a#....#aa#...#aa#...#aa#....#a#....", +"....#aa#...#aa#...#aa#...#aa#...#aa#....", +".....#a#...#aa#..#aaaa#..#aa#...#a#.....", +".....#aa#..#aaa#.#aaaa#.#aaa#..#aa#.....", +"......#aa#.#aaa#.#aaaa#.#aaa#.#aa#......", +"......#aaa##aaa#.#aaaa#.#aaa##aaa#......", +"......#aaaa#aaaa#aaaaaa#aaaa#aaaa#......", +".......#aaaaaaaaaaaaaaaaaaaaaaaa#.......", +".......#aaaaaaa##########aaaaaaa#.......", +"........#a#####aaaaaaaaaa#####a#........", +"........##aaaaaaaaaaaaaaaaaaaa##........", +".........#aaaaaaaaaaaaaaaaaaaa#.........", +".........#aaaaa##########aaaaa#.........", +".........######aaaaaaaaaa######.........", +".........#aaaaaaaaaaaaaaaaaaaa#.........", +"........#aaaaaa##########aaaaaa#........", +"........#######aaaaaaaaaa#######........", +"........#aaaaaaaaaaaaaaaaaaaaaa#........", +"........#aaaaaaaaaaaaaaaaaaaaaa#........", +".........######################.........", +"........................................", +"........................................", +"........................................"}; |