File indexing completed on 2024-04-14 03:57:10

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2001 Ian Reinhart Geiser <geiseri@yahoo.com>
0004     SPDX-FileCopyrightText: 2006 Thiago Macieira <thiago@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #include "kmainwindowiface_p.h"
0010 
0011 #include "kactioncollection.h"
0012 #include "kxmlguiwindow.h"
0013 
0014 #include <QAction>
0015 #include <QApplication>
0016 #include <QClipboard>
0017 
0018 #include <algorithm>
0019 
0020 KMainWindowInterface::KMainWindowInterface(KXmlGuiWindow *mainWindow)
0021     : QDBusAbstractAdaptor(mainWindow)
0022     , m_MainWindow(mainWindow)
0023 {
0024 }
0025 
0026 KMainWindowInterface::~KMainWindowInterface()
0027 {
0028 }
0029 
0030 QStringList KMainWindowInterface::actions()
0031 {
0032     QStringList tmp_actions;
0033     const QList<QAction *> lst = m_MainWindow->actionCollection()->actions();
0034     for (QAction *it : lst) {
0035         const QList<QObject *> associatedObjects = it->associatedObjects();
0036         const bool hasAssociatedWidgets = std::any_of(associatedObjects.cbegin(), associatedObjects.cend(), [](QObject *object) {
0037             return (qobject_cast<QWidget *>(object) != nullptr);
0038         });
0039         if (hasAssociatedWidgets) {
0040             tmp_actions.append(it->objectName());
0041         }
0042     }
0043     return tmp_actions;
0044 }
0045 
0046 bool KMainWindowInterface::activateAction(const QString &action)
0047 {
0048     QAction *tmp_Action = m_MainWindow->actionCollection()->action(action);
0049     if (tmp_Action) {
0050         tmp_Action->trigger();
0051         return true;
0052     } else {
0053         return false;
0054     }
0055 }
0056 
0057 bool KMainWindowInterface::disableAction(const QString &action)
0058 {
0059     QAction *tmp_Action = m_MainWindow->actionCollection()->action(action);
0060     if (tmp_Action) {
0061         tmp_Action->setEnabled(false);
0062         return true;
0063     } else {
0064         return false;
0065     }
0066 }
0067 
0068 bool KMainWindowInterface::enableAction(const QString &action)
0069 {
0070     QAction *tmp_Action = m_MainWindow->actionCollection()->action(action);
0071     if (tmp_Action) {
0072         tmp_Action->setEnabled(true);
0073         return true;
0074     } else {
0075         return false;
0076     }
0077 }
0078 
0079 bool KMainWindowInterface::actionIsEnabled(const QString &action)
0080 {
0081     QAction *tmp_Action = m_MainWindow->actionCollection()->action(action);
0082     if (tmp_Action) {
0083         return tmp_Action->isEnabled();
0084     } else {
0085         return false;
0086     }
0087 }
0088 
0089 QString KMainWindowInterface::actionToolTip(const QString &action)
0090 {
0091     QAction *tmp_Action = m_MainWindow->actionCollection()->action(action);
0092     if (tmp_Action) {
0093         return tmp_Action->toolTip();
0094     } else {
0095         return QStringLiteral("Error no such object!");
0096     }
0097 }
0098 
0099 qlonglong KMainWindowInterface::winId()
0100 {
0101     return qlonglong(m_MainWindow->winId());
0102 }
0103 
0104 void KMainWindowInterface::grabWindowToClipBoard()
0105 {
0106     QClipboard *clipboard = QApplication::clipboard();
0107     clipboard->setPixmap(m_MainWindow->grab());
0108 }
0109 
0110 #include "moc_kmainwindowiface_p.cpp"