Update KDE Frameworks to 5.24.0 and add KArchive
[gpg4win.git] / patches / kxmlgui / 0002-Make-QDBus-dependency-optional.patch
1 #! /bin/sh
2 patch -p1 -l -f $* < $0
3 exit $?
4
5 From 7e0831d090db72319a8b0629d16693fef690808f Mon Sep 17 00:00:00 2001
6 From: Andre Heinecke <aheinecke@intevation.de>
7 Date: Tue, 26 Jan 2016 18:18:56 +0100
8 Subject: [PATCH] Make QDBus dependency optional
9
10 If an application is "standalone" DBus IPC may not be neccessary.
11 This main use case for this are platforms like Windows where DBus
12 is foreign.
13
14 Features lost without DBus are the handling of global style changes
15 in KToolBar and the general KDE DBus integration of KMainWindow.
16 So this should not be done and is guarded as a FORCE option
17 accordingly.
18 ---
19  CMakeLists.txt                     | 15 ++++++++++++---
20  KF5XmlGuiConfig.cmake.in           |  2 +-
21  autotests/kmainwindow_unittest.cpp | 10 ++++++++++
22  autotests/ktoolbar_unittest.cpp    | 20 +++++++++++++++++++-
23  src/CMakeLists.txt                 | 15 ++++++++++++---
24  src/config-xmlgui.h.cmake          |  3 +++
25  src/kmainwindow.cpp                | 10 ++++++++--
26  src/kmainwindowiface.cpp           |  2 +-
27  src/ktoolbar.cpp                   | 13 +++++++++++--
28  src/kxmlguiwindow.cpp              | 13 +++++++++++--
29  10 files changed, 88 insertions(+), 15 deletions(-)
30
31 diff --git a/CMakeLists.txt b/CMakeLists.txt
32 index 74afa01..a6691fe 100644
33 --- a/CMakeLists.txt
34 +++ b/CMakeLists.txt
35 @@ -30,12 +30,14 @@ ecm_setup_version(${KF5_VERSION}
36                    PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5XmlGuiConfigVersion.cmake"
37                    SOVERSION 5)
38
39 -option(FORCE_DISABLE_KGLOBALACCEL "Force building KXmlGui without KGlobalAccel. Doing this will break global shortcut support. [default=OFF]" OFF)
40 +# Optional packages that usually should not be disabled as this might
41 +# break behavior users (or other developers) of this library rely on.
42 +option(FORCE_DISABLE_KGLOBALACCEL "Force building KXmlGui without KGlobalAccel. This will break global shortcut support. [default=OFF]" OFF)
43 +option(FORCE_DISABLE_DBUS "Force building KXmlGui without a dependency to QDbus. This will break KMainWindow integration and style change notifications. [default=OFF]" OFF)
44
45  # Dependencies
46  set(REQUIRED_QT_VERSION 5.4.0)
47 -find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Widgets DBus Xml Network PrintSupport)
48 -
49 +find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Widgets Xml Network PrintSupport)
50  find_package(KF5CoreAddons ${KF5_DEP_VERSION} REQUIRED)
51  find_package(KF5ItemViews ${KF5_DEP_VERSION} REQUIRED)
52  find_package(KF5Config ${KF5_DEP_VERSION} REQUIRED)
53 @@ -45,6 +47,7 @@ find_package(KF5IconThemes ${KF5_DEP_VERSION} REQUIRED)
54  find_package(KF5TextWidgets ${KF5_DEP_VERSION} REQUIRED)
55  find_package(KF5WidgetsAddons ${KF5_DEP_VERSION} REQUIRED)
56  find_package(KF5WindowSystem ${KF5_DEP_VERSION} REQUIRED)
57 +
58  find_package(KF5Attica ${KF5_DEP_VERSION})
59  set_package_properties(KF5Attica PROPERTIES DESCRIPTION "A Qt library that implements the Open Collaboration Services API"
60                         PURPOSE "Support for Get Hot New Stuff in KXMLGUI"
61 @@ -58,6 +61,12 @@ if (NOT FORCE_DISABLE_KGLOBALACCEL)
62  endif()
63  set (HAVE_GLOBALACCEL ${KF5GlobalAccel_FOUND})
64
65 +if (NOT FORCE_DISABLE_DBUS)
66 +    find_package(Qt5DBus ${REQUIRED_QT_VERSION} CONFIG REQUIRED)
67 +    set(QT5DBUS_FIND_DEPENDENCY "find_dependency(Qt5DBus ${REQUIRED_QT_VERSION})")
68 +endif()
69 +set (HAVE_QDBUS ${Qt5DBus_FOUND})
70 +
71  # Subdirectories
72  add_definitions(-DTRANSLATION_DOMAIN=\"kxmlgui5\")
73  if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po")
74 diff --git a/KF5XmlGuiConfig.cmake.in b/KF5XmlGuiConfig.cmake.in
75 index ff02031..fe556c7 100644
76 --- a/KF5XmlGuiConfig.cmake.in
77 +++ b/KF5XmlGuiConfig.cmake.in
78 @@ -2,7 +2,7 @@
79
80  set(XMLGUI_DBUS_INTERFACES_DIR "@PACKAGE_KDE_INSTALL_DBUSINTERFACEDIR@")
81
82 -find_dependency(Qt5DBus @REQUIRED_QT_VERSION@)
83 +@QT5DBUS_FIND_DEPENDENCY@
84  find_dependency(Qt5Widgets @REQUIRED_QT_VERSION@)
85  find_dependency(Qt5Xml @REQUIRED_QT_VERSION@)
86
87 diff --git a/autotests/kmainwindow_unittest.cpp b/autotests/kmainwindow_unittest.cpp
88 index 00282ef..7bbd581 100644
89 --- a/autotests/kmainwindow_unittest.cpp
90 +++ b/autotests/kmainwindow_unittest.cpp
91 @@ -17,6 +17,8 @@
92      Boston, MA 02110-1301, USA.
93  */
94
95 +#include "config-xmlgui.h"
96 +
97  #include <QTest>
98  #include "kmainwindow_unittest.h"
99  #include <QEventLoopLocker>
100 @@ -91,12 +93,20 @@ void KMainWindow_UnitTest::testNameWithSpecialChars()
101      mw.setObjectName(QStringLiteral("a#@_test/"));
102      mw.show();
103      mw.ensurePolished();
104 +#if HAVE_QDBUS
105      QCOMPARE(mw.dbusName(), QString::fromLatin1("/kmainwindow_unittest/a___test_"));
106 +#else
107 +    QCOMPARE(mw.objectName(), QString::fromLatin1("a#@_test/"));
108 +#endif
109      KMainWindow mw2;
110      mw2.setObjectName(QStringLiteral("a#@_test/"));
111      mw2.show();
112      mw2.ensurePolished();
113 +#if HAVE_QDBUS
114      QCOMPARE(mw2.dbusName(), QString::fromLatin1("/kmainwindow_unittest/a___test_2"));
115 +#else
116 +    QCOMPARE(mw2.objectName(), QString::fromLatin1("a#@_test/2"));
117 +#endif
118  }
119
120  static bool s_mainWindowDeleted;
121 diff --git a/autotests/ktoolbar_unittest.cpp b/autotests/ktoolbar_unittest.cpp
122 index d6c1e05..da0eb4e 100644
123 --- a/autotests/ktoolbar_unittest.cpp
124 +++ b/autotests/ktoolbar_unittest.cpp
125 @@ -18,10 +18,14 @@
126      Boston, MA 02110-1301, USA.
127  */
128
129 +#include "config-xmlgui.h"
130 +
131  #include "testxmlguiwindow.h"
132  #include "testguiclient.h"
133
134 -#include <QDBusConnection>
135 +#if HAVE_QDBUS
136 +# include <QDBusConnection>
137 +#endif
138  #include <QDir>
139  #include <QFile>
140  #include <QFileInfo>
141 @@ -79,7 +83,9 @@ protected:
142  private:
143      void changeGlobalIconSizeSetting(int, int);
144      void deleteGlobalIconSizeSetting();
145 +#if HAVE_QDBUS
146      void changeGlobalToolButtonStyleSetting(const QString &, const QString &);
147 +#endif
148      void deleteGlobalToolButtonStyleSetting();
149      QByteArray m_xml;
150      bool m_showWasCalled;
151 @@ -422,6 +428,7 @@ void tst_KToolBar::testToolButtonStyleNoXmlGui()
152          QCOMPARE((int)mainToolBar->toolButtonStyle(), (int)toolButtonStyle);
153          QCOMPARE((int)otherToolBar->toolButtonStyle(), (int)toolButtonStyle);
154
155 +#if HAVE_QDBUS
156          // Now change KDE-global setting
157          changeGlobalToolButtonStyleSetting(QStringLiteral("IconOnly"), QStringLiteral("TextOnly"));
158
159 @@ -436,6 +443,9 @@ void tst_KToolBar::testToolButtonStyleNoXmlGui()
160          } else {
161              QCOMPARE((int)otherToolBar->toolButtonStyle(), (int)toolButtonStyle);
162          }
163 +#else
164 +        Q_UNUSED(selectedDefaultForOtherToolbar);
165 +#endif
166      }
167  }
168
169 @@ -485,16 +495,23 @@ void tst_KToolBar::testToolButtonStyleXmlGui()
170          // Save settings
171          kmw.saveMainWindowSettings(group);
172
173 +#if HAVE_QDBUS
174          // Now change KDE-global setting
175          changeGlobalToolButtonStyleSetting(QStringLiteral("IconOnly"), QStringLiteral("TextOnly"));
176
177          QCOMPARE((int)mainToolBar->toolButtonStyle(), (int)expectedStyleMainToolbar);
178          QCOMPARE((int)otherToolBar->toolButtonStyle(), (int)expectedStyleOtherToolbar);
179          QCOMPARE((int)cleanToolBar->toolButtonStyle(), (int)expectedStyleCleanToolbar);
180 +#else
181 +        Q_UNUSED(expectedStyleMainToolbar);
182 +        Q_UNUSED(expectedStyleOtherToolbar);
183 +        Q_UNUSED(expectedStyleCleanToolbar);
184 +#endif
185
186      }
187  }
188
189 +#if HAVE_QDBUS
190  void tst_KToolBar::changeGlobalToolButtonStyleSetting(const QString &mainToolBar, const QString &otherToolBars)
191  {
192      KConfigGroup group(KSharedConfig::openConfig(), "Toolbar style");
193 @@ -512,6 +529,7 @@ void tst_KToolBar::changeGlobalToolButtonStyleSetting(const QString &mainToolBar
194      KToolBar::emitToolbarStyleChanged();
195      spy.wait(2000);
196  }
197 +#endif
198
199  void tst_KToolBar::deleteGlobalToolButtonStyleSetting()
200  {
201 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
202 index 8126b5e..e849ab7 100644
203 --- a/src/CMakeLists.txt
204 +++ b/src/CMakeLists.txt
205 @@ -6,6 +6,10 @@ endif ()
206  if (HAVE_GLOBALACCEL)
207     set (XMLGUI_EXTRA_LIBS ${XMLGUI_EXTRA_LIBS} KF5::GlobalAccel)
208  endif ()
209 +if (HAVE_QDBUS)
210 +   set (XMLGUI_QDBUS_LIBS Qt5::DBus)
211 +   set (XMLGUI_DBUS_PRI_NAME "dbus")
212 +endif ()
213  if(WIN32)
214      set (XMLGUI_EXTRA_LIBS ${XMLGUI_EXTRA_LIBS} secur32) # GetUserNameEx()
215  endif()
216 @@ -33,7 +37,6 @@ set(kxmlgui_SRCS
217    khelpmenu.cpp
218    kkeysequencewidget.cpp
219    kmainwindow.cpp
220 -  kmainwindowiface.cpp
221    kmenumenuhandler_p.cpp
222    kshortcuteditwidget.cpp
223    kshortcutschemeseditor.cpp
224 @@ -56,6 +59,12 @@ set(kxmlgui_SRCS
225    kundoactions.cpp
226    kcheckaccelerators.cpp
227  )
228 +if (HAVE_QDBUS)
229 +  set(kxmlgui_SRCS
230 +    ${kxmlgui_SRCS}
231 +    kmainwindowiface.cpp
232 +  )
233 +endif()
234
235  # add the resource file
236  qt5_add_resources(kxmlgui_SRCS kxmlgui.qrc)
237 @@ -77,7 +86,7 @@ target_include_directories(KF5XmlGui INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTAL
238
239  target_link_libraries(KF5XmlGui
240  PUBLIC
241 -    Qt5::DBus           #QDBus connect to signal in KToolBar
242 +    ${XMLGUI_QDBUS_LIBS} #QDBus connect to signal in KToolBar
243      Qt5::Xml            #To parse the configuration (QDomDocument etc)
244      Qt5::Widgets        #QWidget is used everywhere
245      KF5::ConfigCore         #Reading config for ToolbarIcons, Shortcut Schemes...
246 @@ -138,5 +147,5 @@ install(FILES
247  install( FILES ui_standards.rc  DESTINATION  ${KDE_INSTALL_CONFDIR}/ui )
248
249  include(ECMGeneratePriFile)
250 -ecm_generate_pri_file(BASE_NAME KXmlGui LIB_NAME KF5XmlGui DEPS "dbus xml widgets KConfigCore KConfigWidgets" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/KXmlGui)
251 +ecm_generate_pri_file(BASE_NAME KXmlGui LIB_NAME KF5XmlGui DEPS "${XMLGUI_DBUS_PRI_NAME} xml widgets KConfigCore KConfigWidgets" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/KXmlGui)
252  install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR})
253 diff --git a/src/config-xmlgui.h.cmake b/src/config-xmlgui.h.cmake
254 index 9d7f3dc..35c9477 100644
255 --- a/src/config-xmlgui.h.cmake
256 +++ b/src/config-xmlgui.h.cmake
257 @@ -7,3 +7,6 @@
258
259  /* KF5GlobalAccel available */
260  #cmakedefine01 HAVE_GLOBALACCEL
261 +
262 +/* Qt5DBus available */
263 +#cmakedefine01 HAVE_QDBUS
264 diff --git a/src/kmainwindow.cpp b/src/kmainwindow.cpp
265 index cae655d..4c98c3f 100644
266 --- a/src/kmainwindow.cpp
267 +++ b/src/kmainwindow.cpp
268 @@ -23,11 +23,11 @@
269      the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
270      Boston, MA 02110-1301, USA.
271  */
272 +#include "config-xmlgui.h"
273
274  #include "kmainwindow.h"
275
276  #include "kmainwindow_p.h"
277 -#include "kmainwindowiface_p.h"
278  #include "ktoolbarhandler_p.h"
279  #include "khelpmenu.h"
280  #include "ktoolbar.h"
281 @@ -46,7 +46,6 @@
282  #include <QStyle>
283  #include <QWidget>
284  #include <QWindow>
285 -#include <QDBusConnection>
286
287  #include <ktoggleaction.h>
288  #include <kaboutdata.h>
289 @@ -58,6 +57,11 @@
290  #include <kwindowconfig.h>
291  #include <kconfiggui.h>
292
293 +#if HAVE_QDBUS
294 +# include "kmainwindowiface_p.h"
295 +# include <QDBusConnection>
296 +#endif
297 +
298  //#include <ctype.h>
299
300  static const char WINDOW_PROPERTIES[]="WindowProperties";
301 @@ -302,6 +306,7 @@ void KMainWindowPrivate::polish(KMainWindow *q)
302      q->winId(); // workaround for setWindowRole() crashing, and set also window role, just in case TT
303      q->setWindowRole(s);   // will keep insisting that object name suddenly should not be used for window role
304
305 +#if HAVE_QDBUS
306      dbusName = QLatin1Char('/') + QCoreApplication::applicationName() + QLatin1Char('/');
307      dbusName += q->objectName().replace(QLatin1Char('/'), QLatin1Char('_'));
308      // Clean up for dbus usage: any non-alphanumeric char should be turned into '_'
309 @@ -317,6 +322,7 @@ void KMainWindowPrivate::polish(KMainWindow *q)
310              QDBusConnection::ExportNonScriptableSlots |
311              QDBusConnection::ExportNonScriptableProperties |
312              QDBusConnection::ExportAdaptors);
313 +#endif
314  }
315
316  void KMainWindowPrivate::setSettingsDirty(CallCompression callCompression)
317 diff --git a/src/kmainwindowiface.cpp b/src/kmainwindowiface.cpp
318 index c194bec..25439b3 100644
319 --- a/src/kmainwindowiface.cpp
320 +++ b/src/kmainwindowiface.cpp
321 @@ -18,8 +18,8 @@
322     Boston, MA 02110-1301, USA.
323  */
324
325 -#include "kmainwindowiface_p.h"
326
327 +#include "kmainwindowiface_p.h"
328  #include "kactioncollection.h"
329  #include "kxmlguiwindow.h"
330
331 diff --git a/src/ktoolbar.cpp b/src/ktoolbar.cpp
332 index 8fcb9cb..6bda175 100644
333 --- a/src/ktoolbar.cpp
334 +++ b/src/ktoolbar.cpp
335 @@ -24,6 +24,8 @@
336      Boston, MA 02110-1301, USA.
337  */
338
339 +#include "config-xmlgui.h"
340 +
341  #include "ktoolbar.h"
342
343  #include <QPointer>
344 @@ -38,10 +40,13 @@
345  #include <QMouseEvent>
346  #include <QToolButton>
347  #include <QtXml/QDomElement>
348 -#include <QDBusConnection>
349 -#include <QDBusMessage>
350  #include <QDebug>
351
352 +#if HAVE_QDBUS
353 +# include <QDBusConnection>
354 +# include <QDBusMessage>
355 +#endif
356 +
357  #include <kauthorized.h>
358  #include <kconfig.h>
359  #include <ksharedconfig.h>
360 @@ -273,8 +278,10 @@ void KToolBar::Private::init(bool readConfig, bool _isMainToolBar)
361
362      q->setAcceptDrops(true);
363
364 +#if HAVE_QDBUS
365      QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KToolBar"), QStringLiteral("org.kde.KToolBar"),
366                                            QStringLiteral("styleChanged"), q, SLOT(slotAppearanceChanged()));
367 +#endif
368      connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()),
369              q, SLOT(slotAppearanceChanged()));
370  }
371 @@ -1465,8 +1472,10 @@ bool KToolBar::toolBarsLocked()
372
373  void KToolBar::emitToolbarStyleChanged()
374  {
375 +#if HAVE_QDBUS
376      QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KToolBar"), QStringLiteral("org.kde.KToolBar"), QStringLiteral("styleChanged"));
377      QDBusConnection::sessionBus().send(message);
378 +#endif
379  }
380
381  #include "moc_ktoolbar.cpp"
382 diff --git a/src/kxmlguiwindow.cpp b/src/kxmlguiwindow.cpp
383 index b4162c8..9e76928 100644
384 --- a/src/kxmlguiwindow.cpp
385 +++ b/src/kxmlguiwindow.cpp
386 @@ -23,11 +23,12 @@
387      Boston, MA 02110-1301, USA.
388  */
389
390 +#include "config-xmlgui.h"
391 +
392  #include "kxmlguiwindow.h"
393
394  #include "kmainwindow_p.h"
395  #include "kactioncollection.h"
396 -#include "kmainwindowiface_p.h"
397  #include "ktoolbarhandler_p.h"
398  #include "kxmlguifactory.h"
399  #include "kedittoolbar.h"
400 @@ -35,7 +36,6 @@
401  #include "ktoolbar.h"
402
403  #include <QCloseEvent>
404 -#include <QDBusConnection>
405  #include <QtXml/QDomDocument>
406  #include <QLayout>
407  #include <QDebug>
408 @@ -46,6 +46,11 @@
409  #include <QWidget>
410  #include <QList>
411
412 +#if HAVE_QDBUS
413 +# include "kmainwindowiface_p.h"
414 +# include <QDBusConnection>
415 +#endif
416 +
417  #include <ktoggleaction.h>
418  #include <kstandardaction.h>
419  #include <kconfig.h>
420 @@ -86,7 +91,9 @@ KXmlGuiWindow::KXmlGuiWindow(QWidget *parent, Qt::WindowFlags f)
421      d->toolBarHandler = 0;
422      d->showStatusBarAction = 0;
423      d->factory = 0;
424 +#if HAVE_QDBUS
425      new KMainWindowInterface(this);
426 +#endif
427  }
428
429  QAction *KXmlGuiWindow::toolBarMenuAction()
430 @@ -116,6 +123,7 @@ KXmlGuiWindow::~KXmlGuiWindow()
431  bool KXmlGuiWindow::event(QEvent *ev)
432  {
433      bool ret = KMainWindow::event(ev);
434 +#if HAVE_QDBUS
435      if (ev->type() == QEvent::Polish) {
436          QDBusConnection::sessionBus().registerObject(dbusName() + QStringLiteral("/actions"), actionCollection(),
437                  QDBusConnection::ExportScriptableSlots |
438 @@ -124,6 +132,7 @@ bool KXmlGuiWindow::event(QEvent *ev)
439                  QDBusConnection::ExportNonScriptableProperties |
440                  QDBusConnection::ExportChildObjects);
441      }
442 +#endif
443      return ret;
444  }
445
446 --
447 2.1.4