File indexing completed on 2024-05-19 05:41:55

0001 // codevisdbusinterface.cpp                                     -*-C++-*-
0002 
0003 /*
0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk>
0005 // SPDX-License-Identifier: Apache-2.0
0006 //
0007 // Licensed under the Apache License, Version 2.0 (the "License");
0008 // you may not use this file except in compliance with the License.
0009 // You may obtain a copy of the License at
0010 //
0011 //     http://www.apache.org/licenses/LICENSE-2.0
0012 //
0013 // Unless required by applicable law or agreed to in writing, software
0014 // distributed under the License is distributed on an "AS IS" BASIS,
0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016 // See the License for the specific language governing permissions and
0017 // limitations under the License.
0018 */
0019 
0020 #include <codevis_dbus_interface.h>
0021 
0022 // dbus is not linux only but conan is having issues compiling the
0023 // needed library, so blocking it on Mac and Windows temporarily.
0024 #ifdef Q_OS_LINUX
0025 #include <QDBusConnection>
0026 #include <codevisadaptor.h>
0027 #endif
0028 
0029 CodeVisDBusInterface::CodeVisDBusInterface(MainWindow& mainWindow): mainWindow(mainWindow)
0030 {
0031 #ifdef Q_OS_LINUX
0032     new CodeVisAdaptor(this);
0033 
0034     auto bus = QDBusConnection::sessionBus();
0035     bus.registerObject("/Application", this);
0036     bus.registerService("org.codethink.CodeVis");
0037 #endif
0038 }
0039 
0040 void CodeVisDBusInterface::requestNewTab()
0041 {
0042     mainWindow.newTab();
0043 }
0044 
0045 void CodeVisDBusInterface::requestCloseCurrentTab()
0046 {
0047     mainWindow.closeCurrentTab();
0048 }
0049 
0050 // toggles the split view on / off
0051 void CodeVisDBusInterface::requestToggleSplitView()
0052 {
0053     mainWindow.toggleSplitView();
0054 }
0055 
0056 // requests to close the application
0057 void CodeVisDBusInterface::requestQuit()
0058 {
0059     mainWindow.close();
0060 }
0061 
0062 // requests a database to open.
0063 bool CodeVisDBusInterface::requestLoadProject(const QString& projectPath)
0064 {
0065     return mainWindow.openProjectFromPath(projectPath);
0066 }
0067 
0068 // requests to load a class on the current tab
0069 void CodeVisDBusInterface::requestLoadPackage(const QString& qualifiedName)
0070 {
0071     mainWindow.setCurrentGraphFromString(Codethink::lvtmdl::NodeType::Enum::e_Package, qualifiedName);
0072 }
0073 
0074 // requests to load a class on the current tab
0075 void CodeVisDBusInterface::requestLoadClass(const QString& qualifiedName)
0076 {
0077     mainWindow.setCurrentGraphFromString(Codethink::lvtmdl::NodeType::Enum::e_Class, qualifiedName);
0078 }
0079 
0080 // requests to load a class on the current tab
0081 void CodeVisDBusInterface::requestLoadComponent(const QString& qualifiedName)
0082 {
0083     mainWindow.setCurrentGraphFromString(Codethink::lvtmdl::NodeType::Enum::e_Component, qualifiedName);
0084 }
0085 
0086 void CodeVisDBusInterface::requestSelectLeftSplitView()
0087 {
0088     mainWindow.selectLeftSplitView();
0089 }
0090 
0091 void CodeVisDBusInterface::requestSelectRightSplitView()
0092 {
0093     mainWindow.selectRightSplitView();
0094 }