debian/0000775000000000000000000000000012306312037007165 5ustar debian/libtelepathy-logger-qt5-0.install0000664000000000000000000000005012305543166015367 0ustar usr/lib/*/libtelepathy-logger-qt5.so.0* debian/libtelepathy-logger-qt5-dev.install0000664000000000000000000000011112305543166016004 0ustar usr/include/* usr/lib/*/libtelepathy-logger-qt5.so usr/lib/*/pkgconfig/* debian/copyright0000664000000000000000000000700512305543166011132 0ustar Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: telepathy-logger-qt Upstream-Contact: KDE Telepathy Project Source: http://download.kde.org/unstable/kde-telepathy/ License: LGPL-2.1+ Files: * Copyright: 2005-2011 Collabora Ltd. 2005-2011 Nokia Corporation 2006 INdT 2011 Stefano Sanfilippo 2012 David Edmundson 2010 George Kiagiadakis License: LGPL-2.1+ Files: cmake/* Copyright: 2010-2011 Collabora Ltd 2006 Alexander Neundorf 2010 Dario Freddi 2006, 2008 Allen Winter 2007 Simon Edwards 2006 Tim Beaulen 2008 Kevin Kofler 2008 Helio Chissini de Castro 2008 Laurent Montel 2009 Andre Moreira Magalhaes 2009 Sebastian Trueg License: BSD-3-clause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . 1. Redistributions of source code must retain the copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Files: debian/* Copyright: 2012 George Kiagiadakis License: LGPL-2.1+ License: LGPL-2.1+ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. . This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. . You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA . On Debian systems, the complete text of the GNU Lesser General Public License v2.1 can be found in `/usr/share/common-licenses/LGPL-2.1'. debian/patches/0000775000000000000000000000000012306312037010614 5ustar debian/patches/series0000664000000000000000000000003612305543166012040 0ustar 01-Porting-to-Qt5-final.patch debian/patches/01-Porting-to-Qt5-final.patch0000664000000000000000000160337312305543166015700 0ustar Author: Tiago Salem Herrmann , Gustavo Pichorim Boiko Subject: Porting telepathy-logger-qt to Qt5 Port needed by Ubuntu Touch. Work is on going to upstream such changes. diff --git a/CMakeLists.txt b/CMakeLists.txt index b88e06e..54a11ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -project(TelepathyLoggerQt4) +project(TelepathyLoggerQt) cmake_minimum_required(VERSION 2.6) @@ -38,29 +38,29 @@ endif(POLICY CMP0011) # set nano_version to 0 # make the release, tag it # set nano_version to 1 -set(TP_LOGGER_QT4_MAJOR_VERSION 0) -set(TP_LOGGER_QT4_MINOR_VERSION 5) -set(TP_LOGGER_QT4_MICRO_VERSION 1) -set(TP_LOGGER_QT4_NANO_VERSION 0) +set(TP_LOGGER_QT_MAJOR_VERSION 0) +set(TP_LOGGER_QT_MINOR_VERSION 5) +set(TP_LOGGER_QT_MICRO_VERSION 1) +set(TP_LOGGER_QT_NANO_VERSION 0) # This value contains the library's SOVERSION. This value is to be increased everytime an API/ABI break # occurs, and will be used for the SOVERSION of the generated shared libraries. -set(TP_LOGGER_QT4_ABI_VERSION 1) +set(TP_LOGGER_QT_ABI_VERSION 0) # This variable is used for the library's long version. It is generated dynamically, so don't change its -# value! Change TP_LOGGER_QT4_ABI_VERSION and TP_LOGGER_QT4_*_VERSION instead. -if (${TP_LOGGER_QT4_NANO_VERSION} EQUAL 0) - set(TP_LOGGER_QT4_LIBRARY_VERSION ${TP_LOGGER_QT4_ABI_VERSION}.${TP_LOGGER_QT4_MAJOR_VERSION}.${TP_LOGGER_QT4_MINOR_VERSION}.${TP_LOGGER_QT4_MICRO_VERSION}) -else (${TP_LOGGER_QT4_NANO_VERSION} EQUAL 0) - set(TP_LOGGER_QT4_LIBRARY_VERSION ${TP_LOGGER_QT4_ABI_VERSION}.${TP_LOGGER_QT4_MAJOR_VERSION}.${TP_LOGGER_QT4_MINOR_VERSION}.${TP_LOGGER_QT4_MICRO_VERSION}.${TP_QT4_NANO_VERSION}) -endif (${TP_LOGGER_QT4_NANO_VERSION} EQUAL 0) +# value! Change TP_LOGGER_QT_ABI_VERSION and TP_LOGGER_QT_*_VERSION instead. +if (${TP_LOGGER_QT_NANO_VERSION} EQUAL 0) + set(TP_LOGGER_QT_LIBRARY_VERSION ${TP_LOGGER_QT_ABI_VERSION}.${TP_LOGGER_QT_MAJOR_VERSION}.${TP_LOGGER_QT_MINOR_VERSION}.${TP_LOGGER_QT_MICRO_VERSION}) +else (${TP_LOGGER_QT_NANO_VERSION} EQUAL 0) + set(TP_LOGGER_QT_LIBRARY_VERSION ${TP_LOGGER_QT_ABI_VERSION}.${TP_LOGGER_QT_MAJOR_VERSION}.${TP_LOGGER_QT_MINOR_VERSION}.${TP_LOGGER_QT_MICRO_VERSION}.${TP_QT_NANO_VERSION}) +endif (${TP_LOGGER_QT_NANO_VERSION} EQUAL 0) -set(PACKAGE_NAME telepathy-logger-qt4) +set(PACKAGE_NAME telepathy-logger-qt) -if (${TP_LOGGER_QT4_NANO_VERSION} EQUAL 0) - set(PACKAGE_VERSION ${TP_LOGGER_QT4_MAJOR_VERSION}.${TP_LOGGER_QT4_MINOR_VERSION}.${TP_LOGGER_QT4_MICRO_VERSION}) -else (${TP_LOGGER_QT4_NANO_VERSION} EQUAL 0) - set(PACKAGE_VERSION ${TP_LOGGER_QT4_MAJOR_VERSION}.${TP_LOGGER_QT4_MINOR_VERSION}.${TP_LOGGER_QT4_MICRO_VERSION}.${TP_LOGGER_QT4_NANO_VERSION}) -endif (${TP_LOGGER_QT4_NANO_VERSION} EQUAL 0) +if (${TP_LOGGER_QT_NANO_VERSION} EQUAL 0) + set(PACKAGE_VERSION ${TP_LOGGER_QT_MAJOR_VERSION}.${TP_LOGGER_QT_MINOR_VERSION}.${TP_LOGGER_QT_MICRO_VERSION}) +else (${TP_LOGGER_QT_NANO_VERSION} EQUAL 0) + set(PACKAGE_VERSION ${TP_LOGGER_QT_MAJOR_VERSION}.${TP_LOGGER_QT_MINOR_VERSION}.${TP_LOGGER_QT_MICRO_VERSION}.${TP_LOGGER_QT_NANO_VERSION}) +endif (${TP_LOGGER_QT_NANO_VERSION} EQUAL 0) # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is # checked @@ -69,23 +69,23 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules") # Default build type is RelWithDebInfo for release versions and Debug for developement # versions if(NOT CMAKE_BUILD_TYPE) - if(TP_LOGGER_QT4_NANO_VERSION EQUAL 0) + if(TP_LOGGER_QT_NANO_VERSION EQUAL 0) set(CMAKE_BUILD_TYPE RelWithDebInfo) - else(TP_LOGGER_QT4_NANO_VERSION EQUAL 0) + else(TP_LOGGER_QT_NANO_VERSION EQUAL 0) set(CMAKE_BUILD_TYPE Debug) - endif(TP_LOGGER_QT4_NANO_VERSION EQUAL 0) + endif(TP_LOGGER_QT_NANO_VERSION EQUAL 0) endif(NOT CMAKE_BUILD_TYPE) # This file contains all the needed initialization macros include(TelepathyDefaults) -# TelepathyLoggerQt4 specific defines needed to trigger deprecation warnings +# TelepathyLoggerQt specific defines needed to trigger deprecation warnings if (CXX_DEPRECATED_DECLARATIONS) - set(DEPRECATED_DECLARATIONS_FLAGS "${DEPRECATED_DECLARATIONS_FLAGS} -DTELEPATHY_LOGGER_QT4_DEPRECATED_WARNINGS") + set(DEPRECATED_DECLARATIONS_FLAGS "${DEPRECATED_DECLARATIONS_FLAGS} -DTELEPATHY_LOGGER_QT_DEPRECATED_WARNINGS") endif (CXX_DEPRECATED_DECLARATIONS) # This file contains all macros used in the buildsystem -include(TpQt4Macros) +include(TpQtMacros) include(Doxygen) include(MacroLogFeature) @@ -93,13 +93,16 @@ include(MacroLogFeature) # external dependencies # Required dependencies -# Find qt4 version >= 4.5 -set (QT_MIN_VERSION "4.5.0") -find_package(Qt4 REQUIRED) -set (TELEPATHYQT4_MIN_VERSION "0.9.1") -find_package(TelepathyQt4 ${TELEPATHYQT4_MIN_VERSION} REQUIRED) +find_package(Qt5Core REQUIRED) +find_package(Qt5DBus REQUIRED) +find_package(Qt5Network REQUIRED) +find_package(Qt5Xml REQUIRED) +find_package(Qt5Test REQUIRED) -#add_definitions(-DQT_NO_CAST_FROM_ASCII) +set (TELEPATHYQT_MIN_VERSION "0.9.1") +find_package(TelepathyQt5 ${TELEPATHYQT_MIN_VERSION} REQUIRED) + +set(TP_LOGGER_QT_LIBRARY_LINKER_FLAGS "-fPIC") set(ENABLE_DEBUG_OUTPUT ON CACHE BOOL "If activated, compiles support for printing debug output to stderr") if (ENABLE_DEBUG_OUTPUT) @@ -115,11 +118,11 @@ else(${PYTHON_SHORT_VERSION} VERSION_GREATER ${REQUIRED_PY} OR ${PYTHON_SHORT_VE message(SEND_ERROR "Python >= ${REQUIRED_PY} is required") endif(${PYTHON_SHORT_VERSION} VERSION_GREATER ${REQUIRED_PY} OR ${PYTHON_SHORT_VERSION} VERSION_EQUAL ${REQUIRED_PY}) -# Check for Qt4 Glib support +# Check for Qt5 Glib support include(CheckCXXSourceCompiles) -set(CMAKE_REQUIRED_INCLUDES ${QT_INCLUDES}) +set(CMAKE_REQUIRED_INCLUDES "${Qt5Core_INCLUDE_DIRS}") set(CMAKE_REQUIRED_DEFINITIONS "") -set(CMAKE_REQUIRED_FLAGS "") +set(CMAKE_REQUIRED_FLAGS "${TP_LOGGER_QT_LIBRARY_LINKER_FLAGS}") CHECK_CXX_SOURCE_COMPILES(" #include @@ -130,8 +133,8 @@ int main() #endif return 0; }" -QT4_GLIB_SUPPORT) -macro_log_feature(QT4_GLIB_SUPPORT "Qt4 Glib Support" +QT_GLIB_SUPPORT) +macro_log_feature(QT_GLIB_SUPPORT "Qt5 Glib Support" "QtCore library using Glib's main event loop" "http://qt.nokia.com/" FALSE "" "Needed, together with Telepathy-Glib, to build most of the unit tests") @@ -152,11 +155,14 @@ find_package(TelepathyGlib REQUIRED) # Activate debug symbols generation #set(CMAKE_CXX_FLAGS "-g -Wall") +set(CMAKE_CXX_FLAGS "${CMAKE_REQUIRED_FLAGS}") include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} - ${QT_INCLUDES} - ${TELEPATHY_QT4_INCLUDE_DIR} + ${Qt5Core_INCLUDE_DIRS} + ${Qt5DBus_INCLUDE_DIRS} + ${Qt5Network_INCLUDE_DIRS} + ${TELEPATHY_QT5_INCLUDE_DIR} ${TELEPATHY_LOGGER_INCLUDE_DIR} ${TELEPATHY_GLIB_INCLUDE_DIR} ${GLIB2_INCLUDE_DIR} @@ -184,9 +190,9 @@ endmacro() # Add the source subdirectories add_subdirectory(codegen) -add_subdirectory(TelepathyLoggerQt4) +add_subdirectory(TelepathyLoggerQt) #add_subdirectory(tests) -#add_subdirectory(tools) +add_subdirectory(tools) # Generate config.h configure_file(${CMAKE_SOURCE_DIR}/config.h.in ${CMAKE_BINARY_DIR}/config.h) @@ -205,7 +211,7 @@ macro_display_feature_log() add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/FIXME.out COMMAND egrep - ARGS -A 5 '[F]IXME|[T]ODO|[X]XX' ${CMAKE_SOURCE_DIR}/TelepathyLoggerQt4/*.[ch]* + ARGS -A 5 '[F]IXME|[T]ODO|[X]XX' ${CMAKE_SOURCE_DIR}/TelepathyLoggerQt/*.[ch]* > FIXME.out || true) add_custom_target(check-local DEPENDS ${CMAKE_BINARY_DIR}/FIXME.out) diff --git a/HACKING b/HACKING index 6fde4dc..98cbe40 100644 --- a/HACKING +++ b/HACKING @@ -19,7 +19,7 @@ The current development version of QTpLogger is available from a scratch repo: Short version =============================================================================== -QTpLogger follows the same conventions as Tp-Qt4 and Qt itself. +QTpLogger follows the same conventions as Tp-Qt5 and Qt itself. =============================================================================== Coding style @@ -28,7 +28,7 @@ Coding style For C++ code: ------------- -QTpLogger uses the standard Qt4 coding style for the Qt/C++ code, as also +QTpLogger uses the standard Qt5 coding style for the Qt/C++ code, as also followed by eg. KDELibs. The coding style is described in more detail in the KDE TechBase at ; in short, it amounts to: diff --git a/TelepathyLoggerQt/CMakeLists.txt b/TelepathyLoggerQt/CMakeLists.txt new file mode 100644 index 0000000..fe20e42 --- /dev/null +++ b/TelepathyLoggerQt/CMakeLists.txt @@ -0,0 +1,216 @@ +file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/_gen") + +set(TelepathyLoggerQt_CODEGEN_HEADERS + call-event.h + entity.h + event.h + log-manager.h + logger.h + text-event.h + types.h) + +set(TelepathyLoggerQt_CODEGEN_INCLUDES + -Itelepathy-logger/call-event.h + -Itelepathy-logger/entity.h + -Itelepathy-logger/log-manager.h + -Itelepathy-logger/event.h + -Itelepathy-logger/text-event.h + -ITelepathyLoggerQt/CallEvent + -ITelepathyLoggerQt/Entity + -ITelepathyLoggerQt/Event + -ITelepathyLoggerQt/LogManager + -ITelepathyLoggerQt/Logger + -ITelepathyLoggerQt/TextEvent + -ITelepathyLoggerQt/Types + -IQGlib/Quark) + +# Add command to generate gen.cpp using codegen +run_codegen("TelepathyLoggerQt" "${TelepathyLoggerQt_CODEGEN_INCLUDES}" "${TelepathyLoggerQt_CODEGEN_HEADERS}") + +# Set the required flags found in TelepathyDefaults +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VISIBILITY_HIDDEN_FLAGS} ${COMPILER_COVERAGE_FLAGS} ${DEPRECATED_DECLARATIONS_FLAGS}") +set(LD_FLAGS "${LD_FLAGS} ${VISIBILITY_HIDDEN_FLAGS} ${COMPILER_COVERAGE_FLAGS} ${DEPRECATED_DECLARATIONS_FLAGS}") + +# We are building telepathy-logger-qt +add_definitions(-DBUILDING_TELEPATHY_LOGGER_QT) +add_definitions (-DQT_NO_KEYWORDS) +add_definitions(-fPIC) + +# Sources for Tp-Logger-Qt5 +set(telepathy_logger_qt_SRCS + call-event.cpp + entity.cpp + event.cpp + log-manager.cpp + logger.cpp + pending-dates.cpp + pending-entities.cpp + pending-events.cpp + pending-logger.cpp + pending-operation.cpp + pending-search.cpp + search-hit.cpp + text-event.cpp + utils.cpp + init.cpp + ${CMAKE_CURRENT_BINARY_DIR}/gen.cpp) + +# Exported headers for Tp-Logger-Qt5 +set(telepathy_logger_qt_HEADERS + CallEvent + Entity + Event + Global + Init + Logger + LogManager + PendingDates + PendingEntities + PendingEvents + PendingOperation + PendingSearch + SearchHit + TextEvent + Types + call-event.h + entity.h + event.h + global.h + init.h + log-manager.h + logger.h + pending-dates.h + pending-entities.h + pending-events.h + pending-operation.h + pending-search.h + search-hit.h + text-event.h + types.h + ) + +# Headers file moc will be run on +set(telepathy_logger_qt_MOC_SRCS + pending-dates.h + pending-entities.h + pending-events.h + pending-logger.h + pending-operation.h + pending-search.h + logger.h) + +# Generated headers which will be installed and exported +set(telepathy_logger_qt_gen_HEADERS + ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-logger.h + ${CMAKE_CURRENT_BINARY_DIR}/_gen/constants.h + ${CMAKE_CURRENT_BINARY_DIR}/_gen/types.h) + +# The escape character in MSVC is ^ +if(MSVC) + set(TYPES_INCLUDE ^ ) + set(GLOBAL_INCLUDE ^ ) + set(LOGGER_EXTRA_INCLUDES '^' ) +else(MSVC) + set(TYPES_INCLUDE '' ) + set(GLOBAL_INCLUDE '' ) + set(LOGGER_EXTRA_INCLUDES '' ) +endif(MSVC) + +# Generate the spec files +set(gen_stable_spec_xml ${CMAKE_CURRENT_BINARY_DIR}/_gen/stable-spec.xml) + +tpqt_xincludator(stable-ifaces-includator ${CMAKE_CURRENT_SOURCE_DIR}/stable-interfaces.xml ${gen_stable_spec_xml}) + +add_custom_target(all-generated-sources) +tpqt_constants_gen(stable-constants ${gen_stable_spec_xml} ${CMAKE_CURRENT_BINARY_DIR}/_gen/constants.h + --namespace=Tpl + --define-prefix=TP_LOGGER_QT_ + --must-define=IN_TELEPATHY_LOGGER_QT_HEADER + DEPENDS stable-ifaces-includator) + +tpqt_types_gen(stable-typesgen ${gen_stable_spec_xml} + ${CMAKE_CURRENT_BINARY_DIR}/_gen/types.h ${CMAKE_CURRENT_BINARY_DIR}/_gen/types-body.hpp + Tpl TelepathyLoggerQt/types.h TelepathyLoggerQt/Types + --must-define=IN_TELEPATHY_LOGGER_QT_HEADER + --visibility=TELEPATHY_LOGGER_QT_EXPORT + --extraincludes=${GLOBAL_INCLUDE} + DEPENDS stable-constants) + +# Add the generated types to the library's sources +list(APPEND telepathy_logger_qt_SRCS ${CMAKE_CURRENT_BINARY_DIR}/_gen/types.h) +list(APPEND telepathy_logger_qt_SRCS ${CMAKE_CURRENT_BINARY_DIR}/_gen/types-body.hpp) + +# For each spec, generate a cli file and add it to the sources (including mocs). +set(SPECS + logger) +foreach(spec ${SPECS}) + tpqt_xincludator(${spec}-spec-xincludator ${CMAKE_CURRENT_SOURCE_DIR}/${spec}.xml ${CMAKE_CURRENT_BINARY_DIR}/_gen/spec-${spec}.xml DEPENDS stable-typesgen) + set(NEW_FILES + ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}-body.hpp + ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}.moc.hpp) + list(APPEND telepathy_logger_qt_SRCS ${NEW_FILES}) + list(APPEND telepathy_logger_qt_generated_specs_mocs "moc-cli-${spec}.moc.hpp") + set_source_files_properties(${NEW_FILES} PROPERTIES GENERATED true) +endforeach(spec ${SPECS}) + +#SET(telepathy_logger_qt_generated_specs_mocs types.h) + +# Use the client generator for generating headers out of specs +tpqt_client_generator(${gen_stable_spec_xml} logger clientlogger TelepathyLoggerQt/logger.h TelepathyLoggerQt Tpl Tpl IN_TELEPATHY_LOGGER_QT_HEADER TELEPATHY_LOGGER_QT_EXPORT DEPENDS logger-spec-xincludator ) + +# Create the library +add_library(telepathy-logger-qt${Qt5Core_VERSION_MAJOR} ${telepathy_logger_qt_SRCS}) + +# generate client moc files +foreach(moc_src ${telepathy_logger_qt_MOC_SRCS}) + set(generated_file _gen/${moc_src}) + string(REPLACE ".h" ".moc.hpp" generated_file ${generated_file}) + tpqt_generate_moc_i_target_deps(${CMAKE_CURRENT_SOURCE_DIR}/${moc_src} ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} + ${telepathy_logger_qt_generated_specs_mocs}) + list(APPEND telepathy_logger_qt_SRCS ${CMAKE_CURRENT_BINARY_DIR}/${generated_file}) + string(REPLACE ".h" ".moc.hpp" moc_src ${moc_src}) + add_dependencies(telepathy-logger-qt${Qt5Core_VERSION_MAJOR} "moc-${moc_src}") +endforeach(moc_src ${telepathy_logger_qt_MOC_SRCS}) + +# Link +target_link_libraries(telepathy-logger-qt${Qt5Core_VERSION_MAJOR} + ${Qt5Core_LIBRARIES} + ${GLIB2_LIBRARIES} + ${GOBJECT_LIBRARIES} + -lgio-2.0 + ${Qt5DBus_LIBRARIES} + ${DBUS_LIBRARIES} + ${LIBXML2_LIBRARIES} + ${DBUS_GLIB_LIBRARIES} + ${TELEPATHY_GLIB_LIBRARIES} + ${TELEPATHY_LOGGER_LIBRARIES} + ${TELEPATHY_QT5_LIBRARIES} + ${QTGLIB_LIBRARIES}) + +if (ENABLE_COMPILER_COVERAGE) + target_link_libraries(telepathy-logger-qt${Qt5Core_VERSION_MAJOR} gcov) +endif (ENABLE_COMPILER_COVERAGE) + +# Set the correct version number +set_target_properties(telepathy-logger-qt${Qt5Core_VERSION_MAJOR} PROPERTIES + SOVERSION ${TP_LOGGER_QT_ABI_VERSION} + VERSION ${TP_LOGGER_QT_LIBRARY_VERSION}) + +# Install header files +install(FILES ${telepathy_logger_qt_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/telepathy-logger-0.2/TelepathyLoggerQt COMPONENT headers) +install(FILES ${telepathy_logger_qt_gen_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/telepathy-logger-0.2/TelepathyLoggerQt/_gen COMPONENT headers) + +# Install the library - watch out for the correct components +if (WIN32) + install(TARGETS telepathy-logger-qt${Qt5Core_VERSION_MAJOR} RUNTIME DESTINATION ${LIB_INSTALL_DIR} COMPONENT mainlibrary + ARCHIVE DESTINATION ${LIB_INSTALL_DIR} COMPONENT headers) +else (WIN32) + install(TARGETS telepathy-logger-qt${Qt5Core_VERSION_MAJOR} LIBRARY DESTINATION ${LIB_INSTALL_DIR} COMPONENT mainlibrary + ARCHIVE DESTINATION ${LIB_INSTALL_DIR} COMPONENT headers) +endif (WIN32) + +# pkg-config file +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/TelepathyLoggerQt5.pc.in ${CMAKE_CURRENT_BINARY_DIR}/TelepathyLoggerQt5.pc) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/TelepathyLoggerQt5-uninstalled.pc.in ${CMAKE_CURRENT_BINARY_DIR}/TelepathyLoggerQt5-uninstalled.pc) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/TelepathyLoggerQt5.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig COMPONENT headers) + diff --git a/TelepathyLoggerQt/CallEvent b/TelepathyLoggerQt/CallEvent new file mode 100644 index 0000000..4acd1f5 --- /dev/null +++ b/TelepathyLoggerQt/CallEvent @@ -0,0 +1,12 @@ +#ifndef _TelepathyLoggerQt_CallEvent_HEADER_GUARD_ +#define _TelepathyLoggerQt_CallEvent_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#define IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include + +#undef IN_TELEPATHY_LOGGER_QT_HEADER + +#endif diff --git a/TelepathyLoggerQt/Entity b/TelepathyLoggerQt/Entity new file mode 100644 index 0000000..54c6477 --- /dev/null +++ b/TelepathyLoggerQt/Entity @@ -0,0 +1,12 @@ +#ifndef _TelepathyLoggerQt_Entity_HEADER_GUARD_ +#define _TelepathyLoggerQt_Entity_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#define IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include + +#undef IN_TELEPATHY_LOGGER_QT_HEADER + +#endif diff --git a/TelepathyLoggerQt/Event b/TelepathyLoggerQt/Event new file mode 100644 index 0000000..6e4b098 --- /dev/null +++ b/TelepathyLoggerQt/Event @@ -0,0 +1,12 @@ +#ifndef _TelepathyLoggerQt_Event_HEADER_GUARD_ +#define _TelepathyLoggerQt_Event_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#define IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include + +#undef IN_TELEPATHY_LOGGER_QT_HEADER + +#endif diff --git a/TelepathyLoggerQt/Global b/TelepathyLoggerQt/Global new file mode 100644 index 0000000..3c8a0e5 --- /dev/null +++ b/TelepathyLoggerQt/Global @@ -0,0 +1,12 @@ +#ifndef _TelepathyLoggerQt_Global_HEADER_GUARD_ +#define _TelepathyLoggerQt_Global_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#define IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include + +#undef IN_TELEPATHY_LOGGER_QT_HEADER + +#endif diff --git a/TelepathyLoggerQt/Init b/TelepathyLoggerQt/Init new file mode 100644 index 0000000..680f473 --- /dev/null +++ b/TelepathyLoggerQt/Init @@ -0,0 +1,12 @@ +#ifndef _TelepathyLoggerQt_Init_HEADER_GUARD_ +#define _TelepathyLoggerQt_Init_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#define IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include + +#undef IN_TELEPATHY_LOGGER_QT_HEADER + +#endif diff --git a/TelepathyLoggerQt/LogManager b/TelepathyLoggerQt/LogManager new file mode 100644 index 0000000..ab07577 --- /dev/null +++ b/TelepathyLoggerQt/LogManager @@ -0,0 +1,12 @@ +#ifndef _TelepathyLoggerQt_LogManager_HEADER_GUARD_ +#define _TelepathyLoggerQt_LogManager_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#define IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include + +#undef IN_TELEPATHY_LOGGER_QT_HEADER + +#endif diff --git a/TelepathyLoggerQt/Logger b/TelepathyLoggerQt/Logger new file mode 100644 index 0000000..0b4355a --- /dev/null +++ b/TelepathyLoggerQt/Logger @@ -0,0 +1,32 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2010 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _TelepathyLoggerQt_Logger_HEADER_GUARD_ +#define _TelepathyLoggerQt_Logger_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#define IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include + +#undef IN_TELEPATHY_LOGGER_QT_HEADER + +#endif diff --git a/TelepathyLoggerQt/PendingDates b/TelepathyLoggerQt/PendingDates new file mode 100644 index 0000000..8b3055a --- /dev/null +++ b/TelepathyLoggerQt/PendingDates @@ -0,0 +1,12 @@ +#ifndef _TelepathyLoggerQt_PendingDates_HEADER_GUARD_ +#define _TelepathyLoggerQt_PendingDates_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#define IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include + +#undef IN_TELEPATHY_LOGGER_QT_HEADER + +#endif diff --git a/TelepathyLoggerQt/PendingEntities b/TelepathyLoggerQt/PendingEntities new file mode 100644 index 0000000..540597f --- /dev/null +++ b/TelepathyLoggerQt/PendingEntities @@ -0,0 +1,12 @@ +#ifndef _TelepathyLoggerQt_PendingEntities_HEADER_GUARD_ +#define _TelepathyLoggerQt_PendingEntities_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#define IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include + +#undef IN_TELEPATHY_LOGGER_QT_HEADER + +#endif diff --git a/TelepathyLoggerQt/PendingEvents b/TelepathyLoggerQt/PendingEvents new file mode 100644 index 0000000..449214a --- /dev/null +++ b/TelepathyLoggerQt/PendingEvents @@ -0,0 +1,12 @@ +#ifndef _TelepathyLoggerQt_PendingEvents_HEADER_GUARD_ +#define _TelepathyLoggerQt_PendingEvents_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#define IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include + +#undef IN_TELEPATHY_LOGGER_QT_HEADER + +#endif diff --git a/TelepathyLoggerQt/PendingOperation b/TelepathyLoggerQt/PendingOperation new file mode 100644 index 0000000..dabe3e5 --- /dev/null +++ b/TelepathyLoggerQt/PendingOperation @@ -0,0 +1,12 @@ +#ifndef _TelepathyLoggerQt_PendingOperation_HEADER_GUARD_ +#define _TelepathyLoggerQt_PendingOperation_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#define IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include + +#undef IN_TELEPATHY_LOGGER_QT_HEADER + +#endif diff --git a/TelepathyLoggerQt/PendingSearch b/TelepathyLoggerQt/PendingSearch new file mode 100644 index 0000000..177918d --- /dev/null +++ b/TelepathyLoggerQt/PendingSearch @@ -0,0 +1,12 @@ +#ifndef _TelepathyLoggerQt_PendingSearch_HEADER_GUARD_ +#define _TelepathyLoggerQt_PendingSearch_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#define IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include + +#undef IN_TELEPATHY_LOGGER_QT_HEADER + +#endif diff --git a/TelepathyLoggerQt/SearchHit b/TelepathyLoggerQt/SearchHit new file mode 100644 index 0000000..3d9c07f --- /dev/null +++ b/TelepathyLoggerQt/SearchHit @@ -0,0 +1,12 @@ +#ifndef _TelepathyLoggerQt_SearchHit_HEADER_GUARD_ +#define _TelepathyLoggerQt_SearchHit_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#define IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include + +#undef IN_TELEPATHY_LOGGER_QT_HEADER + +#endif diff --git a/TelepathyLoggerQt/TelepathyLoggerQt5-uninstalled.pc.in b/TelepathyLoggerQt/TelepathyLoggerQt5-uninstalled.pc.in new file mode 100644 index 0000000..3e2f463 --- /dev/null +++ b/TelepathyLoggerQt/TelepathyLoggerQt5-uninstalled.pc.in @@ -0,0 +1,11 @@ +prefix=/nonexistent +exec_prefix=/nonexistent +abs_top_builddir=${CMAKE_BINARY_DIR} +abs_top_srcdir=${CMAKE_SOURCE_DIR} + +Name: Telepathy-Logger-Qt5 (uninstalled copy) +Description: Qt5 utility library to access logs in the Telepathy framework +Version: ${PACKAGE_VERSION} +Requires.private: Qt5Core >= 5.0, TelepathyQt5 >= 0.5 +Libs: ${CMAKE_BINARY_DIR}/TelepathyQt/libtelepathy-logger-qt${Qt5Core_VERSION_MAJOR}.a +Cflags: -I${CMAKE_SOURCE_DIR} -I${CMAKE_BINARY_DIR} diff --git a/TelepathyLoggerQt/TelepathyLoggerQt5.pc.in b/TelepathyLoggerQt/TelepathyLoggerQt5.pc.in new file mode 100644 index 0000000..e7e62a6 --- /dev/null +++ b/TelepathyLoggerQt/TelepathyLoggerQt5.pc.in @@ -0,0 +1,11 @@ +prefix=${CMAKE_INSTALL_PREFIX} +exec_prefix=${CMAKE_INSTALL_PREFIX} +libdir=${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR} +includedir=${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR} + +Name: Telepathy-Logger-Qt5 +Description: Qt5 utility library to access logs in the Telepathy framework +Version: ${PACKAGE_VERSION} +Requires.private: Qt5Core >= 5.0, TelepathyQt5 >= 0.5, QtGLib-2.0 +Libs: -L${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR} -ltelepathy-logger-qt${Qt5Core_VERSION_MAJOR} +Cflags: -I${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR}/telepathy-logger-0.2 diff --git a/TelepathyLoggerQt/TextEvent b/TelepathyLoggerQt/TextEvent new file mode 100644 index 0000000..6b04b5b --- /dev/null +++ b/TelepathyLoggerQt/TextEvent @@ -0,0 +1,12 @@ +#ifndef _TelepathyLoggerQt_TextEvent_HEADER_GUARD_ +#define _TelepathyLoggerQt_TextEvent_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#define IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include + +#undef IN_TELEPATHY_LOGGER_QT_HEADER + +#endif diff --git a/TelepathyLoggerQt/Types b/TelepathyLoggerQt/Types new file mode 100644 index 0000000..ffb2ef4 --- /dev/null +++ b/TelepathyLoggerQt/Types @@ -0,0 +1,12 @@ +#ifndef _TelepathyLoggerQt_Types_HEADER_GUARD_ +#define _TelepathyLoggerQt_Types_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#define IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include + +#undef IN_TELEPATHY_LOGGER_QT_HEADER + +#endif diff --git a/TelepathyLoggerQt/call-event.cpp b/TelepathyLoggerQt/call-event.cpp new file mode 100644 index 0000000..b6adc6e --- /dev/null +++ b/TelepathyLoggerQt/call-event.cpp @@ -0,0 +1,57 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include + +#include +#include + +using namespace Tpl; + +QTime CallEvent::duration() const +{ + GTimeSpan timeSpan = tpl_call_event_get_duration(object()); + int hh = timeSpan / 3600; + timeSpan = timeSpan % 3600; + int mm = timeSpan / 60; + int ss = timeSpan % 60; + int ms = 0; + // FIXME there is no timespan type in Qt yet, use QTime in the meanwhile + QTime ret(hh,mm,ss,ms); + return ret; +} + +EntityPtr CallEvent::endActor() const +{ + TplEntity * entity = tpl_call_event_get_end_actor(object()); + return EntityPtr::wrap(entity, true); +} + +Tp::CallStateChangeReason CallEvent::endReason() const +{ + Tp::CallStateChangeReason er = (Tp::CallStateChangeReason) tpl_call_event_get_end_reason(object()); + return er; +} + +QString CallEvent::detailedEndReason() const +{ + const gchar *s = tpl_call_event_get_detailed_end_reason(object()); + QString str = QString::fromUtf8(s); + return str; +} diff --git a/TelepathyLoggerQt/call-event.h b/TelepathyLoggerQt/call-event.h new file mode 100644 index 0000000..e880699 --- /dev/null +++ b/TelepathyLoggerQt/call-event.h @@ -0,0 +1,49 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +#ifndef _TelepathyLoggerQt_call_event_h_HEADER_GUARD_ +#define _TelepathyLoggerQt_call_event_h_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#error IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include +#include + +namespace Tpl +{ + +/*! \headerfile call-event.h + * \brief Wrapper class for TplCallEvent + */ +class TELEPATHY_LOGGER_QT_EXPORT CallEvent : public Event +{ + QTELEPATHYLOGGERQT_WRAPPER(CallEvent) +public: + QTime duration() const; + EntityPtr endActor() const; + Tp::CallStateChangeReason endReason() const; + QString detailedEndReason() const; +}; + +} //namespace + +QTELEPATHYLOGGERQT_REGISTER_TYPE(Tpl::CallEvent) + +#endif diff --git a/TelepathyLoggerQt/entity.cpp b/TelepathyLoggerQt/entity.cpp new file mode 100644 index 0000000..67a8106 --- /dev/null +++ b/TelepathyLoggerQt/entity.cpp @@ -0,0 +1,80 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Stefano Sanfilippo + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include + +#include +#include +#include + +using namespace Tpl; + +EntityPtr Entity::create(const char *id, EntityType type, const char *alias, const char *avatarToken) +{ + TplEntity *entity = tpl_entity_new(id, (TplEntityType) type, alias, avatarToken); + return EntityPtr::wrap(entity, false); +} + +EntityPtr Entity::create(const Tp::ContactPtr & contact, EntityType type) +{ +#if 0 + // TODO how to go from Tp::ContactPtr to TpContact ? + //TplEntity *entity = tpl_entity_new_from_tp_contact(0, (TplEntityType) type); + return EntityPtr::wrap(entity, false); +#else + QString id = contact->id(); + QString alias = contact->alias(); + QString avatarToken = contact->avatarToken(); + return Entity::create(id.toUtf8(), type, alias.toUtf8(), avatarToken.toUtf8()); +#endif +} + +EntityPtr Entity::create(const char *room_id) +{ + TplEntity *entity = tpl_entity_new_from_room_id(room_id); + return EntityPtr::wrap(entity, false); +} + +QString Entity::alias() const +{ + const gchar *s = tpl_entity_get_alias(object()); + QString str = QString::fromUtf8(s); + return str; +} + +QString Entity::identifier() const +{ + const gchar *s = tpl_entity_get_identifier(object()); + QString str = QString::fromUtf8(s); + return str; +} + +EntityType Entity::entityType() const +{ + TplEntityType entityType = tpl_entity_get_entity_type(object()); + return EntityType(entityType); +} + +QString Entity::avatarToken() const +{ + const gchar *s = tpl_entity_get_avatar_token(object()); + QString str = QString::fromUtf8(s); + return str; +} diff --git a/TelepathyLoggerQt/entity.h b/TelepathyLoggerQt/entity.h new file mode 100644 index 0000000..7541731 --- /dev/null +++ b/TelepathyLoggerQt/entity.h @@ -0,0 +1,54 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Stefano Sanfilippo + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +#ifndef _TelepathyLoggerQt_entity_h_HEADER_GUARD_ +#define _TelepathyLoggerQt_entity_h_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#error IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include +#include + +namespace Tpl +{ + +/*! \headerfile entity.h + * \brief Wrapper class for TplEntity + */ +class TELEPATHY_LOGGER_QT_EXPORT Entity : public QGlib::Object +{ + QTELEPATHYLOGGERQT_WRAPPER(Entity) +public: + static EntityPtr create(const char *id, EntityType type, const char *alias, const char *avatarToken); + static EntityPtr create(const Tp::ContactPtr & contact, EntityType type); + static EntityPtr create(const char *room_id); + + QString alias() const; + QString identifier() const; + EntityType entityType() const; + QString avatarToken() const; +}; + +} //namespace + +QTELEPATHYLOGGERQT_REGISTER_TYPE(Tpl::Entity) + +#endif diff --git a/TelepathyLoggerQt/event.cpp b/TelepathyLoggerQt/event.cpp new file mode 100644 index 0000000..543ce89 --- /dev/null +++ b/TelepathyLoggerQt/event.cpp @@ -0,0 +1,67 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Stefano Sanfilippo + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include + +#include +#include +#include +#include + +using namespace Tpl; + +QDateTime Event::timestamp() const +{ + // FIXME See http://bugs.freedesktop.org/show_bug.cgi?id=21690 + uint seconds = (uint) tpl_event_get_timestamp(object()); + QDateTime dateTime; + dateTime.setTime_t(seconds); + return dateTime; +} + +QString Event::accountPath() const +{ + const gchar *s = tpl_event_get_account_path(object()); + QString str = QString::fromUtf8(s); + return str; +} + +Tp::AccountPtr Event::account() const +{ + TpAccount *account = tpl_event_get_account(object()); + return Utils::instance()->accountPtr(account); +} + +EntityPtr Event::sender() const +{ + TplEntity *entity = tpl_event_get_sender(object()); + return EntityPtr::wrap(entity, true); +} + +EntityPtr Event::receiver() const +{ + TplEntity *entity = tpl_event_get_receiver(object()); + return EntityPtr::wrap(entity, true); +} + +bool Event::equalTo(const EventPtr & rhs) const +{ + return tpl_event_equal (object(), rhs->object()); +} diff --git a/TelepathyLoggerQt/event.h b/TelepathyLoggerQt/event.h new file mode 100644 index 0000000..445d0ce --- /dev/null +++ b/TelepathyLoggerQt/event.h @@ -0,0 +1,52 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Stefano Sanfilippo + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +#ifndef _TelepathyLoggerQt_event_h_HEADER_GUARD_ +#define _TelepathyLoggerQt_event_h_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#error IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include +#include + +namespace Tpl +{ + +/*! \headerfile event.h + * \brief Wrapper class for TplEvent + */ +class TELEPATHY_LOGGER_QT_EXPORT Event : public QGlib::Object +{ + QTELEPATHYLOGGERQT_WRAPPER(Event) +public: + QDateTime timestamp() const; + QString accountPath() const; + Tp::AccountPtr account() const; + EntityPtr sender() const; + EntityPtr receiver() const; + bool equalTo(const EventPtr & rhs) const; +}; + +} //namespace + +QTELEPATHYLOGGERQT_REGISTER_TYPE(Tpl::Event) + +#endif diff --git a/TelepathyLoggerQt/global.h b/TelepathyLoggerQt/global.h new file mode 100644 index 0000000..b00ab93 --- /dev/null +++ b/TelepathyLoggerQt/global.h @@ -0,0 +1,74 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +#ifndef _TelepathyLoggerQt_global_h_HEADER_GUARD_ +#define _TelepathyLoggerQt_global_h_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#error IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include + +/* defined by cmake when building this library */ +#if defined(BUILDING_TELEPATHY_LOGGER_QT) +# define TELEPATHY_LOGGER_QT_EXPORT Q_DECL_EXPORT +#else +# define TELEPATHY_LOGGER_QT_EXPORT Q_DECL_IMPORT +#endif + +#if !defined(Q_OS_WIN) && !defined(Q_CC_NOKIAX86) && \ + !defined(Q_CC_RVCT) && defined(QT_VISIBILITY_AVAILABLE) +# define TELEPATHY_LOGGER_QT_NO_EXPORT __attribute__((visibility("hidden"))) +#else +# define TELEPATHY_LOGGER_QT_NO_EXPORT +#endif + +#define QTELEPATHYLOGGERQT_REGISTER_TYPE(T) \ + QGLIB_REGISTER_TYPE_WITH_EXPORT_MACRO(T, TELEPATHY_LOGGER_QT_EXPORT) + + +#define QTELEPATHYLOGGERQT_WRAPPER_TPLCLASS_DECLARATION(Class) \ + typedef struct _Tpl##Class Tpl##Class; + +#define QTELEPATHYLOGGERQT_WRAPPER_REFPOINTER_DECLARATION(Class) \ + namespace Tpl { \ + class Class; \ + typedef QGlib::RefPointer Class##Ptr; \ + } + +#define QTELEPATHYLOGGERQT_WRAPPER_DECLARATION(Class) \ + QTELEPATHYLOGGERQT_WRAPPER_TPLCLASS_DECLARATION(Class) \ + QTELEPATHYLOGGERQT_WRAPPER_REFPOINTER_DECLARATION(Class) + +QTELEPATHYLOGGERQT_WRAPPER_DECLARATION(CallEvent) +QTELEPATHYLOGGERQT_WRAPPER_DECLARATION(Entity) +QTELEPATHYLOGGERQT_WRAPPER_DECLARATION(Event) +QTELEPATHYLOGGERQT_WRAPPER_DECLARATION(TextEvent) +QTELEPATHYLOGGERQT_WRAPPER_DECLARATION(LogManager) + +#undef QTELEPATHYLOGGERQT_WRAPPER_DECLARATION +#undef QTELEPATHYLOGGERQT_WRAPPER_REFPOINTER_DECLARATION +#undef QTELEPATHYLOGGERQT_WRAPPER_TPLCLASS_DECLARATION + + +#define QTELEPATHYLOGGERQT_WRAPPER(Class) \ + QGLIB_WRAPPER_DECLARATION_MACRO(Class, Class, Tpl, Class) + + +#endif diff --git a/TelepathyLoggerQt/init.cpp b/TelepathyLoggerQt/init.cpp new file mode 100644 index 0000000..085df67 --- /dev/null +++ b/TelepathyLoggerQt/init.cpp @@ -0,0 +1,35 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include +#include + +namespace Tpl { + +namespace Private { + void registerWrapperConstructors(); //generated by codegen +} + +void init() +{ + QGlib::init(); + Private::registerWrapperConstructors(); +} + +}; diff --git a/TelepathyLoggerQt/init.h b/TelepathyLoggerQt/init.h new file mode 100644 index 0000000..0a46e2f --- /dev/null +++ b/TelepathyLoggerQt/init.h @@ -0,0 +1,39 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +#ifndef _TelepathyLoggerQt_init_h_HEADER_GUARD_ +#define _TelepathyLoggerQt_init_h_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#error IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include + +namespace Tpl +{ + +/*! \headerfile init.h + * \brief Initialization of the telepathy logger qt bindings + */ + +TELEPATHY_LOGGER_QT_EXPORT void init(); + +} //namespace + +#endif diff --git a/TelepathyLoggerQt/log-manager.cpp b/TelepathyLoggerQt/log-manager.cpp new file mode 100644 index 0000000..db36ba0 --- /dev/null +++ b/TelepathyLoggerQt/log-manager.cpp @@ -0,0 +1,87 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Stefano Sanfilippo + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Tpl; + +LogManagerPtr LogManager::instance() +{ + TplLogManager *manager = tpl_log_manager_dup_singleton(); + return LogManagerPtr::wrap(manager, false); +} + +Tp::AccountManagerPtr LogManager::accountManagerPtr() const +{ + return Utils::instance()->accountManagerPtr(); +} + +void LogManager::setAccountManagerPtr(const Tp::AccountManagerPtr & accountManager) +{ + Utils::instance()->setAccountManagerPtr(accountManager); +} + +bool LogManager::exists(const Tp::AccountPtr & account, const EntityPtr & target, + EventTypeMask type) const +{ + TpAccount *tpAccount = Utils::instance()->tpAccount(account); + return tpl_log_manager_exists(object(), tpAccount, target, (gint) type); +} + +PendingDates *LogManager::queryDates(const Tp::AccountPtr & account, const EntityPtr & entity, + EventTypeMask typeMask) +{ + return new PendingDates(LogManagerPtr(this), account, entity, typeMask); +} + +PendingEvents *LogManager::queryEvents(const Tp::AccountPtr & account, const EntityPtr & entity, + EventTypeMask typeMask, const QDate & date) +{ + return new PendingEvents(LogManagerPtr(this), account, entity, typeMask, date); +} + +PendingEvents *LogManager::queryFilteredEvents(const Tp::AccountPtr & account, + const EntityPtr & entity, EventTypeMask typeMask, uint numEvents, + LogEventFilter filterFunction, void *filterFunctionUserData) +{ + return new PendingEvents(LogManagerPtr(this), account, entity, typeMask, numEvents, + filterFunction, filterFunctionUserData); +} + +PendingEntities *LogManager::queryEntities(const Tp::AccountPtr & account) +{ + return new PendingEntities(LogManagerPtr(this), account); +} + +PendingSearch *LogManager::search(const QString &text, EventTypeMask typeMask) +{ + return new PendingSearch(LogManagerPtr(this), text, typeMask); +} diff --git a/TelepathyLoggerQt/log-manager.h b/TelepathyLoggerQt/log-manager.h new file mode 100644 index 0000000..cbf31c4 --- /dev/null +++ b/TelepathyLoggerQt/log-manager.h @@ -0,0 +1,62 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Stefano Sanfilippo + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +#ifndef _TelepathyLoggerQt_log_manager_h_HEADER_GUARD_ +#define _TelepathyLoggerQt_log_manager_h_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#error IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include +#include + +namespace Tpl +{ + +/*! \headerfile log-manager.h + * \brief Wrapper class for TplLogManager + */ +class TELEPATHY_LOGGER_QT_EXPORT LogManager : public QGlib::Object +{ + QTELEPATHYLOGGERQT_WRAPPER(LogManager) +public: + static LogManagerPtr instance(); + + Tp::AccountManagerPtr accountManagerPtr() const; + void setAccountManagerPtr(const Tp::AccountManagerPtr & accountManager); + + bool exists(const Tp::AccountPtr & account, const EntityPtr & target, EventTypeMask type) const; + + PendingDates *queryDates(const Tp::AccountPtr & account, const EntityPtr & entity, + EventTypeMask typeMask); + PendingEvents *queryEvents(const Tp::AccountPtr & account, const EntityPtr & entity, + EventTypeMask typeMask, const QDate & date); + PendingEvents *queryFilteredEvents(const Tp::AccountPtr & account, const EntityPtr & entity, + EventTypeMask typeMask, uint numEvents, LogEventFilter filterFunction, + void *filterFunctionUserData); + PendingEntities *queryEntities(const Tp::AccountPtr & account); + PendingSearch *search(const QString &text, EventTypeMask typeMask); +}; + +} //namespace + +QTELEPATHYLOGGERQT_REGISTER_TYPE(Tpl::LogManager) + +#endif diff --git a/TelepathyLoggerQt/logger.cpp b/TelepathyLoggerQt/logger.cpp new file mode 100644 index 0000000..772fc9b --- /dev/null +++ b/TelepathyLoggerQt/logger.cpp @@ -0,0 +1,98 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include + +#include +#include +#include +#include + +#include +#include + +#define TPL_DBUS_SRV_WELL_KNOWN_BUS_NAME "org.freedesktop.Telepathy.Logger" +#define TPL_DBUS_SRV_OBJECT_PATH "/org/freedesktop/Telepathy/Logger" + +namespace Tpl { + +struct TELEPATHY_LOGGER_QT_NO_EXPORT Logger::Private +{ + Private(Logger *self); + + Tpl::LoggerInterface *mInterface; + LoggerPtr mPtr; +}; + +Logger::Private::Private(Logger *self) +{ + mInterface = new Tpl::LoggerInterface(QDBusConnection::sessionBus(), + TPL_DBUS_SRV_WELL_KNOWN_BUS_NAME, + TPL_DBUS_SRV_OBJECT_PATH); + mPtr = LoggerPtr(self); +} + +LoggerPtr Logger::create() +{ + return LoggerPtr(new Logger()); +} + +Logger::Logger() : + Tp::StatelessDBusProxy(QDBusConnection::sessionBus(), + QLatin1String(TPL_DBUS_SRV_WELL_KNOWN_BUS_NAME), + QLatin1String(TPL_DBUS_SRV_OBJECT_PATH), + Tp::Feature()), + mPriv(new Private(this)) +{ +} + +Logger::~Logger() +{ + delete mPriv; +} + +Tp::PendingOperation *Logger::clearLog() const +{ + PendingLogger *operation = new PendingLogger(mPriv->mPtr, mPriv->mInterface); + operation->clearLog(); + return operation; +} + +Tp::PendingOperation *Logger::clearAccount(const Tp::AccountPtr &account) const +{ + PendingLogger *operation = new PendingLogger(mPriv->mPtr, mPriv->mInterface); + operation->clearAccount(account); + return operation; +} + +Tp::PendingOperation *Logger::clearContact(const Tp::AccountPtr &account, const QString &objectId) const +{ + PendingLogger *operation = new PendingLogger(mPriv->mPtr, mPriv->mInterface); + operation->clearContact(account, objectId); + return operation; +} + +Tp::PendingOperation *Logger::clearRoom(const Tp::AccountPtr &account, const QString &objectId) const +{ + PendingLogger *operation = new PendingLogger(mPriv->mPtr, mPriv->mInterface); + operation->clearRoom(account, objectId); + return operation; +} + +} diff --git a/TelepathyLoggerQt/logger.h b/TelepathyLoggerQt/logger.h new file mode 100644 index 0000000..61fa167 --- /dev/null +++ b/TelepathyLoggerQt/logger.h @@ -0,0 +1,61 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2010 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _TelepathyLoggerQt_logger_h_HEADER_GUARD_ +#define _TelepathyLoggerQt_logger_h_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#error IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include +#include +#include +#include + +namespace Tpl +{ + +class Logger; + +class TELEPATHY_LOGGER_QT_EXPORT Logger : public Tp::StatelessDBusProxy +{ + Q_OBJECT + +public: + static LoggerPtr create(); + + ~Logger(); + + Tp::PendingOperation *clearLog() const; + Tp::PendingOperation *clearAccount(const Tp::AccountPtr &account) const; + Tp::PendingOperation *clearContact(const Tp::AccountPtr &account, const QString &objectId) const; + Tp::PendingOperation *clearRoom(const Tp::AccountPtr &account, const QString &objectId) const; + +private: + Logger(); + struct Private; + friend struct Private; + Private *mPriv; +}; + +} + +#endif diff --git a/TelepathyLoggerQt/logger.xml b/TelepathyLoggerQt/logger.xml new file mode 100644 index 0000000..3188cb3 --- /dev/null +++ b/TelepathyLoggerQt/logger.xml @@ -0,0 +1,12 @@ + + +Logger interfaces + + + + + + + diff --git a/TelepathyLoggerQt/pending-dates.cpp b/TelepathyLoggerQt/pending-dates.cpp new file mode 100644 index 0000000..790ddff --- /dev/null +++ b/TelepathyLoggerQt/pending-dates.cpp @@ -0,0 +1,158 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Tpl; + +struct TELEPATHY_LOGGER_QT_NO_EXPORT PendingDates::Private +{ + LogManagerPtr manager; + Tp::AccountPtr account; + TpAccount *tpAccount; + EntityPtr entity; + EventTypeMask typeMask; + QDateList dates; + + static void onAccountPrepared(void *logManager, void *result, PendingDates *self); + static void callback(void *logManager, void *result, PendingDates *self); +}; + +PendingDates::PendingDates(const LogManagerPtr & manager, const Tp::AccountPtr & account, + const EntityPtr & entity, EventTypeMask typeMask) + : PendingOperation(), + mPriv(new Private()) +{ + mPriv->manager = manager; + mPriv->account = account; + mPriv->tpAccount = 0; + mPriv->entity = entity; + mPriv->typeMask = typeMask; +} + +PendingDates::~PendingDates() +{ + delete mPriv; +} + +void PendingDates::start() +{ + mPriv->tpAccount = Utils::instance()->tpAccount(mPriv->account); + if (!mPriv->tpAccount) { + setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid account"); + return; + } + + GQuark features[] = { TP_ACCOUNT_FEATURE_CORE, 0 }; + tp_account_prepare_async(mPriv->tpAccount, features, (GAsyncReadyCallback) Private::onAccountPrepared, this); +} + +void PendingDates::Private::onAccountPrepared(void *logManager, void *result, PendingDates *self) +{ + tpl_log_manager_get_dates_async(self->mPriv->manager, + self->mPriv->tpAccount, + self->mPriv->entity, + self->mPriv->typeMask, + (GAsyncReadyCallback) Private::callback, + self); +} + +QDateList PendingDates::dates() const +{ + if (!isFinished()) { + warning() << "PendingDates::dates called before finished, returning empty"; + return QDateList(); + } else if (!isValid()) { + warning() << "PendingDates::dates called when not valid, returning empty"; + return QDateList(); + } + + return mPriv->dates; +} + +const Tp::AccountPtr PendingDates::account() const +{ + if (!isFinished()) { + warning() << "PendingDates::account called before finished"; + } else if (!isValid()) { + warning() << "PendingDates::account called when not valid"; + } + + return mPriv->account; +} + +const EntityPtr PendingDates::entity() const +{ + if (!isFinished()) { + warning() << "PendingDates::entity called before finished"; + } else if (!isValid()) { + warning() << "PendingDates::entity called when not valid"; + } + + return mPriv->entity; +} + + +void PendingDates::Private::callback(void *logManager, void *result, PendingDates *self) +{ + if (!TPL_IS_LOG_MANAGER(logManager)) { + self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid log manager in callback"); + return; + } + + if (!G_IS_ASYNC_RESULT(result)) { + self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid async result in callback"); + return; + } + + GList *dates = NULL; + GError *error = NULL; + gboolean success = tpl_log_manager_get_dates_finish(TPL_LOG_MANAGER(logManager), G_ASYNC_RESULT(result), &dates, &error); + if (error) { + self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, error->message); + g_error_free(error); + return; + } + + if (!success) { + self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Query failed without specific error"); + return; + } + + GList *i; + for (i = dates; i; i = i->next) { + GDate * item = (GDate *) i->data; + self->mPriv->dates << QDate(item->year, item->month, item->day); + } + + g_list_foreach(dates, (GFunc) g_date_free, NULL); + g_list_free(dates); + + self->setFinished(); +} diff --git a/TelepathyLoggerQt/pending-dates.h b/TelepathyLoggerQt/pending-dates.h new file mode 100644 index 0000000..e547ea9 --- /dev/null +++ b/TelepathyLoggerQt/pending-dates.h @@ -0,0 +1,62 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Stefano Sanfilippo + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef _TelepathyLoggerQt_pending_dates_h_HEADER_GUARD_ +#define _TelepathyLoggerQt_pending_dates_h_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#error IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include +#include + +namespace Tpl +{ + +class TELEPATHY_LOGGER_QT_EXPORT PendingDates : public Tpl::PendingOperation +{ + Q_OBJECT + Q_DISABLE_COPY(PendingDates); + +public: + ~PendingDates(); + + QDateList dates() const; + const Tp::AccountPtr account() const; + const Tpl::EntityPtr entity() const; + +private Q_SLOTS: + virtual void start(); + +private: + friend class LogManager; + + PendingDates(const LogManagerPtr & manager, const Tp::AccountPtr & account, + const EntityPtr & entity, EventTypeMask typeMask); + + struct Private; + friend struct Private; + Private *mPriv; +}; + +} // Tpl + +#endif diff --git a/TelepathyLoggerQt/pending-entities.cpp b/TelepathyLoggerQt/pending-entities.cpp new file mode 100644 index 0000000..42e1fb1 --- /dev/null +++ b/TelepathyLoggerQt/pending-entities.cpp @@ -0,0 +1,135 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * Copyright (C) 2012 David Edmundson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Tpl; + +struct TELEPATHY_LOGGER_QT_NO_EXPORT PendingEntities::Private +{ + LogManagerPtr manager; + Tp::AccountPtr account; + TpAccount *tpAccount; + EntityPtrList entities; + + static void onAccountPrepared(void *logManager, void *result, PendingEntities *self); + static void callback(void *logManager, void *result, PendingEntities *self); +}; + +PendingEntities::PendingEntities(const LogManagerPtr & manager, const Tp::AccountPtr & account) + : PendingOperation(), + mPriv(new Private()) +{ + mPriv->manager = manager; + mPriv->account = account; + mPriv->tpAccount = 0; +} + +PendingEntities::~PendingEntities() +{ + delete mPriv; +} + +void PendingEntities::start() +{ + mPriv->tpAccount = Utils::instance()->tpAccount(mPriv->account); + if (!mPriv->tpAccount) { + setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid account"); + return; + } + + GQuark features[] = { TP_ACCOUNT_FEATURE_CORE, 0 }; + tp_account_prepare_async(mPriv->tpAccount, features, (GAsyncReadyCallback) Private::onAccountPrepared, this); +} + +void PendingEntities::Private::onAccountPrepared(void *logManager, void *result, PendingEntities *self) +{ + tpl_log_manager_get_entities_async(self->mPriv->manager, + self->mPriv->tpAccount, + (GAsyncReadyCallback) Private::callback, + self); +} + +EntityPtrList PendingEntities::entities() const +{ + if (!isFinished()) { + warning() << "PendingEntities::entities called before finished, returning empty"; + return EntityPtrList(); + } else if (!isValid()) { + warning() << "PendingEntities::entities called when not valid, returning empty"; + return EntityPtrList(); + } + + return mPriv->entities; +} + +Tp::AccountPtr PendingEntities::account() const +{ + return mPriv->account; +} + + +void PendingEntities::Private::callback(void *logManager, void *result, PendingEntities *self) +{ + if (!TPL_IS_LOG_MANAGER(logManager)) { + self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid log manager in callback"); + return; + } + + if (!G_IS_ASYNC_RESULT(result)) { + self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid async result in callback"); + return; + } + + GList *entities = NULL; + GError *error = NULL; + gboolean success = tpl_log_manager_get_entities_finish(TPL_LOG_MANAGER(logManager), G_ASYNC_RESULT(result), &entities, &error); + if (error) { + self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, error->message); + g_error_free(error); + return; + } + + if (!success) { + self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Query failed without specific error"); + return; + } + + GList *i; + for (i = entities; i; i = i->next) { + TplEntity * item = (TplEntity *) i->data; + self->mPriv->entities << EntityPtr::wrap(item, true); + } + + g_list_foreach(entities, (GFunc) g_object_unref, NULL); + g_list_free(entities); + + self->setFinished(); +} diff --git a/TelepathyLoggerQt/pending-entities.h b/TelepathyLoggerQt/pending-entities.h new file mode 100644 index 0000000..b3d0f47 --- /dev/null +++ b/TelepathyLoggerQt/pending-entities.h @@ -0,0 +1,60 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * Copyright (C) 2012 David Edmundson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef _TelepathyLoggerQt_pending_entities_h_HEADER_GUARD_ +#define _TelepathyLoggerQt_pending_entities_h_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#error IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include +#include + +namespace Tpl +{ + +class TELEPATHY_LOGGER_QT_EXPORT PendingEntities: public Tpl::PendingOperation +{ + Q_OBJECT + Q_DISABLE_COPY(PendingEntities); + +public: + ~PendingEntities(); + + EntityPtrList entities() const; + Tp::AccountPtr account() const; + +private Q_SLOTS: + virtual void start(); + +private: + friend class LogManager; + + PendingEntities(const LogManagerPtr & manager, const Tp::AccountPtr & account); + + struct Private; + friend struct Private; + Private *mPriv; +}; + +} // Tpl + +#endif diff --git a/TelepathyLoggerQt/pending-events.cpp b/TelepathyLoggerQt/pending-events.cpp new file mode 100644 index 0000000..2b9cf35 --- /dev/null +++ b/TelepathyLoggerQt/pending-events.cpp @@ -0,0 +1,212 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Tpl; + +struct TELEPATHY_LOGGER_QT_NO_EXPORT PendingEvents::Private +{ + LogManagerPtr manager; + Tp::AccountPtr account; + TpAccount *tpAccount; + EntityPtr entity; + EventTypeMask typeMask; + QDate date; + + bool filtered; + uint numEvents; + LogEventFilter filterFunction; + void *filterFunctionUserData; + + EventPtrList events; + + static void onAccountPrepared(void *logManager, void *result, PendingEvents *self); + static void callback(void *logManager, void *result, PendingEvents *self); + static gboolean eventFilterMethod(TplEvent *event, gpointer *user_data); +}; + +PendingEvents::PendingEvents(const LogManagerPtr & manager, const Tp::AccountPtr & account, + const EntityPtr & entity, EventTypeMask typeMask, const QDate &date) + : PendingOperation(), + mPriv(new Private()) +{ + mPriv->manager = manager; + mPriv->account = account; + mPriv->tpAccount = 0; + mPriv->entity = entity; + mPriv->typeMask = typeMask; + mPriv->date = date; + mPriv->filtered = false; + mPriv->filterFunction = 0; + mPriv->filterFunctionUserData = 0; +} + +PendingEvents::PendingEvents(const LogManagerPtr & manager, const Tp::AccountPtr & account, + const EntityPtr & entity, EventTypeMask typeMask, uint numEvents, + LogEventFilter filterFunction, void *filterFunctionUserData) + : PendingOperation(), + mPriv(new Private()) +{ + mPriv->manager = manager; + mPriv->account = account; + mPriv->entity = entity; + mPriv->typeMask = typeMask; + mPriv->filtered = true; + mPriv->numEvents = numEvents; + mPriv->filterFunction = filterFunction; + mPriv->filterFunctionUserData = filterFunctionUserData; +} + +PendingEvents::~PendingEvents() +{ + delete mPriv; +} + +void PendingEvents::start() +{ + mPriv->tpAccount = Utils::instance()->tpAccount(mPriv->account); + if (!mPriv->tpAccount) { + setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid account"); + return; + } + + GQuark features[] = { TP_ACCOUNT_FEATURE_CORE, 0 }; + tp_account_prepare_async(mPriv->tpAccount, features, (GAsyncReadyCallback) Private::onAccountPrepared, this); +} + +void PendingEvents::Private::onAccountPrepared(void *logManager, void *result, PendingEvents *self) +{ + if (self->mPriv->filtered) { + tpl_log_manager_get_filtered_events_async(self->mPriv->manager, + self->mPriv->tpAccount, + self->mPriv->entity, + self->mPriv->typeMask, + self->mPriv->numEvents, + self->mPriv->filterFunction ? (TplLogEventFilter) Private::eventFilterMethod : 0, + self, + (GAsyncReadyCallback) Private::callback, + self); + } else { + GDate *gdate = g_date_new_dmy( + self->mPriv->date.day(), + (GDateMonth) self->mPriv->date.month(), + self->mPriv->date.year()); + tpl_log_manager_get_events_for_date_async(self->mPriv->manager, + self->mPriv->tpAccount, + self->mPriv->entity, + self->mPriv->typeMask, + gdate, + (GAsyncReadyCallback) Private::callback, + self); + g_date_free(gdate); + } +} + +EventPtrList PendingEvents::events() const +{ + if (!isFinished()) { + warning() << "PendingEvents::events called before finished, returning empty"; + return EventPtrList(); + } else if (!isValid()) { + warning() << "PendingEvents::events called when not valid, returning empty"; + return EventPtrList(); + } + + return mPriv->events; +} + +void PendingEvents::Private::callback(void *logManager, void *result, PendingEvents *self) +{ + if (!TPL_IS_LOG_MANAGER(logManager)) { + self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid log manager in callback"); + return; + } + + if (!G_IS_ASYNC_RESULT(result)) { + self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid async result in callback"); + return; + } + + GList *events = NULL; + GError *error = NULL; + gboolean success = FALSE; + + if (self->mPriv->filtered) { + success = tpl_log_manager_get_filtered_events_finish(TPL_LOG_MANAGER(logManager), G_ASYNC_RESULT(result), &events, &error); + } else { + success = tpl_log_manager_get_events_for_date_finish(TPL_LOG_MANAGER(logManager), G_ASYNC_RESULT(result), &events, &error); + } + + if (error) { + self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, error->message); + g_error_free(error); + return; + } + + if (!success) { + self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Query failed without specific error"); + return; + } + + GList *i; + for (i = events; i; i = i->next) { + TplEvent * item = (TplEvent *) i->data; + if (TPL_IS_TEXT_EVENT(item)) { + TextEventPtr eventPtr = TextEventPtr::wrap(TPL_TEXT_EVENT(item), true); + self->mPriv->events << eventPtr; + } else if (TPL_IS_CALL_EVENT(item)) { + CallEventPtr eventPtr = CallEventPtr::wrap(TPL_CALL_EVENT(item), true); + self->mPriv->events << eventPtr; + } else if (TPL_IS_EVENT(item)) { + EventPtr eventPtr = EventPtr::wrap(TPL_EVENT(item), true); + self->mPriv->events << eventPtr; + } + } + + g_list_foreach(events, (GFunc) g_object_unref, NULL); + g_list_free(events); + + self->setFinished(); +} + +gboolean PendingEvents::Private::eventFilterMethod(TplEvent *event, gpointer *user_data) +{ + PendingEvents *self = (PendingEvents *) user_data; + if (!self) { + return FALSE; + } + + return self->mPriv->filterFunction(EventPtr::wrap(event, true), self->mPriv->filterFunctionUserData); +} diff --git a/TelepathyLoggerQt/pending-events.h b/TelepathyLoggerQt/pending-events.h new file mode 100644 index 0000000..952c489 --- /dev/null +++ b/TelepathyLoggerQt/pending-events.h @@ -0,0 +1,63 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Stefano Sanfilippo + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef _TelepathyLoggerQt_pending_events_h_HEADER_GUARD_ +#define _TelepathyLoggerQt_pending_events_h_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#error IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include +#include + +namespace Tpl +{ + +class TELEPATHY_LOGGER_QT_EXPORT PendingEvents : public Tpl::PendingOperation +{ + Q_OBJECT + Q_DISABLE_COPY(PendingEvents); + +public: + ~PendingEvents(); + + EventPtrList events() const; + +private Q_SLOTS: + virtual void start(); + +private: + friend class LogManager; + + PendingEvents(const LogManagerPtr & manager, const Tp::AccountPtr & account, + const EntityPtr & entity, EventTypeMask typeMask, const QDate &date); + PendingEvents(const LogManagerPtr & manager, const Tp::AccountPtr & account, + const EntityPtr & entity, EventTypeMask typeMask, uint numEvents, + LogEventFilter filterFunction, void *filterFunctionUserData); + + struct Private; + friend struct Private; + Private *mPriv; +}; + +} // Tpl + +#endif diff --git a/TelepathyLoggerQt/pending-logger.cpp b/TelepathyLoggerQt/pending-logger.cpp new file mode 100644 index 0000000..de86118 --- /dev/null +++ b/TelepathyLoggerQt/pending-logger.cpp @@ -0,0 +1,115 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include "utils.h" +#include +#include + +namespace Tpl { + +PendingLogger::PendingLogger(const Tp::SharedPtr &logger, Tpl::LoggerInterface *interface) + : Tp::PendingOperation(logger), + mInterface(interface) +{ +} + +void PendingLogger::setError(const QString &errorName, const QString &errorMessage) +{ + Q_ASSERT(this->errorName.isEmpty()); + Q_ASSERT(this->errorMessage.isEmpty()); + + Q_ASSERT(!errorName.isEmpty()); + + this->errorName = errorName; + this->errorMessage = errorMessage; +} + +void PendingLogger::finish() +{ + if (errorName.isEmpty()) { + setFinished(); + } else { + setFinishedWithError(errorName, errorMessage); + } +} + +void PendingLogger::clearLog() +{ + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher( + mInterface->Clear()); + connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, + SLOT(onLogCleared(QDBusPendingCallWatcher*))); +} + +void PendingLogger::clearAccount(const Tp::AccountPtr &account) +{ + QDBusObjectPath path = QDBusObjectPath(account->objectPath()); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher( + mInterface->ClearAccount(path)); + + connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, + SLOT(onLogCleared(QDBusPendingCallWatcher*))); +} + +void PendingLogger::clearContact(const Tp::AccountPtr &account, const QString &objectId) +{ + QDBusObjectPath path = QDBusObjectPath(account->objectPath()); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher( + mInterface->ClearEntity(path, objectId, EntityTypeContact)); + + connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, + SLOT(onLogCleared(QDBusPendingCallWatcher*))); +} + +void PendingLogger::clearRoom(const Tp::AccountPtr &account, const QString &objectId) +{ + QDBusObjectPath path = QDBusObjectPath(account->objectPath()); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher( + mInterface->ClearEntity(path, objectId, EntityTypeRoom)); + + connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, + SLOT(onLogCleared(QDBusPendingCallWatcher*))); +} + +void PendingLogger::onLogCleared(QDBusPendingCallWatcher *watcher) +{ + QDBusPendingReply<> reply = *watcher; + + if (!reply.isError()) { + debug() << "PendingLogger:onLogCleared: Log has been cleared"; + } else { + warning() << "PendingLogger:onLogCleared: Clear log failed with " << + reply.error().name() << ":" << reply.error().message(); + } + + if(!reply.isError()) { + finish(); + } else { + setError(reply.error().name(), reply.error().message()); + finish(); + } + +} + +} + diff --git a/TelepathyLoggerQt/pending-logger.h b/TelepathyLoggerQt/pending-logger.h new file mode 100644 index 0000000..b38c4fd --- /dev/null +++ b/TelepathyLoggerQt/pending-logger.h @@ -0,0 +1,60 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2010 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _TelepathyLoggerQt_pending_logger_h_HEADER_GUARD_ +#define _TelepathyLoggerQt_pending_logger_h_HEADER_GUARD_ + +#include +#include +#include + +namespace Tpl +{ + +class Logger; + +class TELEPATHY_LOGGER_QT_NO_EXPORT PendingLogger : public Tp::PendingOperation +{ + Q_OBJECT + +public: + PendingLogger(const Tp::SharedPtr &logger, Tpl::LoggerInterface *interface); + ~PendingLogger() {}; + + void clearLog(); + void clearAccount(const Tp::AccountPtr &account); + void clearContact(const Tp::AccountPtr &account, const QString &objectId); + void clearRoom(const Tp::AccountPtr &account, const QString &objectId); + +protected: + void setError(const QString &errorName, const QString &errorMessage); + void finish(); + +private Q_SLOTS: + void onLogCleared(QDBusPendingCallWatcher *watcher); + +private: + QString errorName, errorMessage; + Tpl::LoggerInterface *mInterface; +}; + +} + +#endif diff --git a/TelepathyLoggerQt/pending-operation.cpp b/TelepathyLoggerQt/pending-operation.cpp new file mode 100644 index 0000000..aede97e --- /dev/null +++ b/TelepathyLoggerQt/pending-operation.cpp @@ -0,0 +1,243 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * Copyright (C) 2011 Nokia Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include +#include +#include + +using namespace Tpl; + +struct TELEPATHY_LOGGER_QT_NO_EXPORT PendingOperation::Private +{ + Private() + : finished(false) + { + } + + QString errorName; + QString errorMessage; + bool finished; +}; + +/** + * \class PendingOperation + * \headerfile TelepathyQt/pending-operation.h + * + * \brief Abstract base class for pending asynchronous operations. + * + * This class represents an incomplete asynchronous operation, such as a + * D-Bus method call. When the operation has finished, it emits + * #finished. The slot or slots connected to the #finished() signal may obtain + * additional information from the %PendingOperation. + * + * In simple cases, like a D-Bus method with no 'out' arguments or for which + * all 'out' arguments are to be ignored (so the possible results are + * success with no extra information, or failure with an error code), the + * trivial subclass %PendingVoid can be used. + * + * For pending operations that produce a result, another subclass of + * %PendingOperation can be used, with additional methods that provide that + * result to the library user. + * + * After #finished() is emitted, the %PendingOperation is automatically + * deleted using deleteLater(), so library users must not explicitly + * delete this object. + * + * The design is loosely based on KDE's KJob. + */ + +/** + * Protected constructor. Only subclasses of this class may be constructed. + * + * \param object The object on which this pending operation takes place + */ +PendingOperation::PendingOperation() + : QObject(), + mPriv(new Private()) +{ + QTimer::singleShot(0, this, SLOT(start())); +} + +/** + * Class destructor. + */ +PendingOperation::~PendingOperation() +{ + if (!mPriv->finished) { + qWarning() << this << + "still pending when it was deleted - finished will " + "never be emitted"; + } + + delete mPriv; +} + +void PendingOperation::emitFinished() +{ + Q_ASSERT(mPriv->finished); + Q_EMIT finished(this); + deleteLater(); +} + +/** + * Record that this pending operation has finished successfully, and + * emit the #finished() signal next time the event loop runs. + */ +void PendingOperation::setFinished() +{ + if (mPriv->finished) { + if (!mPriv->errorName.isEmpty()) { + qWarning() << this << "trying to finish with success, but already" + " failed with" << mPriv->errorName << ":" << mPriv->errorMessage; + } else { + qWarning() << this << "trying to finish with success, but already" + " succeeded"; + } + return; + } + + mPriv->finished = true; + Q_ASSERT(isValid()); + QTimer::singleShot(0, this, SLOT(emitFinished())); +} + +/** + * Record that this pending operation has finished with an error, and + * emit the #finished() signal next time the event loop runs. + * + * \param name A D-Bus error name, which must be non-empty + * \param message A debugging message + */ +void PendingOperation::setFinishedWithError(const QString &name, + const QString &message) +{ + if (mPriv->finished) { + if (mPriv->errorName.isEmpty()) { + qWarning() << this << "trying to fail with" << name << + "but already failed with" << errorName() << ":" << + errorMessage(); + } else { + qWarning() << this << "trying to fail with" << name << + "but already succeeded"; + } + return; + } + + if (name.isEmpty()) { + qWarning() << this << "should be given a non-empty error name"; + mPriv->errorName = QLatin1String("org.freedesktop.Telepathy.Qt5.ErrorHandlingError"); + } else { + mPriv->errorName = name; + } + + mPriv->errorMessage = message; + mPriv->finished = true; + Q_ASSERT(isError()); + QTimer::singleShot(0, this, SLOT(emitFinished())); +} + +/** + * Returns whether or not the request completed successfully. If the + * request has not yet finished processing (isFinished() returns + * false), this cannot yet be known, and false + * will be returned. + * + * Equivalent to (isFinished() && !isError()). + * + * \return true iff the request has finished processing AND + * has completed successfully. + */ +bool PendingOperation::isValid() const +{ + return (mPriv->finished && mPriv->errorName.isEmpty()); +} + +/** + * Returns whether or not the request has finished processing. #finished() + * is emitted when this changes from false to + * true. + * + * Equivalent to (isValid() || isError()). + * + * \sa finished() + * + * \return true if the request has finished + */ +bool PendingOperation::isFinished() const +{ + return mPriv->finished; +} + +/** + * Returns whether or not the request resulted in an error. If the + * request has not yet finished processing (isFinished() returns + * false), this cannot yet be known, and false + * will be returned. + * + * Equivalent to (isFinished() && !isValid()). + * + * \return true iff the request has finished processing AND + * has resulted in an error. + */ +bool PendingOperation::isError() const +{ + return (mPriv->finished && !mPriv->errorName.isEmpty()); +} + +/** + * If isError() would return true, returns the D-Bus error with which + * the operation failed. If the operation succeeded or has not yet + * finished, returns an empty string. + * + * \return a D-Bus error name or an empty string + */ +QString PendingOperation::errorName() const +{ + return mPriv->errorName; +} + +/** + * If isError() would return true, returns a debugging message associated + * with the error, which may be an empty string. Otherwise, return an + * empty string. + * + * \return a debugging message or an empty string + */ +QString PendingOperation::errorMessage() const +{ + return mPriv->errorMessage; +} + +/** + * \fn void PendingOperation::finished(Tp::PendingOperation* operation) + * + * Emitted when the pending operation finishes, i.e. when #isFinished() + * changes from false to true. + * + * \param operation This operation object, from which further information + * may be obtained + */ + +void PendingOperation::start() +{ +} diff --git a/TelepathyLoggerQt/pending-operation.h b/TelepathyLoggerQt/pending-operation.h new file mode 100644 index 0000000..486f5ed --- /dev/null +++ b/TelepathyLoggerQt/pending-operation.h @@ -0,0 +1,70 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * Copyright (C) 2011 Nokia Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef _TelepathyLoggerQt_pending_operation_h_HEADER_GUARD_ +#define _TelepathyLoggerQt_pending_operation_h_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#error IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include +#include + +namespace Tpl +{ + +class TELEPATHY_LOGGER_QT_EXPORT PendingOperation : public QObject +{ + Q_OBJECT + Q_DISABLE_COPY(PendingOperation) + +public: + virtual ~PendingOperation(); + + bool isFinished() const; + bool isValid() const; + bool isError() const; + QString errorName() const; + QString errorMessage() const; + +Q_SIGNALS: + void finished(Tpl::PendingOperation *operation); + +protected: + PendingOperation(); + +protected Q_SLOTS: + void setFinished(); + void setFinishedWithError(const QString &name, const QString &message); + +private Q_SLOTS: + virtual void start(); + void emitFinished(); + +private: + struct Private; + friend struct Private; + Private *mPriv; +}; + +} // Tpl + +#endif diff --git a/TelepathyLoggerQt/pending-search.cpp b/TelepathyLoggerQt/pending-search.cpp new file mode 100644 index 0000000..926a9e5 --- /dev/null +++ b/TelepathyLoggerQt/pending-search.cpp @@ -0,0 +1,125 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Tpl; + +struct TELEPATHY_LOGGER_QT_NO_EXPORT PendingSearch::Private +{ + LogManagerPtr manager; + QString text; + EventTypeMask typeMask; + SearchHitList hits; + + static void callback(void *logManager, void *result, PendingSearch *self); +}; + +PendingSearch::PendingSearch(const LogManagerPtr & manager, const QString &text, EventTypeMask typeMask) + : PendingOperation(), + mPriv(new Private()) +{ + mPriv->manager = manager; + mPriv->text = text; + mPriv->typeMask = typeMask; +} + +PendingSearch::~PendingSearch() +{ + delete mPriv; +} + +void PendingSearch::start() +{ + tpl_log_manager_search_async(mPriv->manager, + mPriv->text.toUtf8(), + mPriv->typeMask, + (GAsyncReadyCallback) Private::callback, + this); +} + +SearchHitList PendingSearch::hits() const +{ + if (!isFinished()) { + warning() << "PendingSearch::dates called before finished, returning empty"; + return SearchHitList(); + } else if (!isValid()) { + warning() << "PendingSearch::dates called when not valid, returning empty"; + return SearchHitList(); + } + + return mPriv->hits; +} + +void PendingSearch::Private::callback(void *logManager, void *result, PendingSearch *self) +{ + if (!TPL_IS_LOG_MANAGER(logManager)) { + self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid log manager in callback"); + return; + } + + if (!G_IS_ASYNC_RESULT(result)) { + self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid async result in callback"); + return; + } + + GList *hits = NULL; + GError *error = NULL; + gboolean success = tpl_log_manager_search_finish(TPL_LOG_MANAGER(logManager), G_ASYNC_RESULT(result), &hits, &error); + if (error) { + self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, error->message); + g_error_free(error); + return; + } + + if (!success) { + self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Query failed without specific error"); + return; + } + + GList *i; + int count = 0; + for (i = hits; i; i = i->next) { + TplLogSearchHit *item = (TplLogSearchHit *) i->data; + debugfn() << "hit " << count++ << "account=" << item->account + << "date=" << g_date_get_year(item->date) << g_date_get_month(item->date) << g_date_get_day(item->date) + << "target=" << item->target + << tpl_entity_get_identifier(item->target) + << "/" << tpl_entity_get_alias(item->target) + << "/" << tpl_entity_get_entity_type(item->target) + << "/" << tpl_entity_get_avatar_token(item->target); + SearchHit hit(Utils::instance()->accountPtr(item->account), EntityPtr::wrap(item->target, true), QDate(item->date->year, item->date->month, item->date->day)); + self->mPriv->hits << hit; + } + + tpl_log_manager_search_free(hits); + + self->setFinished(); +} diff --git a/TelepathyLoggerQt/pending-search.h b/TelepathyLoggerQt/pending-search.h new file mode 100644 index 0000000..6b19a62 --- /dev/null +++ b/TelepathyLoggerQt/pending-search.h @@ -0,0 +1,58 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef _TelepathyLoggerQt_pending_search_h_HEADER_GUARD_ +#define _TelepathyLoggerQt_pending_search_h_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#error IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include +#include + +namespace Tpl +{ + +class TELEPATHY_LOGGER_QT_EXPORT PendingSearch : public Tpl::PendingOperation +{ + Q_OBJECT + Q_DISABLE_COPY(PendingSearch); + +public: + ~PendingSearch(); + + SearchHitList hits() const; + +private Q_SLOTS: + virtual void start(); + +private: + friend class LogManager; + + PendingSearch(const LogManagerPtr & manager, const QString &text, EventTypeMask typeMask); + + struct Private; + friend struct Private; + Private *mPriv; +}; + +} // Tpl + +#endif diff --git a/TelepathyLoggerQt/search-hit.cpp b/TelepathyLoggerQt/search-hit.cpp new file mode 100644 index 0000000..50ab25f --- /dev/null +++ b/TelepathyLoggerQt/search-hit.cpp @@ -0,0 +1,76 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * Copyright (C) 2012 David Edmundson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include +#include +#include + +using namespace Tpl; + +struct TELEPATHY_LOGGER_QT_NO_EXPORT SearchHit::Private : public QSharedData +{ + Tp::AccountPtr account; + EntityPtr target; + QDate date; +}; + +SearchHit::SearchHit(const Tp::AccountPtr &account, const Tpl::EntityPtr &target, const QDate &date) : + mPriv(new Private()) +{ + mPriv->account = account; + mPriv->target = target; + mPriv->date = date; +} + +SearchHit::SearchHit(const SearchHit &other) + : mPriv(other.mPriv) +{ +} + +SearchHit & SearchHit::operator=(const SearchHit &other) +{ + mPriv = other.mPriv; + return *this; +} + +SearchHit::~SearchHit() +{ +} + +Tp::AccountPtr SearchHit::account() const +{ + return mPriv->account; +} + +EntityPtr SearchHit::target() const +{ + return mPriv->target; +} + +QDate SearchHit::date() const +{ + return mPriv->date; +} + + + diff --git a/TelepathyLoggerQt/search-hit.h b/TelepathyLoggerQt/search-hit.h new file mode 100644 index 0000000..aa17d54 --- /dev/null +++ b/TelepathyLoggerQt/search-hit.h @@ -0,0 +1,56 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * Copyright (C) 2012 David Edmundson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef _TelepathyLoggerQt_search_hit_h_HEADER_GUARD_ +#define _TelepathyLoggerQt_search_hit_h_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#error IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include +#include +#include + +#include + +namespace Tpl +{ + +class TELEPATHY_LOGGER_QT_EXPORT SearchHit +{ +public: + SearchHit(const Tp::AccountPtr &account, const EntityPtr &target, const QDate &date); + SearchHit(const SearchHit &other); + SearchHit & operator=(const SearchHit &other); + ~SearchHit(); + + Tp::AccountPtr account() const; + EntityPtr target() const; + QDate date() const; + +private: + struct Private; + QSharedDataPointer mPriv; +}; + +} // Tpl + +#endif diff --git a/TelepathyLoggerQt/stable-interfaces.xml b/TelepathyLoggerQt/stable-interfaces.xml new file mode 100644 index 0000000..17174a0 --- /dev/null +++ b/TelepathyLoggerQt/stable-interfaces.xml @@ -0,0 +1,12 @@ + + +Telepathy D-Bus Interface Specification, TelepathyQt5Yell copy + + + + + + + diff --git a/TelepathyLoggerQt/text-event.cpp b/TelepathyLoggerQt/text-event.cpp new file mode 100644 index 0000000..c14be6b --- /dev/null +++ b/TelepathyLoggerQt/text-event.cpp @@ -0,0 +1,54 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Stefano Sanfilippo + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include + +#include + +using namespace Tpl; + +Tp::ChannelTextMessageType TextEvent::messageType() const +{ + return (Tp::ChannelTextMessageType) tpl_text_event_get_message_type(object()); +} + +QString TextEvent::message() const +{ + const gchar *s = tpl_text_event_get_message(object()); + QString str = QString::fromUtf8(s); + return str; +} + +QString TextEvent::messageToken() const +{ + const gchar *s = tpl_text_event_get_message_token(object()); + QString str = QString::fromUtf8(s); + return str; +} + +QDateTime TextEvent::editTimestamp() const +{ + // FIXME See http://bugs.freedesktop.org/show_bug.cgi?id=21690 + uint seconds = (uint) tpl_text_event_get_edit_timestamp(object()); + QDateTime dateTime; + dateTime.setTime_t(seconds); + return dateTime; +} + diff --git a/TelepathyLoggerQt/text-event.h b/TelepathyLoggerQt/text-event.h new file mode 100644 index 0000000..3ece7a1 --- /dev/null +++ b/TelepathyLoggerQt/text-event.h @@ -0,0 +1,50 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Stefano Sanfilippo + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +#ifndef _TelepathyLoggerQt_text_event_h_HEADER_GUARD_ +#define _TelepathyLoggerQt_text_event_h_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#error IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include +#include + +namespace Tpl +{ + +/*! \headerfile text-event.h + * \brief Wrapper class for TplTextEvent + */ +class TELEPATHY_LOGGER_QT_EXPORT TextEvent : public Event +{ + QTELEPATHYLOGGERQT_WRAPPER(TextEvent) +public: + Tp::ChannelTextMessageType messageType() const; + QString message() const; + QString messageToken() const; + QDateTime editTimestamp() const; +}; + +} //namespace + +QTELEPATHYLOGGERQT_REGISTER_TYPE(Tpl::TextEvent) + +#endif diff --git a/TelepathyLoggerQt/types.h b/TelepathyLoggerQt/types.h new file mode 100644 index 0000000..7f3eac4 --- /dev/null +++ b/TelepathyLoggerQt/types.h @@ -0,0 +1,74 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +#ifndef _TelepathyLoggerQt_types_h_HEADER_GUARD_ +#define _TelepathyLoggerQt_types_h_HEADER_GUARD_ + +#ifndef IN_TELEPATHY_LOGGER_QT_HEADER +#error IN_TELEPATHY_LOGGER_QT_HEADER +#endif + +#include +#include +#include +#include + +namespace Tpl +{ + +enum EntityType +{ + //codegen: EntityTypeUnknown=ENTITY_UNKNOWN,EntityTypeContact=ENTITY_CONTACT,EntityTypeRoom=ENTITY_ROOM,EntityTypeSelf=ENTITY_SELF + EntityTypeUnknown, + EntityTypeContact, + EntityTypeRoom, + EntityTypeSelf +}; + +enum LogManagerError +{ + LogManagerErrorAddEvent +}; + +enum EventTypeMask +{ + //codegen: EventTypeMaskText=EVENT_MASK_TEXT,EventTypeMaskCall=EVENT_MASK_CALL,EventTypeMaskAny=EVENT_MASK_ANY + EventTypeMaskText = 1 << 0, + EventTypeMaskCall = 1 << 1, + EventTypeMaskAny = 0xffff +}; + +class Logger; +class PendingDates; +class PendingEvents; +class PendingEntities; +class PendingSearch; +class SearchHit; + +typedef Tp::SharedPtr LoggerPtr; +typedef QList ContactPtrList; +typedef QList EntityPtrList; +typedef QList EventPtrList; +typedef QList QDateList; +typedef QList SearchHitList; + +typedef bool (*LogEventFilter)(const EventPtr &event, void *user_data); + +} //namespace + +#endif diff --git a/TelepathyLoggerQt/utils.cpp b/TelepathyLoggerQt/utils.cpp new file mode 100644 index 0000000..f102e20 --- /dev/null +++ b/TelepathyLoggerQt/utils.cpp @@ -0,0 +1,193 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Tpl; + +Utils *Utils::instance() +{ + static Utils *instance = 0; + + if (!instance) { + instance = new Utils(); + } + + return instance; +} + +Utils::Utils() +{ +} + +Utils::~Utils() +{ +} + +void Utils::setAccountManagerPtr(const Tp::AccountManagerPtr & accountManager) +{ + mAccountManagerPtr = accountManager; +} + +Tp::AccountManagerPtr Utils::accountManagerPtr() +{ + if (mAccountManagerPtr.isNull()) { + mAccountManagerPtr = Tp::AccountManager::create(); + } + + return mAccountManagerPtr; +} + +TpAccountManager *Utils::tpAccountManager() +{ + return tp_account_manager_dup(); +} + +Tp::AccountPtr Utils::accountPtr(TpAccount *account) +{ + if (!account) { + return Tp::AccountPtr(); + } + + const gchar *objectPath = tp_proxy_get_object_path(account); + if (!objectPath) { + return Tp::AccountPtr(); + } + + return accountPtr(objectPath); +} + +Tp::AccountPtr Utils::accountPtr(const QString &objectPath) +{ + Tp::AccountPtr accountPtr = accountManagerPtr()->accountForPath(objectPath); + + return accountPtr; +} + +TpAccount *Utils::tpAccount(const Tp::AccountPtr & accountPtr) +{ + QString objectPath = accountPtr->objectPath(); + if (objectPath.isEmpty()) { + return 0; + } + + TpAccount * account = tp_account_manager_ensure_account(tpAccountManager(), objectPath.toUtf8()); + return account; +} + +#if 0 +TpContact *ToTpContact(Tp::ContactPtr contact) +{ + if (contact.isNull()) { + return 0; + } + + Tp::ReferencedHandles handles = contact->handle(); + if (handles.isEmpty()) { + return 0; + } + + GError *error = 0; + TpDBusDaemon * tpDBusDaemon = tp_dbus_daemon_dup(&error); + if (error) { + g_error_free(error); + return 0; + } + + if (!tpDBusDaemon) { + return 0; + } + + if (!contact->manager()) { + return 0; + } + + Tp::ConnectionPtr connection = contact->manager()->connection(); + if (!connection) { + return 0; + } + + QString busName = connection->busName(); + QString objectPath = connection->objectPath(); + TpConnection *tpConnection = tp_connection_new(tpDBusDaemon, busName.toLatin1(), objectPath.toLatin1(), &error); + if (error) { + return 0; + } + + if (!tpConnection) { + return 0; + } + + Tp::ReferencedHandles::const_iterator it; + for(it = handles.constBegin(); it != handles.constEnd(); it++) { + // todo use async version: tp_connection_get_contacts_by_handle + TpContact *tpContact = tp_connection_dup_contact_if_possible(tpConnection, *it, contact->id().toLatin1()); + if (tpContact) { + return tpContact; + } + } + + return 0; +} + +Tp::ContactPtr ToTpContactPtr(TpContact * tpContact) +{ + if (!tpContact) { + return Tp::ContactPtr(); + } + + TpConnection * tpConnection = tp_contact_get_connection(tpContact); + if (!tpConnection) { + return Tp::ContactPtr(); + } + + const gchar *busName = tp_proxy_get_bus_name(TP_PROXY(tpConnection)); + if (!busName) { + return Tp::ContactPtr(); + } + + const gchar *objectPath = tp_proxy_get_object_path(TP_PROXY(tpConnection)); + if (!objectPath) { + return Tp::ContactPtr(); + } + + Tp::ConnectionPtr connection = Tp::Connection::create(busName, objectPath); + if (connection.isNull()) { + return Tp::ContactPtr(); + } + + if (connection->contactManager().isNull()) { + return Tp::ContactPtr(); + } + + TpHandle handle = tp_contact_get_handle(contact); + // TODO use async version + return connection->contactManager()->lookupContactByHandle(handle); +} +#endif diff --git a/TelepathyLoggerQt/utils.h b/TelepathyLoggerQt/utils.h new file mode 100644 index 0000000..91affe2 --- /dev/null +++ b/TelepathyLoggerQt/utils.h @@ -0,0 +1,64 @@ +/* + * This file is part of TelepathyLoggerQt + * + * Copyright (C) 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +#ifndef _TelepathyLoggerQt_utils_h_HEADER_GUARD_ +#define _TelepathyLoggerQt_utils_h_HEADER_GUARD_ + +#include +#include +#include +#include +#include + +#if __GNUC__ >= 2 +# define __func__ __PRETTY_FUNCTION__ +#elif __STDC_VERSION__ >= 199901L +# define __func__ __FUNCTION__ +#else +# define __func__ "" +#endif + +#define debug() qDebug() << "tp-qt-tpl DEBUG: " +#define debugfn() debug() << __func__ << " : " +#define warning() qWarning() << "tp-qt-tpl WARN: " +#define warningfn() qWarning() << "tp-qt-tpl WARN: " << __func__ << " : " + +namespace Tpl { + +class TELEPATHY_LOGGER_QT_EXPORT Utils { +public: + static Utils *instance(); + + void setAccountManagerPtr(const Tp::AccountManagerPtr & accountManager); + Tp::AccountManagerPtr accountManagerPtr(); + TpAccountManager *tpAccountManager(); + + Tp::AccountPtr accountPtr(TpAccount *account); + Tp::AccountPtr accountPtr(const QString &objectPath); + TpAccount *tpAccount(const Tp::AccountPtr & accountPtr); + +private: + Utils(); + ~Utils(); + + Tp::AccountManagerPtr mAccountManagerPtr; +}; + +}; + +#endif diff --git a/TelepathyLoggerQt4/CMakeLists.txt b/TelepathyLoggerQt4/CMakeLists.txt deleted file mode 100644 index 7320581..0000000 --- a/TelepathyLoggerQt4/CMakeLists.txt +++ /dev/null @@ -1,215 +0,0 @@ -file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/_gen") - -set(TelepathyLoggerQt4_CODEGEN_HEADERS - call-event.h - entity.h - event.h - log-manager.h - logger.h - text-event.h - types.h) - -set(TelepathyLoggerQt4_CODEGEN_INCLUDES - -Itelepathy-logger/call-event.h - -Itelepathy-logger/entity.h - -Itelepathy-logger/log-manager.h - -Itelepathy-logger/event.h - -Itelepathy-logger/text-event.h - -ITelepathyLoggerQt4/CallEvent - -ITelepathyLoggerQt4/Entity - -ITelepathyLoggerQt4/Event - -ITelepathyLoggerQt4/LogManager - -ITelepathyLoggerQt4/Logger - -ITelepathyLoggerQt4/TextEvent - -ITelepathyLoggerQt4/Types - -IQGlib/Quark) - -# Add command to generate gen.cpp using codegen -run_codegen("TelepathyLoggerQt4" "${TelepathyLoggerQt4_CODEGEN_INCLUDES}" "${TelepathyLoggerQt4_CODEGEN_HEADERS}") - -# Set the required flags found in TelepathyDefaults -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VISIBILITY_HIDDEN_FLAGS} ${COMPILER_COVERAGE_FLAGS} ${DEPRECATED_DECLARATIONS_FLAGS}") -set(LD_FLAGS "${LD_FLAGS} ${VISIBILITY_HIDDEN_FLAGS} ${COMPILER_COVERAGE_FLAGS} ${DEPRECATED_DECLARATIONS_FLAGS}") - -# We are building telepathy-logger-qt4 -add_definitions(-DBUILDING_TELEPATHY_LOGGER_QT4) -add_definitions (-DQT_NO_KEYWORDS) -add_definitions(-fPIC) - -# Sources for Tp-Logger-Qt4 -set(telepathy_logger_qt4_SRCS - call-event.cpp - entity.cpp - event.cpp - log-manager.cpp - logger.cpp - pending-dates.cpp - pending-entities.cpp - pending-events.cpp - pending-logger.cpp - pending-operation.cpp - pending-search.cpp - search-hit.cpp - text-event.cpp - utils.cpp - init.cpp - ${CMAKE_CURRENT_BINARY_DIR}/gen.cpp) - -# Exported headers for Tp-Logger-Qt4 -set(telepathy_logger_qt4_HEADERS - CallEvent - Entity - Event - Global - Init - Logger - LogManager - PendingDates - PendingEntities - PendingEvents - PendingOperation - PendingSearch - SearchHit - TextEvent - Types - call-event.h - entity.h - event.h - global.h - init.h - log-manager.h - logger.h - pending-dates.h - pending-entities.h - pending-events.h - pending-operation.h - pending-search.h - search-hit.h - text-event.h - types.h - ) - -# Headers file moc will be run on -set(telepathy_logger_qt4_MOC_SRCS - pending-dates.h - pending-entities.h - pending-events.h - pending-logger.h - pending-operation.h - pending-search.h - logger.h) - -# Generated headers which will be installed and exported -set(telepathy_logger_qt4_gen_HEADERS - ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-logger.h - ${CMAKE_CURRENT_BINARY_DIR}/_gen/constants.h - ${CMAKE_CURRENT_BINARY_DIR}/_gen/types.h) - -# The escape character in MSVC is ^ -if(MSVC) - set(TYPES_INCLUDE ^ ) - set(GLOBAL_INCLUDE ^ ) - set(LOGGER_EXTRA_INCLUDES '^' ) -else(MSVC) - set(TYPES_INCLUDE '' ) - set(GLOBAL_INCLUDE '' ) - set(LOGGER_EXTRA_INCLUDES '' ) -endif(MSVC) - -# Generate the spec files -set(gen_stable_spec_xml ${CMAKE_CURRENT_BINARY_DIR}/_gen/stable-spec.xml) - -tpqt4_xincludator(stable-ifaces-includator ${CMAKE_CURRENT_SOURCE_DIR}/stable-interfaces.xml ${gen_stable_spec_xml}) - -tpqt4_constants_gen(stable-constants ${gen_stable_spec_xml} ${CMAKE_CURRENT_BINARY_DIR}/_gen/constants.h - --namespace=Tpl - --define-prefix=TP_LOGGER_QT4_ - --must-define=IN_TELEPATHY_LOGGER_QT4_HEADER - DEPENDS stable-ifaces-includator) - -tpqt4_types_gen(stable-typesgen ${gen_stable_spec_xml} - ${CMAKE_CURRENT_BINARY_DIR}/_gen/types.h ${CMAKE_CURRENT_BINARY_DIR}/_gen/types-body.hpp - Tpl TelepathyLoggerQt4/types.h TelepathyLoggerQt4/Types - --must-define=IN_TELEPATHY_LOGGER_QT4_HEADER - --visibility=TELEPATHY_LOGGER_QT4_EXPORT - --extraincludes=${GLOBAL_INCLUDE} - DEPENDS stable-constants) - -# Add the generated types to the library's sources -list(APPEND telepathy_logger_qt4_SRCS ${CMAKE_CURRENT_BINARY_DIR}/_gen/types.h) -list(APPEND telepathy_logger_qt4_SRCS ${CMAKE_CURRENT_BINARY_DIR}/_gen/types-body.hpp) - -# For each spec, generate a cli file and add it to the sources (including mocs). -set(SPECS - logger) -foreach(spec ${SPECS}) - tpqt4_xincludator(${spec}-spec-xincludator ${CMAKE_CURRENT_SOURCE_DIR}/${spec}.xml ${CMAKE_CURRENT_BINARY_DIR}/_gen/spec-${spec}.xml DEPENDS stable-typesgen) - set(NEW_FILES - ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}-body.hpp - ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}.moc.hpp) - list(APPEND telepathy_logger_qt4_SRCS ${NEW_FILES}) - list(APPEND telepathy_logger_qt4_generated_specs_mocs "moc-cli-${spec}.moc.hpp") - set_source_files_properties(${NEW_FILES} PROPERTIES GENERATED true) -endforeach(spec ${SPECS}) - -#SET(telepathy_logger_qt4_generated_specs_mocs types.h) - -# Use the client generator for generating headers out of specs -tpqt4_client_generator(${gen_stable_spec_xml} logger clientlogger TelepathyLoggerQt4/logger.h TelepathyLoggerQt4/Logger Tpl Tpl IN_TELEPATHY_LOGGER_QT4_HEADER TELEPATHY_LOGGER_QT4_EXPORT DEPENDS logger-spec-xincludator ) - -# Create the library -add_library(telepathy-logger-qt4 ${telepathy_logger_qt4_SRCS}) - -# generate client moc files -foreach(moc_src ${telepathy_logger_qt4_MOC_SRCS}) - set(generated_file _gen/${moc_src}) - string(REPLACE ".h" ".moc.hpp" generated_file ${generated_file}) - tpqt4_generate_moc_i_target_deps(${CMAKE_CURRENT_SOURCE_DIR}/${moc_src} ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} - ${telepathy_logger_qt4_generated_specs_mocs}) - list(APPEND telepathy_logger_qt4_SRCS ${CMAKE_CURRENT_BINARY_DIR}/${generated_file}) - string(REPLACE ".h" ".moc.hpp" moc_src ${moc_src}) - add_dependencies(telepathy-logger-qt4 "moc-${moc_src}") -endforeach(moc_src ${telepathy_logger_qt4_MOC_SRCS}) - -# Link -target_link_libraries(telepathy-logger-qt4 - ${QT_QTCORE_LIBRARY} - ${GLIB2_LIBRARIES} - ${GOBJECT_LIBRARIES} - -lgio-2.0 - ${QT_QTDBUS_LIBRARY} - ${DBUS_LIBRARIES} - ${LIBXML2_LIBRARIES} - ${DBUS_GLIB_LIBRARIES} - ${TELEPATHY_GLIB_LIBRARIES} - ${TELEPATHY_LOGGER_LIBRARIES} - ${TELEPATHY_QT4_LIBRARIES} - ${QTGLIB_LIBRARIES}) - -if (ENABLE_COMPILER_COVERAGE) - target_link_libraries(telepathy-logger-qt4 gcov) -endif (ENABLE_COMPILER_COVERAGE) - -# Set the correct version number -set_target_properties(telepathy-logger-qt4 PROPERTIES - SOVERSION ${TP_LOGGER_QT4_ABI_VERSION} - VERSION ${TP_LOGGER_QT4_LIBRARY_VERSION}) - -# Install header files -install(FILES ${telepathy_logger_qt4_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/telepathy-logger-0.2/TelepathyLoggerQt4 COMPONENT headers) -install(FILES ${telepathy_logger_qt4_gen_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/telepathy-logger-0.2/TelepathyLoggerQt4/_gen COMPONENT headers) - -# Install the library - watch out for the correct components -if (WIN32) - install(TARGETS telepathy-logger-qt4 RUNTIME DESTINATION ${LIB_INSTALL_DIR} COMPONENT mainlibrary - ARCHIVE DESTINATION ${LIB_INSTALL_DIR} COMPONENT headers) -else (WIN32) - install(TARGETS telepathy-logger-qt4 LIBRARY DESTINATION ${LIB_INSTALL_DIR} COMPONENT mainlibrary - ARCHIVE DESTINATION ${LIB_INSTALL_DIR} COMPONENT headers) -endif (WIN32) - -# pkg-config file -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/TelepathyLoggerQt4.pc.in ${CMAKE_CURRENT_BINARY_DIR}/TelepathyLoggerQt4.pc) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/TelepathyLoggerQt4-uninstalled.pc.in ${CMAKE_CURRENT_BINARY_DIR}/TelepathyLoggerQt4-uninstalled.pc) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/TelepathyLoggerQt4.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig COMPONENT headers) - diff --git a/TelepathyLoggerQt4/CallEvent b/TelepathyLoggerQt4/CallEvent deleted file mode 100644 index 7f19b4c..0000000 --- a/TelepathyLoggerQt4/CallEvent +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _TelepathyLoggerQt4_CallEvent_HEADER_GUARD_ -#define _TelepathyLoggerQt4_CallEvent_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#define IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include - -#undef IN_TELEPATHY_LOGGER_QT4_HEADER - -#endif diff --git a/TelepathyLoggerQt4/Entity b/TelepathyLoggerQt4/Entity deleted file mode 100644 index 458bfda..0000000 --- a/TelepathyLoggerQt4/Entity +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _TelepathyLoggerQt4_Entity_HEADER_GUARD_ -#define _TelepathyLoggerQt4_Entity_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#define IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include - -#undef IN_TELEPATHY_LOGGER_QT4_HEADER - -#endif diff --git a/TelepathyLoggerQt4/Event b/TelepathyLoggerQt4/Event deleted file mode 100644 index bcb82a2..0000000 --- a/TelepathyLoggerQt4/Event +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _TelepathyLoggerQt4_Event_HEADER_GUARD_ -#define _TelepathyLoggerQt4_Event_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#define IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include - -#undef IN_TELEPATHY_LOGGER_QT4_HEADER - -#endif diff --git a/TelepathyLoggerQt4/Global b/TelepathyLoggerQt4/Global deleted file mode 100644 index 10e22ef..0000000 --- a/TelepathyLoggerQt4/Global +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _TelepathyLoggerQt4_Global_HEADER_GUARD_ -#define _TelepathyLoggerQt4_Global_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#define IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include - -#undef IN_TELEPATHY_LOGGER_QT4_HEADER - -#endif diff --git a/TelepathyLoggerQt4/Init b/TelepathyLoggerQt4/Init deleted file mode 100644 index 79afb0c..0000000 --- a/TelepathyLoggerQt4/Init +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _TelepathyLoggerQt4_Init_HEADER_GUARD_ -#define _TelepathyLoggerQt4_Init_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#define IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include - -#undef IN_TELEPATHY_LOGGER_QT4_HEADER - -#endif diff --git a/TelepathyLoggerQt4/LogManager b/TelepathyLoggerQt4/LogManager deleted file mode 100644 index d7aa536..0000000 --- a/TelepathyLoggerQt4/LogManager +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _TelepathyLoggerQt4_LogManager_HEADER_GUARD_ -#define _TelepathyLoggerQt4_LogManager_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#define IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include - -#undef IN_TELEPATHY_LOGGER_QT4_HEADER - -#endif diff --git a/TelepathyLoggerQt4/Logger b/TelepathyLoggerQt4/Logger deleted file mode 100644 index c3f4164..0000000 --- a/TelepathyLoggerQt4/Logger +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2010 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef _TelepathyLoggerQt4_Logger_HEADER_GUARD_ -#define _TelepathyLoggerQt4_Logger_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#define IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include - -#undef IN_TELEPATHY_LOGGER_QT4_HEADER - -#endif diff --git a/TelepathyLoggerQt4/PendingDates b/TelepathyLoggerQt4/PendingDates deleted file mode 100644 index 666dd0d..0000000 --- a/TelepathyLoggerQt4/PendingDates +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _TelepathyLoggerQt4_PendingDates_HEADER_GUARD_ -#define _TelepathyLoggerQt4_PendingDates_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#define IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include - -#undef IN_TELEPATHY_LOGGER_QT4_HEADER - -#endif diff --git a/TelepathyLoggerQt4/PendingEntities b/TelepathyLoggerQt4/PendingEntities deleted file mode 100644 index 1508bdd..0000000 --- a/TelepathyLoggerQt4/PendingEntities +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _TelepathyLoggerQt4_PendingEntities_HEADER_GUARD_ -#define _TelepathyLoggerQt4_PendingEntities_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#define IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include - -#undef IN_TELEPATHY_LOGGER_QT4_HEADER - -#endif diff --git a/TelepathyLoggerQt4/PendingEvents b/TelepathyLoggerQt4/PendingEvents deleted file mode 100644 index 8d0e3e6..0000000 --- a/TelepathyLoggerQt4/PendingEvents +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _TelepathyLoggerQt4_PendingEvents_HEADER_GUARD_ -#define _TelepathyLoggerQt4_PendingEvents_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#define IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include - -#undef IN_TELEPATHY_LOGGER_QT4_HEADER - -#endif diff --git a/TelepathyLoggerQt4/PendingOperation b/TelepathyLoggerQt4/PendingOperation deleted file mode 100644 index 3df44f6..0000000 --- a/TelepathyLoggerQt4/PendingOperation +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _TelepathyLoggerQt4_PendingOperation_HEADER_GUARD_ -#define _TelepathyLoggerQt4_PendingOperation_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#define IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include - -#undef IN_TELEPATHY_LOGGER_QT4_HEADER - -#endif diff --git a/TelepathyLoggerQt4/PendingSearch b/TelepathyLoggerQt4/PendingSearch deleted file mode 100644 index 00b8db1..0000000 --- a/TelepathyLoggerQt4/PendingSearch +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _TelepathyLoggerQt4_PendingSearch_HEADER_GUARD_ -#define _TelepathyLoggerQt4_PendingSearch_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#define IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include - -#undef IN_TELEPATHY_LOGGER_QT4_HEADER - -#endif diff --git a/TelepathyLoggerQt4/SearchHit b/TelepathyLoggerQt4/SearchHit deleted file mode 100644 index 45a5a83..0000000 --- a/TelepathyLoggerQt4/SearchHit +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _TelepathyLoggerQt4_SearchHit_HEADER_GUARD_ -#define _TelepathyLoggerQt4_SearchHit_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#define IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include - -#undef IN_TELEPATHY_LOGGER_QT4_HEADER - -#endif diff --git a/TelepathyLoggerQt4/TelepathyLoggerQt4-uninstalled.pc.in b/TelepathyLoggerQt4/TelepathyLoggerQt4-uninstalled.pc.in deleted file mode 100644 index 575607d..0000000 --- a/TelepathyLoggerQt4/TelepathyLoggerQt4-uninstalled.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=/nonexistent -exec_prefix=/nonexistent -abs_top_builddir=${CMAKE_BINARY_DIR} -abs_top_srcdir=${CMAKE_SOURCE_DIR} - -Name: Telepathy-Logger-Qt4 (uninstalled copy) -Description: Qt4 utility library to access logs in the Telepathy framework -Version: ${PACKAGE_VERSION} -Requires.private: QtCore >= 4.5, TelepathyQt4 >= 0.5 -Libs: ${CMAKE_BINARY_DIR}/TelepathyQt/libtelepathy-logger-qt4.a -Cflags: -I${CMAKE_SOURCE_DIR} -I${CMAKE_BINARY_DIR} diff --git a/TelepathyLoggerQt4/TelepathyLoggerQt4.pc.in b/TelepathyLoggerQt4/TelepathyLoggerQt4.pc.in deleted file mode 100644 index 508fe25..0000000 --- a/TelepathyLoggerQt4/TelepathyLoggerQt4.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=${CMAKE_INSTALL_PREFIX} -exec_prefix=${CMAKE_INSTALL_PREFIX} -libdir=${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR} -includedir=${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR} - -Name: Telepathy-Logger-Qt4 -Description: Qt4 utility library to access logs in the Telepathy framework -Version: ${PACKAGE_VERSION} -Requires.private: QtCore >= 4.5, TelepathyQt4 >= 0.5 -Libs: -L${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR} -ltelepathy-logger-qt4 -Cflags: -I${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR}/telepathy-logger-0.2 diff --git a/TelepathyLoggerQt4/TextEvent b/TelepathyLoggerQt4/TextEvent deleted file mode 100644 index 83754d2..0000000 --- a/TelepathyLoggerQt4/TextEvent +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _TelepathyLoggerQt4_TextEvent_HEADER_GUARD_ -#define _TelepathyLoggerQt4_TextEvent_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#define IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include - -#undef IN_TELEPATHY_LOGGER_QT4_HEADER - -#endif diff --git a/TelepathyLoggerQt4/Types b/TelepathyLoggerQt4/Types deleted file mode 100644 index 4fe0a0a..0000000 --- a/TelepathyLoggerQt4/Types +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _TelepathyLoggerQt4_Types_HEADER_GUARD_ -#define _TelepathyLoggerQt4_Types_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#define IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include - -#undef IN_TELEPATHY_LOGGER_QT4_HEADER - -#endif diff --git a/TelepathyLoggerQt4/call-event.cpp b/TelepathyLoggerQt4/call-event.cpp deleted file mode 100644 index 1addd02..0000000 --- a/TelepathyLoggerQt4/call-event.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#include - -#include -#include - -using namespace Tpl; - -QTime CallEvent::duration() const -{ - GTimeSpan timeSpan = tpl_call_event_get_duration(object()); - int hh = timeSpan / 3600; - timeSpan = timeSpan % 3600; - int mm = timeSpan / 60; - int ss = timeSpan % 60; - int ms = 0; - // FIXME there is no timespan type in Qt yet, use QTime in the meanwhile - QTime ret(hh,mm,ss,ms); - return ret; -} - -EntityPtr CallEvent::endActor() const -{ - TplEntity * entity = tpl_call_event_get_end_actor(object()); - return EntityPtr::wrap(entity, true); -} - -Tp::CallStateChangeReason CallEvent::endReason() const -{ - Tp::CallStateChangeReason er = (Tp::CallStateChangeReason) tpl_call_event_get_end_reason(object()); - return er; -} - -QString CallEvent::detailedEndReason() const -{ - const gchar *s = tpl_call_event_get_detailed_end_reason(object()); - QString str = QString::fromUtf8(s); - return str; -} diff --git a/TelepathyLoggerQt4/call-event.h b/TelepathyLoggerQt4/call-event.h deleted file mode 100644 index 7135717..0000000 --- a/TelepathyLoggerQt4/call-event.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ -#ifndef _TelepathyLoggerQt4_call_event_h_HEADER_GUARD_ -#define _TelepathyLoggerQt4_call_event_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#error IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include -#include - -namespace Tpl -{ - -/*! \headerfile call-event.h - * \brief Wrapper class for TplCallEvent - */ -class TELEPATHY_LOGGER_QT4_EXPORT CallEvent : public Event -{ - QTELEPATHYLOGGERQT4_WRAPPER(CallEvent) -public: - QTime duration() const; - EntityPtr endActor() const; - Tp::CallStateChangeReason endReason() const; - QString detailedEndReason() const; -}; - -} //namespace - -QTELEPATHYLOGGERQT4_REGISTER_TYPE(Tpl::CallEvent) - -#endif diff --git a/TelepathyLoggerQt4/entity.cpp b/TelepathyLoggerQt4/entity.cpp deleted file mode 100644 index 9ddb516..0000000 --- a/TelepathyLoggerQt4/entity.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Stefano Sanfilippo - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#include - -#include -#include -#include - -using namespace Tpl; - -EntityPtr Entity::create(const char *id, EntityType type, const char *alias, const char *avatarToken) -{ - TplEntity *entity = tpl_entity_new(id, (TplEntityType) type, alias, avatarToken); - return EntityPtr::wrap(entity, false); -} - -EntityPtr Entity::create(const Tp::ContactPtr & contact, EntityType type) -{ -#if 0 - // TODO how to go from Tp::ContactPtr to TpContact ? - //TplEntity *entity = tpl_entity_new_from_tp_contact(0, (TplEntityType) type); - return EntityPtr::wrap(entity, false); -#else - QString id = contact->id(); - QString alias = contact->alias(); - QString avatarToken = contact->avatarToken(); - return Entity::create(id.toUtf8(), type, alias.toUtf8(), avatarToken.toUtf8()); -#endif -} - -EntityPtr Entity::create(const char *room_id) -{ - TplEntity *entity = tpl_entity_new_from_room_id(room_id); - return EntityPtr::wrap(entity, false); -} - -QString Entity::alias() const -{ - const gchar *s = tpl_entity_get_alias(object()); - QString str = QString::fromUtf8(s); - return str; -} - -QString Entity::identifier() const -{ - const gchar *s = tpl_entity_get_identifier(object()); - QString str = QString::fromUtf8(s); - return str; -} - -EntityType Entity::entityType() const -{ - TplEntityType entityType = tpl_entity_get_entity_type(object()); - return EntityType(entityType); -} - -QString Entity::avatarToken() const -{ - const gchar *s = tpl_entity_get_avatar_token(object()); - QString str = QString::fromUtf8(s); - return str; -} diff --git a/TelepathyLoggerQt4/entity.h b/TelepathyLoggerQt4/entity.h deleted file mode 100644 index d39c343..0000000 --- a/TelepathyLoggerQt4/entity.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Stefano Sanfilippo - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ -#ifndef _TelepathyLoggerQt4_entity_h_HEADER_GUARD_ -#define _TelepathyLoggerQt4_entity_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#error IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include -#include - -namespace Tpl -{ - -/*! \headerfile entity.h - * \brief Wrapper class for TplEntity - */ -class TELEPATHY_LOGGER_QT4_EXPORT Entity : public QGlib::Object -{ - QTELEPATHYLOGGERQT4_WRAPPER(Entity) -public: - static EntityPtr create(const char *id, EntityType type, const char *alias, const char *avatarToken); - static EntityPtr create(const Tp::ContactPtr & contact, EntityType type); - static EntityPtr create(const char *room_id); - - QString alias() const; - QString identifier() const; - EntityType entityType() const; - QString avatarToken() const; -}; - -} //namespace - -QTELEPATHYLOGGERQT4_REGISTER_TYPE(Tpl::Entity) - -#endif diff --git a/TelepathyLoggerQt4/event.cpp b/TelepathyLoggerQt4/event.cpp deleted file mode 100644 index c29d0fc..0000000 --- a/TelepathyLoggerQt4/event.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Stefano Sanfilippo - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#include - -#include -#include -#include -#include - -using namespace Tpl; - -QDateTime Event::timestamp() const -{ - // FIXME See http://bugs.freedesktop.org/show_bug.cgi?id=21690 - uint seconds = (uint) tpl_event_get_timestamp(object()); - QDateTime dateTime; - dateTime.setTime_t(seconds); - return dateTime; -} - -QString Event::accountPath() const -{ - const gchar *s = tpl_event_get_account_path(object()); - QString str = QString::fromUtf8(s); - return str; -} - -Tp::AccountPtr Event::account() const -{ - TpAccount *account = tpl_event_get_account(object()); - return Utils::instance()->accountPtr(account); -} - -EntityPtr Event::sender() const -{ - TplEntity *entity = tpl_event_get_sender(object()); - return EntityPtr::wrap(entity, true); -} - -EntityPtr Event::receiver() const -{ - TplEntity *entity = tpl_event_get_receiver(object()); - return EntityPtr::wrap(entity, true); -} - -bool Event::equalTo(const EventPtr & rhs) const -{ - return tpl_event_equal (object(), rhs->object()); -} diff --git a/TelepathyLoggerQt4/event.h b/TelepathyLoggerQt4/event.h deleted file mode 100644 index c028753..0000000 --- a/TelepathyLoggerQt4/event.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Stefano Sanfilippo - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ -#ifndef _TelepathyLoggerQt4_event_h_HEADER_GUARD_ -#define _TelepathyLoggerQt4_event_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#error IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include -#include - -namespace Tpl -{ - -/*! \headerfile event.h - * \brief Wrapper class for TplEvent - */ -class TELEPATHY_LOGGER_QT4_EXPORT Event : public QGlib::Object -{ - QTELEPATHYLOGGERQT4_WRAPPER(Event) -public: - QDateTime timestamp() const; - QString accountPath() const; - Tp::AccountPtr account() const; - EntityPtr sender() const; - EntityPtr receiver() const; - bool equalTo(const EventPtr & rhs) const; -}; - -} //namespace - -QTELEPATHYLOGGERQT4_REGISTER_TYPE(Tpl::Event) - -#endif diff --git a/TelepathyLoggerQt4/global.h b/TelepathyLoggerQt4/global.h deleted file mode 100644 index 86436b5..0000000 --- a/TelepathyLoggerQt4/global.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ -#ifndef _TelepathyLoggerQt4_global_h_HEADER_GUARD_ -#define _TelepathyLoggerQt4_global_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#error IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include - -/* defined by cmake when building this library */ -#if defined(BUILDING_TELEPATHY_LOGGER_QT4) -# define TELEPATHY_LOGGER_QT4_EXPORT Q_DECL_EXPORT -#else -# define TELEPATHY_LOGGER_QT4_EXPORT Q_DECL_IMPORT -#endif - -#if !defined(Q_OS_WIN) && !defined(Q_CC_NOKIAX86) && \ - !defined(Q_CC_RVCT) && defined(QT_VISIBILITY_AVAILABLE) -# define TELEPATHY_LOGGER_QT4_NO_EXPORT __attribute__((visibility("hidden"))) -#else -# define TELEPATHY_LOGGER_QT4_NO_EXPORT -#endif - -#define QTELEPATHYLOGGERQT4_REGISTER_TYPE(T) \ - QGLIB_REGISTER_TYPE_WITH_EXPORT_MACRO(T, TELEPATHY_LOGGER_QT4_EXPORT) - - -#define QTELEPATHYLOGGERQT4_WRAPPER_TPLCLASS_DECLARATION(Class) \ - typedef struct _Tpl##Class Tpl##Class; - -#define QTELEPATHYLOGGERQT4_WRAPPER_REFPOINTER_DECLARATION(Class) \ - namespace Tpl { \ - class Class; \ - typedef QGlib::RefPointer Class##Ptr; \ - } - -#define QTELEPATHYLOGGERQT4_WRAPPER_DECLARATION(Class) \ - QTELEPATHYLOGGERQT4_WRAPPER_TPLCLASS_DECLARATION(Class) \ - QTELEPATHYLOGGERQT4_WRAPPER_REFPOINTER_DECLARATION(Class) - -QTELEPATHYLOGGERQT4_WRAPPER_DECLARATION(CallEvent) -QTELEPATHYLOGGERQT4_WRAPPER_DECLARATION(Entity) -QTELEPATHYLOGGERQT4_WRAPPER_DECLARATION(Event) -QTELEPATHYLOGGERQT4_WRAPPER_DECLARATION(TextEvent) -QTELEPATHYLOGGERQT4_WRAPPER_DECLARATION(LogManager) - -#undef QTELEPATHYLOGGERQT4_WRAPPER_DECLARATION -#undef QTELEPATHYLOGGERQT4_WRAPPER_REFPOINTER_DECLARATION -#undef QTELEPATHYLOGGERQT4_WRAPPER_TPLCLASS_DECLARATION - - -#define QTELEPATHYLOGGERQT4_WRAPPER(Class) \ - QGLIB_WRAPPER_DECLARATION_MACRO(Class, Class, Tpl, Class) - - -#endif diff --git a/TelepathyLoggerQt4/init.cpp b/TelepathyLoggerQt4/init.cpp deleted file mode 100644 index fbd17f6..0000000 --- a/TelepathyLoggerQt4/init.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include -#include - -namespace Tpl { - -namespace Private { - void registerWrapperConstructors(); //generated by codegen -} - -void init() -{ - QGlib::init(); - Private::registerWrapperConstructors(); -} - -}; diff --git a/TelepathyLoggerQt4/init.h b/TelepathyLoggerQt4/init.h deleted file mode 100644 index a6d7c77..0000000 --- a/TelepathyLoggerQt4/init.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ -#ifndef _TelepathyLoggerQt4_init_h_HEADER_GUARD_ -#define _TelepathyLoggerQt4_init_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#error IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include - -namespace Tpl -{ - -/*! \headerfile init.h - * \brief Initialization of the telepathy logger qt4 bindings - */ - -TELEPATHY_LOGGER_QT4_EXPORT void init(); - -} //namespace - -#endif diff --git a/TelepathyLoggerQt4/log-manager.cpp b/TelepathyLoggerQt4/log-manager.cpp deleted file mode 100644 index e6acf40..0000000 --- a/TelepathyLoggerQt4/log-manager.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Stefano Sanfilippo - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace Tpl; - -LogManagerPtr LogManager::instance() -{ - TplLogManager *manager = tpl_log_manager_dup_singleton(); - return LogManagerPtr::wrap(manager, false); -} - -Tp::AccountManagerPtr LogManager::accountManagerPtr() const -{ - return Utils::instance()->accountManagerPtr(); -} - -void LogManager::setAccountManagerPtr(const Tp::AccountManagerPtr & accountManager) -{ - Utils::instance()->setAccountManagerPtr(accountManager); -} - -bool LogManager::exists(const Tp::AccountPtr & account, const EntityPtr & target, - EventTypeMask type) const -{ - TpAccount *tpAccount = Utils::instance()->tpAccount(account); - return tpl_log_manager_exists(object(), tpAccount, target, (gint) type); -} - -PendingDates *LogManager::queryDates(const Tp::AccountPtr & account, const EntityPtr & entity, - EventTypeMask typeMask) -{ - return new PendingDates(LogManagerPtr(this), account, entity, typeMask); -} - -PendingEvents *LogManager::queryEvents(const Tp::AccountPtr & account, const EntityPtr & entity, - EventTypeMask typeMask, const QDate & date) -{ - return new PendingEvents(LogManagerPtr(this), account, entity, typeMask, date); -} - -PendingEvents *LogManager::queryFilteredEvents(const Tp::AccountPtr & account, - const EntityPtr & entity, EventTypeMask typeMask, uint numEvents, - LogEventFilter filterFunction, void *filterFunctionUserData) -{ - return new PendingEvents(LogManagerPtr(this), account, entity, typeMask, numEvents, - filterFunction, filterFunctionUserData); -} - -PendingEntities *LogManager::queryEntities(const Tp::AccountPtr & account) -{ - return new PendingEntities(LogManagerPtr(this), account); -} - -PendingSearch *LogManager::search(const QString &text, EventTypeMask typeMask) -{ - return new PendingSearch(LogManagerPtr(this), text, typeMask); -} diff --git a/TelepathyLoggerQt4/log-manager.h b/TelepathyLoggerQt4/log-manager.h deleted file mode 100644 index c245965..0000000 --- a/TelepathyLoggerQt4/log-manager.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Stefano Sanfilippo - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ -#ifndef _TelepathyLoggerQt4_log_manager_h_HEADER_GUARD_ -#define _TelepathyLoggerQt4_log_manager_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#error IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include -#include - -namespace Tpl -{ - -/*! \headerfile log-manager.h - * \brief Wrapper class for TplLogManager - */ -class TELEPATHY_LOGGER_QT4_EXPORT LogManager : public QGlib::Object -{ - QTELEPATHYLOGGERQT4_WRAPPER(LogManager) -public: - static LogManagerPtr instance(); - - Tp::AccountManagerPtr accountManagerPtr() const; - void setAccountManagerPtr(const Tp::AccountManagerPtr & accountManager); - - bool exists(const Tp::AccountPtr & account, const EntityPtr & target, EventTypeMask type) const; - - PendingDates *queryDates(const Tp::AccountPtr & account, const EntityPtr & entity, - EventTypeMask typeMask); - PendingEvents *queryEvents(const Tp::AccountPtr & account, const EntityPtr & entity, - EventTypeMask typeMask, const QDate & date); - PendingEvents *queryFilteredEvents(const Tp::AccountPtr & account, const EntityPtr & entity, - EventTypeMask typeMask, uint numEvents, LogEventFilter filterFunction, - void *filterFunctionUserData); - PendingEntities *queryEntities(const Tp::AccountPtr & account); - PendingSearch *search(const QString &text, EventTypeMask typeMask); -}; - -} //namespace - -QTELEPATHYLOGGERQT4_REGISTER_TYPE(Tpl::LogManager) - -#endif diff --git a/TelepathyLoggerQt4/logger.cpp b/TelepathyLoggerQt4/logger.cpp deleted file mode 100644 index c1954d8..0000000 --- a/TelepathyLoggerQt4/logger.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#include - -#include -#include -#include -#include - -#include -#include - -#define TPL_DBUS_SRV_WELL_KNOWN_BUS_NAME "org.freedesktop.Telepathy.Logger" -#define TPL_DBUS_SRV_OBJECT_PATH "/org/freedesktop/Telepathy/Logger" - -namespace Tpl { - -struct TELEPATHY_LOGGER_QT4_NO_EXPORT Logger::Private -{ - Private(Logger *self); - - Tpl::LoggerInterface *mInterface; - LoggerPtr mPtr; -}; - -Logger::Private::Private(Logger *self) -{ - mInterface = new Tpl::LoggerInterface(QDBusConnection::sessionBus(), - TPL_DBUS_SRV_WELL_KNOWN_BUS_NAME, - TPL_DBUS_SRV_OBJECT_PATH); - mPtr = LoggerPtr(self); -} - -LoggerPtr Logger::create() -{ - return LoggerPtr(new Logger()); -} - -Logger::Logger() : - Tp::StatelessDBusProxy(QDBusConnection::sessionBus(), - QLatin1String(TPL_DBUS_SRV_WELL_KNOWN_BUS_NAME), - QLatin1String(TPL_DBUS_SRV_OBJECT_PATH), - Tp::Feature()), - mPriv(new Private(this)) -{ -} - -Logger::~Logger() -{ - delete mPriv; -} - -Tp::PendingOperation *Logger::clearLog() const -{ - PendingLogger *operation = new PendingLogger(mPriv->mPtr, mPriv->mInterface); - operation->clearLog(); - return operation; -} - -Tp::PendingOperation *Logger::clearAccount(const Tp::AccountPtr &account) const -{ - PendingLogger *operation = new PendingLogger(mPriv->mPtr, mPriv->mInterface); - operation->clearAccount(account); - return operation; -} - -Tp::PendingOperation *Logger::clearContact(const Tp::AccountPtr &account, const QString &objectId) const -{ - PendingLogger *operation = new PendingLogger(mPriv->mPtr, mPriv->mInterface); - operation->clearContact(account, objectId); - return operation; -} - -Tp::PendingOperation *Logger::clearRoom(const Tp::AccountPtr &account, const QString &objectId) const -{ - PendingLogger *operation = new PendingLogger(mPriv->mPtr, mPriv->mInterface); - operation->clearRoom(account, objectId); - return operation; -} - -} diff --git a/TelepathyLoggerQt4/logger.h b/TelepathyLoggerQt4/logger.h deleted file mode 100644 index bf12cb1..0000000 --- a/TelepathyLoggerQt4/logger.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2010 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef _TelepathyLoggerQt4_logger_h_HEADER_GUARD_ -#define _TelepathyLoggerQt4_logger_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#error IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include -#include -#include -#include - -namespace Tpl -{ - -class Logger; - -class TELEPATHY_LOGGER_QT4_EXPORT Logger : public Tp::StatelessDBusProxy -{ - Q_OBJECT - -public: - static LoggerPtr create(); - - ~Logger(); - - Tp::PendingOperation *clearLog() const; - Tp::PendingOperation *clearAccount(const Tp::AccountPtr &account) const; - Tp::PendingOperation *clearContact(const Tp::AccountPtr &account, const QString &objectId) const; - Tp::PendingOperation *clearRoom(const Tp::AccountPtr &account, const QString &objectId) const; - -private: - Logger(); - struct Private; - friend struct Private; - Private *mPriv; -}; - -} - -#endif diff --git a/TelepathyLoggerQt4/logger.xml b/TelepathyLoggerQt4/logger.xml deleted file mode 100644 index 3188cb3..0000000 --- a/TelepathyLoggerQt4/logger.xml +++ /dev/null @@ -1,12 +0,0 @@ - - -Logger interfaces - - - - - - - diff --git a/TelepathyLoggerQt4/pending-dates.cpp b/TelepathyLoggerQt4/pending-dates.cpp deleted file mode 100644 index 089b7c2..0000000 --- a/TelepathyLoggerQt4/pending-dates.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace Tpl; - -struct TELEPATHY_LOGGER_QT4_NO_EXPORT PendingDates::Private -{ - LogManagerPtr manager; - Tp::AccountPtr account; - TpAccount *tpAccount; - EntityPtr entity; - EventTypeMask typeMask; - QDateList dates; - - static void onAccountPrepared(void *logManager, void *result, PendingDates *self); - static void callback(void *logManager, void *result, PendingDates *self); -}; - -PendingDates::PendingDates(const LogManagerPtr & manager, const Tp::AccountPtr & account, - const EntityPtr & entity, EventTypeMask typeMask) - : PendingOperation(), - mPriv(new Private()) -{ - mPriv->manager = manager; - mPriv->account = account; - mPriv->tpAccount = 0; - mPriv->entity = entity; - mPriv->typeMask = typeMask; -} - -PendingDates::~PendingDates() -{ - delete mPriv; -} - -void PendingDates::start() -{ - mPriv->tpAccount = Utils::instance()->tpAccount(mPriv->account); - if (!mPriv->tpAccount) { - setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid account"); - return; - } - - GQuark features[] = { TP_ACCOUNT_FEATURE_CORE, 0 }; - tp_account_prepare_async(mPriv->tpAccount, features, (GAsyncReadyCallback) Private::onAccountPrepared, this); -} - -void PendingDates::Private::onAccountPrepared(void *logManager, void *result, PendingDates *self) -{ - tpl_log_manager_get_dates_async(self->mPriv->manager, - self->mPriv->tpAccount, - self->mPriv->entity, - self->mPriv->typeMask, - (GAsyncReadyCallback) Private::callback, - self); -} - -QDateList PendingDates::dates() const -{ - if (!isFinished()) { - qWarning() << "PendingDates::dates called before finished, returning empty"; - return QDateList(); - } else if (!isValid()) { - qWarning() << "PendingDates::dates called when not valid, returning empty"; - return QDateList(); - } - - return mPriv->dates; -} - -const Tp::AccountPtr PendingDates::account() const -{ - if (!isFinished()) { - qWarning() << "PendingDates::account called before finished"; - } else if (!isValid()) { - qWarning() << "PendingDates::account called when not valid"; - } - - return mPriv->account; -} - -const EntityPtr PendingDates::entity() const -{ - if (!isFinished()) { - qWarning() << "PendingDates::entity called before finished"; - } else if (!isValid()) { - qWarning() << "PendingDates::entity called when not valid"; - } - - return mPriv->entity; -} - - -void PendingDates::Private::callback(void *logManager, void *result, PendingDates *self) -{ - if (!TPL_IS_LOG_MANAGER(logManager)) { - self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid log manager in callback"); - return; - } - - if (!G_IS_ASYNC_RESULT(result)) { - self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid async result in callback"); - return; - } - - GList *dates = NULL; - GError *error = NULL; - gboolean success = tpl_log_manager_get_dates_finish(TPL_LOG_MANAGER(logManager), G_ASYNC_RESULT(result), &dates, &error); - if (error) { - self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, error->message); - g_error_free(error); - return; - } - - if (!success) { - self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Query failed without specific error"); - return; - } - - GList *i; - for (i = dates; i; i = i->next) { - GDate * item = (GDate *) i->data; - self->mPriv->dates << QDate(item->year, item->month, item->day); - } - - g_list_foreach(dates, (GFunc) g_date_free, NULL); - g_list_free(dates); - - self->setFinished(); -} diff --git a/TelepathyLoggerQt4/pending-dates.h b/TelepathyLoggerQt4/pending-dates.h deleted file mode 100644 index 6f2bd11..0000000 --- a/TelepathyLoggerQt4/pending-dates.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Stefano Sanfilippo - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -#ifndef _TelepathyLoggerQt4_pending_dates_h_HEADER_GUARD_ -#define _TelepathyLoggerQt4_pending_dates_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#error IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include -#include - -namespace Tpl -{ - -class TELEPATHY_LOGGER_QT4_EXPORT PendingDates : public Tpl::PendingOperation -{ - Q_OBJECT - Q_DISABLE_COPY(PendingDates); - -public: - ~PendingDates(); - - QDateList dates() const; - const Tp::AccountPtr account() const; - const Tpl::EntityPtr entity() const; - -private Q_SLOTS: - virtual void start(); - -private: - friend class LogManager; - - PendingDates(const LogManagerPtr & manager, const Tp::AccountPtr & account, - const EntityPtr & entity, EventTypeMask typeMask); - - struct Private; - friend struct Private; - Private *mPriv; -}; - -} // Tpl - -#endif diff --git a/TelepathyLoggerQt4/pending-entities.cpp b/TelepathyLoggerQt4/pending-entities.cpp deleted file mode 100644 index 9a2a735..0000000 --- a/TelepathyLoggerQt4/pending-entities.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * Copyright (C) 2012 David Edmundson - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace Tpl; - -struct TELEPATHY_LOGGER_QT4_NO_EXPORT PendingEntities::Private -{ - LogManagerPtr manager; - Tp::AccountPtr account; - TpAccount *tpAccount; - EntityPtrList entities; - - static void onAccountPrepared(void *logManager, void *result, PendingEntities *self); - static void callback(void *logManager, void *result, PendingEntities *self); -}; - -PendingEntities::PendingEntities(const LogManagerPtr & manager, const Tp::AccountPtr & account) - : PendingOperation(), - mPriv(new Private()) -{ - mPriv->manager = manager; - mPriv->account = account; - mPriv->tpAccount = 0; -} - -PendingEntities::~PendingEntities() -{ - delete mPriv; -} - -void PendingEntities::start() -{ - mPriv->tpAccount = Utils::instance()->tpAccount(mPriv->account); - if (!mPriv->tpAccount) { - setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid account"); - return; - } - - GQuark features[] = { TP_ACCOUNT_FEATURE_CORE, 0 }; - tp_account_prepare_async(mPriv->tpAccount, features, (GAsyncReadyCallback) Private::onAccountPrepared, this); -} - -void PendingEntities::Private::onAccountPrepared(void *logManager, void *result, PendingEntities *self) -{ - tpl_log_manager_get_entities_async(self->mPriv->manager, - self->mPriv->tpAccount, - (GAsyncReadyCallback) Private::callback, - self); -} - -EntityPtrList PendingEntities::entities() const -{ - if (!isFinished()) { - qWarning() << "PendingEntities::entities called before finished, returning empty"; - return EntityPtrList(); - } else if (!isValid()) { - qWarning() << "PendingEntities::entities called when not valid, returning empty"; - return EntityPtrList(); - } - - return mPriv->entities; -} - -Tp::AccountPtr PendingEntities::account() const -{ - return mPriv->account; -} - - -void PendingEntities::Private::callback(void *logManager, void *result, PendingEntities *self) -{ - if (!TPL_IS_LOG_MANAGER(logManager)) { - self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid log manager in callback"); - return; - } - - if (!G_IS_ASYNC_RESULT(result)) { - self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid async result in callback"); - return; - } - - GList *entities = NULL; - GError *error = NULL; - gboolean success = tpl_log_manager_get_entities_finish(TPL_LOG_MANAGER(logManager), G_ASYNC_RESULT(result), &entities, &error); - if (error) { - self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, error->message); - g_error_free(error); - return; - } - - if (!success) { - self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Query failed without specific error"); - return; - } - - GList *i; - for (i = entities; i; i = i->next) { - TplEntity * item = (TplEntity *) i->data; - self->mPriv->entities << EntityPtr::wrap(item, true); - } - - g_list_foreach(entities, (GFunc) g_object_unref, NULL); - g_list_free(entities); - - self->setFinished(); -} diff --git a/TelepathyLoggerQt4/pending-entities.h b/TelepathyLoggerQt4/pending-entities.h deleted file mode 100644 index e2a20bf..0000000 --- a/TelepathyLoggerQt4/pending-entities.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * Copyright (C) 2012 David Edmundson - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -#ifndef _TelepathyLoggerQt4_pending_entities_h_HEADER_GUARD_ -#define _TelepathyLoggerQt4_pending_entities_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#error IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include -#include - -namespace Tpl -{ - -class TELEPATHY_LOGGER_QT4_EXPORT PendingEntities: public Tpl::PendingOperation -{ - Q_OBJECT - Q_DISABLE_COPY(PendingEntities); - -public: - ~PendingEntities(); - - EntityPtrList entities() const; - Tp::AccountPtr account() const; - -private Q_SLOTS: - virtual void start(); - -private: - friend class LogManager; - - PendingEntities(const LogManagerPtr & manager, const Tp::AccountPtr & account); - - struct Private; - friend struct Private; - Private *mPriv; -}; - -} // Tpl - -#endif diff --git a/TelepathyLoggerQt4/pending-events.cpp b/TelepathyLoggerQt4/pending-events.cpp deleted file mode 100644 index cc5909a..0000000 --- a/TelepathyLoggerQt4/pending-events.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace Tpl; - -struct TELEPATHY_LOGGER_QT4_NO_EXPORT PendingEvents::Private -{ - LogManagerPtr manager; - Tp::AccountPtr account; - TpAccount *tpAccount; - EntityPtr entity; - EventTypeMask typeMask; - QDate date; - - bool filtered; - uint numEvents; - LogEventFilter filterFunction; - void *filterFunctionUserData; - - EventPtrList events; - - static void onAccountPrepared(void *logManager, void *result, PendingEvents *self); - static void callback(void *logManager, void *result, PendingEvents *self); - static gboolean eventFilterMethod(TplEvent *event, gpointer *user_data); -}; - -PendingEvents::PendingEvents(const LogManagerPtr & manager, const Tp::AccountPtr & account, - const EntityPtr & entity, EventTypeMask typeMask, const QDate &date) - : PendingOperation(), - mPriv(new Private()) -{ - mPriv->manager = manager; - mPriv->account = account; - mPriv->tpAccount = 0; - mPriv->entity = entity; - mPriv->typeMask = typeMask; - mPriv->date = date; - mPriv->filtered = false; - mPriv->filterFunction = 0; - mPriv->filterFunctionUserData = 0; -} - -PendingEvents::PendingEvents(const LogManagerPtr & manager, const Tp::AccountPtr & account, - const EntityPtr & entity, EventTypeMask typeMask, uint numEvents, - LogEventFilter filterFunction, void *filterFunctionUserData) - : PendingOperation(), - mPriv(new Private()) -{ - mPriv->manager = manager; - mPriv->account = account; - mPriv->entity = entity; - mPriv->typeMask = typeMask; - mPriv->filtered = true; - mPriv->numEvents = numEvents; - mPriv->filterFunction = filterFunction; - mPriv->filterFunctionUserData = filterFunctionUserData; -} - -PendingEvents::~PendingEvents() -{ - delete mPriv; -} - -void PendingEvents::start() -{ - mPriv->tpAccount = Utils::instance()->tpAccount(mPriv->account); - if (!mPriv->tpAccount) { - setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid account"); - return; - } - - GQuark features[] = { TP_ACCOUNT_FEATURE_CORE, 0 }; - tp_account_prepare_async(mPriv->tpAccount, features, (GAsyncReadyCallback) Private::onAccountPrepared, this); -} - -void PendingEvents::Private::onAccountPrepared(void *logManager, void *result, PendingEvents *self) -{ - if (self->mPriv->filtered) { - tpl_log_manager_get_filtered_events_async(self->mPriv->manager, - self->mPriv->tpAccount, - self->mPriv->entity, - self->mPriv->typeMask, - self->mPriv->numEvents, - self->mPriv->filterFunction ? (TplLogEventFilter) Private::eventFilterMethod : 0, - self, - (GAsyncReadyCallback) Private::callback, - self); - } else { - GDate *gdate = g_date_new_dmy( - self->mPriv->date.day(), - (GDateMonth) self->mPriv->date.month(), - self->mPriv->date.year()); - tpl_log_manager_get_events_for_date_async(self->mPriv->manager, - self->mPriv->tpAccount, - self->mPriv->entity, - self->mPriv->typeMask, - gdate, - (GAsyncReadyCallback) Private::callback, - self); - g_date_free(gdate); - } -} - -EventPtrList PendingEvents::events() const -{ - if (!isFinished()) { - qWarning() << "PendingEvents::events called before finished, returning empty"; - return EventPtrList(); - } else if (!isValid()) { - qWarning() << "PendingEvents::events called when not valid, returning empty"; - return EventPtrList(); - } - - return mPriv->events; -} - -void PendingEvents::Private::callback(void *logManager, void *result, PendingEvents *self) -{ - if (!TPL_IS_LOG_MANAGER(logManager)) { - self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid log manager in callback"); - return; - } - - if (!G_IS_ASYNC_RESULT(result)) { - self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid async result in callback"); - return; - } - - GList *events = NULL; - GError *error = NULL; - gboolean success = FALSE; - - if (self->mPriv->filtered) { - success = tpl_log_manager_get_filtered_events_finish(TPL_LOG_MANAGER(logManager), G_ASYNC_RESULT(result), &events, &error); - } else { - success = tpl_log_manager_get_events_for_date_finish(TPL_LOG_MANAGER(logManager), G_ASYNC_RESULT(result), &events, &error); - } - - if (error) { - self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, error->message); - g_error_free(error); - return; - } - - if (!success) { - self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Query failed without specific error"); - return; - } - - GList *i; - for (i = events; i; i = i->next) { - TplEvent * item = (TplEvent *) i->data; - if (TPL_IS_TEXT_EVENT(item)) { - TextEventPtr eventPtr = TextEventPtr::wrap(TPL_TEXT_EVENT(item), true); - self->mPriv->events << eventPtr; - } else if (TPL_IS_CALL_EVENT(item)) { - CallEventPtr eventPtr = CallEventPtr::wrap(TPL_CALL_EVENT(item), true); - self->mPriv->events << eventPtr; - } else if (TPL_IS_EVENT(item)) { - EventPtr eventPtr = EventPtr::wrap(TPL_EVENT(item), true); - self->mPriv->events << eventPtr; - } - } - - g_list_foreach(events, (GFunc) g_object_unref, NULL); - g_list_free(events); - - self->setFinished(); -} - -gboolean PendingEvents::Private::eventFilterMethod(TplEvent *event, gpointer *user_data) -{ - PendingEvents *self = (PendingEvents *) user_data; - if (!self) { - return FALSE; - } - - return self->mPriv->filterFunction(EventPtr::wrap(event, true), self->mPriv->filterFunctionUserData); -} diff --git a/TelepathyLoggerQt4/pending-events.h b/TelepathyLoggerQt4/pending-events.h deleted file mode 100644 index a1b0a09..0000000 --- a/TelepathyLoggerQt4/pending-events.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Stefano Sanfilippo - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -#ifndef _TelepathyLoggerQt4_pending_events_h_HEADER_GUARD_ -#define _TelepathyLoggerQt4_pending_events_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#error IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include -#include - -namespace Tpl -{ - -class TELEPATHY_LOGGER_QT4_EXPORT PendingEvents : public Tpl::PendingOperation -{ - Q_OBJECT - Q_DISABLE_COPY(PendingEvents); - -public: - ~PendingEvents(); - - EventPtrList events() const; - -private Q_SLOTS: - virtual void start(); - -private: - friend class LogManager; - - PendingEvents(const LogManagerPtr & manager, const Tp::AccountPtr & account, - const EntityPtr & entity, EventTypeMask typeMask, const QDate &date); - PendingEvents(const LogManagerPtr & manager, const Tp::AccountPtr & account, - const EntityPtr & entity, EventTypeMask typeMask, uint numEvents, - LogEventFilter filterFunction, void *filterFunctionUserData); - - struct Private; - friend struct Private; - Private *mPriv; -}; - -} // Tpl - -#endif diff --git a/TelepathyLoggerQt4/pending-logger.cpp b/TelepathyLoggerQt4/pending-logger.cpp deleted file mode 100644 index 6d2a58b..0000000 --- a/TelepathyLoggerQt4/pending-logger.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#include -#include - -namespace Tpl { - -PendingLogger::PendingLogger(const Tp::SharedPtr &logger, Tpl::LoggerInterface *interface) - : Tp::PendingOperation(logger), - mInterface(interface) -{ -} - -void PendingLogger::setError(const QString &errorName, const QString &errorMessage) -{ - Q_ASSERT(this->errorName.isEmpty()); - Q_ASSERT(this->errorMessage.isEmpty()); - - Q_ASSERT(!errorName.isEmpty()); - - this->errorName = errorName; - this->errorMessage = errorMessage; -} - -void PendingLogger::finish() -{ - if (errorName.isEmpty()) { - setFinished(); - } else { - setFinishedWithError(errorName, errorMessage); - } -} - -void PendingLogger::clearLog() -{ - QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher( - mInterface->Clear()); - connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - this, - SLOT(onLogCleared(QDBusPendingCallWatcher*))); -} - -void PendingLogger::clearAccount(const Tp::AccountPtr &account) -{ - QDBusObjectPath path = QDBusObjectPath(account->objectPath()); - QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher( - mInterface->ClearAccount(path)); - - connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - this, - SLOT(onLogCleared(QDBusPendingCallWatcher*))); -} - -void PendingLogger::clearContact(const Tp::AccountPtr &account, const QString &objectId) -{ - QDBusObjectPath path = QDBusObjectPath(account->objectPath()); - QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher( - mInterface->ClearEntity(path, objectId, EntityTypeContact)); - - connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - this, - SLOT(onLogCleared(QDBusPendingCallWatcher*))); -} - -void PendingLogger::clearRoom(const Tp::AccountPtr &account, const QString &objectId) -{ - QDBusObjectPath path = QDBusObjectPath(account->objectPath()); - QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher( - mInterface->ClearEntity(path, objectId, EntityTypeRoom)); - - connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - this, - SLOT(onLogCleared(QDBusPendingCallWatcher*))); -} - -void PendingLogger::onLogCleared(QDBusPendingCallWatcher *watcher) -{ - QDBusPendingReply<> reply = *watcher; - - if (!reply.isError()) { - qDebug() << "PendingLogger:onLogCleared: Log has been cleared"; - } else { - qWarning().nospace() << "PendingLogger:onLogCleared: Clear log failed with " << - reply.error().name() << ":" << reply.error().message(); - } - - if(!reply.isError()) { - finish(); - } else { - setError(reply.error().name(), reply.error().message()); - finish(); - } - -} - -} - diff --git a/TelepathyLoggerQt4/pending-logger.h b/TelepathyLoggerQt4/pending-logger.h deleted file mode 100644 index f2f32dd..0000000 --- a/TelepathyLoggerQt4/pending-logger.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2010 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef _TelepathyLoggerQt4_pending_logger_h_HEADER_GUARD_ -#define _TelepathyLoggerQt4_pending_logger_h_HEADER_GUARD_ - -#include -#include -#include - -namespace Tpl -{ - -class Logger; - -class TELEPATHY_LOGGER_QT4_NO_EXPORT PendingLogger : public Tp::PendingOperation -{ - Q_OBJECT - -public: - PendingLogger(const Tp::SharedPtr &logger, Tpl::LoggerInterface *interface); - ~PendingLogger() {}; - - void clearLog(); - void clearAccount(const Tp::AccountPtr &account); - void clearContact(const Tp::AccountPtr &account, const QString &objectId); - void clearRoom(const Tp::AccountPtr &account, const QString &objectId); - -protected: - void setError(const QString &errorName, const QString &errorMessage); - void finish(); - -private Q_SLOTS: - void onLogCleared(QDBusPendingCallWatcher *watcher); - -private: - QString errorName, errorMessage; - Tpl::LoggerInterface *mInterface; -}; - -} - -#endif diff --git a/TelepathyLoggerQt4/pending-operation.cpp b/TelepathyLoggerQt4/pending-operation.cpp deleted file mode 100644 index a377f47..0000000 --- a/TelepathyLoggerQt4/pending-operation.cpp +++ /dev/null @@ -1,243 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * Copyright (C) 2011 Nokia Corporation - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include -#include -#include - -using namespace Tpl; - -struct TELEPATHY_LOGGER_QT4_NO_EXPORT PendingOperation::Private -{ - Private() - : finished(false) - { - } - - QString errorName; - QString errorMessage; - bool finished; -}; - -/** - * \class PendingOperation - * \headerfile TelepathyQt/pending-operation.h - * - * \brief Abstract base class for pending asynchronous operations. - * - * This class represents an incomplete asynchronous operation, such as a - * D-Bus method call. When the operation has finished, it emits - * #finished. The slot or slots connected to the #finished() signal may obtain - * additional information from the %PendingOperation. - * - * In simple cases, like a D-Bus method with no 'out' arguments or for which - * all 'out' arguments are to be ignored (so the possible results are - * success with no extra information, or failure with an error code), the - * trivial subclass %PendingVoid can be used. - * - * For pending operations that produce a result, another subclass of - * %PendingOperation can be used, with additional methods that provide that - * result to the library user. - * - * After #finished() is emitted, the %PendingOperation is automatically - * deleted using deleteLater(), so library users must not explicitly - * delete this object. - * - * The design is loosely based on KDE's KJob. - */ - -/** - * Protected constructor. Only subclasses of this class may be constructed. - * - * \param object The object on which this pending operation takes place - */ -PendingOperation::PendingOperation() - : QObject(), - mPriv(new Private()) -{ - QTimer::singleShot(0, this, SLOT(start())); -} - -/** - * Class destructor. - */ -PendingOperation::~PendingOperation() -{ - if (!mPriv->finished) { - qWarning() << this << - "still pending when it was deleted - finished will " - "never be emitted"; - } - - delete mPriv; -} - -void PendingOperation::emitFinished() -{ - Q_ASSERT(mPriv->finished); - Q_EMIT finished(this); - deleteLater(); -} - -/** - * Record that this pending operation has finished successfully, and - * emit the #finished() signal next time the event loop runs. - */ -void PendingOperation::setFinished() -{ - if (mPriv->finished) { - if (!mPriv->errorName.isEmpty()) { - qWarning() << this << "trying to finish with success, but already" - " failed with" << mPriv->errorName << ":" << mPriv->errorMessage; - } else { - qWarning() << this << "trying to finish with success, but already" - " succeeded"; - } - return; - } - - mPriv->finished = true; - Q_ASSERT(isValid()); - QTimer::singleShot(0, this, SLOT(emitFinished())); -} - -/** - * Record that this pending operation has finished with an error, and - * emit the #finished() signal next time the event loop runs. - * - * \param name A D-Bus error name, which must be non-empty - * \param message A debugging message - */ -void PendingOperation::setFinishedWithError(const QString &name, - const QString &message) -{ - if (mPriv->finished) { - if (mPriv->errorName.isEmpty()) { - qWarning() << this << "trying to fail with" << name << - "but already failed with" << errorName() << ":" << - errorMessage(); - } else { - qWarning() << this << "trying to fail with" << name << - "but already succeeded"; - } - return; - } - - if (name.isEmpty()) { - qWarning() << this << "should be given a non-empty error name"; - mPriv->errorName = QLatin1String("org.freedesktop.Telepathy.Qt4.ErrorHandlingError"); - } else { - mPriv->errorName = name; - } - - mPriv->errorMessage = message; - mPriv->finished = true; - Q_ASSERT(isError()); - QTimer::singleShot(0, this, SLOT(emitFinished())); -} - -/** - * Returns whether or not the request completed successfully. If the - * request has not yet finished processing (isFinished() returns - * false), this cannot yet be known, and false - * will be returned. - * - * Equivalent to (isFinished() && !isError()). - * - * \return true iff the request has finished processing AND - * has completed successfully. - */ -bool PendingOperation::isValid() const -{ - return (mPriv->finished && mPriv->errorName.isEmpty()); -} - -/** - * Returns whether or not the request has finished processing. #finished() - * is emitted when this changes from false to - * true. - * - * Equivalent to (isValid() || isError()). - * - * \sa finished() - * - * \return true if the request has finished - */ -bool PendingOperation::isFinished() const -{ - return mPriv->finished; -} - -/** - * Returns whether or not the request resulted in an error. If the - * request has not yet finished processing (isFinished() returns - * false), this cannot yet be known, and false - * will be returned. - * - * Equivalent to (isFinished() && !isValid()). - * - * \return true iff the request has finished processing AND - * has resulted in an error. - */ -bool PendingOperation::isError() const -{ - return (mPriv->finished && !mPriv->errorName.isEmpty()); -} - -/** - * If isError() would return true, returns the D-Bus error with which - * the operation failed. If the operation succeeded or has not yet - * finished, returns an empty string. - * - * \return a D-Bus error name or an empty string - */ -QString PendingOperation::errorName() const -{ - return mPriv->errorName; -} - -/** - * If isError() would return true, returns a debugging message associated - * with the error, which may be an empty string. Otherwise, return an - * empty string. - * - * \return a debugging message or an empty string - */ -QString PendingOperation::errorMessage() const -{ - return mPriv->errorMessage; -} - -/** - * \fn void PendingOperation::finished(Tp::PendingOperation* operation) - * - * Emitted when the pending operation finishes, i.e. when #isFinished() - * changes from false to true. - * - * \param operation This operation object, from which further information - * may be obtained - */ - -void PendingOperation::start() -{ -} diff --git a/TelepathyLoggerQt4/pending-operation.h b/TelepathyLoggerQt4/pending-operation.h deleted file mode 100644 index 33f382f..0000000 --- a/TelepathyLoggerQt4/pending-operation.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * Copyright (C) 2011 Nokia Corporation - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -#ifndef _TelepathyLoggerQt4_pending_operation_h_HEADER_GUARD_ -#define _TelepathyLoggerQt4_pending_operation_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#error IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include -#include - -namespace Tpl -{ - -class TELEPATHY_LOGGER_QT4_EXPORT PendingOperation : public QObject -{ - Q_OBJECT - Q_DISABLE_COPY(PendingOperation) - -public: - virtual ~PendingOperation(); - - bool isFinished() const; - bool isValid() const; - bool isError() const; - QString errorName() const; - QString errorMessage() const; - -Q_SIGNALS: - void finished(Tpl::PendingOperation *operation); - -protected: - PendingOperation(); - -protected Q_SLOTS: - void setFinished(); - void setFinishedWithError(const QString &name, const QString &message); - -private Q_SLOTS: - virtual void start(); - void emitFinished(); - -private: - struct Private; - friend struct Private; - Private *mPriv; -}; - -} // Tpl - -#endif diff --git a/TelepathyLoggerQt4/pending-search.cpp b/TelepathyLoggerQt4/pending-search.cpp deleted file mode 100644 index e4df41a..0000000 --- a/TelepathyLoggerQt4/pending-search.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace Tpl; - -struct TELEPATHY_LOGGER_QT4_NO_EXPORT PendingSearch::Private -{ - LogManagerPtr manager; - QString text; - EventTypeMask typeMask; - SearchHitList hits; - - static void callback(void *logManager, void *result, PendingSearch *self); -}; - -PendingSearch::PendingSearch(const LogManagerPtr & manager, const QString &text, EventTypeMask typeMask) - : PendingOperation(), - mPriv(new Private()) -{ - mPriv->manager = manager; - mPriv->text = text; - mPriv->typeMask = typeMask; -} - -PendingSearch::~PendingSearch() -{ - delete mPriv; -} - -void PendingSearch::start() -{ - tpl_log_manager_search_async(mPriv->manager, - mPriv->text.toUtf8(), - mPriv->typeMask, - (GAsyncReadyCallback) Private::callback, - this); -} - -SearchHitList PendingSearch::hits() const -{ - if (!isFinished()) { - qWarning() << "PendingSearch::dates called before finished, returning empty"; - return SearchHitList(); - } else if (!isValid()) { - qWarning() << "PendingSearch::dates called when not valid, returning empty"; - return SearchHitList(); - } - - return mPriv->hits; -} - -void PendingSearch::Private::callback(void *logManager, void *result, PendingSearch *self) -{ - if (!TPL_IS_LOG_MANAGER(logManager)) { - self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid log manager in callback"); - return; - } - - if (!G_IS_ASYNC_RESULT(result)) { - self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid async result in callback"); - return; - } - - GList *hits = NULL; - GError *error = NULL; - gboolean success = tpl_log_manager_search_finish(TPL_LOG_MANAGER(logManager), G_ASYNC_RESULT(result), &hits, &error); - if (error) { - self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, error->message); - g_error_free(error); - return; - } - - if (!success) { - self->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Query failed without specific error"); - return; - } - - GList *i; - int count = 0; - for (i = hits; i; i = i->next) { - TplLogSearchHit *item = (TplLogSearchHit *) i->data; - debugfn() << "hit " << count++ << "account=" << item->account - << "date=" << g_date_get_year(item->date) << g_date_get_month(item->date) << g_date_get_day(item->date) - << "target=" << item->target - << tpl_entity_get_identifier(item->target) - << "/" << tpl_entity_get_alias(item->target) - << "/" << tpl_entity_get_entity_type(item->target) - << "/" << tpl_entity_get_avatar_token(item->target); - SearchHit hit(Utils::instance()->accountPtr(item->account), EntityPtr::wrap(item->target, true), QDate(item->date->year, item->date->month, item->date->day)); - self->mPriv->hits << hit; - } - - tpl_log_manager_search_free(hits); - - self->setFinished(); -} diff --git a/TelepathyLoggerQt4/pending-search.h b/TelepathyLoggerQt4/pending-search.h deleted file mode 100644 index c1665f3..0000000 --- a/TelepathyLoggerQt4/pending-search.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -#ifndef _TelepathyLoggerQt4_pending_search_h_HEADER_GUARD_ -#define _TelepathyLoggerQt4_pending_search_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#error IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include -#include - -namespace Tpl -{ - -class TELEPATHY_LOGGER_QT4_EXPORT PendingSearch : public Tpl::PendingOperation -{ - Q_OBJECT - Q_DISABLE_COPY(PendingSearch); - -public: - ~PendingSearch(); - - SearchHitList hits() const; - -private Q_SLOTS: - virtual void start(); - -private: - friend class LogManager; - - PendingSearch(const LogManagerPtr & manager, const QString &text, EventTypeMask typeMask); - - struct Private; - friend struct Private; - Private *mPriv; -}; - -} // Tpl - -#endif diff --git a/TelepathyLoggerQt4/search-hit.cpp b/TelepathyLoggerQt4/search-hit.cpp deleted file mode 100644 index 22e48e1..0000000 --- a/TelepathyLoggerQt4/search-hit.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * Copyright (C) 2012 David Edmundson - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include -#include -#include - -using namespace Tpl; - -struct TELEPATHY_LOGGER_QT4_NO_EXPORT SearchHit::Private : public QSharedData -{ - Tp::AccountPtr account; - EntityPtr target; - QDate date; -}; - -SearchHit::SearchHit(const Tp::AccountPtr &account, const Tpl::EntityPtr &target, const QDate &date) : - mPriv(new Private()) -{ - mPriv->account = account; - mPriv->target = target; - mPriv->date = date; -} - -SearchHit::SearchHit(const SearchHit &other) - : mPriv(other.mPriv) -{ -} - -SearchHit & SearchHit::operator=(const SearchHit &other) -{ - mPriv = other.mPriv; - return *this; -} - -SearchHit::~SearchHit() -{ -} - -Tp::AccountPtr SearchHit::account() const -{ - return mPriv->account; -} - -EntityPtr SearchHit::target() const -{ - return mPriv->target; -} - -QDate SearchHit::date() const -{ - return mPriv->date; -} - - - diff --git a/TelepathyLoggerQt4/search-hit.h b/TelepathyLoggerQt4/search-hit.h deleted file mode 100644 index 2ec3ffd..0000000 --- a/TelepathyLoggerQt4/search-hit.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * Copyright (C) 2012 David Edmundson - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -#ifndef _TelepathyLoggerQt4_search_hit_h_HEADER_GUARD_ -#define _TelepathyLoggerQt4_search_hit_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#error IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include -#include -#include - -#include - -namespace Tpl -{ - -class TELEPATHY_LOGGER_QT4_EXPORT SearchHit -{ -public: - SearchHit(const Tp::AccountPtr &account, const EntityPtr &target, const QDate &date); - SearchHit(const SearchHit &other); - SearchHit & operator=(const SearchHit &other); - ~SearchHit(); - - Tp::AccountPtr account() const; - EntityPtr target() const; - QDate date() const; - -private: - struct Private; - QSharedDataPointer mPriv; -}; - -} // Tpl - -#endif diff --git a/TelepathyLoggerQt4/stable-interfaces.xml b/TelepathyLoggerQt4/stable-interfaces.xml deleted file mode 100644 index 7ead98f..0000000 --- a/TelepathyLoggerQt4/stable-interfaces.xml +++ /dev/null @@ -1,12 +0,0 @@ - - -Telepathy D-Bus Interface Specification, TelepathyQt4Yell copy - - - - - - - diff --git a/TelepathyLoggerQt4/text-event.cpp b/TelepathyLoggerQt4/text-event.cpp deleted file mode 100644 index 675f2f4..0000000 --- a/TelepathyLoggerQt4/text-event.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Stefano Sanfilippo - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#include - -#include - -using namespace Tpl; - -Tp::ChannelTextMessageType TextEvent::messageType() const -{ - return (Tp::ChannelTextMessageType) tpl_text_event_get_message_type(object()); -} - -QString TextEvent::message() const -{ - const gchar *s = tpl_text_event_get_message(object()); - QString str = QString::fromUtf8(s); - return str; -} - -QString TextEvent::messageToken() const -{ - const gchar *s = tpl_text_event_get_message_token(object()); - QString str = QString::fromUtf8(s); - return str; -} diff --git a/TelepathyLoggerQt4/text-event.h b/TelepathyLoggerQt4/text-event.h deleted file mode 100644 index 2ea73f7..0000000 --- a/TelepathyLoggerQt4/text-event.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Stefano Sanfilippo - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ -#ifndef _TelepathyLoggerQt4_text_event_h_HEADER_GUARD_ -#define _TelepathyLoggerQt4_text_event_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#error IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include -#include - -namespace Tpl -{ - -/*! \headerfile text-event.h - * \brief Wrapper class for TplTextEvent - */ -class TELEPATHY_LOGGER_QT4_EXPORT TextEvent : public Event -{ - QTELEPATHYLOGGERQT4_WRAPPER(TextEvent) -public: - Tp::ChannelTextMessageType messageType() const; - QString message() const; - QString messageToken() const; -}; - -} //namespace - -QTELEPATHYLOGGERQT4_REGISTER_TYPE(Tpl::TextEvent) - -#endif diff --git a/TelepathyLoggerQt4/types.h b/TelepathyLoggerQt4/types.h deleted file mode 100644 index c5f3f16..0000000 --- a/TelepathyLoggerQt4/types.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ -#ifndef _TelepathyLoggerQt4_types_h_HEADER_GUARD_ -#define _TelepathyLoggerQt4_types_h_HEADER_GUARD_ - -#ifndef IN_TELEPATHY_LOGGER_QT4_HEADER -#error IN_TELEPATHY_LOGGER_QT4_HEADER -#endif - -#include -#include -#include -#include - -namespace Tpl -{ - -enum EntityType -{ - //codegen: EntityTypeUnknown=ENTITY_UNKNOWN,EntityTypeContact=ENTITY_CONTACT,EntityTypeRoom=ENTITY_ROOM,EntityTypeSelf=ENTITY_SELF - EntityTypeUnknown, - EntityTypeContact, - EntityTypeRoom, - EntityTypeSelf -}; - -enum LogManagerError -{ - LogManagerErrorAddEvent -}; - -enum EventTypeMask -{ - //codegen: EventTypeMaskText=EVENT_MASK_TEXT,EventTypeMaskAny=EVENT_MASK_ANY - EventTypeMaskText = 1 << 0, - EventTypeMaskAny = 0xffff -}; - -class Logger; -class PendingDates; -class PendingEvents; -class PendingEntities; -class PendingSearch; -struct SearchHit; - -typedef Tp::SharedPtr LoggerPtr; -typedef QList ContactPtrList; -typedef QList EntityPtrList; -typedef QList EventPtrList; -typedef QList QDateList; -typedef QList SearchHitList; - -typedef bool (*LogEventFilter)(const EventPtr &event, void *user_data); - -} //namespace - -#endif diff --git a/TelepathyLoggerQt4/utils.cpp b/TelepathyLoggerQt4/utils.cpp deleted file mode 100644 index 2a31277..0000000 --- a/TelepathyLoggerQt4/utils.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace Tpl; - -Utils *Utils::instance() -{ - static Utils *instance = 0; - - if (!instance) { - debugfn() << "Created Utils instance"; - instance = new Utils(); - } - - return instance; -} - -Utils::Utils() -{ -} - -Utils::~Utils() -{ -} - -void Utils::setAccountManagerPtr(const Tp::AccountManagerPtr & accountManager) -{ - mAccountManagerPtr = accountManager; -} - -Tp::AccountManagerPtr Utils::accountManagerPtr() -{ - debugfn(); - if (mAccountManagerPtr.isNull()) { - debugfn() << "Created Tp::AccountManager instance"; - mAccountManagerPtr = Tp::AccountManager::create(); - } - - return mAccountManagerPtr; -} - -TpAccountManager *Utils::tpAccountManager() -{ - debugfn(); - return tp_account_manager_dup(); -} - -Tp::AccountPtr Utils::accountPtr(TpAccount *account) -{ - debugfn() << "account=" << account; - - if (!account) { - return Tp::AccountPtr(); - } - - const gchar *objectPath = tp_proxy_get_object_path(account); - debugfn() << "objectPath=" << objectPath; - if (!objectPath) { - return Tp::AccountPtr(); - } - - return accountPtr(objectPath); -} - -Tp::AccountPtr Utils::accountPtr(const QString &objectPath) -{ - debugfn() << "objectPath=" << objectPath; - - Tp::AccountPtr accountPtr = accountManagerPtr()->accountForPath(objectPath); - - debugfn() << "accountPtr=" << accountPtr; - return accountPtr; -} - -TpAccount *Utils::tpAccount(const Tp::AccountPtr & accountPtr) -{ - debugfn() << "account=" << accountPtr; - - QString objectPath = accountPtr->objectPath(); - debugfn() << "objectPath=" << objectPath; - if (objectPath.isEmpty()) { - return 0; - } - - TpAccount * account = tp_account_manager_ensure_account(tpAccountManager(), objectPath.toUtf8()); - debugfn() << "account=" << account; - return account; -} - -#if 0 -TpContact *ToTpContact(Tp::ContactPtr contact) -{ - if (contact.isNull()) { - return 0; - } - - Tp::ReferencedHandles handles = contact->handle(); - if (handles.isEmpty()) { - return 0; - } - - GError *error = 0; - TpDBusDaemon * tpDBusDaemon = tp_dbus_daemon_dup(&error); - if (error) { - g_error_free(error); - return 0; - } - - if (!tpDBusDaemon) { - return 0; - } - - if (!contact->manager()) { - return 0; - } - - Tp::ConnectionPtr connection = contact->manager()->connection(); - if (!connection) { - return 0; - } - - QString busName = connection->busName(); - QString objectPath = connection->objectPath(); - TpConnection *tpConnection = tp_connection_new(tpDBusDaemon, busName.toLatin1(), objectPath.toLatin1(), &error); - if (error) { - return 0; - } - - if (!tpConnection) { - return 0; - } - - Tp::ReferencedHandles::const_iterator it; - for(it = handles.constBegin(); it != handles.constEnd(); it++) { - // todo use async version: tp_connection_get_contacts_by_handle - TpContact *tpContact = tp_connection_dup_contact_if_possible(tpConnection, *it, contact->id().toLatin1()); - if (tpContact) { - return tpContact; - } - } - - return 0; -} - -Tp::ContactPtr ToTpContactPtr(TpContact * tpContact) -{ - if (!tpContact) { - return Tp::ContactPtr(); - } - - TpConnection * tpConnection = tp_contact_get_connection(tpContact); - if (!tpConnection) { - return Tp::ContactPtr(); - } - - const gchar *busName = tp_proxy_get_bus_name(TP_PROXY(tpConnection)); - if (!busName) { - return Tp::ContactPtr(); - } - - const gchar *objectPath = tp_proxy_get_object_path(TP_PROXY(tpConnection)); - if (!objectPath) { - return Tp::ContactPtr(); - } - - Tp::ConnectionPtr connection = Tp::Connection::create(busName, objectPath); - if (connection.isNull()) { - return Tp::ContactPtr(); - } - - if (connection->contactManager().isNull()) { - return Tp::ContactPtr(); - } - - TpHandle handle = tp_contact_get_handle(contact); - // TODO use async version - return connection->contactManager()->lookupContactByHandle(handle); -} -#endif diff --git a/TelepathyLoggerQt4/utils.h b/TelepathyLoggerQt4/utils.h deleted file mode 100644 index 89e4f68..0000000 --- a/TelepathyLoggerQt4/utils.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file is part of TelepathyLoggerQt4 - * - * Copyright (C) 2011 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ -#ifndef _TelepathyLoggerQt4_utils_h_HEADER_GUARD_ -#define _TelepathyLoggerQt4_utils_h_HEADER_GUARD_ - -#include -#include -#include -#include -#include - -#if __GNUC__ >= 2 -# define __func__ __PRETTY_FUNCTION__ -#elif __STDC_VERSION__ >= 199901L -# define __func__ __FUNCTION__ -#else -# define __func__ "" -#endif - -#define debug() qDebug() << "tp-qt4-tpl DEBUG: " -#define debugfn() qDebug() << "tp-qt4-tpl DEBUG: " << __func__ << " : " -#define warning() qWarning() << "tp-qt4-tpl WARN: " -#define warningfn() qWarning() << "tp-qt4-tpl WARN: " << __func__ << " : " - -namespace Tpl { - -class TELEPATHY_LOGGER_QT4_NO_EXPORT Utils { -public: - static Utils *instance(); - - void setAccountManagerPtr(const Tp::AccountManagerPtr & accountManager); - Tp::AccountManagerPtr accountManagerPtr(); - TpAccountManager *tpAccountManager(); - - Tp::AccountPtr accountPtr(TpAccount *account); - Tp::AccountPtr accountPtr(const QString &objectPath); - TpAccount *tpAccount(const Tp::AccountPtr & accountPtr); - -private: - Utils(); - ~Utils(); - - Tp::AccountManagerPtr mAccountManagerPtr; -}; - -}; - -#endif diff --git a/cmake/modules/Qt5Macros.cmake b/cmake/modules/Qt5Macros.cmake new file mode 100644 index 0000000..e7eb0cb --- /dev/null +++ b/cmake/modules/Qt5Macros.cmake @@ -0,0 +1,63 @@ +# This file is included by FindQt5.cmake, don't include it directly. + +# Copyright (C) 2001-2009 Kitware, Inc. +# Copyright (C) 2011 Collabora Ltd. +# Copyright (C) 2011 Nokia Corporation +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +MACRO (QT5_GET_MOC_FLAGS _moc_flags) + SET(${_moc_flags}) + GET_DIRECTORY_PROPERTY(_inc_DIRS INCLUDE_DIRECTORIES) + + FOREACH(_current ${_inc_DIRS}) + IF("${_current}" MATCHES "\\.framework/?$") + STRING(REGEX REPLACE "/[^/]+\\.framework" "" framework_path "${_current}") + SET(${_moc_flags} ${${_moc_flags}} "-F${framework_path}") + ELSE("${_current}" MATCHES "\\.framework/?$") + SET(${_moc_flags} ${${_moc_flags}} "-I${_current}") + ENDIF("${_current}" MATCHES "\\.framework/?$") + ENDFOREACH(_current ${_inc_DIRS}) + + GET_DIRECTORY_PROPERTY(_defines COMPILE_DEFINITIONS) + FOREACH(_current ${_defines}) + SET(${_moc_flags} ${${_moc_flags}} "-D${_current}") + ENDFOREACH(_current ${_defines}) + + IF(Q_WS_WIN) + SET(${_moc_flags} ${${_moc_flags}} -DWIN32) + ENDIF(Q_WS_WIN) + +ENDMACRO (QT5_GET_MOC_FLAGS) + +# helper macro to set up a moc rule +MACRO (QT5_CREATE_MOC_COMMAND infile outfile moc_flags moc_options) + # For Windows, create a parameters file to work around command line length limit + IF (WIN32) + # Pass the parameters in a file. Set the working directory to + # be that containing the parameters file and reference it by + # just the file name. This is necessary because the moc tool on + # MinGW builds does not seem to handle spaces in the path to the + # file given with the @ syntax. + GET_FILENAME_COMPONENT(_moc_outfile_name "${outfile}" NAME) + GET_FILENAME_COMPONENT(_moc_outfile_dir "${outfile}" PATH) + IF(_moc_outfile_dir) + SET(_moc_working_dir WORKING_DIRECTORY ${_moc_outfile_dir}) + ENDIF(_moc_outfile_dir) + SET (_moc_parameters_file ${outfile}_parameters) + SET (_moc_parameters ${moc_flags} ${moc_options} -o "${outfile}" "${infile}") + STRING (REPLACE ";" "\n" _moc_parameters "${_moc_parameters}") + FILE (WRITE ${_moc_parameters_file} "${_moc_parameters}") + ADD_CUSTOM_COMMAND(OUTPUT ${outfile} + COMMAND ${QT_MOC_EXECUTABLE} @${_moc_outfile_name}_parameters + DEPENDS ${infile} + ${_moc_working_dir} + VERBATIM) + ELSE (WIN32) + ADD_CUSTOM_COMMAND(OUTPUT ${outfile} + COMMAND ${QT_MOC_EXECUTABLE} + ARGS ${moc_flags} ${moc_options} -o ${outfile} ${infile} + DEPENDS ${infile}) + ENDIF (WIN32) +ENDMACRO (QT5_CREATE_MOC_COMMAND) diff --git a/cmake/modules/TelepathyDefaults.cmake b/cmake/modules/TelepathyDefaults.cmake index 5c4d3f4..abf7b9a 100644 --- a/cmake/modules/TelepathyDefaults.cmake +++ b/cmake/modules/TelepathyDefaults.cmake @@ -49,11 +49,11 @@ if(CMAKE_COMPILER_IS_GNUCXX) set(DEPRECATED_DECLARATIONS_FLAGS) endif (CXX_DEPRECATED_DECLARATIONS) - if(${TP_LOGGER_QT4_NANO_VERSION} EQUAL 0) + if(${TP_LOGGER_QT_NANO_VERSION} EQUAL 0) set(NOT_RELEASE 0) - else(${TP_LOGGER_QT4_NANO_VERSION} EQUAL 0) + else(${TP_LOGGER_QT_NANO_VERSION} EQUAL 0) set(NOT_RELEASE 1) - endif(${TP_LOGGER_QT4_NANO_VERSION} EQUAL 0) + endif(${TP_LOGGER_QT_NANO_VERSION} EQUAL 0) set(desired all diff --git a/cmake/modules/TpQt4Macros.cmake b/cmake/modules/TpQt4Macros.cmake deleted file mode 100644 index 85fb925..0000000 --- a/cmake/modules/TpQt4Macros.cmake +++ /dev/null @@ -1,428 +0,0 @@ -# - Common macros for Tp-Qt4 - -# Copyright (c) 2010, Collabora Ltd. -# -# Redistribution and use is allowed according to the terms of the BSD license. - -# -# These macros/functions are not exported - they are meant for internal usage into Telepathy-Qt4's build system. -# -# Preamble: How dynamic generators are handled with the CMake build system. -# Telepathy-Qt4 strongly relies upon lots of files generated at build time through some python programs, found -# in tools/. To avoid developers the struggle of handling those manually, a set of convenience macros have been -# created to handle them with the correct dependencies. Each of those macros takes a target name as a first argument -# and creates a target with that exact name. In a similar fashion, in the last argument you can specify a list -# of targets the generated target will depend on. This way, you can handle transparently dependencies between -# generated files, while the dirty stuff is done for you in the background. -# -# macro TPQT4_EXTRACT_DEPENDS (tpqt4_other tpqt4_depends) -# Internal macro used to extract arguments from ARGN -# -# function TPQT4_CREATE_MOC_COMMAND_TARGET_DEPS(inputfile outputfile moc_flags moc_options target_dependencies ...) -# This function behaves exactly like qt4_create_moc_command, but creates a custom target for the -# moc file generation, allowing to specify a list of targets the generated moc target will depend on. -# Just like qt4_create_moc_command, it is an internal macro and it's not meant to be used explicitely. -# -# function TPQT4_GENERATE_MOC_I(inputfile outputfile) -# This function behaves exactly like qt4_generate_moc, but it generates moc files with the -i option, -# which disables the generation of an #include directive. This macro has to be used always when building -# library internals due to the internal header files restrictions. -# -# function TPQT4_GENERATE_MOC_I_TARGET_DEPS(inputfile outputfile target_dependencies ...) -# This function acts as an overload to QT4_GENERATE_MOC_I: it does exactly the same thing, but creates a -# custom target for the moc file generation, and adds target_dependencies to it as dependencies. -# -# function TPQT4_GENERATE_MOCS(sourcefile ...) -# Generates mocs from a list of header files. You usually want to use this function when building tests -# or examples. Please remember the list of the header files passed to this function MUST be added to the -# target's sources. -# -# function TPQT4_CLIENT_GENERATOR(spec_xml spec group real_include pretty_include namespace types_namespace must_define visibility [arguments] [DEPENDS dependencies ...]) -# This function takes care of invoking qt4-client-gen.py with the correct arguments, which generates -# headers out of specs. spec is the name of the spec headers will be generated from, group represents -# the spec's group, pretty_include is the name of the capitalized header (for example ClientGenerator), -# namespace is the C++ namespace the generated header will belong to. This function also accepts -# as an optional last argument a list of additional command line arguments which will be passed to -# qt4-client-gen.py upon execution. After issuing DEPENDS in the last argument you can pass a list of targets -# the generated target will depend on. -# -# function TPQT4_FUTURE_CLIENT_GENERATOR(future_spec_xml spec real_include pretty_include namespace types_namespace visibility [arguments] [DEPENDS dependencies ...]) -# Same as tpqt4_client_generator, but for future interfaces -# -# function TPQT4_GENERATE_MANAGER_FILE(MANAGER_FILE OUTPUT_FILENAME DEPEND_FILENAME) -# This function takes care of invoking manager-file.py with the correct arguments. The first argument is the -# path to the manager-file.py file which should be used, the second is the output filename of the manager, -# and the third is the path to the file which depends on the generated manager file. -# -# function TPQT4_XINCLUDATOR (TARGET_NAME INPUT_FILE OUTPUT_FILE [additional_arguments ...] [DEPENDS dependencies ...]) -# This function takes care of invoking xincludator.py with the correct arguments. TARGET_NAME is the name of -# the generated target (see preamble), INPUT_FILE is the input spec file, OUTPUT_FILE is the filename -# the generated file will be saved to. This function also accepts as an optional last argument a list of -# additional command line arguments which will be passed to xincludator upon execution. -# After issuing DEPENDS in the last argument you can pass a list of targets the generated target will depend on. -# -# function TPQT4_CONSTANTS_GEN (TARGET_NAME SPEC_XML OUTPUT_FILE [additional_arguments ...] [DEPENDS dependencies ...]) -# This function takes care of invoking qt4-constants-gen.py with the correct arguments. TARGET_NAME is the name of -# the generated target (see preamble), SPEC_XML is the spec input file, OUTPUT_FILE is the filename -# the generated file will be saved to. This function also accepts as an optional last argument a list of -# additional command line arguments which will be passed to qt4-constants-gen.py upon execution. -# After issuing DEPENDS in the last argument you can pass a list of targets the generated target will depend on. -# -# function TPQT4_TYPES_GEN (TARGET_NAME SPEC_XML OUTFILE_DECL OUTFILE_IMPL NAMESPACE -# REAL_INCLUDE PRETTY_INCLUDE [additional_arguments ...] [DEPENDS dependencies ...]) -# This function takes care of invoking qt4-types-gen.py with the correct arguments. TARGET_NAME is the name of -# the generated target (see preamble), SPEC_XML is the input spec file, OUTFILE_DECL is the filename -# the header of the generated file will be saved to, OUTFILE_IMPL is the filename the implementation of the -# generated file will be saved to, NAMESPACE is the C++ namespace the generated header will belong to, -# REAL_INCLUDE is the real include file you want to use, PRETTY_INCLUDE is the name of the capitalized header -# (for example ClientGenerator). -# This function also accepts as an optional last argument a list of additional command line arguments -# which will be passed to qt4-constants-gen.py upon execution. -# After issuing DEPENDS in the last argument you can pass a list of targets the generated target will depend on. -# -# macro TPQT4_ADD_GENERIC_UNIT_TEST (fancyName name [libraries ...]) -# This macro takes care of building and adding a generic unit test to the automatic CTest suite. The requirement -# for using this macro is to have the unit test contained in a single source file named ${name}.cpp. fancyName will -# be used as the test and target's name, and you can specify as a third and optional argument a set of additional -# libraries the target will link to. -# -# macro TPQT4_ADD_DBUS_UNIT_TEST (fancyName name [libraries ...]) -# This macro takes care of building and adding an unit test requiring DBus emulation to the automatic -# CTest suite. The requirement for using this macro is to have the unit test contained in a single -# source file named ${name}.cpp. fancyName will be used as the test and target's name, and you can specify as a third -# and optional argument a set of additional libraries the target will link to. Please remember that you need to -# set up the DBus environment by calling TPQT4_SETUP_DBUS_TEST_ENVIRONMENT BEFORE you call this macro. -# -# macro _TPQT4_ADD_CHECK_TARGETS (fancyName name command [args]) -# This is an internal macro which is meant to be used by TPQT4_ADD_DBUS_UNIT_TEST and TPQT4_ADD_GENERIC_UNIT_TEST. -# It takes care of generating a check target for each test method available (currently normal execution, valgrind and -# callgrind). This macro accepts the same arguments as the add test macros, but accepts a command and a list of -# arguments for running the test instead of the link libraries. However, you are not meant to call this macro from -# your CMakeLists.txt files. -# -# function TPQT4_SETUP_DBUS_TEST_ENVIRONMENT () -# This function MUST be called before calling TPQT4_ADD_DBUS_UNIT_TEST. It takes care of preparing the test -# environment for DBus tests and generating the needed files. -# - -MACRO (TPQT4_EXTRACT_DEPENDS _tpqt4_other _tpqt4_depends) - SET(${_tpqt4_other}) - SET(${_tpqt4_depends}) - SET(_TPQT4_DOING_DEPENDS FALSE) - FOREACH(_currentArg ${ARGN}) - IF ("${_currentArg}" STREQUAL "DEPENDS") - SET(_TPQT4_DOING_DEPENDS TRUE) - ELSE ("${_currentArg}" STREQUAL "DEPENDS") - IF(_TPQT4_DOING_DEPENDS) - LIST(APPEND ${_tpqt4_depends} "${_currentArg}") - ELSE(_TPQT4_DOING_DEPENDS) - LIST(APPEND ${_tpqt4_other} "${_currentArg}") - ENDIF(_TPQT4_DOING_DEPENDS) - ENDIF ("${_currentArg}" STREQUAL "DEPENDS") - ENDFOREACH(_currentArg) -ENDMACRO (TPQT4_EXTRACT_DEPENDS) - -# helper function to set up a moc rule -FUNCTION (TPQT4_CREATE_MOC_COMMAND_TARGET_DEPS infile outfile moc_flags moc_options) - # For Windows, create a parameters file to work around command line length limit - GET_FILENAME_COMPONENT(_moc_outfile_name "${outfile}" NAME) - IF (WIN32) - # Pass the parameters in a file. Set the working directory to - # be that containing the parameters file and reference it by - # just the file name. This is necessary because the moc tool on - # MinGW builds does not seem to handle spaces in the path to the - # file given with the @ syntax. - GET_FILENAME_COMPONENT(_moc_outfile_dir "${outfile}" PATH) - IF(_moc_outfile_dir) - SET(_moc_working_dir WORKING_DIRECTORY ${_moc_outfile_dir}) - ENDIF(_moc_outfile_dir) - SET (_moc_parameters_file ${outfile}_parameters) - SET (_moc_parameters ${moc_flags} ${moc_options} -o "${outfile}" "${infile}") - FILE (REMOVE ${_moc_parameters_file}) - FOREACH(arg ${_moc_parameters}) - FILE (APPEND ${_moc_parameters_file} "${arg}\n") - ENDFOREACH(arg) - ADD_CUSTOM_COMMAND(OUTPUT ${outfile} - COMMAND ${QT_MOC_EXECUTABLE} @${_moc_outfile_name}_parameters - DEPENDS ${infile} - ${_moc_working_dir} - VERBATIM) - ELSE (WIN32) - ADD_CUSTOM_COMMAND(OUTPUT ${outfile} - COMMAND ${QT_MOC_EXECUTABLE} - ARGS ${moc_flags} ${moc_options} -o ${outfile} ${infile} - DEPENDS ${infile}) - ENDIF (WIN32) - - add_custom_target(moc-${_moc_outfile_name} DEPENDS ${outfile}) - add_dependencies(moc-${_moc_outfile_name} ${ARGN}) -ENDFUNCTION (TPQT4_CREATE_MOC_COMMAND_TARGET_DEPS) - -# add the -i option to QT4_GENERATE_MOC -function(TPQT4_GENERATE_MOC_I infile outfile) - qt4_get_moc_flags(moc_flags) - get_filename_component(abs_infile ${infile} ABSOLUTE) - qt4_create_moc_command(${abs_infile} ${outfile} "${moc_flags}" "-i") - set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC TRUE) # dont run automoc on this file -endfunction(TPQT4_GENERATE_MOC_I) - -# same as tpqt4_generate_moc_i, but lets the caller specify a list of targets which the mocs should depend on -function(TPQT4_GENERATE_MOC_I_TARGET_DEPS infile outfile) - qt4_get_moc_flags(moc_flags) - get_filename_component(abs_infile ${infile} ABSOLUTE) - tpqt4_create_moc_command_target_deps(${abs_infile} ${outfile} "${moc_flags}" "-i" ${ARGN}) - set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC TRUE) # dont run automoc on this file -endfunction(TPQT4_GENERATE_MOC_I_TARGET_DEPS) - -# generates mocs for the passed list. The list should be added to the target's sources -function(tpqt4_generate_mocs) - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/_gen" ) - foreach(moc_src ${ARGN}) - string(REPLACE ".h" ".moc.hpp" generated_file ${moc_src}) - tpqt4_generate_moc_i(${CMAKE_CURRENT_SOURCE_DIR}/${moc_src} ${CMAKE_CURRENT_BINARY_DIR}/_gen/${generated_file}) - macro_add_file_dependencies(${moc_src} ${CMAKE_CURRENT_BINARY_DIR}/_gen/${generated_file}) - endforeach(moc_src ${ARGN}) -endfunction(tpqt4_generate_mocs) - -function(tpqt4_client_generator spec_xml spec group real_include pretty_include namespace types_namespace must_define visibility) - tpqt4_extract_depends(client_generator_args client_generator_depends ${ARGN}) - set(ARGS - ${CMAKE_SOURCE_DIR}/tools/qt4-client-gen.py - --group=${group} - --namespace=${namespace} - --typesnamespace=${types_namespace} - --headerfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}.h - --implfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}-body.hpp - --realinclude=${real_include} - --prettyinclude=${pretty_include} - --specxml=${spec_xml} - --ifacexml=${CMAKE_CURRENT_BINARY_DIR}/_gen/spec-${spec}.xml - --extraincludes=${TYPES_INCLUDE} - --must-define=${must_define} - --visibility=${visibility} - ${client_generator_args}) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}.h ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}-body.hpp - COMMAND ${PYTHON_EXECUTABLE} - ARGS ${ARGS} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - - DEPENDS ${CMAKE_SOURCE_DIR}/tools/libqt4codegen.py - ${CMAKE_SOURCE_DIR}/tools/qt4-client-gen.py) - add_custom_target(generate_cli-${spec}-body DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}-body.hpp) - - if (client_generator_depends) - add_dependencies(generate_cli-${spec}-body ${client_generator_depends}) - endif (client_generator_depends) - - tpqt4_generate_moc_i_target_deps(${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}.h - ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}.moc.hpp - "generate_cli-${spec}-body") -endfunction(tpqt4_client_generator spec_xml spec group real_include pretty_include namespace types_namespace must_define visibility) - -function(tpqt4_future_client_generator future_spec_xml spec real_include pretty_include namespace types_namespace visibility) - tpqt4_extract_depends(future_client_generator_args future_client_generator_depends ${ARGN}) - set(ARGS - ${CMAKE_SOURCE_DIR}/tools/qt4-client-gen.py - --namespace=${namespace} - --typesnamespace=${types_namespace} - --headerfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.h - --implfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}-body.hpp - --realinclude=${real_include} - --prettyinclude=${pretty_include} - --specxml=${future_spec_xml} - --ifacexml=${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.xml - --extraincludes=${TYPES_INCLUDE} - --visibility=${visibility} - ${future_client_generator_args}) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.h ${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}-body.hpp - COMMAND ${PYTHON_EXECUTABLE} - ARGS ${ARGS} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - - DEPENDS ${CMAKE_SOURCE_DIR}/tools/libqt4codegen.py - ${CMAKE_SOURCE_DIR}/tools/qt4-client-gen.py) - add_custom_target(generate_future-${spec}-body DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}-body.hpp) - - if (future_client_generator_depends) - add_dependencies(generate_future-${spec}-body ${future_client_generator_depends}) - endif (future_client_generator_depends) - - tpqt4_generate_moc_i_target_deps(${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.h - ${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.moc.hpp - "generate_future-${spec}-body") -endfunction(tpqt4_future_client_generator future_spec_xml spec real_include pretty_include namespace types_namespace visibility) - -# This function is used for generating CM in various examples -function(tpqt4_generate_manager_file MANAGER_FILE OUTPUT_FILENAME DEPEND_FILENAME) - # make_directory is required, otherwise the command won't work!! - make_directory(${CMAKE_CURRENT_BINARY_DIR}/_gen) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_gen/param-spec-struct.h - ${CMAKE_CURRENT_BINARY_DIR}/_gen/${OUTPUT_FILENAME} - - COMMAND ${PYTHON_EXECUTABLE} - - ARGS ${CMAKE_SOURCE_DIR}/tools/manager-file.py - ${MANAGER_FILE} - _gen - - DEPENDS ${CMAKE_SOURCE_DIR}/tools/manager-file.py) - - set_source_files_properties(${DEPEND_FILENAME} - PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_gen/param-spec-struct.h) -endfunction(tpqt4_generate_manager_file MANAGER_FILE) - -function(tpqt4_xincludator _TARGET_NAME _INPUT_FILE _OUTPUT_FILE) - tpqt4_extract_depends(xincludator_gen_args xincludator_gen_depends ${ARGN}) - # Gather all .xml files in spec/ and make this target depend on those - file(GLOB depends_xml_files ${CMAKE_SOURCE_DIR}/spec/*.xml) - - add_custom_command(OUTPUT ${_OUTPUT_FILE} - - COMMAND ${PYTHON_EXECUTABLE} - - ARGS ${CMAKE_SOURCE_DIR}/tools/xincludator.py - ${_INPUT_FILE} - ${xincludator_gen_args} - > ${_OUTPUT_FILE} - - DEPENDS ${CMAKE_SOURCE_DIR}/tools/xincludator.py - ${_INPUT_FILE} ${depends_xml_files}) - add_custom_target(${_TARGET_NAME} DEPENDS ${_OUTPUT_FILE}) - - if (xincludator_gen_depends) - add_dependencies(${_TARGET_NAME} ${xincludator_gen_depends}) - endif (xincludator_gen_depends) -endfunction(tpqt4_xincludator _TARGET_NAME _INPUT_FILE _OUTPUT_FILE) - -function(tpqt4_constants_gen _TARGET_NAME _SPEC_XML _OUTFILE) - tpqt4_extract_depends(constants_gen_args constants_gen_depends ${ARGN}) - # Gather all .xml files in spec/ and make this target depend on those - file(GLOB depends_xml_files ${CMAKE_SOURCE_DIR}/spec/*.xml) - - add_custom_command(OUTPUT ${_OUTFILE} - - COMMAND ${PYTHON_EXECUTABLE} - - ARGS ${CMAKE_SOURCE_DIR}/tools/qt4-constants-gen.py - ${constants_gen_args} - --specxml=${_SPEC_XML} - > ${_OUTFILE} - - DEPENDS ${CMAKE_SOURCE_DIR}/tools/libqt4codegen.py - ${CMAKE_SOURCE_DIR}/tools/qt4-constants-gen.py - ${_SPEC_XML} ${depends_xml_files}) - add_custom_target(${_TARGET_NAME} DEPENDS ${_OUTFILE}) - - if (constants_gen_depends) - add_dependencies(${_TARGET_NAME} ${constants_gen_depends}) - endif (constants_gen_depends) -endfunction (tpqt4_constants_gen _TARGET_NAME _SPEC_XML _OUTFILE) - -function(tpqt4_types_gen _TARGET_NAME _SPEC_XML _OUTFILE_DECL _OUTFILE_IMPL _NAMESPACE _REALINCLUDE _PRETTYINCLUDE) - tpqt4_extract_depends(types_gen_args types_gen_depends ${ARGN}) - # Gather all .xml files in spec/ and make this target depend on those - file(GLOB depends_xml_files ${CMAKE_SOURCE_DIR}/spec/*.xml) - - add_custom_command(OUTPUT ${_OUTFILE_DECL} ${_OUTFILE_IMPL} - COMMAND ${PYTHON_EXECUTABLE} - ARGS ${CMAKE_SOURCE_DIR}/tools/qt4-types-gen.py - --namespace=${_NAMESPACE} - --declfile=${_OUTFILE_DECL} - --implfile=${_OUTFILE_IMPL} - --realinclude=${_REALINCLUDE} - --prettyinclude=${_PRETTYINCLUDE} - ${types_gen_args} - --specxml=${_SPEC_XML} - - DEPENDS ${CMAKE_SOURCE_DIR}/tools/libqt4codegen.py - ${CMAKE_SOURCE_DIR}/tools/qt4-types-gen.py - ${_SPEC_XML} ${depends_xml_files}) - add_custom_target(${_TARGET_NAME} DEPENDS ${_OUTFILE_IMPL}) - - if (types_gen_depends) - add_dependencies(${_TARGET_NAME} ${types_gen_depends}) - endif (types_gen_depends) -endfunction(tpqt4_types_gen _TARGET_NAME _SPEC_XML _OUTFILE_DECL _OUTFILE_IMPL _NAMESPACE _REALINCLUDE _PRETTYINCLUDE) - -macro(tpqt4_add_generic_unit_test _fancyName _name) - tpqt4_generate_moc_i(${_name}.cpp ${CMAKE_CURRENT_BINARY_DIR}/_gen/${_name}.cpp.moc.hpp) - add_executable(test-${_name} ${_name}.cpp ${CMAKE_CURRENT_BINARY_DIR}/_gen/${_name}.cpp.moc.hpp) - target_link_libraries(test-${_name} ${QT_LIBRARIES} ${QT_QTTEST_LIBRARY} ${TELEPATHY_QT4_LIBRARIES} ${ARGN}) - add_test(${_fancyName} ${SH} ${CMAKE_CURRENT_BINARY_DIR}/runGenericTest.sh ${CMAKE_CURRENT_BINARY_DIR}/test-${_name}) - list(APPEND tpqt4_test_cases test-${_name}) - - # Valgrind and Callgrind targets - _tpqt4_add_check_targets(${_fancyName} ${_name} ${CMAKE_CURRENT_BINARY_DIR}/runGenericTest.sh ${CMAKE_CURRENT_BINARY_DIR}/test-${_name}) -endmacro(tpqt4_add_generic_unit_test _fancyName _name) - -macro(tpqt4_add_dbus_unit_test _fancyName _name) - tpqt4_generate_moc_i(${_name}.cpp ${CMAKE_CURRENT_BINARY_DIR}/_gen/${_name}.cpp.moc.hpp) - add_executable(test-${_name} ${_name}.cpp ${CMAKE_CURRENT_BINARY_DIR}/_gen/${_name}.cpp.moc.hpp) - target_link_libraries(test-${_name} ${QT_LIBRARIES} ${QT_QTTEST_LIBRARY} ${TELEPATHY_QT4_LIBRARIES} ${ARGN}) - set(with_session_bus ${CMAKE_CURRENT_BINARY_DIR}/runDbusTest.sh) - add_test(${_fancyName} ${SH} ${with_session_bus} ${CMAKE_CURRENT_BINARY_DIR}/test-${_name}) - list(APPEND tpqt4_test_cases test-${_name}) - - # Valgrind and Callgrind targets - _tpqt4_add_check_targets(${_fancyName} ${_name} ${with_session_bus} ${CMAKE_CURRENT_BINARY_DIR}/test-${_name}) -endmacro(tpqt4_add_dbus_unit_test _fancyName _name) - -macro(_tpqt4_add_check_targets _fancyName _name _runnerScript) - set_tests_properties(${_fancyName} - PROPERTIES - FAIL_REGULAR_EXPRESSION "^FAIL!") - - # Standard check target - add_custom_target(check-${_fancyName} ${SH} ${_runnerScript} ${ARGN}) - add_dependencies(check-${_fancyName} test-${_name}) - - # Lcov target - add_dependencies(lcov-check test-${_name}) - - # Valgrind target - add_custom_target(check-valgrind-${_fancyName}) - add_dependencies(check-valgrind-${_fancyName} test-${_name}) - - add_custom_command( - TARGET check-valgrind-${_fancyName} - COMMAND G_SLICE=always-malloc ${SH} ${_runnerScript} /usr/bin/valgrind - --tool=memcheck - --leak-check=full - --leak-resolution=high - --child-silent-after-fork=yes - --num-callers=20 - --gen-suppressions=all - --log-file=${CMAKE_CURRENT_BINARY_DIR}/test-${_fancyName}.memcheck.log - --suppressions=${CMAKE_SOURCE_DIR}/tools/telepathy-qt4.supp - --suppressions=${CMAKE_SOURCE_DIR}/tools/telepathy-glib.supp - ${ARGN} - WORKING_DIRECTORY - ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Running valgrind on test \"${_fancyName}\"") - add_dependencies(check-valgrind check-valgrind-${_fancyName}) - - # Callgrind target - add_custom_target(check-callgrind-${_fancyName}) - add_dependencies(check-callgrind-${_fancyName} test-${_name}) - add_custom_command( - TARGET check-callgrind-${_fancyName} - COMMAND ${SH} ${_runnerScript} /usr/bin/valgrind - --tool=callgrind - --dump-instr=yes - --log-file=${CMAKE_CURRENT_BINARY_DIR}/test-${_fancyName}.callgrind.log - --callgrind-out-file=${CMAKE_CURRENT_BINARY_DIR}/test-${_fancyName}.callgrind.out - ${ARGN} - WORKING_DIRECTORY - ${CMAKE_CURRENT_BINARY_DIR} - COMMENT - "Running callgrind on test \"${_fancyName}\"") - add_dependencies(check-callgrind check-callgrind-${_fancyName}) -endmacro(_tpqt4_add_check_targets _fancyName _name) - -function(tpqt4_setup_dbus_test_environment) - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/runDbusTest.sh " -${test_environment} -sh ${CMAKE_SOURCE_DIR}/tools/with-session-bus.sh \\ - --config-file=${CMAKE_BINARY_DIR}/tests/dbus-1/session.conf -- $@ -") -endfunction(tpqt4_setup_dbus_test_environment) diff --git a/cmake/modules/TpQtMacros.cmake b/cmake/modules/TpQtMacros.cmake new file mode 100644 index 0000000..35cf8d4 --- /dev/null +++ b/cmake/modules/TpQtMacros.cmake @@ -0,0 +1,492 @@ +# - Common macros for Tp-Qt + +# Copyright (c) 2010, Collabora Ltd. +# +# Redistribution and use is allowed according to the terms of the BSD license. + +# +# These macros/functions are not exported - they are meant for internal usage into Telepathy-Qt's build system. +# +# Preamble: How dynamic generators are handled with the CMake build system. +# Telepathy-Qt strongly relies upon lots of files generated at build time through some python programs, found +# in tools/. To avoid developers the struggle of handling those manually, a set of convenience macros have been +# created to handle them with the correct dependencies. Each of those macros takes a target name as a first argument +# and creates a target with that exact name. In a similar fashion, in the last argument you can specify a list +# of targets the generated target will depend on. This way, you can handle transparently dependencies between +# generated files, while the dirty stuff is done for you in the background. +# +# macro TPQT_EXTRACT_DEPENDS (tpqt_other tpqt_depends) +# Internal macro used to extract arguments from ARGN +# +# function TPQT_CREATE_MOC_COMMAND_TARGET_DEPS(inputfile outputfile moc_flags moc_options target_dependencies ...) +# This function behaves exactly like qt_create_moc_command, but creates a custom target for the +# moc file generation, allowing to specify a list of targets the generated moc target will depend on. +# Just like qt_create_moc_command, it is an internal macro and it's not meant to be used explicitely. +# +# function TPQT_GENERATE_MOC_I(inputfile outputfile) +# This function behaves exactly like qt_generate_moc, but it generates moc files with the -i option, +# which disables the generation of an #include directive. This macro has to be used always when building +# Tp-Qt internals due to the internal header files restrictions. +# +# function TPQT_GENERATE_MOC_I_TARGET_DEPS(inputfile outputfile target_dependencies ...) +# This function acts as an overload to QT_GENERATE_MOC_I: it does exactly the same thing, but creates a +# custom target for the moc file generation, and adds target_dependencies to it as dependencies. +# +# function TPQT_GENERATE_MOCS(sourcefile ...) +# Generates mocs from a list of header files. You usually want to use this function when building tests +# or examples. Please remember the list of the header files passed to this function MUST be added to the +# target's sources. +# +# function TPQT_CLIENT_GENERATOR(spec group pretty_include namespace [arguments] [DEPENDS dependencies ...]) +# This function takes care of invoking qt-client-gen.py with the correct arguments, which generates +# headers out of specs. spec is the name of the spec headers will be generated from, group represents +# the spec's group, pretty_include is the name of the capitalized header (for example ClientGenerator), +# namespace is the C++ namespace the generated header will belong to. This function also accepts +# as an optional last argument a list of additional command line arguments which will be passed to +# qt-client-gen.py upon execution. After issuing DEPENDS in the last argument you can pass a list of targets +# the generated target will depend on. +# +# function TPQT_FUTURE_CLIENT_GENERATOR(spec namespace [arguments] [DEPENDS dependencies ...]) +# Same as tpqt_client_generator, but for future interfaces +# +# function TPQT_SERVICE_GENERATOR(spec group pretty_include namespace [arguments] [DEPENDS dependencies ...]) +# This function takes care of invoking qt-svc-gen.py with the correct arguments, which generates +# headers out of specs. spec is the name of the spec headers will be generated from, group represents +# the spec's group, pretty_include is the name of the capitalized header (for example ServiceGenerator), +# namespace is the C++ namespace the generated header will belong to. This function also accepts +# as an optional last argument a list of additional command line arguments which will be passed to +# qt-svc-gen.py upon execution. After issuing DEPENDS in the last argument you can pass a list of targets +# the generated target will depend on. +# +# function TPQT_GENERATE_MANAGER_FILE(MANAGER_FILE OUTPUT_FILENAME DEPEND_FILENAME) +# This function takes care of invoking manager-file.py with the correct arguments. The first argument is the +# path to the manager-file.py file which should be used, the second is the output filename of the manager, +# and the third is the path to the file which depends on the generated manager file. +# +# function TPQT_XINCLUDATOR (TARGET_NAME INPUT_FILE OUTPUT_FILE [additional_arguments ...] [DEPENDS dependencies ...]) +# This function takes care of invoking xincludator.py with the correct arguments. TARGET_NAME is the name of +# the generated target (see preamble), INPUT_FILE is the input spec file, OUTPUT_FILE is the filename +# the generated file will be saved to. This function also accepts as an optional last argument a list of +# additional command line arguments which will be passed to xincludator upon execution. +# After issuing DEPENDS in the last argument you can pass a list of targets the generated target will depend on. +# +# function TPQT_CONSTANTS_GEN (TARGET_NAME SPEC_XML OUTPUT_FILE [additional_arguments ...] [DEPENDS dependencies ...]) +# This function takes care of invoking qt-constants-gen.py with the correct arguments. TARGET_NAME is the name of +# the generated target (see preamble), SPEC_XML is the spec input file, OUTPUT_FILE is the filename +# the generated file will be saved to. This function also accepts as an optional last argument a list of +# additional command line arguments which will be passed to qt-constants-gen.py upon execution. +# After issuing DEPENDS in the last argument you can pass a list of targets the generated target will depend on. +# +# function TPQT_TYPES_GEN (TARGET_NAME SPEC_XML OUTFILE_DECL OUTFILE_IMPL NAMESPACE +# REAL_INCLUDE PRETTY_INCLUDE [additional_arguments ...] [DEPENDS dependencies ...]) +# This function takes care of invoking qt-types-gen.py with the correct arguments. TARGET_NAME is the name of +# the generated target (see preamble), SPEC_XML is the input spec file, OUTFILE_DECL is the filename +# the header of the generated file will be saved to, OUTFILE_IMPL is the filename the implementation of the +# generated file will be saved to, NAMESPACE is the C++ namespace the generated header will belong to, +# REAL_INCLUDE is the real include file you want to use, PRETTY_INCLUDE is the name of the capitalized header +# (for example ClientGenerator). +# This function also accepts as an optional last argument a list of additional command line arguments +# which will be passed to qt-constants-gen.py upon execution. +# After issuing DEPENDS in the last argument you can pass a list of targets the generated target will depend on. +# +# macro TPQT_ADD_GENERIC_UNIT_TEST (fancyName name [libraries ...]) +# This macro takes care of building and adding a generic unit test to the automatic CTest suite. The requirement +# for using this macro is to have the unit test contained in a single source file named ${name}.cpp. fancyName will +# be used as the test and target's name, and you can specify as a third and optional argument a set of additional +# libraries the target will link to. +# +# macro TPQT_ADD_DBUS_UNIT_TEST (fancyName name [libraries ...]) +# This macro takes care of building and adding an unit test requiring DBus emulation to the automatic +# CTest suite. The requirement for using this macro is to have the unit test contained in a single +# source file named ${name}.cpp. fancyName will be used as the test and target's name, and you can specify as a third +# and optional argument a set of additional libraries the target will link to. Please remember that you need to +# set up the DBus environment by calling TPQT_SETUP_DBUS_TEST_ENVIRONMENT BEFORE you call this macro. +# +# macro _TPQT_ADD_CHECK_TARGETS (fancyName name command [args]) +# This is an internal macro which is meant to be used by TPQT_ADD_DBUS_UNIT_TEST and TPQT_ADD_GENERIC_UNIT_TEST. +# It takes care of generating a check target for each test method available (currently normal execution, valgrind and +# callgrind). This macro accepts the same arguments as the add test macros, but accepts a command and a list of +# arguments for running the test instead of the link libraries. However, you are not meant to call this macro from +# your CMakeLists.txt files. +# +# function TPQT_SETUP_DBUS_TEST_ENVIRONMENT () +# This function MUST be called before calling TPQT_ADD_DBUS_UNIT_TEST. It takes care of preparing the test +# environment for DBus tests and generating the needed files. +# +# macro MAKE_INSTALL_PATH_ABSOLUTE (out in) +# This macro makes the path given in the "in" variable absolute (or leaves it unchanged +# if it's absolute already) by prefixing it with TELEPATHY_QT_INSTALL_DIR, +# and returns the absolute path in the "out" variable. This macro is mainly used for +# generating *Config.cmake files. +# +# + +MACRO (TPQT_EXTRACT_DEPENDS _tpqt_other _tpqt_depends) + SET(${_tpqt_other}) + SET(${_tpqt_depends}) + SET(_TPQT_DOING_DEPENDS FALSE) + FOREACH(_currentArg ${ARGN}) + IF ("${_currentArg}" STREQUAL "DEPENDS") + SET(_TPQT_DOING_DEPENDS TRUE) + ELSE ("${_currentArg}" STREQUAL "DEPENDS") + IF(_TPQT_DOING_DEPENDS) + LIST(APPEND ${_tpqt_depends} "${_currentArg}") + ELSE(_TPQT_DOING_DEPENDS) + LIST(APPEND ${_tpqt_other} "${_currentArg}") + ENDIF(_TPQT_DOING_DEPENDS) + ENDIF ("${_currentArg}" STREQUAL "DEPENDS") + ENDFOREACH(_currentArg) +ENDMACRO (TPQT_EXTRACT_DEPENDS) + +# helper function to set up a moc rule +FUNCTION (TPQT_CREATE_MOC_COMMAND_TARGET_DEPS infile outfile moc_flags moc_options) + # For Windows, create a parameters file to work around command line length limit + GET_FILENAME_COMPONENT(_moc_outfile_name "${outfile}" NAME) + IF (WIN32) + # Pass the parameters in a file. Set the working directory to + # be that containing the parameters file and reference it by + # just the file name. This is necessary because the moc tool on + # MinGW builds does not seem to handle spaces in the path to the + # file given with the @ syntax. + GET_FILENAME_COMPONENT(_moc_outfile_dir "${outfile}" PATH) + IF(_moc_outfile_dir) + SET(_moc_working_dir WORKING_DIRECTORY ${_moc_outfile_dir}) + ENDIF(_moc_outfile_dir) + SET (_moc_parameters_file ${outfile}_parameters) + SET (_moc_parameters ${moc_flags} ${moc_options} -o "${outfile}" "${infile}") + FILE (REMOVE ${_moc_parameters_file}) + FOREACH(arg ${_moc_parameters}) + FILE (APPEND ${_moc_parameters_file} "${arg}\n") + ENDFOREACH(arg) + ADD_CUSTOM_COMMAND(OUTPUT ${outfile} + COMMAND ${QT_MOC_EXECUTABLE} @${_moc_outfile_name}_parameters + DEPENDS ${infile} + ${_moc_working_dir} + VERBATIM) + ELSE (WIN32) + ADD_CUSTOM_COMMAND(OUTPUT ${outfile} + COMMAND ${QT_MOC_EXECUTABLE} + ARGS ${moc_flags} ${moc_options} -o ${outfile} ${infile} + DEPENDS ${infile}) + ENDIF (WIN32) + + add_custom_target(moc-${_moc_outfile_name} DEPENDS ${outfile}) + add_dependencies(moc-${_moc_outfile_name} ${ARGN}) +ENDFUNCTION (TPQT_CREATE_MOC_COMMAND_TARGET_DEPS) + +# add the -i option to QT_GENERATE_MOC +function(TPQT_GENERATE_MOC_I infile outfile) + qt5_get_moc_flags(moc_flags) + get_filename_component(abs_infile ${infile} ABSOLUTE) + qt5_create_moc_command(${abs_infile} ${outfile} "${moc_flags}" "-i") + set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC TRUE) # dont run automoc on this file +endfunction(TPQT_GENERATE_MOC_I) + +# same as tpqt_generate_moc_i, but lets the caller specify a list of targets which the mocs should depend on +function(TPQT_GENERATE_MOC_I_TARGET_DEPS infile outfile) + qt5_get_moc_flags(moc_flags) + get_filename_component(abs_infile ${infile} ABSOLUTE) + tpqt_create_moc_command_target_deps(${abs_infile} ${outfile} "${moc_flags}" "-i" ${ARGN}) + set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC TRUE) # dont run automoc on this file +endfunction(TPQT_GENERATE_MOC_I_TARGET_DEPS) + +# generates mocs for the passed list. The list should be added to the target's sources +function(tpqt_generate_mocs) + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/_gen" ) + foreach(moc_src ${ARGN}) + string(REPLACE ".h" ".moc.hpp" generated_file ${moc_src}) + tpqt_generate_moc_i(${CMAKE_CURRENT_SOURCE_DIR}/${moc_src} ${CMAKE_CURRENT_BINARY_DIR}/_gen/${generated_file}) + set_property(SOURCE ${moc_src} APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_gen/${generated_file}) + endforeach(moc_src ${ARGN}) +endfunction(tpqt_generate_mocs) + +function(tpqt_client_generator spec_xml spec group real_include pretty_include namespace types_namespace must_define visibility) + tpqt_extract_depends(client_generator_args client_generator_depends ${ARGN}) + set(ARGS + ${CMAKE_SOURCE_DIR}/tools/qt-client-gen.py + --group=${group} + --namespace=${namespace} + --typesnamespace=${types_namespace} + --headerfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}.h + --implfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}-body.hpp + --realinclude=${real_include} + --prettyinclude=${pretty_include} + --specxml=${spec_xml} + --ifacexml=${CMAKE_CURRENT_BINARY_DIR}/_gen/spec-${spec}.xml + --extraincludes=${TYPES_INCLUDE} + --must-define=${must_define} + --visibility=${visibility} + ${client_generator_args}) + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}.h ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}-body.hpp + COMMAND ${PYTHON_EXECUTABLE} + ARGS ${ARGS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + + DEPENDS ${CMAKE_SOURCE_DIR}/tools/libqtcodegen.py + ${CMAKE_SOURCE_DIR}/tools/qt-client-gen.py) + add_custom_target(generate_cli-${spec}-body DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}-body.hpp) + + if (client_generator_depends) + add_dependencies(generate_cli-${spec}-body ${client_generator_depends}) + endif (client_generator_depends) + + tpqt_generate_moc_i_target_deps(${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}.h + ${CMAKE_CURRENT_BINARY_DIR}/_gen/cli-${spec}.moc.hpp + "generate_cli-${spec}-body") +endfunction(tpqt_client_generator spec_xml spec group real_include pretty_include namespace types_namespace must_define visibility) + +function(tpqt_future_client_generator spec namespace) + tpqt_extract_depends(future_client_generator_args future_client_generator_depends ${ARGN}) + set(ARGS + ${CMAKE_SOURCE_DIR}/tools/qt-client-gen.py + --namespace=${namespace} + --typesnamespace=TpFuture + --headerfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.h + --implfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}-body.hpp + --realinclude=TelepathyQt/future-internal.h + --prettyinclude=TelepathyQt/future-internal.h + --specxml=${CMAKE_CURRENT_BINARY_DIR}/_gen/future-spec.xml + --ifacexml=${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.xml + --extraincludes=${TYPES_INCLUDE} + --extraincludes='' + --extraincludes='' + --visibility=TP_QT_NO_EXPORT + ${future_client_generator_args}) + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.h ${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}-body.hpp + COMMAND ${PYTHON_EXECUTABLE} + ARGS ${ARGS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + + DEPENDS ${CMAKE_SOURCE_DIR}/tools/libqtcodegen.py + ${CMAKE_SOURCE_DIR}/tools/qt-client-gen.py) + add_custom_target(generate_future-${spec}-body DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}-body.hpp) + add_dependencies(all-generated-sources generate_future-${spec}-body) + + if (future_client_generator_depends) + add_dependencies(generate_future-${spec}-body ${future_client_generator_depends}) + endif (future_client_generator_depends) + + tpqt_generate_moc_i_target_deps(${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.h + ${CMAKE_CURRENT_BINARY_DIR}/_gen/future-${spec}.moc.hpp + "generate_future-${spec}-body") +endfunction(tpqt_future_client_generator spec namespace) + +function(tpqt_service_generator spec group pretty_include namespace) + tpqt_extract_depends(service_generator_args service_generator_depends ${ARGN}) + string(REPLACE "svc-" "" spec ${spec}) + set(ARGS + ${CMAKE_SOURCE_DIR}/tools/qt-svc-gen.py + --group=${group} + --namespace=${namespace} + --typesnamespace=Tp + --headerfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.h + --implfile=${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.cpp + --realinclude=TelepathyQt/_gen/svc-${spec}.h + --mocinclude=TelepathyQt/_gen/svc-${spec}.moc.hpp + --specxml=${CMAKE_CURRENT_BINARY_DIR}/_gen/stable-spec.xml + --ifacexml=${CMAKE_CURRENT_BINARY_DIR}/_gen/spec-svc-${spec}.xml + --visibility=TP_QT_EXPORT + ${service_generator_args}) + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.h ${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.cpp + COMMAND ${PYTHON_EXECUTABLE} + ARGS ${ARGS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + + DEPENDS ${CMAKE_SOURCE_DIR}/tools/libqtcodegen.py + ${CMAKE_SOURCE_DIR}/tools/qt-svc-gen.py) + add_custom_target(generate_service-${spec}-body DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.cpp) + add_dependencies(all-generated-service-sources generate_service-${spec}-body) + + if (service_generator_depends) + add_dependencies(generate_service-${spec}-body ${service_generator_depends}) + endif (service_generator_depends) + + tpqt_generate_moc_i_target_deps(${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.h + ${CMAKE_CURRENT_BINARY_DIR}/_gen/svc-${spec}.moc.hpp + "generate_service-${spec}-body") +endfunction(tpqt_service_generator spec group pretty_include namespace) + +# This function is used for generating CM in various examples +function(tpqt_generate_manager_file MANAGER_FILE OUTPUT_FILENAME DEPEND_FILENAME) + # make_directory is required, otherwise the command won't work!! + make_directory(${CMAKE_CURRENT_BINARY_DIR}/_gen) + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_gen/param-spec-struct.h + ${CMAKE_CURRENT_BINARY_DIR}/_gen/${OUTPUT_FILENAME} + + COMMAND ${PYTHON_EXECUTABLE} + + ARGS ${CMAKE_SOURCE_DIR}/tools/manager-file.py + ${MANAGER_FILE} + _gen + + DEPENDS ${CMAKE_SOURCE_DIR}/tools/manager-file.py) + + set_source_files_properties(${DEPEND_FILENAME} + PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_gen/param-spec-struct.h) +endfunction(tpqt_generate_manager_file MANAGER_FILE) + +function(tpqt_xincludator _TARGET_NAME _INPUT_FILE _OUTPUT_FILE) + tpqt_extract_depends(xincludator_gen_args xincludator_gen_depends ${ARGN}) + # Gather all .xml files in TelepathyQt and spec/ and make this target depend on those + file(GLOB depends_xml_files ${CMAKE_SOURCE_DIR}/TelepathyQt/*.xml ${CMAKE_SOURCE_DIR}/spec/*.xml) + + add_custom_command(OUTPUT ${_OUTPUT_FILE} + + COMMAND ${PYTHON_EXECUTABLE} + + ARGS ${CMAKE_SOURCE_DIR}/tools/xincludator.py + ${_INPUT_FILE} + ${xincludator_gen_args} + > ${_OUTPUT_FILE} + + DEPENDS ${CMAKE_SOURCE_DIR}/tools/xincludator.py + ${_INPUT_FILE} ${depends_xml_files}) + add_custom_target(${_TARGET_NAME} DEPENDS ${_OUTPUT_FILE}) + + if (xincludator_gen_depends) + add_dependencies(${_TARGET_NAME} ${xincludator_gen_depends}) + endif (xincludator_gen_depends) +endfunction(tpqt_xincludator _TARGET_NAME _INPUT_FILE _OUTPUT_FILE) + +function(tpqt_constants_gen _TARGET_NAME _SPEC_XML _OUTFILE) + tpqt_extract_depends(constants_gen_args constants_gen_depends ${ARGN}) + # Gather all .xml files in TelepathyQt and spec/ and make this target depend on those + file(GLOB depends_xml_files ${CMAKE_SOURCE_DIR}/TelepathyQt/*.xml ${CMAKE_SOURCE_DIR}/spec/*.xml) + + add_custom_command(OUTPUT ${_OUTFILE} + + COMMAND ${PYTHON_EXECUTABLE} + + ARGS ${CMAKE_SOURCE_DIR}/tools/qt-constants-gen.py + ${constants_gen_args} + --specxml=${_SPEC_XML} + > ${_OUTFILE} + + DEPENDS ${CMAKE_SOURCE_DIR}/tools/libqtcodegen.py + ${CMAKE_SOURCE_DIR}/tools/qt-constants-gen.py + ${_SPEC_XML} ${depends_xml_files}) + add_custom_target(${_TARGET_NAME} DEPENDS ${_OUTFILE}) + add_dependencies(all-generated-sources ${_TARGET_NAME}) + + if (constants_gen_depends) + add_dependencies(${_TARGET_NAME} ${constants_gen_depends}) + endif (constants_gen_depends) +endfunction (tpqt_constants_gen _TARGET_NAME _SPEC_XML _OUTFILE) + +function(tpqt_types_gen _TARGET_NAME _SPEC_XML _OUTFILE_DECL _OUTFILE_IMPL _NAMESPACE _REALINCLUDE _PRETTYINCLUDE) + tpqt_extract_depends(types_gen_args types_gen_depends ${ARGN}) + # Gather all .xml files in TelepathyQt and spec/ and make this target depend on those + file(GLOB depends_xml_files ${CMAKE_SOURCE_DIR}/TelepathyQt/*.xml ${CMAKE_SOURCE_DIR}/spec/*.xml) + + add_custom_command(OUTPUT ${_OUTFILE_DECL} ${_OUTFILE_IMPL} + COMMAND ${PYTHON_EXECUTABLE} + ARGS ${CMAKE_SOURCE_DIR}/tools/qt-types-gen.py + --namespace=${_NAMESPACE} + --declfile=${_OUTFILE_DECL} + --implfile=${_OUTFILE_IMPL} + --realinclude=${_REALINCLUDE} + --prettyinclude=${_PRETTYINCLUDE} + ${types_gen_args} + --specxml=${_SPEC_XML} + + DEPENDS ${CMAKE_SOURCE_DIR}/tools/libqtcodegen.py + ${CMAKE_SOURCE_DIR}/tools/qt-types-gen.py + ${_SPEC_XML} ${depends_xml_files}) + add_custom_target(${_TARGET_NAME} DEPENDS ${_OUTFILE_IMPL}) + add_dependencies(all-generated-sources ${_TARGET_NAME}) + + if (types_gen_depends) + add_dependencies(${_TARGET_NAME} ${types_gen_depends}) + endif (types_gen_depends) +endfunction(tpqt_types_gen _TARGET_NAME _SPEC_XML _OUTFILE_DECL _OUTFILE_IMPL _NAMESPACE _REALINCLUDE _PRETTYINCLUDE) + +macro(tpqt_add_generic_unit_test _fancyName _name) + tpqt_generate_moc_i(${_name}.cpp ${CMAKE_CURRENT_BINARY_DIR}/_gen/${_name}.cpp.moc.hpp) + add_executable(test-${_name} ${_name}.cpp ${CMAKE_CURRENT_BINARY_DIR}/_gen/${_name}.cpp.moc.hpp) + target_link_libraries(test-${_name} ${Qt5Core_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5Xml_LIBRARIES} ${Qt5Test_LIBRARIES} telepathy-qt${Qt5Core_VERSION_MAJOR} tp-qt-tests ${TP_QT_EXECUTABLE_LINKER_FLAGS} ${ARGN}) + add_test(${_fancyName} ${SH} ${CMAKE_CURRENT_BINARY_DIR}/runGenericTest.sh ${CMAKE_CURRENT_BINARY_DIR}/test-${_name}) + list(APPEND _telepathy_qt_test_cases test-${_name}) + + # Valgrind and Callgrind targets + _tpqt_add_check_targets(${_fancyName} ${_name} ${CMAKE_CURRENT_BINARY_DIR}/runGenericTest.sh ${CMAKE_CURRENT_BINARY_DIR}/test-${_name}) +endmacro(tpqt_add_generic_unit_test _fancyName _name) + +macro(tpqt_add_dbus_unit_test _fancyName _name) + tpqt_generate_moc_i(${_name}.cpp ${CMAKE_CURRENT_BINARY_DIR}/_gen/${_name}.cpp.moc.hpp) + add_executable(test-${_name} ${_name}.cpp ${CMAKE_CURRENT_BINARY_DIR}/_gen/${_name}.cpp.moc.hpp) + target_link_libraries(test-${_name} ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5Xml_LIBRARIES} ${Qt5Test_LIBRARIES} telepathy-qt${Qt5Core_VERSION_MAJOR} tp-qt-tests ${TP_QT_EXECUTABLE_LINKER_FLAGS} ${ARGN}) + set(with_session_bus ${CMAKE_CURRENT_BINARY_DIR}/runDbusTest.sh) + add_test(${_fancyName} ${SH} ${with_session_bus} ${CMAKE_CURRENT_BINARY_DIR}/test-${_name}) + list(APPEND _telepathy_qt_test_cases test-${_name}) + + # Valgrind and Callgrind targets + _tpqt_add_check_targets(${_fancyName} ${_name} ${with_session_bus} ${CMAKE_CURRENT_BINARY_DIR}/test-${_name}) +endmacro(tpqt_add_dbus_unit_test _fancyName _name) + +macro(_tpqt_add_check_targets _fancyName _name _runnerScript) + set_tests_properties(${_fancyName} + PROPERTIES + FAIL_REGULAR_EXPRESSION "^FAIL!") + + # Standard check target + add_custom_target(check-${_fancyName} ${SH} ${_runnerScript} ${ARGN}) + add_dependencies(check-${_fancyName} test-${_name}) + + # Lcov target + add_dependencies(lcov-check test-${_name}) + + # Valgrind target + add_custom_target(check-valgrind-${_fancyName}) + add_dependencies(check-valgrind-${_fancyName} test-${_name}) + + add_custom_command( + TARGET check-valgrind-${_fancyName} + COMMAND G_SLICE=always-malloc ${SH} ${_runnerScript} /usr/bin/valgrind + --tool=memcheck + --leak-check=full + --leak-resolution=high + --child-silent-after-fork=yes + --num-callers=20 + --gen-suppressions=all + --log-file=${CMAKE_CURRENT_BINARY_DIR}/test-${_fancyName}.memcheck.log + --suppressions=${CMAKE_SOURCE_DIR}/tools/tp-qt-tests.supp + --suppressions=${CMAKE_SOURCE_DIR}/tools/telepathy-glib.supp + ${ARGN} + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Running valgrind on test \"${_fancyName}\"") + add_dependencies(check-valgrind check-valgrind-${_fancyName}) + + # Callgrind target + add_custom_target(check-callgrind-${_fancyName}) + add_dependencies(check-callgrind-${_fancyName} test-${_name}) + add_custom_command( + TARGET check-callgrind-${_fancyName} + COMMAND ${SH} ${_runnerScript} /usr/bin/valgrind + --tool=callgrind + --dump-instr=yes + --log-file=${CMAKE_CURRENT_BINARY_DIR}/test-${_fancyName}.callgrind.log + --callgrind-out-file=${CMAKE_CURRENT_BINARY_DIR}/test-${_fancyName}.callgrind.out + ${ARGN} + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR} + COMMENT + "Running callgrind on test \"${_fancyName}\"") + add_dependencies(check-callgrind check-callgrind-${_fancyName}) +endmacro(_tpqt_add_check_targets _fancyName _name) + +function(tpqt_setup_dbus_test_environment) + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/runDbusTest.sh " +${test_environment} +sh ${CMAKE_SOURCE_DIR}/tools/with-session-bus.sh \\ + --config-file=${CMAKE_BINARY_DIR}/tests/dbus-1/session.conf -- $@ +") +endfunction(tpqt_setup_dbus_test_environment) + +macro(make_install_path_absolute out in) + if (IS_ABSOLUTE "${in}") + set(${out} "${in}") + else (IS_ABSOLUTE "${in}") + set(${out} "\${TELEPATHY_QT${Qt5Core_VERSION_MAJOR}_INSTALL_DIR}/${in}") + endif (IS_ABSOLUTE "${in}") +endmacro(make_install_path_absolute out in) diff --git a/codegen/CMakeLists.txt b/codegen/CMakeLists.txt index bcf3ffe..e7cd8f7 100644 --- a/codegen/CMakeLists.txt +++ b/codegen/CMakeLists.txt @@ -20,4 +20,4 @@ if (MSVC) endif() add_executable(codegen ${FLEX_analyzer_OUTPUTS} ${BISON_parser_OUTPUTS} generator.cpp) -target_link_libraries(codegen ${QT_QTCORE_LIBRARY}) +target_link_libraries(codegen ${Qt5Core_LIBRARIES}) diff --git a/doxygen.cfg.in b/doxygen.cfg.in index b464b26..f61982e 100644 --- a/doxygen.cfg.in +++ b/doxygen.cfg.in @@ -535,7 +535,7 @@ WARN_LOGFILE = doxygen.log # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = ${abs_top_srcdir}/TelepathyLoggerQt4 ${abs_top_builddir}/TelepathyLoggerQt4 +INPUT = ${abs_top_srcdir}/TelepathyLoggerQt ${abs_top_builddir}/TelepathyLoggerQt # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is @@ -1431,12 +1431,12 @@ DOT_CLEANUP = YES SEARCHENGINE = NO GENERATE_QHP = ${GENERATE_QHP} -QHP_NAMESPACE = "org.freedesktop.Telepathy.Logger.Qt4" +QHP_NAMESPACE = "org.freedesktop.Telepathy.Logger.Qt5" QHP_VIRTUAL_FOLDER = "${PROJECT_NAME}-${PACKAGE_VERSION}" -QCH_FILE = ${abs_top_builddir}/doc/help/telepathy-logger-qt4.qch +QCH_FILE = ${abs_top_builddir}/doc/help/telepathy-logger-qt5.qch QHG_LOCATION = ${QHELPGENERATOR_EXECUTABLE}" -### TelepathyLoggerQt4 Settings +### TelepathyLoggerQt Settings ALIASES = \ "intern=\parInternal use only." \ "reimp=\parReimplemented from superclass." \ @@ -1448,7 +1448,7 @@ ALIASES = \ "faq=\xrefitem FAQ \"F.A.Q.\" \"F.A.Q.\"" \ "authors=\xrefitem authors \"Author(s)\" \"Authors\"" \ "maintainers=\xrefitem maintainers \"Maintainer(s)\" \"Maintainers\"" \ - "glossary=\xrefitem glossary \"TelepathyLoggerQt4 Glossary\" \"TelepathyLoggerQt4 Glossary\"" \ + "glossary=\xrefitem glossary \"TelepathyLoggerQt Glossary\" \"TelepathyLoggerQt Glossary\"" \ "acronym=\b "\ "licenses=\xrefitem licenses \"License(s)\" \"Licenses\"" \ "short=@brief "\ @@ -1464,7 +1464,7 @@ ALIASES = \ "qpl=QPL" PREDEFINED = DOXYGEN_SHOULD_SKIP_THIS \ - TELEPATHY_LOGGER_QT4_EXPORT="" \ - TELEPATHY_LOGGER_QT4_NO_EXPORT="" \ + TELEPATHY_LOGGER_QT_EXPORT="" \ + TELEPATHY_LOGGER_QT_NO_EXPORT="" \ Q_SLOTS="slots" \ Q_SIGNALS="signals" diff --git a/spec/errors.xml b/spec/errors.xml index eccbd09..f890803 100644 --- a/spec/errors.xml +++ b/spec/errors.xml @@ -16,11 +16,11 @@ indicate specialized failure conditions. For better interoperability, if a suitable Telepathy error exists, it should be preferred.

-

The namespace org.freedesktop.Telepathy.Qt4.Error. - is reserved for use by the D-Bus client implementation in telepathy-qt4, +

The namespace org.freedesktop.Telepathy.Qt5.Error. + is reserved for use by the D-Bus client implementation in telepathy-qt5, which uses it to represent certain error situations that did not involve a D-Bus ERROR message. These errors are defined and documented as part of - telepathy-qt4's C++ API, and should not be used on D-Bus.

+ telepathy-qt5's C++ API, and should not be used on D-Bus.

@@ -539,7 +539,7 @@ also analogous to Media_Stream_Error_Invalid_CM_Behavior, TP_DBUS_ERROR_INCONSISTENT in telepathy-glib, and - TELEPATHY_QT4_ERROR_INCONSISTENT in telepathy-qt4. + TELEPATHY_QT_ERROR_INCONSISTENT in telepathy-qt5. diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7d6e9b3..28abfe3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,4 +8,4 @@ link_directories (${PROJECT_BINARY_DIR}/QTpLogger) add_executable (QTpLogger-test dummy-main.cpp) -target_link_libraries (QTpLogger-test telepathy-logger-qt4 ${QT_LIBRARIES}) +target_link_libraries (QTpLogger-test telepathy-logger-qt${Qt5Core_VERSION_MAJOR} ${QT_LIBRARIES}) diff --git a/tests/dummy-main.cpp b/tests/dummy-main.cpp index 484f139..171c9d4 100644 --- a/tests/dummy-main.cpp +++ b/tests/dummy-main.cpp @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -//#include +//#include #include #include diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 36d70a0..c22b89b 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -62,10 +62,10 @@ set(toolchain_files glib-signals-marshal-gen.py libtpcodegen.py libglibcodegen.py - libqt4codegen.py - qt4-client-gen.py - qt4-constants-gen.py - qt4-types-gen.py + libqtcodegen.py + qt-client-gen.py + qt-constants-gen.py + qt-types-gen.py manager-file.py with-session-bus.sh xincludator.py @@ -103,11 +103,11 @@ add_custom_target(maintainer-update-from-telepathy-glib ${SH} ${CMAKE_CURRENT_BI file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/_gen") -include (${QT_USE_FILE}) +#include (${QT_USE_FILE}) include_directories (${PROJECT_SOURCE_DIR}) -link_directories (${PROJECT_BINARY_DIR}/TelepathyLoggerQt4) +link_directories (${PROJECT_BINARY_DIR}/TelepathyLoggerQt) # Headers file moc will be run on set(tpl_tool_MOC_SRCS tpl-tool.h) @@ -118,15 +118,15 @@ set(tpl_tool_generated_specs_mocs tpl-tool.h) foreach(moc_src ${tpl_tool_MOC_SRCS}) set(generated_file _gen/${moc_src}) string(REPLACE ".h" ".moc.hpp" generated_file ${generated_file}) - tpqt4_generate_moc_i_target_deps(${CMAKE_CURRENT_SOURCE_DIR}/${moc_src} ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} + tpqt_generate_moc_i_target_deps(${CMAKE_CURRENT_SOURCE_DIR}/${moc_src} ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} ${tpl_tool_generated_specs_mocs}) - list(APPEND telepathy_logger_qt4_SRCS ${CMAKE_CURRENT_BINARY_DIR}/${generated_file}) + list(APPEND telepathy_logger_qt_SRCS ${CMAKE_CURRENT_BINARY_DIR}/${generated_file}) string(REPLACE ".h" ".moc.hpp" moc_src ${moc_src}) - add_dependencies(telepathy-logger-qt4 "moc-${moc_src}") -endforeach(moc_src ${telepathy_logger_qt4_MOC_SRCS}) + add_dependencies(telepathy-logger-qt${Qt5Core_VERSION_MAJOR} "moc-${moc_src}") +endforeach(moc_src ${telepathy_logger_qt_MOC_SRCS}) add_executable (tpl-tool tpl-tool.cpp) add_definitions (-DQT_NO_KEYWORDS) -target_link_libraries (tpl-tool telepathy-logger-qt4 ${QT_LIBRARIES}) +target_link_libraries (tpl-tool telepathy-logger-qt${Qt5Core_VERSION_MAJOR} ${Qt5Core_LIBRARIES}) diff --git a/tools/libqt4codegen.py b/tools/libqt4codegen.py index 8cf1889..9ccb860 100644 --- a/tools/libqt4codegen.py +++ b/tools/libqt4codegen.py @@ -1,6 +1,6 @@ -"""Library code for Qt4 D-Bus-related code generation. +"""Library code for Qt D-Bus-related code generation. -The master copy of this library is in the telepathy-qt4 repository - +The master copy of this library is in the telepathy-qt repository - please make any changes there. """ @@ -21,12 +21,26 @@ please make any changes there. # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -from sys import maxint +from sys import maxint, stderr import re from libtpcodegen import get_by_path, get_descendant_text, NS_TP, xml_escape - -class _Qt4TypeBinding: +class Xzibit(Exception): + def __init__(self, parent, child): + self.parent = parent + self.child = child + + def __str__(self): + print """ + Nested <%s>s are forbidden. + Parent: + %s... + Child: + %s... + """ % (self.parent.nodeName, self.parent.toxml()[:100], + self.child.toxml()[:100]) + +class _QtTypeBinding: def __init__(self, val, inarg, outarg, array_val, custom_type, array_of, array_depth=None): self.val = val @@ -44,6 +58,88 @@ class _Qt4TypeBinding: else: assert not array_val +class RefTarget(object): + KIND_INTERFACE, KIND_METHOD, KIND_SIGNAL, KIND_PROPERTY = 'node', 'method', 'signal', 'property' + + def __init__(self, el): + self.kind = el.localName + assert self.kind in (self.KIND_INTERFACE, self.KIND_METHOD, self.KIND_SIGNAL, self.KIND_PROPERTY) + + if self.kind == self.KIND_INTERFACE: + self.dbus_text = el.getAttribute('name').lstrip('/').replace('_', '') + 'Interface' + else: + self.member_text = el.getAttribute('name') + + assert el.parentNode.parentNode.localName == self.KIND_INTERFACE + host_class = el.parentNode.parentNode.getAttribute('name').lstrip('/').replace('_', '') + 'Interface' + + if self.kind == self.KIND_PROPERTY: + self.member_link = 'requestProperty%s()' % (self.member_text) + self.dbus_link = '%s::%s' % (host_class, self.member_link) + else: + self.member_text = '%s()' % self.member_text + + self.dbus_text = '%s::%s' % (host_class, self.member_text) + +class RefRegistry(object): + def __init__(self, spec): + self.targets = {} + for node in spec.getElementsByTagName('node'): + iface, = get_by_path(node, 'interface') + iface_name = iface.getAttribute('name') + + self.targets[iface_name] = RefTarget(node) + + for method in iface.getElementsByTagName(RefTarget.KIND_METHOD): + self.targets[iface_name + '.' + method.getAttribute('name')] = RefTarget(method) + + for signal in iface.getElementsByTagName(RefTarget.KIND_SIGNAL): + self.targets[iface_name + '.' + signal.getAttribute('name')] = RefTarget(signal) + + for prop in iface.getElementsByTagName(RefTarget.KIND_PROPERTY): + self.targets[iface_name + '.' + prop.getAttribute('name')] = RefTarget(prop) + + def process(self, ref): + assert ref.namespaceURI == NS_TP + + def get_closest_parent(el, needle): + node = el + while node is not None and node.localName != needle: + node = node.parentNode + return node + + local = get_descendant_text(ref).strip() + if ref.localName == 'member-ref': + ns = get_closest_parent(ref, 'interface').getAttribute('name') + path = ns + '.' + local.strip() + else: + if ref.hasAttribute('namespace'): + ns = ref.getAttribute('namespace').replace('ofdT', 'org.freedesktop.Telepathy') + path = ns + '.' + local.strip() + else: + path = local + + target = self.targets.get(path) + + if target is None: + parent = get_closest_parent(ref, 'interface') or get_closest_parent(ref, 'error') + parent_name = parent.getAttribute('name') + if (path + parent_name).find('.DRAFT') == -1 and (path + parent_name).find('.FUTURE') == -1: + print >> stderr, 'WARNING: Failed to resolve %s to "%s" in "%s"' % ( + ref.localName, path, parent_name) + return path + + if ref.localName == 'member-ref': + if target.kind == target.KIND_PROPERTY: + return '\\link %s %s \\endlink' % (target.member_link, target.member_text) + else: + return target.member_text + else: + if target.kind == target.KIND_PROPERTY: + return '\\link %s %s \\endlink' % (target.dbus_link, target.dbus_text) + else: + return target.dbus_text + def binding_from_usage(sig, tptype, custom_lists, external=False, explicit_own_ns=None): # 'signature' : ('qt-type', 'pass-by-reference', 'array-type') natives = { @@ -60,9 +156,9 @@ def binding_from_usage(sig, tptype, custom_lists, external=False, explicit_own_n 'v' : ('QDBusVariant', True, None), 'o' : ('QDBusObjectPath', True, 'ObjectPathList'), 'g' : ('QDBusSignature', True, 'SignatureList'), - 'as' : ('QStringList', True, None), - 'ay' : ('QByteArray', True, None), - 'av' : ('QVariantList', True, None), + 'as' : ('QStringList', True, "StringListList"), + 'ay' : ('QByteArray', True, "ByteArrayList"), + 'av' : ('QVariantList', True, "VariantListList"), 'a{sv}' : ('QVariantMap', True, None) } @@ -74,12 +170,12 @@ def binding_from_usage(sig, tptype, custom_lists, external=False, explicit_own_n typename, pass_by_ref, array_name = natives[sig] val = typename inarg = (pass_by_ref and ('const %s&' % val)) or val - elif sig[0] == 'a' and natives.has_key(sig[1]) and natives[sig[1]][2]: - val = natives[sig[1]][2] + elif sig[0] == 'a' and natives.has_key(sig[1:]) and natives[sig[1:]][2]: + val = natives[sig[1:]][2] if explicit_own_ns: val = explicit_own_ns + '::' + val inarg = 'const %s&' % val - array_of = natives[sig[1]][0] + array_of = natives[sig[1:]][0] elif tptype: tptype = tptype.replace('_', '') custom_type = True @@ -107,7 +203,7 @@ def binding_from_usage(sig, tptype, custom_lists, external=False, explicit_own_n assert False, 'Don\'t know how to map type (%s, %s)' % (sig, tptype) outarg = val + '&' - return _Qt4TypeBinding(val, inarg, outarg, None, custom_type, array_of) + return _QtTypeBinding(val, inarg, outarg, None, custom_type, array_of) def binding_from_decl(name, array_name, array_depth=None, external=False, explicit_own_ns=''): val = name.replace('_', '') @@ -117,16 +213,16 @@ def binding_from_decl(name, array_name, array_depth=None, external=False, explic val = explicit_own_ns + '::' + val inarg = 'const %s&' % val outarg = '%s&' % val - return _Qt4TypeBinding(val, inarg, outarg, array_name.replace('_', ''), True, None, array_depth) + return _QtTypeBinding(val, inarg, outarg, array_name.replace('_', ''), True, None, array_depth) -def extract_arg_or_member_info(els, custom_lists, externals, typesns, docstring_indent=' * ', docstring_brackets=None, docstring_maxwidth=80): +def extract_arg_or_member_info(els, custom_lists, externals, typesns, refs, docstring_indent=' * ', docstring_brackets=None, docstring_maxwidth=80): names = [] docstrings = [] bindings = [] for el in els: - names.append(get_qt4_name(el)) - docstrings.append(format_docstring(el, docstring_indent, docstring_brackets, docstring_maxwidth)) + names.append(get_qt_name(el)) + docstrings.append(format_docstring(el, refs, docstring_indent, docstring_brackets, docstring_maxwidth)) sig = el.getAttribute('type') tptype = el.getAttributeNS(NS_TP, 'type') @@ -134,7 +230,7 @@ def extract_arg_or_member_info(els, custom_lists, externals, typesns, docstring_ return names, docstrings, bindings -def format_docstring(el, indent=' * ', brackets=None, maxwidth=80): +def format_docstring(el, refs, indent=' * ', brackets=None, maxwidth=80): docstring_el = None for x in el.childNodes: @@ -146,11 +242,49 @@ def format_docstring(el, indent=' * ', brackets=None, maxwidth=80): lines = [] + # escape backslashes, so they won't be interpreted starting doxygen commands and we can later + # insert doxygen commands we actually want + def escape_slashes(x): + if x.nodeType == x.TEXT_NODE: + x.data = x.data.replace('\\', '\\\\') + elif x.nodeType == x.ELEMENT_NODE: + for y in x.childNodes: + escape_slashes(y) + else: + return + + escape_slashes(docstring_el) + doc = docstring_el.ownerDocument + + for n in docstring_el.getElementsByTagNameNS(NS_TP, 'rationale'): + nested = n.getElementsByTagNameNS(NS_TP, 'rationale') + if nested: + raise Xzibit(n, nested[0]) + + div = doc.createElement('div') + div.setAttribute('class', 'rationale') + + for rationale_body in n.childNodes: + div.appendChild(rationale_body.cloneNode(True)) + + n.parentNode.replaceChild(div, n) + if docstring_el.getAttribute('xmlns') == 'http://www.w3.org/1999/xhtml': + for ref in docstring_el.getElementsByTagNameNS(NS_TP, 'member-ref') + docstring_el.getElementsByTagNameNS(NS_TP, 'dbus-ref'): + nested = ref.getElementsByTagNameNS(NS_TP, 'member-ref') + ref.getElementsByTagNameNS(NS_TP, 'dbus-ref') + if nested: + raise Xzibit(n, nested[0]) + + text = doc.createTextNode(' \\endhtmlonly ') + text.data += refs.process(ref) + text.data += ' \\htmlonly ' + + ref.parentNode.replaceChild(text, ref) + splitted = ''.join([el.toxml() for el in docstring_el.childNodes]).strip(' ').strip('\n').split('\n') level = min([not match and maxint or match.end() - 1 for match in [re.match('^ *[^ ]', line) for line in splitted]]) assert level != maxint - lines = [line[level:].replace('\\', '\\\\') for line in splitted] + lines = ['\\htmlonly'] + [line[level:] for line in splitted] + ['\\endhtmlonly'] else: content = xml_escape(get_descendant_text(docstring_el).replace('\n', ' ').strip()) @@ -173,7 +307,7 @@ def format_docstring(el, indent=' * ', brackets=None, maxwidth=80): content = content[step:] if line: - lines.append(line.replace('\\', '\\\\')) + lines.append(line) output = [] @@ -182,7 +316,7 @@ def format_docstring(el, indent=' * ', brackets=None, maxwidth=80): output.append(brackets[0]) else: output.append(indent) - + output.append('\n') for line in lines: @@ -236,11 +370,14 @@ def gather_custom_lists(spec, typesns): def get_headerfile_cmd(realinclude, prettyinclude, indent=' * '): prettyinclude = prettyinclude or realinclude if realinclude: - return indent + ('\\headerfile %s <%s>\n' % (realinclude, prettyinclude)) + if prettyinclude: + return indent + ('\\headerfile %s <%s>\n' % (realinclude, prettyinclude)) + else: + return indent + ('\\headerfile %s <%s>\n' % (realinclude)) else: return '' -def get_qt4_name(el): +def get_qt_name(el): name = el.getAttribute('name') if el.localName in ('method', 'signal', 'property'): @@ -255,9 +392,9 @@ def get_qt4_name(el): if name[0].isupper() and name[1].islower(): name = name[0].lower() + name[1:] - return qt4_identifier_escape(name.replace('_', '')) + return qt_identifier_escape(name.replace('_', '')) -def qt4_identifier_escape(str): +def qt_identifier_escape(str): built = (str[0].isdigit() and ['_']) or [] for c in str: diff --git a/tools/libqtcodegen.py b/tools/libqtcodegen.py new file mode 100644 index 0000000..9ccb860 --- /dev/null +++ b/tools/libqtcodegen.py @@ -0,0 +1,502 @@ +"""Library code for Qt D-Bus-related code generation. + +The master copy of this library is in the telepathy-qt repository - +please make any changes there. +""" + +# Copyright (C) 2008 Collabora Limited +# Copyright (C) 2008 Nokia Corporation +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +from sys import maxint, stderr +import re +from libtpcodegen import get_by_path, get_descendant_text, NS_TP, xml_escape + +class Xzibit(Exception): + def __init__(self, parent, child): + self.parent = parent + self.child = child + + def __str__(self): + print """ + Nested <%s>s are forbidden. + Parent: + %s... + Child: + %s... + """ % (self.parent.nodeName, self.parent.toxml()[:100], + self.child.toxml()[:100]) + +class _QtTypeBinding: + def __init__(self, val, inarg, outarg, array_val, custom_type, array_of, + array_depth=None): + self.val = val + self.inarg = inarg + self.outarg = outarg + self.array_val = array_val + self.custom_type = custom_type + self.array_of = array_of + self.array_depth = array_depth + + if array_depth is None: + self.array_depth = int(bool(array_val)) + elif array_depth >= 1: + assert array_val + else: + assert not array_val + +class RefTarget(object): + KIND_INTERFACE, KIND_METHOD, KIND_SIGNAL, KIND_PROPERTY = 'node', 'method', 'signal', 'property' + + def __init__(self, el): + self.kind = el.localName + assert self.kind in (self.KIND_INTERFACE, self.KIND_METHOD, self.KIND_SIGNAL, self.KIND_PROPERTY) + + if self.kind == self.KIND_INTERFACE: + self.dbus_text = el.getAttribute('name').lstrip('/').replace('_', '') + 'Interface' + else: + self.member_text = el.getAttribute('name') + + assert el.parentNode.parentNode.localName == self.KIND_INTERFACE + host_class = el.parentNode.parentNode.getAttribute('name').lstrip('/').replace('_', '') + 'Interface' + + if self.kind == self.KIND_PROPERTY: + self.member_link = 'requestProperty%s()' % (self.member_text) + self.dbus_link = '%s::%s' % (host_class, self.member_link) + else: + self.member_text = '%s()' % self.member_text + + self.dbus_text = '%s::%s' % (host_class, self.member_text) + +class RefRegistry(object): + def __init__(self, spec): + self.targets = {} + for node in spec.getElementsByTagName('node'): + iface, = get_by_path(node, 'interface') + iface_name = iface.getAttribute('name') + + self.targets[iface_name] = RefTarget(node) + + for method in iface.getElementsByTagName(RefTarget.KIND_METHOD): + self.targets[iface_name + '.' + method.getAttribute('name')] = RefTarget(method) + + for signal in iface.getElementsByTagName(RefTarget.KIND_SIGNAL): + self.targets[iface_name + '.' + signal.getAttribute('name')] = RefTarget(signal) + + for prop in iface.getElementsByTagName(RefTarget.KIND_PROPERTY): + self.targets[iface_name + '.' + prop.getAttribute('name')] = RefTarget(prop) + + def process(self, ref): + assert ref.namespaceURI == NS_TP + + def get_closest_parent(el, needle): + node = el + while node is not None and node.localName != needle: + node = node.parentNode + return node + + local = get_descendant_text(ref).strip() + if ref.localName == 'member-ref': + ns = get_closest_parent(ref, 'interface').getAttribute('name') + path = ns + '.' + local.strip() + else: + if ref.hasAttribute('namespace'): + ns = ref.getAttribute('namespace').replace('ofdT', 'org.freedesktop.Telepathy') + path = ns + '.' + local.strip() + else: + path = local + + target = self.targets.get(path) + + if target is None: + parent = get_closest_parent(ref, 'interface') or get_closest_parent(ref, 'error') + parent_name = parent.getAttribute('name') + if (path + parent_name).find('.DRAFT') == -1 and (path + parent_name).find('.FUTURE') == -1: + print >> stderr, 'WARNING: Failed to resolve %s to "%s" in "%s"' % ( + ref.localName, path, parent_name) + return path + + if ref.localName == 'member-ref': + if target.kind == target.KIND_PROPERTY: + return '\\link %s %s \\endlink' % (target.member_link, target.member_text) + else: + return target.member_text + else: + if target.kind == target.KIND_PROPERTY: + return '\\link %s %s \\endlink' % (target.dbus_link, target.dbus_text) + else: + return target.dbus_text + +def binding_from_usage(sig, tptype, custom_lists, external=False, explicit_own_ns=None): + # 'signature' : ('qt-type', 'pass-by-reference', 'array-type') + natives = { + 'y' : ('uchar', False, None), + 'b' : ('bool', False, 'BoolList'), + 'n' : ('short', False, 'ShortList'), + 'q' : ('ushort', False, 'UShortList'), + 'i' : ('int', False, 'IntList'), + 'u' : ('uint', False, 'UIntList'), + 'x' : ('qlonglong', False, 'LongLongList'), + 't' : ('qulonglong', False, 'ULongLongList'), + 'd' : ('double', False, 'DoubleList'), + 's' : ('QString', True, None), + 'v' : ('QDBusVariant', True, None), + 'o' : ('QDBusObjectPath', True, 'ObjectPathList'), + 'g' : ('QDBusSignature', True, 'SignatureList'), + 'as' : ('QStringList', True, "StringListList"), + 'ay' : ('QByteArray', True, "ByteArrayList"), + 'av' : ('QVariantList', True, "VariantListList"), + 'a{sv}' : ('QVariantMap', True, None) + } + + val, inarg = None, None + custom_type = False + array_of = None + + if natives.has_key(sig): + typename, pass_by_ref, array_name = natives[sig] + val = typename + inarg = (pass_by_ref and ('const %s&' % val)) or val + elif sig[0] == 'a' and natives.has_key(sig[1:]) and natives[sig[1:]][2]: + val = natives[sig[1:]][2] + if explicit_own_ns: + val = explicit_own_ns + '::' + val + inarg = 'const %s&' % val + array_of = natives[sig[1:]][0] + elif tptype: + tptype = tptype.replace('_', '') + custom_type = True + + if external: + tptype = 'Tp::' + tptype + elif explicit_own_ns: + tptype = explicit_own_ns + '::' + tptype + + if tptype.endswith('[]'): + tptype = tptype[:-2] + extra_list_nesting = 0 + + while tptype.endswith('[]'): + extra_list_nesting += 1 + tptype = tptype[:-2] + + assert custom_lists.has_key(tptype), ('No array version of custom type %s in the spec, but array version used' % tptype) + val = custom_lists[tptype] + 'List' * extra_list_nesting + else: + val = tptype + + inarg = 'const %s&' % val + else: + assert False, 'Don\'t know how to map type (%s, %s)' % (sig, tptype) + + outarg = val + '&' + return _QtTypeBinding(val, inarg, outarg, None, custom_type, array_of) + +def binding_from_decl(name, array_name, array_depth=None, external=False, explicit_own_ns=''): + val = name.replace('_', '') + if external: + val = 'Tp::' + val + elif explicit_own_ns: + val = explicit_own_ns + '::' + val + inarg = 'const %s&' % val + outarg = '%s&' % val + return _QtTypeBinding(val, inarg, outarg, array_name.replace('_', ''), True, None, array_depth) + +def extract_arg_or_member_info(els, custom_lists, externals, typesns, refs, docstring_indent=' * ', docstring_brackets=None, docstring_maxwidth=80): + names = [] + docstrings = [] + bindings = [] + + for el in els: + names.append(get_qt_name(el)) + docstrings.append(format_docstring(el, refs, docstring_indent, docstring_brackets, docstring_maxwidth)) + + sig = el.getAttribute('type') + tptype = el.getAttributeNS(NS_TP, 'type') + bindings.append(binding_from_usage(sig, tptype, custom_lists, (sig, tptype) in externals, typesns)) + + return names, docstrings, bindings + +def format_docstring(el, refs, indent=' * ', brackets=None, maxwidth=80): + docstring_el = None + + for x in el.childNodes: + if x.namespaceURI == NS_TP and x.localName == 'docstring': + docstring_el = x + + if not docstring_el: + return '' + + lines = [] + + # escape backslashes, so they won't be interpreted starting doxygen commands and we can later + # insert doxygen commands we actually want + def escape_slashes(x): + if x.nodeType == x.TEXT_NODE: + x.data = x.data.replace('\\', '\\\\') + elif x.nodeType == x.ELEMENT_NODE: + for y in x.childNodes: + escape_slashes(y) + else: + return + + escape_slashes(docstring_el) + doc = docstring_el.ownerDocument + + for n in docstring_el.getElementsByTagNameNS(NS_TP, 'rationale'): + nested = n.getElementsByTagNameNS(NS_TP, 'rationale') + if nested: + raise Xzibit(n, nested[0]) + + div = doc.createElement('div') + div.setAttribute('class', 'rationale') + + for rationale_body in n.childNodes: + div.appendChild(rationale_body.cloneNode(True)) + + n.parentNode.replaceChild(div, n) + + if docstring_el.getAttribute('xmlns') == 'http://www.w3.org/1999/xhtml': + for ref in docstring_el.getElementsByTagNameNS(NS_TP, 'member-ref') + docstring_el.getElementsByTagNameNS(NS_TP, 'dbus-ref'): + nested = ref.getElementsByTagNameNS(NS_TP, 'member-ref') + ref.getElementsByTagNameNS(NS_TP, 'dbus-ref') + if nested: + raise Xzibit(n, nested[0]) + + text = doc.createTextNode(' \\endhtmlonly ') + text.data += refs.process(ref) + text.data += ' \\htmlonly ' + + ref.parentNode.replaceChild(text, ref) + + splitted = ''.join([el.toxml() for el in docstring_el.childNodes]).strip(' ').strip('\n').split('\n') + level = min([not match and maxint or match.end() - 1 for match in [re.match('^ *[^ ]', line) for line in splitted]]) + assert level != maxint + lines = ['\\htmlonly'] + [line[level:] for line in splitted] + ['\\endhtmlonly'] + else: + content = xml_escape(get_descendant_text(docstring_el).replace('\n', ' ').strip()) + + while content.find(' ') != -1: + content = content.replace(' ', ' ') + + left = maxwidth - len(indent) - 1 + line = '' + + while content: + step = (content.find(' ') + 1) or len(content) + + if step > left: + lines.append(line) + line = '' + left = maxwidth - len(indent) - 1 + + left = left - step + line = line + content[:step] + content = content[step:] + + if line: + lines.append(line) + + output = [] + + if lines: + if brackets: + output.append(brackets[0]) + else: + output.append(indent) + + output.append('\n') + + for line in lines: + output.append(indent) + output.append(line) + output.append('\n') + + if lines and brackets: + output.append(brackets[1]) + output.append('\n') + + return ''.join(output) + +def gather_externals(spec): + externals = [] + + for ext in spec.getElementsByTagNameNS(NS_TP, 'external-type'): + sig = ext.getAttribute('type') + tptype = ext.getAttribute('name') + externals.append((sig, tptype)) + + return externals + +def gather_custom_lists(spec, typesns): + custom_lists = {} + structs = [(provider, typesns) for provider in spec.getElementsByTagNameNS(NS_TP, 'struct')] + mappings = [(provider, typesns) for provider in spec.getElementsByTagNameNS(NS_TP, 'mapping')] + exts = [(provider, 'Telepathy') for provider in spec.getElementsByTagNameNS(NS_TP, 'external-type')] + + for (provider, ns) in structs + mappings + exts: + tptype = provider.getAttribute('name').replace('_', '') + array_val = provider.getAttribute('array-name').replace('_', '') + array_depth = provider.getAttribute('array-depth') + if array_depth: + array_depth = int(array_depth) + else: + array_depth = None + + if array_val: + custom_lists[tptype] = array_val + custom_lists[ns + '::' + tptype] = ns + '::' + array_val + if array_depth >= 2: + for i in xrange(array_depth): + custom_lists[tptype + ('[]' * (i+1))] = ( + array_val + ('List' * i)) + custom_lists[ns + '::' + tptype + ('[]' * (i+1))] = ( + ns + '::' + array_val + ('List' * i)) + + return custom_lists + +def get_headerfile_cmd(realinclude, prettyinclude, indent=' * '): + prettyinclude = prettyinclude or realinclude + if realinclude: + if prettyinclude: + return indent + ('\\headerfile %s <%s>\n' % (realinclude, prettyinclude)) + else: + return indent + ('\\headerfile %s <%s>\n' % (realinclude)) + else: + return '' + +def get_qt_name(el): + name = el.getAttribute('name') + + if el.localName in ('method', 'signal', 'property'): + bname = el.getAttributeNS(NS_TP, 'name-for-bindings') + + if bname: + name = bname + + if not name: + return None + + if name[0].isupper() and name[1].islower(): + name = name[0].lower() + name[1:] + + return qt_identifier_escape(name.replace('_', '')) + +def qt_identifier_escape(str): + built = (str[0].isdigit() and ['_']) or [] + + for c in str: + if c.isalnum(): + built.append(c) + else: + built.append('_') + + str = ''.join(built) + + # List of reserved identifiers + # Initial list from http://cs.smu.ca/~porter/csc/ref/cpp_keywords.html + + # Keywords inherited from C90 + reserved = ['auto', + 'const', + 'double', + 'float', + 'int', + 'short', + 'struct', + 'unsigned', + 'break', + 'continue', + 'else', + 'for', + 'long', + 'signed', + 'switch', + 'void', + 'case', + 'default', + 'enum', + 'goto', + 'register', + 'sizeof', + 'typedef', + 'volatile', + 'char', + 'do', + 'extern', + 'if', + 'return', + 'static', + 'union', + 'while', + # C++-only keywords + 'asm', + 'dynamic_cast', + 'namespace', + 'reinterpret_cast', + 'try', + 'bool', + 'explicit', + 'new', + 'static_cast', + 'typeid', + 'catch', + 'false', + 'operator', + 'template', + 'typename', + 'class', + 'friend', + 'private', + 'this', + 'using', + 'const_cast', + 'inline', + 'public', + 'throw', + 'virtual', + 'delete', + 'mutable', + 'protected', + 'true', + 'wchar_t', + # Operator replacements + 'and', + 'bitand', + 'compl', + 'not_eq', + 'or_eq', + 'xor_eq', + 'and_eq', + 'bitor', + 'not', + 'or', + 'xor', + # Predefined identifiers + 'INT_MIN', + 'INT_MAX', + 'MAX_RAND', + 'NULL', + # Qt + 'SIGNAL', + 'SLOT', + 'signals', + 'slots'] + + while str in reserved: + str = str + '_' + + return str + diff --git a/tools/qt-client-gen.py b/tools/qt-client-gen.py new file mode 100644 index 0000000..d79ac30 --- /dev/null +++ b/tools/qt-client-gen.py @@ -0,0 +1,547 @@ +#!/usr/bin/python +# +# Copyright (C) 2008 Collabora Limited +# Copyright (C) 2008 Nokia Corporation +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +from sys import argv +import xml.dom.minidom +import codecs +from getopt import gnu_getopt + +from libtpcodegen import NS_TP, get_descendant_text, get_by_path +from libqtcodegen import binding_from_usage, extract_arg_or_member_info, format_docstring, gather_externals, gather_custom_lists, get_headerfile_cmd, get_qt_name, qt_identifier_escape, RefRegistry + +class Generator(object): + def __init__(self, opts): + try: + self.group = opts.get('--group', '') + self.headerfile = opts['--headerfile'] + self.implfile = opts['--implfile'] + self.namespace = opts['--namespace'] + self.typesnamespace = opts['--typesnamespace'] + self.realinclude = opts['--realinclude'] + self.prettyinclude = opts.get('--prettyinclude') + self.extraincludes = opts.get('--extraincludes', None) + self.mainiface = opts.get('--mainiface', None) + self.must_define = opts.get('--must-define', None) + self.dbus_proxy = opts.get('--dbus-proxy', + 'Tp::DBusProxy') + self.visibility = opts.get('--visibility', '') + ifacedom = xml.dom.minidom.parse(opts['--ifacexml']) + specdom = xml.dom.minidom.parse(opts['--specxml']) + except KeyError, k: + assert False, 'Missing required parameter %s' % k.args[0] + + self.hs = [] + self.bs = [] + self.ifacenodes = ifacedom.getElementsByTagName('node') + self.spec, = get_by_path(specdom, "spec") + self.custom_lists = gather_custom_lists(self.spec, self.typesnamespace) + self.externals = gather_externals(self.spec) + self.refs = RefRegistry(self.spec) + + def __call__(self): + # Output info header and includes + self.h("""\ +/* + * This file contains D-Bus client proxy classes generated by qt-client-gen.py. + * + * This file can be distributed under the same terms as the specification from + * which it was generated. + */ +""") + + if self.must_define: + self.h('\n') + self.h('#ifndef %s\n' % self.must_define) + self.h('#error %s\n' % self.must_define) + self.h('#endif\n') + + self.h('\n') + + if self.extraincludes: + for include in self.extraincludes.split(','): + self.h('#include %s\n' % include) + + self.h(""" +#include + +#include +#include +#include + +#include + +#include +#include +#include + +namespace Tp +{ +class PendingVariant; +class PendingOperation; +} + +""") + + if self.must_define: + self.b("""#define %s\n""" % (self.must_define)) + + self.b("""#include "%s" + +""" % self.realinclude) + + # Begin namespace + for ns in self.namespace.split('::'): + self.hb("""\ +namespace %s +{ +""" % ns) + + # Output interface proxies + def ifacenodecmp(x, y): + xname, yname = [self.namespace + '::' + node.getAttribute('name').replace('/', '').replace('_', '') + 'Interface' for node in x, y] + + if xname == self.mainiface: + return -1 + elif yname == self.mainiface: + return 1 + else: + return cmp(xname, yname) + + self.ifacenodes.sort(cmp=ifacenodecmp) + for ifacenode in self.ifacenodes: + self.do_ifacenode(ifacenode) + + # End namespace + self.hb(''.join(['}\n' for ns in self.namespace.split('::')])) + + # Add metatype declaration - otherwise QTBUG #2151 might be triggered + for ifacenode in self.ifacenodes: + classname = ifacenode.getAttribute('name').replace('/', '').replace('_', '') + 'Interface' + self.h("Q_DECLARE_METATYPE(" + self.namespace + "::" + classname + "*)\n") + + # Write output to files + (codecs.getwriter('utf-8')(open(self.headerfile, 'w'))).write(''.join(self.hs)) + (codecs.getwriter('utf-8')(open(self.implfile, 'w'))).write(''.join(self.bs)) + + def do_ifacenode(self, ifacenode): + # Extract info + name = ifacenode.getAttribute('name').replace('/', '').replace('_', '') + 'Interface' + iface, = get_by_path(ifacenode, 'interface') + dbusname = iface.getAttribute('name') + + # Begin class, constructors + self.h(""" +/** + * \\class %(name)s +%(headercmd)s\ +%(groupcmd)s\ + * + * Proxy class providing a 1:1 mapping of the D-Bus interface "%(dbusname)s". + */ +class %(visibility)s %(name)s : public Tp::AbstractInterface +{ + Q_OBJECT + +public: + /** + * Returns the name of the interface "%(dbusname)s", which this class + * represents. + * + * \\return The D-Bus interface name. + */ + static inline QLatin1String staticInterfaceName() + { + return QLatin1String("%(dbusname)s"); + } + + /** + * Creates a %(name)s associated with the given object on the session bus. + * + * \\param busName Name of the service the object is on. + * \\param objectPath Path to the object on the service. + * \\param parent Passed to the parent class constructor. + */ + %(name)s( + const QString& busName, + const QString& objectPath, + QObject* parent = 0 + ); + + /** + * Creates a %(name)s associated with the given object on the given bus. + * + * \\param connection The bus via which the object can be reached. + * \\param busName Name of the service the object is on. + * \\param objectPath Path to the object on the service. + * \\param parent Passed to the parent class constructor. + */ + %(name)s( + const QDBusConnection& connection, + const QString& busName, + const QString& objectPath, + QObject* parent = 0 + ); +""" % {'name' : name, + 'headercmd' : get_headerfile_cmd(self.realinclude, self.prettyinclude), + 'groupcmd' : self.group and (' * \\ingroup %s\n' % self.group), + 'dbusname' : dbusname, + 'visibility': self.visibility, + }) + + self.b(""" +%(name)s::%(name)s(const QString& busName, const QString& objectPath, QObject *parent) + : Tp::AbstractInterface(busName, objectPath, staticInterfaceName(), QDBusConnection::sessionBus(), parent) +{ +} + +%(name)s::%(name)s(const QDBusConnection& connection, const QString& busName, const QString& objectPath, QObject *parent) + : Tp::AbstractInterface(busName, objectPath, staticInterfaceName(), connection, parent) +{ +} +""" % {'name' : name}) + + # Construct from DBusProxy subclass + self.h(""" + /** + * Creates a %(name)s associated with the same object as the given proxy. + * + * \\param proxy The proxy to use. It will also be the QObject::parent() + * for this object. + */ + %(name)s(%(dbus_proxy)s *proxy); +""" % {'name' : name, + 'dbus_proxy' : self.dbus_proxy}) + + self.b(""" +%(name)s::%(name)s(%(dbus_proxy)s *proxy) + : Tp::AbstractInterface(proxy, staticInterfaceName()) +{ +} +""" % {'name' : name, + 'dbus_proxy' : self.dbus_proxy}) + + # Main interface + mainiface = self.mainiface or 'Tp::AbstractInterface' + + if mainiface != self.namespace + '::' + name: + self.h(""" + /** + * Creates a %(name)s associated with the same object as the given proxy. + * Additionally, the created proxy will have the same parent as the given + * proxy. + * + * \\param mainInterface The proxy to use. + */ + explicit %(name)s(const %(mainiface)s& mainInterface); + + /** + * Creates a %(name)s associated with the same object as the given proxy. + * However, a different parent object can be specified. + * + * \\param mainInterface The proxy to use. + * \\param parent Passed to the parent class constructor. + */ + %(name)s(const %(mainiface)s& mainInterface, QObject* parent); +""" % {'name' : name, + 'mainiface' : mainiface}) + + self.b(""" +%(name)s::%(name)s(const %(mainiface)s& mainInterface) + : Tp::AbstractInterface(mainInterface.service(), mainInterface.path(), staticInterfaceName(), mainInterface.connection(), mainInterface.parent()) +{ +} + +%(name)s::%(name)s(const %(mainiface)s& mainInterface, QObject *parent) + : Tp::AbstractInterface(mainInterface.service(), mainInterface.path(), staticInterfaceName(), mainInterface.connection(), parent) +{ +} +""" % {'name' : name, + 'mainiface' : mainiface}) + + # Properties + has_props = False + for prop in get_by_path(iface, 'property'): + # Skip tp:properties + if not prop.namespaceURI: + self.do_prop(prop) + has_props = True + + self.h(""" + /** + * Request all of the DBus properties on the interface. + * + * \\return A pending variant map which will emit finished when the properties have + * been retrieved. + */ + Tp::PendingVariantMap *requestAllProperties() const + { + return internalRequestAllProperties(); + } +""") + + # Methods + methods = get_by_path(iface, 'method') + + if methods: + self.h(""" +public Q_SLOTS:\ +""") + + for method in methods: + self.do_method(method) + + # Signals + signals = get_by_path(iface, 'signal') + + if signals: + self.h(""" +Q_SIGNALS:\ +""") + + for signal in signals: + self.do_signal(signal) + + # invalidated handler (already a slot in the superclass) + # we can't just use disconnect(this, NULL, NULL, NULL) because + # (a) that would disconnect QObject::destroyed() and other non-D-Bus + # signals, and (b) QtDBus doesn't support that usage anyway (it needs + # specific signals in order to remove its signal match rules) + self.h(""" +protected: + virtual void invalidate(Tp::DBusProxy *, const QString &, const QString &); +""") + + self.b(""" +void %(name)s::invalidate(Tp::DBusProxy *proxy, + const QString &error, const QString &message) +{ +""" % {'name' : name}) + + for signal in signals: + self.do_signal_disconnect(signal) + + self.b(""" + Tp::AbstractInterface::invalidate(proxy, error, message); +} +""") + + # Close class + self.h("""\ +}; +""") + + def do_prop(self, prop): + name = prop.getAttribute('name') + access = prop.getAttribute('access') + gettername = name + settername = None + docstring = format_docstring(prop, self.refs, ' * ').replace('*/', '*/') + + sig = prop.getAttribute('type') + tptype = prop.getAttributeNS(NS_TP, 'type') + binding = binding_from_usage(sig, tptype, self.custom_lists, (sig, tptype) in self.externals, self.typesnamespace) + + if 'write' in access: + settername = 'set' + name + + if 'read' in access: + self.h(""" + /** + * Asynchronous getter for the remote object property \\c %(name)s of type \\c %(val)s. + * +%(docstring)s\ + * + * \\return A pending variant which will emit finished when the property has been + * retrieved. + */ + inline Tp::PendingVariant *%(gettername)s() const + { + return internalRequestProperty(QLatin1String("%(name)s")); + } +""" % {'name' : name, + 'docstring' : docstring, + 'val' : binding.val, + 'gettername' : 'requestProperty' + name}) + + if 'write' in access: + self.h(""" + /** + * Asynchronous setter for the remote object property \\c %(name)s of type \\c %(type)s. + * +%(docstring)s\ + * + * \\return A pending operation which will emit finished when the property has been + * set. + */ + inline Tp::PendingOperation *%(settername)s(%(type)s newValue) + { + return internalSetProperty(QLatin1String("%(name)s"), QVariant::fromValue(newValue)); + } +""" % {'name' : name, + 'docstring' : docstring, + 'type' : binding.val, + 'name' : name, + 'settername' : 'setProperty' + name}) + + def do_method(self, method): + name = method.getAttribute('name') + args = get_by_path(method, 'arg') + argnames, argdocstrings, argbindings = extract_arg_or_member_info(args, self.custom_lists, + self.externals, self.typesnamespace, self.refs, ' * ') + + inargs = [] + outargs = [] + + for i in xrange(len(args)): + if args[i].getAttribute('direction') == 'out': + outargs.append(i) + else: + inargs.append(i) + assert argnames[i] != None, 'No argument name for input argument at index %d for method %s' % (i, name) + + rettypes = ', '.join([argbindings[i].val for i in outargs]) + params = ', '.join([argbindings[i].inarg + ' ' + argnames[i] for i in inargs]) + if params: + params += ', int timeout = -1' + else: + params = 'int timeout = -1' + + self.h(""" + /** + * Begins a call to the D-Bus method \\c %s on the remote object. +%s\ + * + * Note that \\a timeout is ignored as of now. It will be used once + * http://bugreports.qt.nokia.com/browse/QTBUG-11775 is fixed. + * +""" % (name, format_docstring(method, self.refs, ' * '))) + + for i in inargs: + if argdocstrings[i]: + self.h("""\ + * + * \\param %s +%s\ +""" % (argnames[i], argdocstrings[i])) + + self.h("""\ + * \\param timeout The timeout in milliseconds. +""") + + for i in outargs: + if argdocstrings[i]: + self.h("""\ + * + * \\return +%s\ +""" % argdocstrings[i]) + + self.h("""\ + */ + inline QDBusPendingReply<%(rettypes)s> %(name)s(%(params)s) + { + if (!invalidationReason().isEmpty()) { + return QDBusPendingReply<%(rettypes)s>(QDBusMessage::createError( + invalidationReason(), + invalidationMessage() + )); + } +""" % {'rettypes' : rettypes, + 'name' : name, + 'params' : params}) + + if inargs: + self.h(""" + QDBusMessage callMessage = QDBusMessage::createMethodCall(this->service(), this->path(), + this->staticInterfaceName(), QLatin1String("%s")); + callMessage << %s; + return this->connection().asyncCall(callMessage, timeout); + } +""" % (name, ' << '.join(['QVariant::fromValue(%s)' % argnames[i] for i in inargs]))) + else: + self.h(""" + QDBusMessage callMessage = QDBusMessage::createMethodCall(this->service(), this->path(), + this->staticInterfaceName(), QLatin1String("%s")); + return this->connection().asyncCall(callMessage, timeout); + } +""" % name) + + def do_signal(self, signal): + name = signal.getAttribute('name') + argnames, argdocstrings, argbindings = extract_arg_or_member_info(get_by_path(signal, + 'arg'), self.custom_lists, self.externals, self.typesnamespace, self.refs, ' * ') + + self.h(""" + /** + * Represents the signal \\c %s on the remote object. +%s\ +""" % (name, format_docstring(signal, self.refs, ' * '))) + + for i in xrange(len(argnames)): + assert argnames[i] != None, 'Name missing from argument at index %d for signal %s' % (i, name) + if argdocstrings[i]: + self.h("""\ + * + * \\param %s +%s\ +""" % (argnames[i], argdocstrings[i])) + + self.h("""\ + */ + void %s(%s); +""" % (name, ', '.join(['%s %s' % (binding.inarg, name) for binding, name in zip(argbindings, argnames)]))) + + def do_signal_disconnect(self, signal): + name = signal.getAttribute('name') + _, _, argbindings = extract_arg_or_member_info(get_by_path(signal, 'arg'), + self.custom_lists, self.externals, self.typesnamespace, self.refs, ' * ') + + self.b("""\ + disconnect(this, SIGNAL(%s(%s)), NULL, NULL); +""" % (name, ', '.join([binding.inarg for binding in argbindings]))) + + def h(self, str): + self.hs.append(str) + + def b(self, str): + self.bs.append(str) + + def hb(self, str): + self.h(str) + self.b(str) + + +if __name__ == '__main__': + options, argv = gnu_getopt(argv[1:], '', + ['group=', + 'namespace=', + 'typesnamespace=', + 'headerfile=', + 'implfile=', + 'ifacexml=', + 'specxml=', + 'realinclude=', + 'prettyinclude=', + 'extraincludes=', + 'mainiface=', + 'must-define=', + 'dbus-proxy=', + 'visibility=']) + + Generator(dict(options))() diff --git a/tools/qt-constants-gen.py b/tools/qt-constants-gen.py new file mode 100644 index 0000000..48fdc43 --- /dev/null +++ b/tools/qt-constants-gen.py @@ -0,0 +1,310 @@ +#!/usr/bin/python +# +# Copyright (C) 2008 Collabora Limited +# Copyright (C) 2008 Nokia Corporation +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +from sys import argv, stdout, stderr +import codecs +import xml.dom.minidom +from getopt import gnu_getopt + +from libtpcodegen import NS_TP, get_descendant_text, get_by_path +from libqtcodegen import format_docstring, RefRegistry + +class Generator(object): + def __init__(self, opts): + try: + self.namespace = opts['--namespace'] + self.must_define = opts.get('--must-define', None) + dom = xml.dom.minidom.parse(opts['--specxml']) + except KeyError, k: + assert False, 'Missing required parameter %s' % k.args[0] + + self.define_prefix = None + if '--define-prefix' in opts: + self.define_prefix = opts['--define-prefix'] + + self.old_prefix = None + if '--str-constant-prefix' in opts: + self.old_prefix = opts['--str-constant-prefix'] + + self.spec = get_by_path(dom, "spec")[0] + self.out = codecs.getwriter('utf-8')(stdout) + self.refs = RefRegistry(self.spec) + + def h(self, code): + self.out.write(code) + + def __call__(self): + # Header + self.h('/* Generated from ') + self.h(get_descendant_text(get_by_path(self.spec, 'title'))) + version = get_by_path(self.spec, "version") + + if version: + self.h(', version ' + get_descendant_text(version)) + + self.h(""" + */ + """) + + if self.must_define: + self.h(""" +#ifndef %s +#error %s +#endif +""" % (self.must_define, self.must_define)) + + self.h(""" +#include + +/** + * \\addtogroup typesconstants Types and constants + * + * Enumerated, flag, structure, list and mapping types and utility constants. + */ + +/** + * \\defgroup flagtypeconsts Flag type constants + * \\ingroup typesconstants + * + * Types generated from the specification representing bit flag constants and + * combinations of them (bitfields). + */ + +/** + * \\defgroup enumtypeconsts Enumerated type constants + * \\ingroup typesconstants + * + * Types generated from the specification representing enumerated types ie. + * types the values of which are mutually exclusive integral constants. + */ + +/** + * \\defgroup ifacestrconsts Interface string constants + * \\ingroup typesconstants + * + * D-Bus interface names of the interfaces in the specification. + */ + +/** + * \\defgroup errorstrconsts Error string constants + * \\ingroup typesconstants + * + * Names of the D-Bus errors in the specification. + */ +""") + + # Begin namespace + self.h(""" +namespace %s +{ +""" % self.namespace) + + # Flags + for flags in self.spec.getElementsByTagNameNS(NS_TP, 'flags'): + self.do_flags(flags) + + # Enums + for enum in self.spec.getElementsByTagNameNS(NS_TP, 'enum'): + self.do_enum(enum) + + # End namespace + self.h("""\ +} + +""") + + # Interface names + for iface in self.spec.getElementsByTagName('interface'): + if self.old_prefix: + self.h("""\ +/** + * \\ingroup ifacestrconsts + * + * The interface name "%(name)s". + */ +#define %(DEFINE)s "%(name)s" + +""" % {'name' : iface.getAttribute('name'), + 'DEFINE' : self.old_prefix + 'INTERFACE_' + get_by_path(iface, '../@name').upper().replace('/', '')}) + + if self.define_prefix: + self.h("""\ +/** + * \\ingroup ifacestrconsts + * + * The interface name "%(name)s" as a QLatin1String, usable in QString requiring contexts even when + * building with Q_NO_CAST_FROM_ASCII defined. + */ +#define %(DEFINE)s (QLatin1String("%(name)s")) + +""" % {'name' : iface.getAttribute('name'), + 'DEFINE' : self.define_prefix + 'IFACE_' + get_by_path(iface, '../@name').upper().replace('/', '')}) + + # Error names + for error in get_by_path(self.spec, 'errors/error'): + name = error.getAttribute('name') + fullname = get_by_path(error, '../@namespace') + '.' + name.replace(' ', '') + + if self.old_prefix: + define = self.old_prefix + 'ERROR_' + name.replace(' ', '_').replace('.', '_').upper() + self.h("""\ +/** + * \\ingroup errorstrconsts + * + * The error name "%(fullname)s". +%(docstring)s\ + */ +#define %(DEFINE)s "%(fullname)s" + +""" % {'fullname' : fullname, + 'docstring': format_docstring(error, self.refs), + 'DEFINE' : define}) + + if self.define_prefix: + define = self.define_prefix + 'ERROR_' + name.replace(' ', '_').replace('.', '_').upper() + self.h("""\ +/** + * \\ingroup errorstrconsts + * + * The error name "%(fullname)s" as a QLatin1String, usable in QString requiring contexts even when + * building with Q_NO_CAST_FROM_ASCII defined. +%(docstring)s\ + */ +#define %(DEFINE)s QLatin1String("%(fullname)s") + +""" % {'fullname' : fullname, + 'docstring': format_docstring(error, self.refs), + 'DEFINE' : define}) + + def do_flags(self, flags): + singular = flags.getAttribute('singular') or \ + flags.getAttribute('value-prefix') + + using_name = False + if not singular: + using_name = True + singular = flags.getAttribute('name') + + if singular.endswith('lags'): + singular = singular[:-1] + + if using_name and singular.endswith('s'): + singular = singular[:-1] + + singular = singular.replace('_', '') + plural = (flags.getAttribute('plural') or flags.getAttribute('name') or singular + 's').replace('_', '') + self.h("""\ +/** + * \\ingroup flagtypeconsts + * + * Flag type generated from the specification. + */ +enum %(singular)s +{ +""" % {'singular' : singular}) + + flagvalues = get_by_path(flags, 'flag') + + for flag in flagvalues: + self.do_val(flag, singular, flag == flagvalues[-1]) + + self.h("""\ + %s = 0xffffffffU +""" % ("_" + singular + "Padding")) + + self.h("""\ +}; + +/** + * \\typedef QFlags<%(singular)s> %(plural)s + * \\ingroup flagtypeconsts + * + * Type representing combinations of #%(singular)s values. +%(docstring)s\ + */ +typedef QFlags<%(singular)s> %(plural)s; +Q_DECLARE_OPERATORS_FOR_FLAGS(%(plural)s) + +""" % {'singular' : singular, 'plural' : plural, 'docstring' : format_docstring(flags, self.refs)}) + + def do_enum(self, enum): + singular = enum.getAttribute('singular') or \ + enum.getAttribute('name') + value_prefix = enum.getAttribute('singular') or \ + enum.getAttribute('value-prefix') or \ + enum.getAttribute('name') + + if singular.endswith('lags'): + singular = singular[:-1] + + plural = enum.getAttribute('plural') or singular + 's' + singular = singular.replace('_', '') + value_prefix = value_prefix.replace('_', '') + vals = get_by_path(enum, 'enumvalue') + + self.h("""\ +/** + * \\enum %(singular)s + * \\ingroup enumtypeconsts + * + * Enumerated type generated from the specification. +%(docstring)s\ + */ +enum %(singular)s +{ +""" % {'singular' : singular, 'docstring' : format_docstring(enum, self.refs)}) + + for val in vals: + self.do_val(val, value_prefix, val == vals[-1]) + + self.h("""\ + %s = 0xffffffffU +}; + +""" % ("_" + singular + "Padding")) + + self.h("""\ +/** + * \\ingroup enumtypeconsts + * + * 1 higher than the highest valid value of %(singular)s. + */ +const int NUM_%(upper-plural)s = (%(last-val)s+1); + +""" % {'singular' : singular, + 'upper-plural' : plural.upper(), + 'last-val' : vals[-1].getAttribute('value')}) + + def do_val(self, val, prefix, last): + name = (val.getAttribute('suffix') or val.getAttribute('name')).replace('_', '') + self.h("""\ +%s\ + %s = %s, + +""" % (format_docstring(val, self.refs, indent=' * ', brackets=(' /**', ' */')), prefix + name, val.getAttribute('value'))) + +if __name__ == '__main__': + options, argv = gnu_getopt(argv[1:], '', + ['namespace=', + 'str-constant-prefix=', + 'define-prefix=', + 'must-define=', + 'specxml=']) + + Generator(dict(options))() diff --git a/tools/qt-svc-gen.py b/tools/qt-svc-gen.py new file mode 100644 index 0000000..58b77bb --- /dev/null +++ b/tools/qt-svc-gen.py @@ -0,0 +1,742 @@ +#!/usr/bin/python +# +# Copyright (C) 2012 Collabora Limited +# Copyright (C) 2012 Nokia Corporation +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +from sys import argv +import xml.dom.minidom +import codecs +from getopt import gnu_getopt + +from libtpcodegen import NS_TP, get_descendant_text, get_by_path +from libqtcodegen import binding_from_usage, extract_arg_or_member_info, format_docstring, gather_externals, gather_custom_lists, get_headerfile_cmd, get_qt_name, qt_identifier_escape, RefRegistry + +# TODO generate docstrings + +def to_lower_camel_case(s): + if len(s) <= 1: + return s.lower() + + i = 0 + for c in s: + if c == '_': + break + i += 1 + + ret = s + if i == len(s): + return s.lower() + else: + ret = s[0:i].lower() + s[i:] + ret = ret.replace('_', '') + return ret + +class Generator(object): + def __init__(self, opts): + try: + self.group = opts.get('--group', '') + self.headerfile = opts['--headerfile'] + self.implfile = opts['--implfile'] + self.namespace = opts['--namespace'] + self.typesnamespace = opts['--typesnamespace'] + self.realinclude = opts.get('--realinclude', None) + self.mocinclude = opts.get('--mocinclude', None) + self.prettyinclude = opts.get('--prettyinclude') + self.extraincludes = opts.get('--extraincludes', None) + self.must_define = opts.get('--must-define', None) + self.visibility = opts.get('--visibility', '') + ifacedom = xml.dom.minidom.parse(opts['--ifacexml']) + specdom = xml.dom.minidom.parse(opts['--specxml']) + except KeyError, k: + assert False, 'Missing required parameter %s' % k.args[0] + + if not self.realinclude: + self.realinclude = self.headerfile + + self.hs = [] + self.bs = [] + self.ifacenodes = ifacedom.getElementsByTagName('node') + self.spec, = get_by_path(specdom, "spec") + self.custom_lists = gather_custom_lists(self.spec, self.typesnamespace) + self.externals = gather_externals(self.spec) + self.refs = RefRegistry(self.spec) + + def __call__(self): + # Output info header and includes + self.h("""\ +/* + * This file contains D-Bus adaptor classes generated by qt-svc-gen.py. + * + * This file can be distributed under the same terms as the specification from + * which it was generated. + */ +""") + + if self.must_define: + self.h('\n') + self.h('#ifndef %s\n' % self.must_define) + self.h('#error %s\n' % self.must_define) + self.h('#endif\n') + + self.h('\n') + + if self.extraincludes: + for include in self.extraincludes.split(','): + self.h('#include %s\n' % include) + + self.h("""\ +#include +#include +#include + +#include +#include + +""") + + if self.must_define: + self.b("""#define %s\n""" % (self.must_define)) + + self.b("""#include "%s" + +""" % self.realinclude) + + if self.mocinclude: + self.b("""#include "%s" + +""" % self.mocinclude) + + self.b("""\ +#include +#include + +""") + + # Begin namespace + for ns in self.namespace.split('::'): + self.hb("""\ +namespace %s +{ +""" % ns) + + # Output interface proxies + def ifacenodecmp(x, y): + xname, yname = [self.namespace + '::' + node.getAttribute('name').replace('/', '').replace('_', '') + 'Adaptor' for node in x, y] + + return cmp(xname, yname) + + self.ifacenodes.sort(cmp=ifacenodecmp) + for ifacenode in self.ifacenodes: + self.do_ifacenode(ifacenode) + + # End namespace + self.hb(''.join(['\n}' for ns in self.namespace.split('::')])) + + # Write output to files + (codecs.getwriter('utf-8')(open(self.headerfile, 'w'))).write(''.join(self.hs)) + (codecs.getwriter('utf-8')(open(self.implfile, 'w'))).write(''.join(self.bs)) + + def do_ifacenode(self, ifacenode): + # Extract info + name = ifacenode.getAttribute('name').replace('/', '').replace('_', '') + 'Adaptor' + iface, = get_by_path(ifacenode, 'interface') + dbusname = iface.getAttribute('name') + props = get_by_path(iface, 'property') + methods = get_by_path(iface, 'method') + signals = get_by_path(iface, 'signal') + + # Begin class, constructors + self.h(""" +/** + * \\class %(name)s +%(headercmd)s\ +%(groupcmd)s\ + * + * Adaptor class providing a 1:1 mapping of the D-Bus interface "%(dbusname)s". + */ +class %(visibility)s %(name)s : public Tp::AbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "%(dbusname)s") + Q_CLASSINFO("D-Bus Introspection", "" +" \\n" +""" % {'name': name, + 'headercmd': get_headerfile_cmd(self.realinclude, self.prettyinclude), + 'groupcmd': self.group and (' * \\ingroup %s\n' % self.group), + 'dbusname': dbusname, + 'visibility': self.visibility, + }) + + self.do_introspection(props, methods, signals) + + self.h("""\ +" \\n" +"") +""") + + self.do_qprops(props) + + self.h(""" +public: + %(name)s(const QDBusConnection& dbusConnection, QObject* adaptee, QObject* parent); + virtual ~%(name)s(); + +""" % {'name': name}) + + self.do_mic_typedefs(methods) + + self.b(""" +%(name)s::%(name)s(const QDBusConnection& bus, QObject* adaptee, QObject* parent) + : Tp::AbstractAdaptor(bus, adaptee, parent) +{ +""" % {'name': name}) + + self.do_signals_connect(signals) + + self.b("""\ +} + +%(name)s::~%(name)s() +{ +} +""" % {'name': name}) + + # Properties + has_props = False + if props: + self.h(""" +public: // PROPERTIES +""") + + for prop in props: + # Skip tp:properties + if not prop.namespaceURI: + self.do_prop(name, prop) + has_props = True + + # Methods + if methods: + self.h(""" +public Q_SLOTS: // METHODS +""") + + for method in methods: + self.do_method(name, method) + + # Signals + if signals: + self.h(""" +Q_SIGNALS: // SIGNALS +""") + + for signal in signals: + self.do_signal(signal) + + # Close class + self.h("""\ +}; +""") + + def do_introspection(self, props, methods, signals): + self.do_prop_introspection(props) + self.do_method_introspection(methods) + self.do_signal_introspection(signals) + + def do_prop_introspection(self, props): + for prop in props: + if prop.namespaceURI: + continue + + name = prop.getAttribute('name') + access = prop.getAttribute('access') + sig = prop.getAttribute('type') + tptype = prop.getAttributeNS(NS_TP, 'type') + binding = binding_from_usage(sig, tptype, self.custom_lists, (sig, tptype) in self.externals, self.typesnamespace) + + if not binding.custom_type: + self.h("""\ +" \\n" +""" % {'access': access, + 'sig': sig, + 'name': name, + }) + else: + self.h("""\ +" \\n" +" \\n" +" \\n" +""" % {'access': access, + 'sig': sig, + 'name': name, + 'type': binding.val, + }) + + def do_method_introspection(self, methods): + for method in methods: + name = method.getAttribute('name') + args = get_by_path(method, 'arg') + argnames, argdocstrings, argbindings = extract_arg_or_member_info(args, + self.custom_lists, self.externals, self.typesnamespace, self.refs, ' * ') + + if not argnames: + self.h("""\ +" \\n" +""" % {'name': name}) + else: + self.h("""\ +" \\n" +""" % {'name': name}) + + outindex = 0 + inindex = 0 + for i in xrange(len(argnames)): + assert argnames[i] != None, 'Name missing from argument at index %d for signal %s' % (i, name) + + argbinding = argbindings[i] + argname = argnames[i] + argsig = args[i].getAttribute('type') + argdirection = args[i].getAttribute('direction') + + # QtDBus requires annotating a{sv} + if argsig == 'a{sv}': + argbinding.custom_type = True + + if not argbinding.custom_type: + self.h("""\ +" \\n" +""" % {'direction': argdirection, + 'sig': argsig, + 'name': argname}) + else: + self.h("""\ +" \\n" +" \\n" +" \\n" +""" % {'direction': argdirection, + 'sig': argsig, + 'name': argname, + 'type': argbinding.val, + 'index': 'In' + str(inindex) if argdirection == 'in' else 'Out' + str(outindex), + }) + + if argdirection == 'out': + outindex += 1 + else: + inindex += 1 + + self.h("""\ +" \\n" +""") + + def do_signal_introspection(self, signals): + for signal in signals: + name = signal.getAttribute('name') + args = get_by_path(signal, 'arg') + argnames, argdocstrings, argbindings = extract_arg_or_member_info(args, + self.custom_lists, self.externals, self.typesnamespace, self.refs, ' * ') + + if not argnames: + self.h("""\ +" \\n" +""" % {'name': name}) + else: + self.h("""\ +" \\n" +""" % {'name': name}) + + for i in xrange(len(argnames)): + assert argnames[i] != None, 'Name missing from argument at index %d for signal %s' % (i, name) + + argbinding = argbindings[i] + argname = argnames[i] + argsig = args[i].getAttribute('type') + + if not argbinding.custom_type: + self.h("""\ +" \\n" +""" % {'sig': argsig, + 'name': argname}) + else: + self.h("""\ +" \\n" +" \\n" +" \\n" +""" % {'sig': argsig, + 'name': argname, + 'type': argbinding.val, + 'index': i, + }) + + self.h("""\ +" \\n" +""") + + def do_mic_typedefs(self, methods): + for method in methods: + name = method.getAttribute('name') + args = get_by_path(method, 'arg') + argnames, argdocstrings, argbindings = extract_arg_or_member_info(args, self.custom_lists, + self.externals, self.typesnamespace, self.refs, ' * ') + + outargs = [] + for i in xrange(len(args)): + if args[i].getAttribute('direction') == 'out': + outargs.append(i) + + if outargs: + outargtypes = ', '.join([argbindings[i].val for i in outargs]) + else: + outargtypes = '' + + self.h("""\ + typedef Tp::MethodInvocationContextPtr< %(outargtypes)s > %(name)sContextPtr; +""" % {'name': name, + 'outargtypes': outargtypes, + }) + + def do_qprops(self, props): + for prop in props: + # Skip tp:properties + if not prop.namespaceURI: + self.do_qprop(prop) + + def do_qprop(self, prop): + name = prop.getAttribute('name') + access = prop.getAttribute('access') + gettername = name + settername = None + if 'write' in access: + settername = 'Set' + name + + sig = prop.getAttribute('type') + tptype = prop.getAttributeNS(NS_TP, 'type') + binding = binding_from_usage(sig, tptype, self.custom_lists, (sig, tptype) in self.externals, self.typesnamespace) + + self.h("""\ + Q_PROPERTY(%(type)s %(name)s %(getter)s %(setter)s) +""" % {'type': binding.val, + 'name': name, + 'getter': 'READ ' + gettername if ('read' in access) else '', + 'setter': 'WRITE ' + settername if ('write' in access) else '', + }) + + def do_prop(self, ifacename, prop): + name = prop.getAttribute('name') + adaptee_name = to_lower_camel_case(prop.getAttribute('tp:name-for-bindings')) + access = prop.getAttribute('access') + gettername = name + settername = None + if 'write' in access: + settername = 'Set' + name + docstring = format_docstring(prop, self.refs, ' * ').replace('*/', '*/') + + sig = prop.getAttribute('type') + tptype = prop.getAttributeNS(NS_TP, 'type') + binding = binding_from_usage(sig, tptype, self.custom_lists, (sig, tptype) in self.externals, self.typesnamespace) + + if 'read' in access: + self.h("""\ + /** + * Return the value of the exported D-Bus object property \\c %(name)s of type \\c %(type)s. + * + * Adaptees should export this property as a Qt property named + * '%(adaptee_name)s' with type %(type)s. + * +%(docstring)s\ + * + * \\return The value of exported property \\c %(name)s. + */ + %(type)s %(gettername)s() const; +""" % {'name': name, + 'adaptee_name': adaptee_name, + 'docstring': docstring, + 'type': binding.val, + 'gettername': gettername, + }) + + self.b(""" +%(type)s %(ifacename)s::%(gettername)s() const +{ + return qvariant_cast< %(type)s >(adaptee()->property("%(adaptee_name)s")); +} +""" % {'type': binding.val, + 'ifacename': ifacename, + 'gettername': gettername, + 'adaptee_name': adaptee_name, + }) + + if 'write' in access: + self.h("""\ + /** + * Set the value of the exported D-Bus object property \\c %(name)s of type \\c %(type)s. + * + * Adaptees should export this property as a writable Qt property named + * '%(adaptee_name)s' with type %(type)s. + * +%(docstring)s\ + */ + void %(settername)s(const %(type)s &newValue); +""" % {'name': name, + 'adaptee_name': adaptee_name, + 'docstring': docstring, + 'settername': settername, + 'type': binding.val, + }) + + self.b(""" +void %(ifacename)s::%(settername)s(const %(type)s &newValue) +{ + adaptee()->setProperty("%(adaptee_name)s", qVariantFromValue(newValue)); +} +""" % {'ifacename': ifacename, + 'settername': settername, + 'type': binding.val, + 'adaptee_name': adaptee_name, + }) + + def do_method(self, ifacename, method): + name = method.getAttribute('name') + adaptee_name = to_lower_camel_case(method.getAttribute('tp:name-for-bindings')) + args = get_by_path(method, 'arg') + argnames, argdocstrings, argbindings = extract_arg_or_member_info(args, self.custom_lists, + self.externals, self.typesnamespace, self.refs, ' * ') + docstring = format_docstring(method, self.refs, ' * ').replace('*/', '*/') + + inargs = [] + outargs = [] + + for i in xrange(len(args)): + if args[i].getAttribute('direction') == 'out': + outargs.append(i) + else: + inargs.append(i) + assert argnames[i] != None, 'No argument name for input argument at index %d for method %s' % (i, name) + + if outargs: + rettype = argbindings[outargs[0]].val + else: + rettype = 'void' + + params = [argbindings[i].inarg + ' ' + argnames[i] for i in inargs] + params.append('const QDBusMessage& dbusMessage') + params += [argbindings[i].outarg + ' ' + argnames[i] for i in outargs[1:]] + params = ', '.join(params) + + if outargs: + outargtypes = ', '.join([argbindings[i].val for i in outargs]) + else: + outargtypes = '' + invokemethodargs = ', '.join(['Q_ARG(' + argbindings[i].val + ', ' + argnames[i] + ')' for i in inargs]) + + inparams = [argbindings[i].val for i in inargs] + inparams.append("%s::%s::%sContextPtr" % (self.namespace, ifacename, name)) + normalized_adaptee_params = ','.join(inparams) + + adaptee_params = [argbindings[i].inarg + ' ' + argnames[i] for i in inargs] + adaptee_params.append('const %(namespace)s::%(ifacename)s::%(name)sContextPtr &context' % + {'namespace': self.namespace, + 'ifacename': ifacename, + 'name': name}) + adaptee_params = ', '.join(adaptee_params) + + self.h("""\ + /** + * Begins a call to the exported D-Bus method \\c %(name)s on this object. + * + * Adaptees should export this method as a Qt slot with the following signature: + * void %(adaptee_name)s(%(adaptee_params)s); + * + * Implementations should call MethodInvocationContext::setFinished (or setFinishedWithError + * accordingly) on the received \\a context object once the method has finished processing. + * +%(docstring)s\ + * +""" % {'name': name, + 'adaptee_name': adaptee_name, + 'adaptee_params': adaptee_params, + 'rettype': rettype, + 'docstring': docstring + }) + + for i in inargs: + if argdocstrings[i]: + self.h("""\ + * \\param %s +%s\ +""" % (argnames[i], argdocstrings[i])) + + for i in outargs[1:]: + if argdocstrings[i]: + self.h("""\ + * \\param %s Output parameter +%s\ +""" % (argnames[i], argdocstrings[i])) + + if outargs: + self.h("""\ + * \\return +%s\ +""" % argdocstrings[outargs[0]]) + + self.h("""\ + */ + %(rettype)s %(name)s(%(params)s); +""" % {'rettype': rettype, + 'name': name, + 'params': params + }) + + self.b(""" +%(rettype)s %(ifacename)s::%(name)s(%(params)s) +{ + if (!adaptee()->metaObject()->indexOfMethod("%(adaptee_name)s(%(normalized_adaptee_params)s)") == -1) { + dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"))); +""" % {'rettype': rettype, + 'ifacename': ifacename, + 'name': name, + 'adaptee_name': adaptee_name, + 'normalized_adaptee_params': normalized_adaptee_params, + 'params': params, + }) + + if rettype != 'void': + self.b("""\ + return %(rettype)s(); +""" % {'rettype': rettype}) + else: + self.b("""\ + return; +""") + + self.b("""\ + } + + %(name)sContextPtr ctx = %(name)sContextPtr( + new Tp::MethodInvocationContext< %(outargtypes)s >(dbusConnection(), dbusMessage)); +""" % {'name': name, + 'outargtypes': outargtypes, + }) + + if invokemethodargs: + self.b("""\ + QMetaObject::invokeMethod(adaptee(), "%(adaptee_name)s", + %(invokemethodargs)s, + Q_ARG(%(namespace)s::%(ifacename)s::%(name)sContextPtr, ctx)); +""" % {'namespace': self.namespace, + 'ifacename': ifacename, + 'name': name, + 'adaptee_name': adaptee_name, + 'invokemethodargs': invokemethodargs, + }) + else: + self.b("""\ + QMetaObject::invokeMethod(adaptee(), "%(lname)s", + Q_ARG(%(namespace)s::%(ifacename)s::%(name)sContextPtr, ctx)); +""" % {'namespace': self.namespace, + 'ifacename': ifacename, + 'name': name, + 'lname': (name[0].lower() + name[1:]), + }) + + if rettype != 'void': + self.b("""\ + return %(rettype)s(); +""" % {'rettype': rettype}) + + self.b("}\n") + + def do_signal(self, signal): + name = signal.getAttribute('name') + adaptee_name = to_lower_camel_case(signal.getAttribute('tp:name-for-bindings')) + argnames, argdocstrings, argbindings = extract_arg_or_member_info(get_by_path(signal, + 'arg'), self.custom_lists, self.externals, self.typesnamespace, self.refs, ' * ') + params = ', '.join(['%s %s' % (binding.inarg, param_name) for binding, param_name in zip(argbindings, argnames)]) + + for i in xrange(len(argnames)): + assert argnames[i] != None, 'Name missing from argument at index %d for signal %s' % (i, name) + + self.h("""\ + /** + * Represents the exported D-Bus signal \\c %(name)s on this object. + * + * Adaptees should export this signal as a Qt signal with the following signature: + * void %(adaptee_name)s(%(params)s); + * + * The adaptee signal will be automatically relayed as a D-Bus signal once emitted. + * +""" % {'name': name, + 'adaptee_name': adaptee_name, + 'params': params + }) + + for i in xrange(len(argnames)): + assert argnames[i] != None, 'Name missing from argument at index %d for signal %s' % (i, name) + if argdocstrings[i]: + self.h("""\ + * \\param %s +%s\ +""" % (argnames[i], argdocstrings[i])) + + self.h("""\ + */ + void %(name)s(%(params)s); +""" % {'name': name, + 'params': params + }) + + def do_signals_connect(self, signals): + for signal in signals: + name = signal.getAttribute('name') + adaptee_name = to_lower_camel_case(signal.getAttribute('tp:name-for-bindings')) + _, _, argbindings = extract_arg_or_member_info(get_by_path(signal, 'arg'), + self.custom_lists, self.externals, self.typesnamespace, self.refs, ' * ') + + self.b("""\ + connect(adaptee, SIGNAL(%(adaptee_name)s(%(params)s)), SIGNAL(%(name)s(%(params)s))); +""" % {'name': name, + 'adaptee_name': adaptee_name, + 'params': ', '.join([binding.inarg for binding in argbindings]) + }) + + def h(self, str): + self.hs.append(str) + + def b(self, str): + self.bs.append(str) + + def hb(self, str): + self.h(str) + self.b(str) + + +if __name__ == '__main__': + options, argv = gnu_getopt(argv[1:], '', + ['group=', + 'headerfile=', + 'implfile=', + 'namespace=', + 'typesnamespace=', + 'realinclude=', + 'mocinclude=', + 'prettyinclude=', + 'extraincludes=', + 'must-define=', + 'visibility=', + 'ifacexml=', + 'specxml=']) + + Generator(dict(options))() diff --git a/tools/qt-types-gen.py b/tools/qt-types-gen.py new file mode 100644 index 0000000..119cf9c --- /dev/null +++ b/tools/qt-types-gen.py @@ -0,0 +1,557 @@ +#!/usr/bin/python +# +# Copyright (C) 2008 Collabora Limited +# Copyright (C) 2008 Nokia Corporation +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import sys +import xml.dom.minidom +from getopt import gnu_getopt + +from libtpcodegen import NS_TP, get_descendant_text, get_by_path +from libqtcodegen import binding_from_usage, binding_from_decl, extract_arg_or_member_info, format_docstring, gather_externals, gather_custom_lists, get_qt_name, get_headerfile_cmd, RefRegistry + +class BrokenSpecException(Exception): + pass + +class MissingTypes(BrokenSpecException): + def __init__(self, types): + super(MissingTypes, self).__init__(self) + self.types = types + + def __str__(self): + typelist = ''.join([' %s' % t for t in self.types]) + return "The following types were used, but not provided by the spec " \ + "or by declarations in all.xml:\n%s" % typelist + +class UnresolvedDependency(BrokenSpecException): + def __init__(self, child, parent): + super(UnresolvedDependency, self).__init__(self) + self.child = child + self.parent = parent + + def __str__(self): + return 'Type %s has unresolved dependency on %s' % ( + self.child, self.parent) + +class EmptyStruct(BrokenSpecException): + def __init__(self, struct_name): + super(EmptyStruct, self).__init__(self) + self.struct_name = struct_name + + def __str__(self): + return 'tp:struct %s should have some members' % self.struct_name + +class MalformedMapping(BrokenSpecException): + def __init__(self, mapping_name, members): + super(MalformedMapping, self).__init__(self) + self.mapping_name = mapping_name + self.members = members + + def __str__(self): + return 'tp:mapping %s should have 2 members, not %u' % ( + self.mapping_name, self.members) + +class WTF(BrokenSpecException): + def __init__(self, element_name): + super(BrokenSpecException, self).__init__(self) + self.element_name = element_name + + def __str__(self): + return 'What the hell is a tp:%s?' % self.element_name + + +class DepInfo: + def __init__(self, el, externals, custom_lists): + self.el = el + name = get_by_path(el, '@name') + array_name = get_by_path(el, '@array-name') + array_depth = get_by_path(el, '@array-depth') + if array_depth: + array_depth = int(array_depth) + else: + array_depth = None + self.binding = binding_from_decl(name, array_name, array_depth) + self.deps = [] + + for member in get_by_path(el, 'member'): + sig = member.getAttribute('type') + tptype = member.getAttributeNS(NS_TP, 'type') + + if (sig, tptype) in externals: + continue + + if tptype.endswith('[]'): + tptype = tptype[:-2] + + binding = binding_from_usage(sig, tptype, custom_lists) + + if binding.custom_type: + self.deps.append(binding.val) + + self.revdeps = [] + +class Generator(object): + def __init__(self, opts): + try: + self.namespace = opts['--namespace'] + self.declfile = opts['--declfile'] + self.implfile = opts['--implfile'] + self.realinclude = opts['--realinclude'] + self.prettyinclude = opts.get('--prettyinclude', self.realinclude) + self.extraincludes = opts.get('--extraincludes', None) + self.must_define = opts.get('--must-define', None) + self.visibility = opts.get('--visibility', '') + dom = xml.dom.minidom.parse(opts['--specxml']) + except KeyError, k: + assert False, 'Missing required parameter %s' % k.args[0] + + self.decls = [] + self.impls = [] + self.spec = get_by_path(dom, "spec")[0] + self.externals = gather_externals(self.spec) + self.custom_lists = gather_custom_lists(self.spec, self.namespace) + self.required_custom = [] + self.required_arrays = [] + self.to_declare = [] + self.depinfos = {} + self.refs = RefRegistry(self.spec) + + def __call__(self): + # Emit comment header + + self.both('/* Generated from ') + self.both(get_descendant_text(get_by_path(self.spec, 'title'))) + version = get_by_path(self.spec, "version") + + if version: + self.both(', version ' + get_descendant_text(version)) + + self.both(' */\n') + + # Gather info on available and required types + + self.gather_required() + + if self.must_define: + self.decl('\n') + self.decl('#ifndef %s\n' % self.must_define) + self.decl('#error %s\n' % self.must_define) + self.decl('#endif') + + self.decl('\n') + + if self.extraincludes: + for include in self.extraincludes.split(','): + self.decl('#include %s\n' % include) + + self.decl(""" +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +/** + * \\addtogroup typesconstants Types and constants + * + * Enumerated, flag, structure, list and mapping types and utility constants. + */ + +/** + * \\defgroup struct Structure types + * \\ingroup typesconstants + * + * Structure types generated from the specification. + */ + +/** + * \\defgroup list List types + * \\ingroup typesconstants + * + * List types generated from the specification. + */ + +/** + * \\defgroup mapping Mapping types + * \\ingroup typesconstants + * + * Mapping types generated from the specification. + */ + +""") + + if self.must_define: + self.impl(""" +#define %s""" % self.must_define) + + self.impl(""" +#include "%s" +""" % self.realinclude) + + self.both(""" +namespace %s +{ +""" % self.namespace) + + # Emit type definitions for types provided in the spec + + self.provide_all() + + # Emit type registration function + + self.decl(""" +} // namespace %s + +""" % self.namespace) + + self.impl("""\ +TP_QT_NO_EXPORT void _registerTypes() +{ + static bool registered = false; + if (registered) + return; + registered = true; + +""") + + # Emit Qt metatype declarations + + self.to_declare.sort() + + for metatype in self.to_declare: + self.decl('Q_DECLARE_METATYPE(%s)\n' % metatype) + self.impl(' qDBusRegisterMetaType<%s>();\n' % ((metatype.endswith('>') and metatype + ' ') or metatype)) + + self.impl("""\ +} + +} // namespace %s +""" % self.namespace) + + # Write output to files + + open(self.declfile, 'w').write(''.join(self.decls).encode("utf-8")) + open(self.implfile, 'w').write(''.join(self.impls).encode("utf-8")) + + def decl(self, str): + self.decls.append(str) + + def impl(self, str): + self.impls.append(str) + + def both(self, str): + self.decl(str) + self.impl(str) + + def gather_required(self): + members = self.spec.getElementsByTagNameNS(NS_TP, 'member') + args = self.spec.getElementsByTagName('arg') + props = self.spec.getElementsByTagName('property') + tp_props = self.spec.getElementsByTagNameNS(NS_TP, 'property') + + for requirer in members + args + props + tp_props: + sig = requirer.getAttribute('type') + tptype = requirer.getAttributeNS(NS_TP, 'type') + external = (sig, tptype) in self.externals + binding = binding_from_usage(sig, tptype, self.custom_lists, external) + + if binding.custom_type and binding.val not in self.required_custom: + self.required_custom.append(binding.val) + + if not binding.custom_type and binding.array_of and (binding.val, binding.array_of) not in self.required_arrays: + self.required_arrays.append((binding.val, binding.array_of)) + + def provide_all(self): + self.required_arrays.sort() + for (val, array_of) in self.required_arrays: + real = 'QList<%s>' % array_of + self.decl("""\ +/** + * \\struct %s + * \\ingroup list +%s\ + * + * Generic list type with %s elements. Convertible with + * %s, but needed to have a discrete type in the Qt type system. + */ +""" % (val, get_headerfile_cmd(self.realinclude, self.prettyinclude), array_of, real)) + self.decl(self.faketype(val, real)) + self.to_declare.append(self.namespace + '::' + val) + + structs = self.spec.getElementsByTagNameNS(NS_TP, 'struct') + mappings = self.spec.getElementsByTagNameNS(NS_TP, 'mapping') + exts = self.spec.getElementsByTagNameNS(NS_TP, 'external-type') + + for deptype in structs + mappings: + info = DepInfo(deptype, self.externals, self.custom_lists) + self.depinfos[info.binding.val] = info + + leaves = [] + next_leaves = [] + + for val, depinfo in self.depinfos.iteritems(): + leaf = True + + for dep in depinfo.deps: + if not self.depinfos.has_key(dep): + raise UnresolvedDependency(val, dep) + + leaf = False + self.depinfos[dep].revdeps.append(val) + + if leaf: + next_leaves.append(val) + + while leaves or next_leaves: + if not leaves: + leaves = next_leaves + leaves.sort() + next_leaves = [] + + val = leaves.pop(0) + depinfo = self.depinfos[val] + self.output_by_depinfo(depinfo) + + for revdep in depinfo.revdeps: + revdepinfo = self.depinfos[revdep] + revdepinfo.deps.remove(val) + + if not revdepinfo.deps: + next_leaves.append(revdep) + + del self.depinfos[val] + + for provider in structs + mappings + exts: + name = get_by_path(provider, '@name') + array_name = get_by_path(provider, '@array-name') + array_depth = get_by_path(provider, '@array-depth') + if array_depth: + array_depth = int(array_depth) + else: + array_depth = None + sig = provider.getAttribute('type') + tptype = provider.getAttribute('name') + external = (sig, tptype) in self.externals + binding = binding_from_decl(name, array_name, array_depth, external) + self.provide(binding.val) + + if binding.array_val: + self.provide(binding.array_val) + + d = binding.array_depth + while d > 1: + d -= 1 + self.provide(binding.array_val + ('List' * d)) + + if self.required_custom: + raise MissingTypes(self.required_custom) + + def provide(self, type): + if type in self.required_custom: + self.required_custom.remove(type) + + def output_by_depinfo(self, depinfo): + names, docstrings, bindings = extract_arg_or_member_info(get_by_path(depinfo.el, 'member'), self.custom_lists, self.externals, None, self.refs, ' * ', (' /**', ' */')) + members = len(names) + + if depinfo.el.localName == 'struct': + if members == 0: + raise EmptyStruct(depinfo.binding.val) + + self.decl("""\ +/** + * \\struct %(name)s + * \\ingroup struct +%(headercmd)s\ + * + * Structure type generated from the specification. +%(docstring)s\ + */ +struct %(visibility)s %(name)s +{ +""" % { + 'name' : depinfo.binding.val, + 'headercmd': get_headerfile_cmd(self.realinclude, self.prettyinclude), + 'docstring' : format_docstring(depinfo.el, self.refs), + 'visibility': self.visibility, + }) + + for i in xrange(members): + self.decl("""\ +%s\ + %s %s; +""" % (docstrings[i], bindings[i].val, names[i])) + + self.decl("""\ +}; + +""") + + self.both('%s bool operator==(%s v1, %s v2)' % + (self.visibility, + depinfo.binding.inarg, + depinfo.binding.inarg)) + self.decl(';\n') + self.impl(""" +{""") + if (bindings[0].val != 'QDBusVariant'): + self.impl(""" + return ((v1.%s == v2.%s)""" % (names[0], names[0])) + else: + self.impl(""" + return ((v1.%s.variant() == v2.%s.variant())""" % (names[0], names[0])) + for i in xrange(1, members): + if (bindings[i].val != 'QDBusVariant'): + self.impl(""" + && (v1.%s == v2.%s)""" % (names[i], names[i])) + else: + self.impl(""" + && (v1.%s.variant() == v2.%s.variant())""" % (names[i], names[i])) + self.impl(""" + ); +} + +""") + + self.decl('inline bool operator!=(%s v1, %s v2)' % + (depinfo.binding.inarg, depinfo.binding.inarg)) + self.decl(""" +{ + return !operator==(v1, v2); +} +""") + + self.both('%s QDBusArgument& operator<<(QDBusArgument& arg, %s val)' % + (self.visibility, depinfo.binding.inarg)) + self.decl(';\n') + self.impl(""" +{ + arg.beginStructure(); + arg << %s; + arg.endStructure(); + return arg; +} + +""" % ' << '.join(['val.' + name for name in names])) + + self.both('%s const QDBusArgument& operator>>(const QDBusArgument& arg, %s val)' % + (self.visibility, depinfo.binding.outarg)) + self.decl(';\n\n') + self.impl(""" +{ + arg.beginStructure(); + arg >> %s; + arg.endStructure(); + return arg; +} + +""" % ' >> '.join(['val.' + name for name in names])) + elif depinfo.el.localName == 'mapping': + if members != 2: + raise MalformedMapping(depinfo.binding.val, members) + + realtype = 'QMap<%s, %s>' % (bindings[0].val, (bindings[1].val.endswith('>') and bindings[1].val + ' ') or bindings[1].val) + self.decl("""\ +/** + * \\struct %s + * \\ingroup mapping +%s\ + * + * Mapping type generated from the specification. Convertible with + * %s, but needed to have a discrete type in the Qt type system. +%s\ + */ +""" % (depinfo.binding.val, get_headerfile_cmd(self.realinclude, self.prettyinclude), realtype, format_docstring(depinfo.el, self.refs))) + self.decl(self.faketype(depinfo.binding.val, realtype)) + else: + raise WTF(depinfo.el.localName) + + self.to_declare.append(self.namespace + '::' + depinfo.binding.val) + + if depinfo.binding.array_val: + self.to_declare.append('%s::%s' % (self.namespace, depinfo.binding.array_val)) + self.decl("""\ +/** + * \\ingroup list +%s\ + * + * Array of %s values. + */ +typedef %s %s; + +""" % (get_headerfile_cmd(self.realinclude, self.prettyinclude), depinfo.binding.val, 'QList<%s>' % depinfo.binding.val, depinfo.binding.array_val)) + + i = depinfo.binding.array_depth + while i > 1: + i -= 1 + self.to_declare.append('%s::%s%s' % (self.namespace, depinfo.binding.array_val, ('List' * i))) + list_of = depinfo.binding.array_val + ('List' * (i-1)) + self.decl("""\ +/** + * \\ingroup list +%s\ + * + * Array of %s values. + */ +typedef QList<%s> %sList; + +""" % (get_headerfile_cmd(self.realinclude, self.prettyinclude), list_of, list_of, list_of)) + + def faketype(self, fake, real): + return """\ +struct %(visibility)s %(fake)s : public %(real)s +{ + inline %(fake)s() : %(real)s() {} + inline %(fake)s(const %(real)s& a) : %(real)s(a) {} + + inline %(fake)s& operator=(const %(real)s& a) + { + *(static_cast<%(real)s*>(this)) = a; + return *this; + } +}; + +""" % {'fake' : fake, 'real' : real, 'visibility': self.visibility} + +if __name__ == '__main__': + options, argv = gnu_getopt(sys.argv[1:], '', + ['declfile=', + 'implfile=', + 'realinclude=', + 'prettyinclude=', + 'extraincludes=', + 'must-define=', + 'namespace=', + 'specxml=', + 'visibility=', + ]) + + try: + Generator(dict(options))() + except BrokenSpecException as e: + print >> sys.stderr, 'Your spec is broken, dear developer! %s' % e + sys.exit(42) diff --git a/tools/qt4-client-gen.py b/tools/qt4-client-gen.py deleted file mode 100644 index 2222394..0000000 --- a/tools/qt4-client-gen.py +++ /dev/null @@ -1,545 +0,0 @@ -#!/usr/bin/python -# -# Copyright (C) 2008 Collabora Limited -# Copyright (C) 2008 Nokia Corporation -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -from sys import argv -import xml.dom.minidom -import codecs -from getopt import gnu_getopt - -from libtpcodegen import NS_TP, get_descendant_text, get_by_path -from libqt4codegen import binding_from_usage, extract_arg_or_member_info, format_docstring, gather_externals, gather_custom_lists, get_headerfile_cmd, get_qt4_name, qt4_identifier_escape - -class Generator(object): - def __init__(self, opts): - try: - self.group = opts.get('--group', '') - self.headerfile = opts['--headerfile'] - self.implfile = opts['--implfile'] - self.namespace = opts['--namespace'] - self.typesnamespace = opts['--typesnamespace'] - self.realinclude = opts['--realinclude'] - self.prettyinclude = opts.get('--prettyinclude') - self.extraincludes = opts.get('--extraincludes', None) - self.mainiface = opts.get('--mainiface', None) - self.must_define = opts.get('--must-define', None) - self.dbus_proxy = opts.get('--dbus-proxy', - 'Tp::DBusProxy') - self.visibility = opts.get('--visibility', '') - ifacedom = xml.dom.minidom.parse(opts['--ifacexml']) - specdom = xml.dom.minidom.parse(opts['--specxml']) - except KeyError, k: - assert False, 'Missing required parameter %s' % k.args[0] - - self.hs = [] - self.bs = [] - self.ifacenodes = ifacedom.getElementsByTagName('node') - self.spec, = get_by_path(specdom, "spec") - self.custom_lists = gather_custom_lists(self.spec, self.typesnamespace) - self.externals = gather_externals(self.spec) - - def __call__(self): - # Output info header and includes - self.h("""\ -/* - * This file contains D-Bus client proxy classes generated by qt4-client-gen.py. - * - * This file can be distributed under the same terms as the specification from - * which it was generated. - */ -""") - - if self.must_define: - self.h('\n') - self.h('#ifndef %s\n' % self.must_define) - self.h('#error %s\n' % self.must_define) - self.h('#endif\n') - - self.h('\n') - - if self.extraincludes: - for include in self.extraincludes.split(','): - self.h('#include %s\n' % include) - - self.h(""" -#include - -#include -#include -#include - -#include - -#include -#include -#include - -namespace Tp -{ -class PendingVariant; -class PendingOperation; -} - -""") - - if self.must_define: - self.b("""#define %s\n""" % (self.must_define)) - - self.b("""#include "%s" - -""" % self.realinclude) - - # Begin namespace - for ns in self.namespace.split('::'): - self.hb("""\ -namespace %s -{ -""" % ns) - - # Output interface proxies - def ifacenodecmp(x, y): - xname, yname = [self.namespace + '::' + node.getAttribute('name').replace('/', '').replace('_', '') + 'Interface' for node in x, y] - - if xname == self.mainiface: - return -1 - elif yname == self.mainiface: - return 1 - else: - return cmp(xname, yname) - - self.ifacenodes.sort(cmp=ifacenodecmp) - for ifacenode in self.ifacenodes: - self.do_ifacenode(ifacenode) - - # End namespace - self.hb(''.join(['}\n' for ns in self.namespace.split('::')])) - - # Add metatype declaration - otherwise QTBUG #2151 might be triggered - for ifacenode in self.ifacenodes: - classname = ifacenode.getAttribute('name').replace('/', '').replace('_', '') + 'Interface' - self.h("Q_DECLARE_METATYPE(" + self.namespace + "::" + classname + "*)\n") - - # Write output to files - (codecs.getwriter('utf-8')(open(self.headerfile, 'w'))).write(''.join(self.hs)) - (codecs.getwriter('utf-8')(open(self.implfile, 'w'))).write(''.join(self.bs)) - - def do_ifacenode(self, ifacenode): - # Extract info - name = ifacenode.getAttribute('name').replace('/', '').replace('_', '') + 'Interface' - iface, = get_by_path(ifacenode, 'interface') - dbusname = iface.getAttribute('name') - - # Begin class, constructors - self.h(""" -/** - * \\class %(name)s -%(headercmd)s\ -%(groupcmd)s\ - * - * Proxy class providing a 1:1 mapping of the D-Bus interface "%(dbusname)s." - */ -class %(visibility)s %(name)s : public Tp::AbstractInterface -{ - Q_OBJECT - -public: - /** - * Returns the name of the interface "%(dbusname)s", which this class - * represents. - * - * \\return The D-Bus interface name. - */ - static inline QLatin1String staticInterfaceName() - { - return QLatin1String("%(dbusname)s"); - } - - /** - * Creates a %(name)s associated with the given object on the session bus. - * - * \\param busName Name of the service the object is on. - * \\param objectPath Path to the object on the service. - * \\param parent Passed to the parent class constructor. - */ - %(name)s( - const QString& busName, - const QString& objectPath, - QObject* parent = 0 - ); - - /** - * Creates a %(name)s associated with the given object on the given bus. - * - * \\param connection The bus via which the object can be reached. - * \\param busName Name of the service the object is on. - * \\param objectPath Path to the object on the service. - * \\param parent Passed to the parent class constructor. - */ - %(name)s( - const QDBusConnection& connection, - const QString& busName, - const QString& objectPath, - QObject* parent = 0 - ); -""" % {'name' : name, - 'headercmd' : get_headerfile_cmd(self.realinclude, self.prettyinclude), - 'groupcmd' : self.group and (' * \\ingroup %s\n' % self.group), - 'dbusname' : dbusname, - 'visibility': self.visibility, - }) - - self.b(""" -%(name)s::%(name)s(const QString& busName, const QString& objectPath, QObject *parent) - : Tp::AbstractInterface(busName, objectPath, staticInterfaceName(), QDBusConnection::sessionBus(), parent) -{ -} - -%(name)s::%(name)s(const QDBusConnection& connection, const QString& busName, const QString& objectPath, QObject *parent) - : Tp::AbstractInterface(busName, objectPath, staticInterfaceName(), connection, parent) -{ -} -""" % {'name' : name}) - - # Construct from DBusProxy subclass - self.h(""" - /** - * Creates a %(name)s associated with the same object as the given proxy. - * - * \\param proxy The proxy to use. It will also be the QObject::parent() - * for this object. - */ - %(name)s(%(dbus_proxy)s *proxy); -""" % {'name' : name, - 'dbus_proxy' : self.dbus_proxy}) - - self.b(""" -%(name)s::%(name)s(%(dbus_proxy)s *proxy) - : Tp::AbstractInterface(proxy, staticInterfaceName()) -{ -} -""" % {'name' : name, - 'dbus_proxy' : self.dbus_proxy}) - - # Main interface - mainiface = self.mainiface or 'Tp::AbstractInterface' - - if mainiface != self.namespace + '::' + name: - self.h(""" - /** - * Creates a %(name)s associated with the same object as the given proxy. - * Additionally, the created proxy will have the same parent as the given - * proxy. - * - * \\param mainInterface The proxy to use. - */ - explicit %(name)s(const %(mainiface)s& mainInterface); - - /** - * Creates a %(name)s associated with the same object as the given proxy. - * However, a different parent object can be specified. - * - * \\param mainInterface The proxy to use. - * \\param parent Passed to the parent class constructor. - */ - %(name)s(const %(mainiface)s& mainInterface, QObject* parent); -""" % {'name' : name, - 'mainiface' : mainiface}) - - self.b(""" -%(name)s::%(name)s(const %(mainiface)s& mainInterface) - : Tp::AbstractInterface(mainInterface.service(), mainInterface.path(), staticInterfaceName(), mainInterface.connection(), mainInterface.parent()) -{ -} - -%(name)s::%(name)s(const %(mainiface)s& mainInterface, QObject *parent) - : Tp::AbstractInterface(mainInterface.service(), mainInterface.path(), staticInterfaceName(), mainInterface.connection(), parent) -{ -} -""" % {'name' : name, - 'mainiface' : mainiface}) - - # Properties - has_props = False - for prop in get_by_path(iface, 'property'): - # Skip tp:properties - if not prop.namespaceURI: - self.do_prop(prop) - has_props = True - - self.h(""" - /** - * Request all of the DBus properties on the interface. - * - * \\return A pending variant map which will emit finished when the properties have - * been retrieved. - */ - Tp::PendingVariantMap *requestAllProperties() const - { - return internalRequestAllProperties(); - } -""") - - # Methods - methods = get_by_path(iface, 'method') - - if methods: - self.h(""" -public Q_SLOTS:\ -""") - - for method in methods: - self.do_method(method) - - # Signals - signals = get_by_path(iface, 'signal') - - if signals: - self.h(""" -Q_SIGNALS:\ -""") - - for signal in signals: - self.do_signal(signal) - - # invalidated handler (already a slot in the superclass) - # we can't just use disconnect(this, NULL, NULL, NULL) because - # (a) that would disconnect QObject::destroyed() and other non-D-Bus - # signals, and (b) QtDBus doesn't support that usage anyway (it needs - # specific signals in order to remove its signal match rules) - self.h(""" -protected: - virtual void invalidate(Tp::DBusProxy *, const QString &, const QString &); -""") - - self.b(""" -void %(name)s::invalidate(Tp::DBusProxy *proxy, - const QString &error, const QString &message) -{ -""" % {'name' : name}) - - for signal in signals: - self.do_signal_disconnect(signal) - - self.b(""" - Tp::AbstractInterface::invalidate(proxy, error, message); -} -""") - - # Close class - self.h("""\ -}; -""") - - def do_prop(self, prop): - name = prop.getAttribute('name') - access = prop.getAttribute('access') - gettername = name - settername = None - - sig = prop.getAttribute('type') - tptype = prop.getAttributeNS(NS_TP, 'type') - binding = binding_from_usage(sig, tptype, self.custom_lists, (sig, tptype) in self.externals, self.typesnamespace) - - if 'write' in access: - settername = 'set' + name - - if 'read' in access: - self.h(""" - /** - * Asynchronous getter for the remote object property "%(name)s" of type %(val)s. - * -%(docstring)s\ - * - * \\return A pending variant which will emit finished when the property has been - * retrieved. - */ - inline Tp::PendingVariant *%(gettername)s() const - { - return internalRequestProperty(QLatin1String("%(name)s")); - } -""" % {'name' : name, - 'docstring' : format_docstring(prop, ' * ').replace('*/', - '*/'), - 'val' : binding.val, - 'name' : name, - 'gettername' : 'requestProperty' + name}) - - if 'write' in access: - self.h(""" - /** - * Asynchronous setter for the remote object property "%(name)s" of type %(type)s. - * -%(docstring)s\ - * - * \\return A pending operation which will emit finished when the property has been - * set. - */ - inline Tp::PendingOperation *%(settername)s(%(type)s newValue) - { - return internalSetProperty(QLatin1String("%(name)s"), QVariant::fromValue(newValue)); - } -""" % {'name' : name, - 'docstring' : format_docstring(prop, ' * ').replace('*/', - '*/'), - 'type' : binding.val, - 'name' : name, - 'settername' : 'setProperty' + name}) - - def do_method(self, method): - name = method.getAttribute('name') - args = get_by_path(method, 'arg') - argnames, argdocstrings, argbindings = extract_arg_or_member_info(args, self.custom_lists, self.externals, self.typesnamespace, ' * ') - - inargs = [] - outargs = [] - - for i in xrange(len(args)): - if args[i].getAttribute('direction') == 'out': - outargs.append(i) - else: - inargs.append(i) - assert argnames[i] != None, 'No argument name for input argument at index %d for method %s' % (i, name) - - rettypes = ', '.join([argbindings[i].val for i in outargs]) - params = ', '.join([argbindings[i].inarg + ' ' + argnames[i] for i in inargs]) - if params: - params += ', int timeout = -1' - else: - params = 'int timeout = -1' - - self.h(""" - /** - * Begins a call to the D-Bus method "%s" on the remote object. -%s\ - * - * Note that \\a timeout is ignored as of now. It will be used once - * http://bugreports.qt.nokia.com/browse/QTBUG-11775 is fixed. - * -""" % (name, format_docstring(method, ' * '))) - - for i in inargs: - if argdocstrings[i]: - self.h("""\ - * - * \\param %s -%s\ -""" % (argnames[i], argdocstrings[i])) - - self.h("""\ - * \\param timeout The timeout in milliseconds. -""") - - for i in outargs: - if argdocstrings[i]: - self.h("""\ - * - * \\return -%s\ -""" % argdocstrings[i]) - - self.h("""\ - */ - inline QDBusPendingReply<%(rettypes)s> %(name)s(%(params)s) - { - if (!invalidationReason().isEmpty()) { - return QDBusPendingReply<%(rettypes)s>(QDBusMessage::createError( - invalidationReason(), - invalidationMessage() - )); - } -""" % {'rettypes' : rettypes, - 'name' : name, - 'params' : params}) - - if inargs: - self.h(""" - QDBusMessage callMessage = QDBusMessage::createMethodCall(this->service(), this->path(), - this->staticInterfaceName(), QLatin1String("%s")); - callMessage << %s; - return this->connection().asyncCall(callMessage, timeout); - } -""" % (name, ' << '.join(['QVariant::fromValue(%s)' % argnames[i] for i in inargs]))) - else: - self.h(""" - QDBusMessage callMessage = QDBusMessage::createMethodCall(this->service(), this->path(), - this->staticInterfaceName(), QLatin1String("%s")); - return this->connection().asyncCall(callMessage, timeout); - } -""" % name) - - def do_signal(self, signal): - name = signal.getAttribute('name') - argnames, argdocstrings, argbindings = extract_arg_or_member_info(get_by_path(signal, 'arg'), self.custom_lists, self.externals, self.typesnamespace, ' * ') - - self.h(""" - /** - * Represents the signal "%s" on the remote object. -%s\ -""" % (name, format_docstring(signal, ' * '))) - - for i in xrange(len(argnames)): - assert argnames[i] != None, 'Name missing from argument at index %d for signal %s' % (i, name) - if argdocstrings[i]: - self.h("""\ - * - * \\param %s -%s\ -""" % (argnames[i], argdocstrings[i])) - - self.h("""\ - */ - void %s(%s); -""" % (name, ', '.join(['%s %s' % (binding.inarg, name) for binding, name in zip(argbindings, argnames)]))) - - def do_signal_disconnect(self, signal): - name = signal.getAttribute('name') - _, _, argbindings = extract_arg_or_member_info(get_by_path(signal, 'arg'), self.custom_lists, self.externals, self.typesnamespace, ' * ') - - self.b("""\ - disconnect(this, SIGNAL(%s(%s)), NULL, NULL); -""" % (name, ', '.join([binding.inarg for binding in argbindings]))) - - def h(self, str): - self.hs.append(str) - - def b(self, str): - self.bs.append(str) - - def hb(self, str): - self.h(str) - self.b(str) - - -if __name__ == '__main__': - options, argv = gnu_getopt(argv[1:], '', - ['group=', - 'namespace=', - 'typesnamespace=', - 'headerfile=', - 'implfile=', - 'ifacexml=', - 'specxml=', - 'realinclude=', - 'prettyinclude=', - 'extraincludes=', - 'mainiface=', - 'must-define=', - 'dbus-proxy=', - 'visibility=']) - - Generator(dict(options))() diff --git a/tools/qt4-constants-gen.py b/tools/qt4-constants-gen.py deleted file mode 100644 index 11c4b5e..0000000 --- a/tools/qt4-constants-gen.py +++ /dev/null @@ -1,309 +0,0 @@ -#!/usr/bin/python -# -# Copyright (C) 2008 Collabora Limited -# Copyright (C) 2008 Nokia Corporation -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -from sys import argv, stdout, stderr -import codecs -import xml.dom.minidom -from getopt import gnu_getopt - -from libtpcodegen import NS_TP, get_descendant_text, get_by_path -from libqt4codegen import format_docstring - -class Generator(object): - def __init__(self, opts): - try: - self.namespace = opts['--namespace'] - self.must_define = opts.get('--must-define', None) - dom = xml.dom.minidom.parse(opts['--specxml']) - except KeyError, k: - assert False, 'Missing required parameter %s' % k.args[0] - - self.define_prefix = None - if '--define-prefix' in opts: - self.define_prefix = opts['--define-prefix'] - - self.old_prefix = None - if '--str-constant-prefix' in opts: - self.old_prefix = opts['--str-constant-prefix'] - - self.spec = get_by_path(dom, "spec")[0] - self.out = codecs.getwriter('utf-8')(stdout) - - def h(self, code): - self.out.write(code) - - def __call__(self): - # Header - self.h('/* Generated from ') - self.h(get_descendant_text(get_by_path(self.spec, 'title'))) - version = get_by_path(self.spec, "version") - - if version: - self.h(', version ' + get_descendant_text(version)) - - self.h(""" - */ - """) - - if self.must_define: - self.h(""" -#ifndef %s -#error %s -#endif -""" % (self.must_define, self.must_define)) - - self.h(""" -#include - -/** - * \\addtogroup typesconstants Types and constants - * - * Enumerated, flag, structure, list and mapping types and utility constants. - */ - -/** - * \\defgroup flagtypeconsts Flag type constants - * \\ingroup typesconstants - * - * Types generated from the specification representing bit flag constants and - * combinations of them (bitfields). - */ - -/** - * \\defgroup enumtypeconsts Enumerated type constants - * \\ingroup typesconstants - * - * Types generated from the specification representing enumerated types ie. - * types the values of which are mutually exclusive integral constants. - */ - -/** - * \\defgroup ifacestrconsts Interface string constants - * \\ingroup typesconstants - * - * D-Bus interface names of the interfaces in the specification. - */ - -/** - * \\defgroup errorstrconsts Error string constants - * \\ingroup typesconstants - * - * Names of the D-Bus errors in the specification. - */ -""") - - # Begin namespace - self.h(""" -namespace %s -{ -""" % self.namespace) - - # Flags - for flags in self.spec.getElementsByTagNameNS(NS_TP, 'flags'): - self.do_flags(flags) - - # Enums - for enum in self.spec.getElementsByTagNameNS(NS_TP, 'enum'): - self.do_enum(enum) - - # End namespace - self.h("""\ -} - -""") - - # Interface names - for iface in self.spec.getElementsByTagName('interface'): - if self.old_prefix: - self.h("""\ -/** - * \\ingroup ifacestrconsts - * - * The interface name "%(name)s". - */ -#define %(DEFINE)s "%(name)s" - -""" % {'name' : iface.getAttribute('name'), - 'DEFINE' : self.old_prefix + 'INTERFACE_' + get_by_path(iface, '../@name').upper().replace('/', '')}) - - if self.define_prefix: - self.h("""\ -/** - * \\ingroup ifacestrconsts - * - * The interface name "%(name)s" as a QLatin1String, usable in QString requiring contexts even when - * building with Q_NO_CAST_FROM_ASCII defined. - */ -#define %(DEFINE)s (QLatin1String("%(name)s")) - -""" % {'name' : iface.getAttribute('name'), - 'DEFINE' : self.define_prefix + 'IFACE_' + get_by_path(iface, '../@name').upper().replace('/', '')}) - - # Error names - for error in get_by_path(self.spec, 'errors/error'): - name = error.getAttribute('name') - fullname = get_by_path(error, '../@namespace') + '.' + name.replace(' ', '') - - if self.old_prefix: - define = self.old_prefix + 'ERROR_' + name.replace(' ', '_').replace('.', '_').upper() - self.h("""\ -/** - * \\ingroup errorstrconsts - * - * The error name "%(fullname)s". -%(docstring)s\ - */ -#define %(DEFINE)s "%(fullname)s" - -""" % {'fullname' : fullname, - 'docstring': format_docstring(error), - 'DEFINE' : define}) - - if self.define_prefix: - define = self.define_prefix + 'ERROR_' + name.replace(' ', '_').replace('.', '_').upper() - self.h("""\ -/** - * \\ingroup errorstrconsts - * - * The error name "%(fullname)s" as a QLatin1String, usable in QString requiring contexts even when - * building with Q_NO_CAST_FROM_ASCII defined. -%(docstring)s\ - */ -#define %(DEFINE)s QLatin1String("%(fullname)s") - -""" % {'fullname' : fullname, - 'docstring': format_docstring(error), - 'DEFINE' : define}) - - def do_flags(self, flags): - singular = flags.getAttribute('singular') or \ - flags.getAttribute('value-prefix') - - using_name = False - if not singular: - using_name = True - singular = flags.getAttribute('name') - - if singular.endswith('lags'): - singular = singular[:-1] - - if using_name and singular.endswith('s'): - singular = singular[:-1] - - singular = singular.replace('_', '') - plural = (flags.getAttribute('plural') or flags.getAttribute('name') or singular + 's').replace('_', '') - self.h("""\ -/** - * \\ingroup flagtypeconsts - * - * Flag type generated from the specification. - */ -enum %(singular)s -{ -""" % {'singular' : singular}) - - flagvalues = get_by_path(flags, 'flag') - - for flag in flagvalues: - self.do_val(flag, singular, flag == flagvalues[-1]) - - self.h("""\ - %s = 0xffffffffU -""" % ("_" + singular + "Padding")) - - self.h("""\ -}; - -/** - * \\typedef QFlags<%(singular)s> %(plural)s - * \\ingroup flagtypeconsts - * - * Type representing combinations of #%(singular)s values. -%(docstring)s\ - */ -typedef QFlags<%(singular)s> %(plural)s; -Q_DECLARE_OPERATORS_FOR_FLAGS(%(plural)s) - -""" % {'singular' : singular, 'plural' : plural, 'docstring' : format_docstring(flags)}) - - def do_enum(self, enum): - singular = enum.getAttribute('singular') or \ - enum.getAttribute('name') - value_prefix = enum.getAttribute('singular') or \ - enum.getAttribute('value-prefix') or \ - enum.getAttribute('name') - - if singular.endswith('lags'): - singular = singular[:-1] - - plural = enum.getAttribute('plural') or singular + 's' - singular = singular.replace('_', '') - value_prefix = value_prefix.replace('_', '') - vals = get_by_path(enum, 'enumvalue') - - self.h("""\ -/** - * \\enum %(singular)s - * \\ingroup enumtypeconsts - * - * Enumerated type generated from the specification. -%(docstring)s\ - */ -enum %(singular)s -{ -""" % {'singular' : singular, 'docstring' : format_docstring(enum)}) - - for val in vals: - self.do_val(val, value_prefix, val == vals[-1]) - - self.h("""\ - %s = 0xffffffffU -}; - -""" % ("_" + singular + "Padding")) - - self.h("""\ -/** - * \\ingroup enumtypeconsts - * - * 1 higher than the highest valid value of %(singular)s. - */ -const int NUM_%(upper-plural)s = (%(last-val)s+1); - -""" % {'singular' : singular, - 'upper-plural' : plural.upper(), - 'last-val' : vals[-1].getAttribute('value')}) - - def do_val(self, val, prefix, last): - name = (val.getAttribute('suffix') or val.getAttribute('name')).replace('_', '') - self.h("""\ -%s\ - %s = %s, - -""" % (format_docstring(val, indent=' * ', brackets=(' /**', ' */')), prefix + name, val.getAttribute('value'))) - -if __name__ == '__main__': - options, argv = gnu_getopt(argv[1:], '', - ['namespace=', - 'str-constant-prefix=', - 'define-prefix=', - 'must-define=', - 'specxml=']) - - Generator(dict(options))() diff --git a/tools/qt4-types-gen.py b/tools/qt4-types-gen.py deleted file mode 100644 index 1a5fef7..0000000 --- a/tools/qt4-types-gen.py +++ /dev/null @@ -1,556 +0,0 @@ -#!/usr/bin/python -# -# Copyright (C) 2008 Collabora Limited -# Copyright (C) 2008 Nokia Corporation -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -import sys -import xml.dom.minidom -from getopt import gnu_getopt - -from libtpcodegen import NS_TP, get_descendant_text, get_by_path -from libqt4codegen import binding_from_usage, binding_from_decl, extract_arg_or_member_info, format_docstring, gather_externals, gather_custom_lists, get_qt4_name, get_headerfile_cmd - -class BrokenSpecException(Exception): - pass - -class MissingTypes(BrokenSpecException): - def __init__(self, types): - super(MissingTypes, self).__init__(self) - self.types = types - - def __str__(self): - typelist = ''.join([' %s' % t for t in self.types]) - return "The following types were used, but not provided by the spec " \ - "or by declarations in all.xml:\n%s" % typelist - -class UnresolvedDependency(BrokenSpecException): - def __init__(self, child, parent): - super(UnresolvedDependency, self).__init__(self) - self.child = child - self.parent = parent - - def __str__(self): - return 'Type %s has unresolved dependency on %s' % ( - self.child, self.parent) - -class EmptyStruct(BrokenSpecException): - def __init__(self, struct_name): - super(EmptyStruct, self).__init__(self) - self.struct_name = struct_name - - def __str__(self): - return 'tp:struct %s should have some members' % self.struct_name - -class MalformedMapping(BrokenSpecException): - def __init__(self, mapping_name, members): - super(MalformedMapping, self).__init__(self) - self.mapping_name = mapping_name - self.members = members - - def __str__(self): - return 'tp:mapping %s should have 2 members, not %u' % ( - self.mapping_name, self.members) - -class WTF(BrokenSpecException): - def __init__(self, element_name): - super(BrokenSpecException, self).__init__(self) - self.element_name = element_name - - def __str__(self): - return 'What the hell is a tp:%s?' % self.element_name - - -class DepInfo: - def __init__(self, el, externals, custom_lists): - self.el = el - name = get_by_path(el, '@name') - array_name = get_by_path(el, '@array-name') - array_depth = get_by_path(el, '@array-depth') - if array_depth: - array_depth = int(array_depth) - else: - array_depth = None - self.binding = binding_from_decl(name, array_name, array_depth) - self.deps = [] - - for member in get_by_path(el, 'member'): - sig = member.getAttribute('type') - tptype = member.getAttributeNS(NS_TP, 'type') - - if (sig, tptype) in externals: - continue - - if tptype.endswith('[]'): - tptype = tptype[:-2] - - binding = binding_from_usage(sig, tptype, custom_lists) - - if binding.custom_type: - self.deps.append(binding.val) - - self.revdeps = [] - -class Generator(object): - def __init__(self, opts): - try: - self.namespace = opts['--namespace'] - self.declfile = opts['--declfile'] - self.implfile = opts['--implfile'] - self.realinclude = opts['--realinclude'] - self.prettyinclude = opts.get('--prettyinclude', self.realinclude) - self.extraincludes = opts.get('--extraincludes', None) - self.must_define = opts.get('--must-define', None) - self.visibility = opts.get('--visibility', '') - dom = xml.dom.minidom.parse(opts['--specxml']) - except KeyError, k: - assert False, 'Missing required parameter %s' % k.args[0] - - self.decls = [] - self.impls = [] - self.spec = get_by_path(dom, "spec")[0] - self.externals = gather_externals(self.spec) - self.custom_lists = gather_custom_lists(self.spec, self.namespace) - self.required_custom = [] - self.required_arrays = [] - self.to_declare = [] - self.depinfos = {} - - def __call__(self): - # Emit comment header - - self.both('/* Generated from ') - self.both(get_descendant_text(get_by_path(self.spec, 'title'))) - version = get_by_path(self.spec, "version") - - if version: - self.both(', version ' + get_descendant_text(version)) - - self.both(' */\n') - - # Gather info on available and required types - - self.gather_required() - - if self.must_define: - self.decl('\n') - self.decl('#ifndef %s\n' % self.must_define) - self.decl('#error %s\n' % self.must_define) - self.decl('#endif') - - self.decl('\n') - - if self.extraincludes: - for include in self.extraincludes.split(','): - self.decl('#include %s\n' % include) - - self.decl(""" -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include - -/** - * \\addtogroup typesconstants Types and constants - * - * Enumerated, flag, structure, list and mapping types and utility constants. - */ - -/** - * \\defgroup struct Structure types - * \\ingroup typesconstants - * - * Structure types generated from the specification. - */ - -/** - * \\defgroup list List types - * \\ingroup typesconstants - * - * List types generated from the specification. - */ - -/** - * \\defgroup mapping Mapping types - * \\ingroup typesconstants - * - * Mapping types generated from the specification. - */ - -""") - - if self.must_define: - self.impl(""" -#define %s""" % self.must_define) - - self.impl(""" -#include "%s" -""" % self.realinclude) - - self.both(""" -namespace %s -{ -""" % self.namespace) - - # Emit type definitions for types provided in the spec - - self.provide_all() - - # Emit type registration function - - self.decl(""" -} // namespace %s - -""" % self.namespace) - - self.impl("""\ -TELEPATHY_QT4_NO_EXPORT void _registerTypes() -{ - static bool registered = false; - if (registered) - return; - registered = true; - -""") - - # Emit Qt4 metatype declarations - - self.to_declare.sort() - - for metatype in self.to_declare: - self.decl('Q_DECLARE_METATYPE(%s)\n' % metatype) - self.impl(' qDBusRegisterMetaType<%s>();\n' % ((metatype.endswith('>') and metatype + ' ') or metatype)) - - self.impl("""\ -} - -} // namespace %s -""" % self.namespace) - - # Write output to files - - open(self.declfile, 'w').write(''.join(self.decls).encode("utf-8")) - open(self.implfile, 'w').write(''.join(self.impls).encode("utf-8")) - - def decl(self, str): - self.decls.append(str) - - def impl(self, str): - self.impls.append(str) - - def both(self, str): - self.decl(str) - self.impl(str) - - def gather_required(self): - members = self.spec.getElementsByTagNameNS(NS_TP, 'member') - args = self.spec.getElementsByTagName('arg') - props = self.spec.getElementsByTagName('property') - tp_props = self.spec.getElementsByTagNameNS(NS_TP, 'property') - - for requirer in members + args + props + tp_props: - sig = requirer.getAttribute('type') - tptype = requirer.getAttributeNS(NS_TP, 'type') - external = (sig, tptype) in self.externals - binding = binding_from_usage(sig, tptype, self.custom_lists, external) - - if binding.custom_type and binding.val not in self.required_custom: - self.required_custom.append(binding.val) - - if not binding.custom_type and binding.array_of and (binding.val, binding.array_of) not in self.required_arrays: - self.required_arrays.append((binding.val, binding.array_of)) - - def provide_all(self): - self.required_arrays.sort() - for (val, array_of) in self.required_arrays: - real = 'QList<%s>' % array_of - self.decl("""\ -/** - * \\struct %s - * \\ingroup list -%s\ - * - * Generic list type with %s elements. Convertible with - * %s, but needed to have a discrete type in the Qt4 type system. - */ -""" % (val, get_headerfile_cmd(self.realinclude, self.prettyinclude), array_of, real)) - self.decl(self.faketype(val, real)) - self.to_declare.append(self.namespace + '::' + val) - - structs = self.spec.getElementsByTagNameNS(NS_TP, 'struct') - mappings = self.spec.getElementsByTagNameNS(NS_TP, 'mapping') - exts = self.spec.getElementsByTagNameNS(NS_TP, 'external-type') - - for deptype in structs + mappings: - info = DepInfo(deptype, self.externals, self.custom_lists) - self.depinfos[info.binding.val] = info - - leaves = [] - next_leaves = [] - - for val, depinfo in self.depinfos.iteritems(): - leaf = True - - for dep in depinfo.deps: - if not self.depinfos.has_key(dep): - raise UnresolvedDependency(val, dep) - - leaf = False - self.depinfos[dep].revdeps.append(val) - - if leaf: - next_leaves.append(val) - - while leaves or next_leaves: - if not leaves: - leaves = next_leaves - leaves.sort() - next_leaves = [] - - val = leaves.pop(0) - depinfo = self.depinfos[val] - self.output_by_depinfo(depinfo) - - for revdep in depinfo.revdeps: - revdepinfo = self.depinfos[revdep] - revdepinfo.deps.remove(val) - - if not revdepinfo.deps: - next_leaves.append(revdep) - - del self.depinfos[val] - - for provider in structs + mappings + exts: - name = get_by_path(provider, '@name') - array_name = get_by_path(provider, '@array-name') - array_depth = get_by_path(provider, '@array-depth') - if array_depth: - array_depth = int(array_depth) - else: - array_depth = None - sig = provider.getAttribute('type') - tptype = provider.getAttribute('name') - external = (sig, tptype) in self.externals - binding = binding_from_decl(name, array_name, array_depth, external) - self.provide(binding.val) - - if binding.array_val: - self.provide(binding.array_val) - - d = binding.array_depth - while d > 1: - d -= 1 - self.provide(binding.array_val + ('List' * d)) - - if self.required_custom: - raise MissingTypes(self.required_custom) - - def provide(self, type): - if type in self.required_custom: - self.required_custom.remove(type) - - def output_by_depinfo(self, depinfo): - names, docstrings, bindings = extract_arg_or_member_info(get_by_path(depinfo.el, 'member'), self.custom_lists, self.externals, None, ' * ', (' /**', ' */')) - members = len(names) - - if depinfo.el.localName == 'struct': - if members == 0: - raise EmptyStruct(depinfo.binding.val) - - self.decl("""\ -/** - * \\struct %(name)s - * \\ingroup struct -%(headercmd)s\ - * - * Structure type generated from the specification. -%(docstring)s\ - */ -struct %(visibility)s %(name)s -{ -""" % { - 'name' : depinfo.binding.val, - 'headercmd': get_headerfile_cmd(self.realinclude, self.prettyinclude), - 'docstring' : format_docstring(depinfo.el), - 'visibility': self.visibility, - }) - - for i in xrange(members): - self.decl("""\ -%s\ - %s %s; -""" % (docstrings[i], bindings[i].val, names[i])) - - self.decl("""\ -}; - -""") - - self.both('%s bool operator==(%s v1, %s v2)' % - (self.visibility, - depinfo.binding.inarg, - depinfo.binding.inarg)) - self.decl(';\n') - self.impl(""" -{""") - if (bindings[0].val != 'QDBusVariant'): - self.impl(""" - return ((v1.%s == v2.%s)""" % (names[0], names[0])) - else: - self.impl(""" - return ((v1.%s.variant() == v2.%s.variant())""" % (names[0], names[0])) - for i in xrange(1, members): - if (bindings[i].val != 'QDBusVariant'): - self.impl(""" - && (v1.%s == v2.%s)""" % (names[i], names[i])) - else: - self.impl(""" - && (v1.%s.variant() == v2.%s.variant())""" % (names[i], names[i])) - self.impl(""" - ); -} - -""") - - self.decl('inline bool operator!=(%s v1, %s v2)' % - (depinfo.binding.inarg, depinfo.binding.inarg)) - self.decl(""" -{ - return !operator==(v1, v2); -} -""") - - self.both('%s QDBusArgument& operator<<(QDBusArgument& arg, %s val)' % - (self.visibility, depinfo.binding.inarg)) - self.decl(';\n') - self.impl(""" -{ - arg.beginStructure(); - arg << %s; - arg.endStructure(); - return arg; -} - -""" % ' << '.join(['val.' + name for name in names])) - - self.both('%s const QDBusArgument& operator>>(const QDBusArgument& arg, %s val)' % - (self.visibility, depinfo.binding.outarg)) - self.decl(';\n\n') - self.impl(""" -{ - arg.beginStructure(); - arg >> %s; - arg.endStructure(); - return arg; -} - -""" % ' >> '.join(['val.' + name for name in names])) - elif depinfo.el.localName == 'mapping': - if members != 2: - raise MalformedMapping(depinfo.binding.val, members) - - realtype = 'QMap<%s, %s>' % (bindings[0].val, (bindings[1].val.endswith('>') and bindings[1].val + ' ') or bindings[1].val) - self.decl("""\ -/** - * \\struct %s - * \\ingroup mapping -%s\ - * - * Mapping type generated from the specification. Convertible with - * %s, but needed to have a discrete type in the Qt4 type system. -%s\ - */ -""" % (depinfo.binding.val, get_headerfile_cmd(self.realinclude, self.prettyinclude), realtype, format_docstring(depinfo.el))) - self.decl(self.faketype(depinfo.binding.val, realtype)) - else: - raise WTF(depinfo.el.localName) - - self.to_declare.append(self.namespace + '::' + depinfo.binding.val) - - if depinfo.binding.array_val: - self.to_declare.append('%s::%s' % (self.namespace, depinfo.binding.array_val)) - self.decl("""\ -/** - * \\ingroup list -%s\ - * - * Array of %s values. - */ -typedef %s %s; - -""" % (get_headerfile_cmd(self.realinclude, self.prettyinclude), depinfo.binding.val, 'QList<%s>' % depinfo.binding.val, depinfo.binding.array_val)) - - i = depinfo.binding.array_depth - while i > 1: - i -= 1 - self.to_declare.append('%s::%s%s' % (self.namespace, depinfo.binding.array_val, ('List' * i))) - list_of = depinfo.binding.array_val + ('List' * (i-1)) - self.decl("""\ -/** - * \\ingroup list -%s\ - * - * Array of %s values. - */ -typedef QList<%s> %sList; - -""" % (get_headerfile_cmd(self.realinclude, self.prettyinclude), list_of, list_of, list_of)) - - def faketype(self, fake, real): - return """\ -struct %(visibility)s %(fake)s : public %(real)s -{ - inline %(fake)s() : %(real)s() {} - inline %(fake)s(const %(real)s& a) : %(real)s(a) {} - - inline %(fake)s& operator=(const %(real)s& a) - { - *(static_cast<%(real)s*>(this)) = a; - return *this; - } -}; - -""" % {'fake' : fake, 'real' : real, 'visibility': self.visibility} - -if __name__ == '__main__': - options, argv = gnu_getopt(sys.argv[1:], '', - ['declfile=', - 'implfile=', - 'realinclude=', - 'prettyinclude=', - 'extraincludes=', - 'must-define=', - 'namespace=', - 'specxml=', - 'visibility=', - ]) - - try: - Generator(dict(options))() - except BrokenSpecException as e: - print >> sys.stderr, 'Your spec is broken, dear developer! %s' % e - sys.exit(42) diff --git a/tools/tp-qt-tests.supp b/tools/tp-qt-tests.supp new file mode 100644 index 0000000..2c0f120 --- /dev/null +++ b/tools/tp-qt-tests.supp @@ -0,0 +1,53 @@ +# QDBus doesn't call dbus_shutdown, so some D-Bus internal data structures are leaked. +# We never call any low-level dbus message creation functions ourselves - if there are leaks, +# they're either caused by not calling dbus_shutdown, QDBus bugs or libdbus bugs - neither of which +# are our problem. + +{ + Initial session bus registration message + Memcheck:Leak + fun:malloc + fun:dbus_message_new_empty_header +} + +# The conference test CM channel object leaks some crazy GValue boxed data which I don't have the +# energy to investigate how to properly free now - it's not production code anyway. + +{ + Conference test CM channel boxed GValue data + Memcheck:Leak + ... + fun:g_boxed_copy + ... + fun:_ZN18TestConferenceChan12initTestCaseEv +} + +# Reported as https://bugs.freedesktop.org/show_bug.cgi?id=32116 + +{ + TpBaseConnectionManager legacy protocol objects + Memcheck:Leak + ... + fun:g_object_new + ... + fun:tp_base_connection_manager_register +} + +# O(number of error domains) leak from dbus_g_method_return_error +{ + dbus_g_method_return_error error domain enum class + Memcheck:Leak + ... + fun:g_type_class_ref + ... + fun:dbus_g_method_return_error +} + +# O(1) leak from tp_base_connection_manager installing the param spec for the dbus-daemon param +{ + tp_base_connection_manager dbus-daemon param spec + Memcheck:Leak + ... + fun:g_param_spec_object + fun:tp_base_connection_manager_class_intern_init +} diff --git a/tools/tpl-tool.cpp b/tools/tpl-tool.cpp index ca35f6b..5de75d4 100644 --- a/tools/tpl-tool.cpp +++ b/tools/tpl-tool.cpp @@ -1,5 +1,5 @@ /* - * This file is part of TelepathyLoggerQt4 + * This file is part of TelepathyLoggerQt * * Copyright (C) 2011 Collabora Ltd. * @@ -19,24 +19,24 @@ #include "tpl-tool.h" #include -#include -#include +#include #include #include #include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -87,7 +87,7 @@ bool TplToolApplication::parseArgs1() Tpl::LogManagerPtr logManager = Tpl::LogManager::instance(); if (logManager.isNull()) { - qWarning() << "LogManager not found"; + warning() << "LogManager not found"; return false; } @@ -97,7 +97,7 @@ bool TplToolApplication::parseArgs1() Tp::AccountPtr account; int i = 0; Q_FOREACH(account, accounts) { - qDebug() << "account " << i++ << account->objectPath(); + debug() << "account " << i++ << account->objectPath(); } this->exit(); return true; @@ -109,14 +109,14 @@ bool TplToolApplication::parseArgs1() (args.size() == 5 && args.at(1) == "filteredEvents")) { Tp::AccountPtr account = accountPtr(args.at(2)); if (account.isNull()) { - qWarning() << "Account not found " << args.at(2); + warning() << "Account not found " << args.at(2); } return true; } else if (args.size() == 3 && args.at(1) == "search") { Tpl::PendingSearch *ps = logManager->search(args.at(2), Tpl::EventTypeMaskAny); debugfn() << "PendingSearch=" << ps; if (!ps) { - qWarning() << "Error in search"; + warning() << "Error in search"; this->exit(-1); return false; } @@ -129,18 +129,18 @@ bool TplToolApplication::parseArgs1() return true; } - qDebug() << "Telepathy logger command line tool (qt4)"; - qDebug() << ""; - qDebug() << "General usage: tpl-tool "; - qDebug() << ""; - qDebug() << "tpl-tool accounts"; - qDebug() << "tpl-tool contacts "; - qDebug() << "tpl-tool exists "; - qDebug() << "tpl-tool entities "; - qDebug() << "tpl-tool dates "; - qDebug() << "tpl-tool events "; - qDebug() << "tpl-tool filteredEvents "; - qDebug() << "tpl-tool search "; + debug() << "Telepathy logger command line tool (qt)"; + debug() << ""; + debug() << "General usage: tpl-tool "; + debug() << ""; + debug() << "tpl-tool accounts"; + debug() << "tpl-tool contacts "; + debug() << "tpl-tool exists "; + debug() << "tpl-tool entities "; + debug() << "tpl-tool dates "; + debug() << "tpl-tool events "; + debug() << "tpl-tool filteredEvents "; + debug() << "tpl-tool search "; this->exit(-1); return false; @@ -154,36 +154,36 @@ bool TplToolApplication::parseArgs2() Tpl::LogManagerPtr logManager = Tpl::LogManager::instance(); if (logManager.isNull()) { - qWarning() << "LogManager not found"; + warning() << "LogManager not found"; return false; } if (args.size() == 3 && args.at(1) == "contacts") { Tp::Contacts contacts = mAccountPtr->connection()->contactManager()->allKnownContacts(); - qDebug() << "number of contacts = " << contacts.size(); + debug() << "number of contacts = " << contacts.size(); Tp::ContactPtr contact; int i = 0; Q_FOREACH(contact, contacts) { - qDebug() << "contact " << i++ << contact->id(); + debug() << "contact " << i++ << contact->id(); } this->exit(); return true; } else if (args.size() == 4 && args.at(1) == "exists") { Tpl::EntityPtr entity = entityPtr(args.at(3)); if (entity.isNull()) { - qWarning() << "Entity not found " << args.at(3); + warning() << "Entity not found " << args.at(3); } bool ret = logManager->exists(mAccountPtr, entity, Tpl::EventTypeMaskAny); - qDebug() << "tpl-tool exists " << args.at(2) << args.at(3) << " -> " << ret; + debug() << "tpl-tool exists " << args.at(2) << args.at(3) << " -> " << ret; this->exit(); return true; } else if (args.at(1) == "entities") { Tpl::PendingEntities *pe = logManager->queryEntities(mAccountPtr); debugfn() << "PendingEntities=" << pe; if (!pe) { - qWarning() << "Error in PendingEntities"; + warning() << "Error in PendingEntities"; this->exit(-1); return false; } @@ -197,13 +197,13 @@ bool TplToolApplication::parseArgs2() } else if (args.at(1) == "dates") { Tpl::EntityPtr entity = entityPtr(args.at(3)); if (entity.isNull()) { - qWarning() << "Entity not found " << args.at(3); + warning() << "Entity not found " << args.at(3); } Tpl::PendingDates *pd = logManager->queryDates(mAccountPtr, entity, Tpl::EventTypeMaskAny); debugfn() << "PendingDates=" << pd; if (!pd) { - qWarning() << "Error in PendingDates"; + warning() << "Error in PendingDates"; this->exit(-1); return false; } @@ -217,7 +217,7 @@ bool TplToolApplication::parseArgs2() } else if (args.at(1) == "events") { Tpl::EntityPtr entity = entityPtr(args.at(3)); if (entity.isNull()) { - qWarning() << "Entity not found " << args.at(3); + warning() << "Entity not found " << args.at(3); } QDate date = QDate::fromString(args.at(4), TPL_TOOL_DATE_FORMAT); @@ -225,7 +225,7 @@ bool TplToolApplication::parseArgs2() Tpl::PendingEvents *pe = logManager->queryEvents(mAccountPtr, entity, Tpl::EventTypeMaskAny, date); debugfn() << "PendingEvents=" << pe << "date=" << date; if (!pe) { - qWarning() << "Error in PendingDates"; + warning() << "Error in PendingDates"; this->exit(-1); return false; } @@ -239,13 +239,13 @@ bool TplToolApplication::parseArgs2() } else if (args.at(1) == "filteredEvents") { Tpl::EntityPtr entity = entityPtr(args.at(3)); if (entity.isNull()) { - qWarning() << "Entity not found " << args.at(3); + warning() << "Entity not found " << args.at(3); } Tpl::PendingEvents *pe = logManager->queryFilteredEvents(mAccountPtr, entity, Tpl::EventTypeMaskAny, args.at(4).toInt(), &TplToolApplication::eventFilterMethod, this); debugfn() << "PendingEvents (filtered) =" << pe << "numEvents=" << args.at(4); if (!pe) { - qWarning() << "Error in PendingDates"; + warning() << "Error in PendingDates"; this->exit(-1); return false; } @@ -267,14 +267,14 @@ void TplToolApplication::onAccountManagerReady(Tp::PendingOperation *po) debugfn() << "po=" << po << "isError=" << po->isError(); if (po->isError()) { - qWarning() << "error getting account mananger ready"; + warning() << "error getting account mananger ready"; exit(-1); return; } Tpl::LogManagerPtr logManager = Tpl::LogManager::instance(); if (logManager.isNull()) { - qWarning() << "LogManager not found"; + warning() << "LogManager not found"; exit(-1); return; } @@ -289,14 +289,14 @@ void TplToolApplication::onAccountReady(Tp::PendingOperation *po) debugfn() << "po=" << po << "isError=" << po->isError(); if (po->isError()) { - qWarning() << "error getting account ready"; + warning() << "error getting account ready"; exit(-1); return; } Tp::ConnectionPtr connection = mAccountPtr->connection(); if (connection.isNull()) { - qWarning() << "error null connection"; + warning() << "error null connection"; exit(-1); return; } @@ -312,7 +312,7 @@ void TplToolApplication::onConnectionReady(Tp::PendingOperation *po) debugfn() << "po=" << po << "isError=" << po->isError(); if (po->isError()) { - qWarning() << "error getting connection ready"; + warning() << "error getting connection ready"; exit(-1); return; } @@ -325,20 +325,20 @@ void TplToolApplication::onPendingSearch(Tpl::PendingOperation *po) Tpl::PendingSearch *ps = (Tpl::PendingSearch*) po; if (ps->isError()) { - qWarning() << "error in search"; + warning() << "error in search"; exit(-1); return; } Tpl::SearchHitList hits = ps->hits(); - qDebug() << " search hits " << hits.size(); + debug() << " search hits " << hits.size(); int count = 0; Q_FOREACH(const Tpl::SearchHit &hit, hits) { - qDebug() << count++ << "account=" << hit.account.data() << (hit.account.isNull() ? "null" : hit.account->objectPath()) - << "date=" << hit.date.toString(TPL_TOOL_DATE_FORMAT) - << "target=" << (hit.target ? hit.target->identifier() + "/" + hit.target->alias() + "/" + QString::number(hit.target->entityType()) + "/" + hit.target->avatarToken() : "null"); + debug() << count++ << "account=" << hit.account().data() << (hit.account().isNull() ? "null" : hit.account()->objectPath()) + << "date=" << hit.date().toString(TPL_TOOL_DATE_FORMAT) + << "target=" << (hit.target() ? hit.target()->identifier() + "/" + hit.target()->alias() + "/" + QString::number(hit.target()->entityType()) + "/" + hit.target()->avatarToken() : "null"); } this->exit(); @@ -349,18 +349,18 @@ void TplToolApplication::onPendingEntities(Tpl::PendingOperation *po) Tpl::PendingEntities *pe = (Tpl::PendingEntities*) po; if (pe->isError()) { - qWarning() << "error in search"; + warning() << "error in search"; exit(-1); return; } Tpl::EntityPtrList entities= pe->entities(); - qDebug() << " Pending entities " << entities.size(); + debug() << " Pending entities " << entities.size(); int count = 0; Tpl::EntityPtr entity; Q_FOREACH(entity, entities) { - qDebug() << count++ << "entity id=" << entity->identifier() << "alias=" << entity->alias() << "type=" << entity->entityType() << "avatarToken=" << entity->avatarToken(); + debug() << count++ << "entity id=" << entity->identifier() << "alias=" << entity->alias() << "type=" << entity->entityType() << "avatarToken=" << entity->avatarToken(); } this->exit(); @@ -371,18 +371,18 @@ void TplToolApplication::onPendingDates(Tpl::PendingOperation *po) Tpl::PendingDates *pd = (Tpl::PendingDates*) po; if (pd->isError()) { - qWarning() << "error in search"; + warning() << "error in search"; exit(-1); return; } Tpl::QDateList dates = pd->dates(); - qDebug() << " Pending dates " << dates.size(); + debug() << " Pending dates " << dates.size(); int count = 0; QDate date; Q_FOREACH(date, dates) { - qDebug() << count++ << "date " << date.toString(TPL_TOOL_DATE_FORMAT); + debug() << count++ << "date " << date.toString(TPL_TOOL_DATE_FORMAT); } this->exit(); @@ -393,13 +393,13 @@ void TplToolApplication::onPendingEvents(Tpl::PendingOperation *po) Tpl::PendingEvents *pe = (Tpl::PendingEvents*) po; if (pe->isError()) { - qWarning() << "error in PendingEvents"; + warning() << "error in PendingEvents"; exit(-1); return; } Tpl::EventPtrList events = pe->events(); - qDebug() << " Pending events " << events.size(); + debug() << " Pending events " << events.size(); int count = 0; QObject a; @@ -408,7 +408,7 @@ void TplToolApplication::onPendingEvents(Tpl::PendingOperation *po) Tpl::TextEventPtr textEvent = event.dynamicCast(); Tpl::CallEventPtr callEvent = event.dynamicCast(); if (!textEvent.isNull()) { - qDebug() << count++ << "textEvent" + debug() << count++ << "textEvent" << "timestamp=" << textEvent->timestamp().toString() << "sender=" << textEvent->sender()->identifier() << "receiver=" << textEvent->receiver()->identifier() @@ -417,7 +417,7 @@ void TplToolApplication::onPendingEvents(Tpl::PendingOperation *po) << "account=" << (textEvent->account() ? textEvent->account()->objectPath() : "null") << "accountPath=" << textEvent->accountPath(); } else if (!callEvent.isNull()) { - qDebug() << count++ << "callEvent" + debug() << count++ << "callEvent" << "timestamp=" << callEvent->timestamp().toString() << "sender=" << callEvent->sender()->identifier() << "receiver=" << callEvent->receiver()->identifier() @@ -428,7 +428,7 @@ void TplToolApplication::onPendingEvents(Tpl::PendingOperation *po) << "account=" << (callEvent->account() ? callEvent->account()->objectPath() : "null") << "accountPath=" << callEvent->accountPath(); } else { - qDebug() << count++ << "event" + debug() << count++ << "event" << "timestamp=" << event->timestamp().toString() << "sender=" << event->sender()->identifier() << "receiver=" << event->receiver()->identifier() diff --git a/tools/tpl-tool.h b/tools/tpl-tool.h index b427b01..10a52cd 100644 --- a/tools/tpl-tool.h +++ b/tools/tpl-tool.h @@ -1,5 +1,5 @@ /* - * This file is part of TelepathyLoggerQt4 + * This file is part of TelepathyLoggerQt * * Copyright (C) 2011 Collabora Ltd. * @@ -17,10 +17,10 @@ * along with this program. If not, see . */ -#include +#include #include -#include -#include +#include +#include class TplToolApplication : public QCoreApplication { Q_OBJECT -- 1.8.1.2 debian/control0000664000000000000000000000441312305543166010602 0ustar Source: telepathy-logger-qt5 Section: libs Priority: optional Maintainer: Kubuntu Developers XSBC-Original-Maintainer: Debian KDE Extras Team Uploaders: George Kiagiadakis Build-Depends: debhelper (>= 9), dpkg-dev (>= 1.16.1~), cmake, quilt, qt5-default (>= 5.0), qtbase5-dev (>= 5.0), libqtgstreamer-dev, libtelepathy-qt5-dev (>= 0.9.3), libtelepathy-logger-dev (>= 0.4), libtelepathy-glib-dev (>= 0.16), libxml2-dev, python (>= 2.6), python-dev, flex, bison # libxml2-dev is basically unavoidable because tp-logger's pkg-config file is wrong Standards-Version: 3.9.4 Homepage: https://projects.kde.org/projects/extragear/network/telepathy/telepathy-logger-qt Vcs-Git: git://anonscm.debian.org/pkg-kde/kde-extras/kde-telepathy/telepathy-logger-qt.git Vcs-Browser: http://anonscm.debian.org/gitweb/?p=pkg-kde/kde-extras/kde-telepathy/telepathy-logger-qt.git Package: libtelepathy-logger-qt5-0 Architecture: any Multi-Arch: same Pre-Depends: ${misc:Pre-Depends} Depends: ${shlibs:Depends}, ${misc:Depends} Description: Qt bindings for the telepathy-logger library This library provides Qt-style C++ bindings for the telepathy-logger library. . The telepathy-logger library provides access to IM chat and event logs that are recorded by the telepathy-logger daemon. Package: libtelepathy-logger-qt5-dev Section: libdevel Architecture: any Depends: libtelepathy-logger-qt5-0 (= ${binary:Version}), ${misc:Depends}, libqtgstreamer-dev, libtelepathy-qt5-dev (>= 0.9.3) Description: Qt bindings for the telepathy-logger library - development files This library provides Qt-style C++ bindings for the telepathy-logger library. . The telepathy-logger library provides access to IM chat and event logs that are recorded by the telepathy-logger daemon. . This package provides the development headers for compiling applications that are using telepathy-logger-qt. Package: libtelepathy-logger-qt5-0-dbg Section: debug Architecture: any Priority: extra Multi-Arch: same Depends: libtelepathy-logger-qt5-0 (= ${binary:Version}), ${misc:Depends} Description: Qt bindings for the telepathy-logger library - debug symbols This package provides debug symbols for the telepathy-logger-qt library. debian/rules0000775000000000000000000000053012305543166010253 0ustar #!/usr/bin/make -f include /usr/share/dpkg/architecture.mk %: dh $@ --parallel --list-missing --dbg-package=libtelepathy-logger-qt5-0-dbg override_dh_auto_configure: dh_auto_configure -- -DBUILD_SHARED_LIBS=1 -DLIB_SUFFIX="/$(DEB_HOST_MULTIARCH)" override_dh_makeshlibs: dh_makeshlibs -V override_dh_clean: dh_clean rm -f tools/*.pyc debian/watch0000664000000000000000000000015612305543166010230 0ustar version=3 ftp://ftp.kde.org/pub/kde/unstable/kde-telepathy/([\d.]+)/src/telepathy-logger-qt-([\d.]+).tar.bz2 debian/source/0000775000000000000000000000000012306312037010465 5ustar debian/source/format0000664000000000000000000000001412305543166011703 0ustar 3.0 (quilt) debian/changelog0000664000000000000000000000255612306312006011043 0ustar telepathy-logger-qt5 (0.5.1-0ubuntu4) trusty; urgency=medium * Rebuild to solve a powerpc dependency problem. -- Timo Jyrinki Fri, 07 Mar 2014 11:40:19 +0200 telepathy-logger-qt5 (0.5.1-0ubuntu3) trusty; urgency=medium * Rebuild against Qt 5.2.1 -- Timo Jyrinki Wed, 05 Mar 2014 09:45:47 +0200 telepathy-logger-qt5 (0.5.1-0ubuntu2) saucy; urgency=low * Renaming source package until upstream supports building both Qt4 and Qt5 versions from the same source (and with Qt5 final) * Applying changes to port to Qt5 done for Ubuntu Touch: - 01-Porting-to-Qt5-final.patch -- Ricardo Salveti de Araujo Thu, 06 Jun 2013 23:07:05 -0300 telepathy-logger-qt (0.5.1-0ubuntu1) quantal-proposed; urgency=low * New upstream release -- Rohan Garg Fri, 05 Oct 2012 03:40:32 +0530 telepathy-logger-qt (0.5.0-0ubuntu1) quantal; urgency=low * New upstream release -- Rohan Garg Sun, 26 Aug 2012 12:47:08 +0530 telepathy-logger-qt (0.4.1-0ubuntu1) quantal; urgency=low * New upstream release -- Michal Zajac Wed, 01 Aug 2012 00:07:22 +0200 telepathy-logger-qt (0.4.0-1) unstable; urgency=low * Initial release. -- George Kiagiadakis Mon, 18 Jun 2012 22:28:46 +0300 debian/compat0000664000000000000000000000000212305543166010373 0ustar 9