Changeset 14624


Ignore:
Timestamp:
Dec 16, 2015, 8:01:03 PM (7 years ago)
Author:
mikedld
Message:

Add ActiveQt?-based COM interop helper

Location:
trunk
Files:
6 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/CMakeLists.txt

    r14622 r14624  
    224224    set(QT_TARGETS)
    225225    if(USE_QT5)
    226         set(QT5_REQUIRED_MODULES Core Gui Widgets Network DBus LinguistTools)
     226        set(QT5_REQUIRED_MODULES Core Gui Widgets Network LinguistTools)
     227        set(QT5_OPTIONAL_MODULES DBus AxContainer AxServer)
    227228        foreach(M ${QT5_REQUIRED_MODULES})
    228229            find_package(Qt5${M} QUIET)
     
    236237            endif()
    237238        endforeach()
     239        if(QT_TARGETS)
     240            foreach(M ${QT5_OPTIONAL_MODULES})
     241                find_package(Qt5${M} QUIET)
     242                if(Qt5${M}_FOUND)
     243                    list(APPEND QT_TARGETS Qt5::${M})
     244                endif()
     245            endforeach()
     246        endif()
    238247    else()
    239         set(QT4_REQUIRED_MODULES QtCore QtGui QtNetwork QtDBus)
    240         find_package(Qt4 4.6.2 QUIET COMPONENTS ${QT4_REQUIRED_MODULES})
     248        set(QT4_REQUIRED_MODULES QtCore QtGui QtNetwork)
     249        set(QT4_OPTIONAL_MODULES QtDBus QAxContainer QAxServer)
     250        find_package(Qt4 4.6.2 QUIET COMPONENTS ${QT4_REQUIRED_MODULES} OPTIONAL_COMPONENTS ${QT4_OPTIONAL_MODULES})
    241251        foreach(M ${QT4_REQUIRED_MODULES})
    242252            string(TOUPPER "${M}" M_UPPER)
     
    248258            endif()
    249259        endforeach()
     260        if (QT_TARGETS)
     261            foreach(M ${QT4_OPTIONAL_MODULES})
     262                string(TOUPPER "${M}" M_UPPER)
     263                if(QT_${M_UPPER}_FOUND)
     264                    list(APPEND QT_TARGETS Qt4::${M})
     265                endif()
     266            endforeach()
     267        endif()
    250268    endif()
    251269
  • trunk/qt/Application.cc

    r14621 r14624  
    1111#include <iostream>
    1212
    13 #include <QDBusConnection>
    14 #include <QDBusMessage>
    15 #include <QDBusReply>
    1613#include <QIcon>
    1714#include <QLibraryInfo>
     
    2118#include <QSystemTrayIcon>
    2219
     20#ifdef QT_DBUS_LIB
     21  #include <QDBusConnection>
     22  #include <QDBusMessage>
     23  #include <QDBusReply>
     24#endif
     25
    2326#include <libtransmission/transmission.h>
    2427#include <libtransmission/tr-getopt.h>
     
    2831#include "AddData.h"
    2932#include "Application.h"
    30 #include "DBusInteropHelper.h"
    3133#include "Formatter.h"
     34#include "InteropHelper.h"
    3235#include "MainWindow.h"
    3336#include "OptionsDialog.h"
     
    158161  // try to delegate the work to an existing copy of Transmission
    159162  // before starting ourselves...
    160   DBusInteropHelper interopClient;
     163  InteropHelper interopClient;
    161164  if (interopClient.isConnected ())
    162165    {
     
    176179            }
    177180
    178           if (metainfo.isEmpty ())
    179             continue;
    180 
    181           const QVariant result = interopClient.addMetainfo (metainfo);
    182           if (result.isValid () && result.toBool ())
     181          if (!metainfo.isEmpty () && interopClient.addMetainfo (metainfo))
    183182            delegated = true;
    184183        }
     
    295294    addTorrent (filename);
    296295
    297   DBusInteropHelper::registerObject (this);
     296  InteropHelper::registerObject (this);
    298297}
    299298
     
    543542Application::notifyApp (const QString& title, const QString& body) const
    544543{
     544#ifdef QT_DBUS_LIB
    545545  const QLatin1String dbusServiceName ("org.freedesktop.Notifications");
    546546  const QLatin1String dbusInterfaceName ("org.freedesktop.Notifications");
     
    565565        return true;
    566566    }
     567#endif
    567568
    568569  myWindow->trayIcon ().showMessage (title, body);
     
    583584         char * argv[])
    584585{
     586  InteropHelper::initialize ();
     587
    585588  Application app (argc, argv);
    586589  return app.exec ();
  • trunk/qt/CMakeLists.txt

    r14623 r14624  
    2121        qt4_add_translation(${ARGN})
    2222    endmacro()
     23endif()
     24
     25set(ENABLE_COM_INTEROP OFF)
     26if(MSVC AND ((Qt5AxContainer_FOUND AND Qt5AxServer_FOUND) OR (QT_QAXCONTAINER_FOUND AND QT_QAXSERVER_FOUND)))
     27    set(ENABLE_COM_INTEROP ON)
     28endif()
     29
     30set(ENABLE_DBUS_INTEROP OFF)
     31if(Qt5DBus_FOUND OR QT_QTDBUS_FOUND)
     32    set(ENABLE_DBUS_INTEROP ON)
     33endif()
     34
     35if(NOT ENABLE_COM_INTEROP AND NOT ENABLE_DBUS_INTEROP)
     36    message(FATAL_ERROR "Neither D-Bus nor COM interop is possible")
    2337endif()
    2438
     
    2842    Application.cc
    2943    ColumnResizer.cc
     44    ComInteropHelper.cc
    3045    DBusInteropHelper.cc
    3146    DetailsDialog.cc
     
    4358    FreeSpaceLabel.cc
    4459    IconToolButton.cc
     60    InteropHelper.cc
    4561    InteropObject.cc
    4662    LicenseDialog.cc
     
    7086)
    7187
     88if (NOT ENABLE_COM_INTEROP)
     89    set_source_files_properties(ComInteropHelper.cc PROPERTIES HEADER_FILE_ONLY ON)
     90endif()
     91if (NOT ENABLE_DBUS_INTEROP)
     92    set_source_files_properties(DBusInteropHelper.cc PROPERTIES HEADER_FILE_ONLY ON)
     93endif()
     94
    7295set(${PROJECT_NAME}_HEADERS
    7396    AboutDialog.h
     
    7699    BaseDialog.h
    77100    ColumnResizer.h
     101    ComInteropHelper.h
    78102    CustomVariantType.h
    79103    DBusInteropHelper.h
     
    92116    FreeSpaceLabel.h
    93117    IconToolButton.h
     118    InteropHelper.h
    94119    InteropObject.h
    95120    LicenseDialog.h
     
    183208)
    184209
    185 add_definitions(
    186     "-DTRANSLATIONS_DIR=\"${CMAKE_INSTALL_FULL_DATADIR}/${TR_NAME}/translations\""
    187     -DQT_NO_CAST_FROM_ASCII
    188 )
    189 
    190210tr_win32_app_info(${PROJECT_NAME}_WIN32_RC_FILE
    191211    "Transmission Qt Client"
     
    193213    "transmission-qt.exe"
    194214    "qtr.ico")
     215
     216if(ENABLE_COM_INTEROP)
     217    find_program(MIDL_EXECUTABLE midl)
     218    add_custom_command(
     219        OUTPUT
     220            ${CMAKE_CURRENT_BINARY_DIR}/transmission-qt.tlb
     221        COMMAND
     222            ${MIDL_EXECUTABLE} /tlb ${CMAKE_CURRENT_BINARY_DIR}/transmission-qt.tlb transmission-qt.idl
     223        DEPENDS
     224            transmission-qt.idl
     225        WORKING_DIRECTORY
     226            ${CMAKE_CURRENT_SOURCE_DIR}
     227    )
     228    list(APPEND ${PROJECT_NAME}_WIN32_RC_FILE transmission-qt.tlb.rc transmission-qt.idl ${CMAKE_CURRENT_BINARY_DIR}/transmission-qt.tlb)
     229    set_source_files_properties(transmission-qt.idl ${CMAKE_CURRENT_BINARY_DIR}/transmission-qt.tlb PROPERTIES HEADER_FILE_ONLY ON)
     230endif()
    195231
    196232add_executable(${TR_NAME}-qt WIN32
     
    210246)
    211247
     248target_compile_definitions(${TR_NAME}-qt PRIVATE
     249    "TRANSLATIONS_DIR=\"${CMAKE_INSTALL_FULL_DATADIR}/${TR_NAME}/translations\""
     250    QT_NO_CAST_FROM_ASCII
     251    $<$<BOOL:${ENABLE_COM_INTEROP}>:ENABLE_COM_INTEROP>
     252    $<$<BOOL:${ENABLE_DBUS_INTEROP}>:ENABLE_DBUS_INTEROP>)
     253
    212254if(MSVC)
    213255    tr_append_target_property(${TR_NAME}-qt LINK_FLAGS "/ENTRY:mainCRTStartup")
  • trunk/qt/InteropObject.h

    r14621 r14624  
    1616{
    1717    Q_OBJECT
     18
     19#ifdef ENABLE_DBUS_INTEROP
    1820    Q_CLASSINFO ("D-Bus Interface", "com.transmissionbt.Transmission")
     21#endif
     22
     23#ifdef ENABLE_COM_INTEROP
     24    Q_CLASSINFO ("ClassID", "{0e2c952c-0597-491f-ba26-249d7e6fab49}")
     25    Q_CLASSINFO ("InterfaceID", "{9402f54f-4906-4f20-ad73-afcfeb5b228d}")
     26    Q_CLASSINFO ("RegisterObject", "yes")
     27    Q_CLASSINFO ("CoClassAlias", "QtClient")
     28    Q_CLASSINFO ("Description", "Transmission Qt Client Class")
     29#endif
    1930
    2031  public:
Note: See TracChangeset for help on using the changeset viewer.