File indexing completed on 2024-04-28 08:42:24

0001 /*
0002     SPDX-FileCopyrightText: 2010 Michal Malek <michalm@jabster.pl>
0003     SPDX-FileCopyrightText: 1998-2007 Sebastian Trueg <trueg@k3b.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 
0009 #include "k3binterface.h"
0010 #include "k3binterfaceadaptor.h"
0011 #include "k3b.h"
0012 #include "k3bapplication.h"
0013 #include "k3bcore.h"
0014 #include "k3bdevicemanager.h"
0015 #include "k3bdoc.h"
0016 #include "k3bglobals.h"
0017 #include "k3bprojectmanager.h"
0018 #include "k3bview.h"
0019 
0020 #include <QList>
0021 #include <QTimer>
0022 #include <QDBusConnection>
0023 
0024 namespace K3b {
0025 
0026 
0027 Interface::Interface(  MainWindow* main  )
0028 :
0029     QObject( main ),
0030     m_main( main )
0031 {
0032     new K3bInterfaceAdaptor( this );
0033     QDBusConnection dbus = QDBusConnection::sessionBus();
0034     dbus.registerObject( "/MainWindow", this );
0035     dbus.registerService( "org.k3b.k3b" );
0036 }
0037 
0038 
0039 Interface::~Interface()
0040 {
0041     QDBusConnection dbus = QDBusConnection::sessionBus();
0042     dbus.unregisterObject( "/MainWindow" );
0043     dbus.unregisterService( "org.k3b.k3b" );
0044 }
0045 
0046 
0047 QString Interface::createDataProject()
0048 {
0049     ProjectManager* projectManager = k3bappcore->projectManager();
0050     return projectManager->dbusPath( projectManager->createProject( Doc::DataProject ) );
0051 }
0052 
0053 
0054 QString Interface::createAudioProject()
0055 {
0056     ProjectManager* projectManager = k3bappcore->projectManager();
0057     return projectManager->dbusPath( projectManager->createProject( Doc::AudioProject ) );
0058 }
0059 
0060 
0061 QString Interface::createMixedProject()
0062 {
0063     ProjectManager* projectManager = k3bappcore->projectManager();
0064     return projectManager->dbusPath( projectManager->createProject( Doc::MixedProject ) );
0065 }
0066 
0067 
0068 QString Interface::createVcdProject()
0069 {
0070     ProjectManager* projectManager = k3bappcore->projectManager();
0071     return projectManager->dbusPath( projectManager->createProject( Doc::VcdProject ) );
0072 }
0073 
0074 
0075 QString Interface::createMovixProject()
0076 {
0077     ProjectManager* projectManager = k3bappcore->projectManager();
0078     return projectManager->dbusPath( projectManager->createProject( Doc::MovixProject ) );
0079 }
0080 
0081 
0082 QString Interface::createVideoDvdProject()
0083 {
0084     ProjectManager* projectManager = k3bappcore->projectManager();
0085     return projectManager->dbusPath( projectManager->createProject( Doc::VideoDvdProject ) );
0086 }
0087 
0088 
0089 QString Interface::currentProject()
0090 {
0091     View* view = m_main->activeView();
0092     if( view )
0093         return k3bappcore->projectManager()->dbusPath( view->doc() );
0094     else
0095         return QString();
0096 }
0097 
0098 
0099 QString Interface::openProject( const QString& url )
0100 {
0101     Doc* doc = k3bappcore->projectManager()->openProject( QUrl( url ) );
0102     if( doc )
0103         return k3bappcore->projectManager()->dbusPath( doc );
0104     else
0105         return QString();
0106 }
0107 
0108 
0109 QStringList Interface::projects()
0110 {
0111     QStringList paths;
0112     QList<Doc*> docs = k3bappcore->projectManager()->projects();
0113     Q_FOREACH( Doc* doc, docs ) {
0114         paths.push_back( k3bappcore->projectManager()->dbusPath( doc ) );
0115     }
0116     return paths;
0117 }
0118 
0119 
0120 void Interface::copyMedium()
0121 {
0122     m_main->slotMediaCopy();
0123 }
0124 
0125 
0126 void Interface::copyMedium( const QString& dev )
0127 {
0128     m_main->mediaCopy( k3bcore->deviceManager()->findDeviceByUdi( dev ) );
0129 }
0130 
0131 
0132 void Interface::formatMedium()
0133 {
0134     m_main->slotFormatMedium();
0135 }
0136 
0137 
0138 void Interface::writeImage()
0139 {
0140     m_main->slotWriteImage();
0141 }
0142 
0143 
0144 void Interface::writeImage( const QString& url )
0145 {
0146     m_main->slotWriteImage( QUrl( url ) );
0147 }
0148 
0149 
0150 void Interface::audioCdRip()
0151 {
0152     m_main->slotCddaRip();
0153 }
0154 
0155 
0156 void Interface::audioCdRip( const QString& dev )
0157 {
0158     m_main->cddaRip( k3bcore->deviceManager()->findDeviceByUdi( dev ) );
0159 }
0160 
0161 
0162 void Interface::videoCdRip()
0163 {
0164     m_main->slotVideoCdRip();
0165 }
0166 
0167 
0168 void Interface::videoCdRip( const QString& dev )
0169 {
0170     m_main->videoCdRip( k3bcore->deviceManager()->findDeviceByUdi( dev ) );
0171 }
0172 
0173 
0174 void Interface::videoDvdRip()
0175 {
0176     m_main->slotVideoDvdRip();
0177 }
0178 
0179 
0180 void Interface::videoDvdRip( const QString& dev )
0181 {
0182     m_main->videoDvdRip( k3bcore->deviceManager()->findDeviceByUdi( dev ) );
0183 }
0184 
0185 
0186 void Interface::addUrls( const QStringList& urls )
0187 {
0188     QList<QUrl> urlList;
0189     for( auto& url : urls ) { urlList.push_back( QUrl::fromUserInput( url ) ); }
0190     m_main->addUrls( urlList );
0191 }
0192 
0193 
0194 void Interface::addUrl( const QString& url )
0195 {
0196     QStringList urls;
0197     urls.push_back( url );
0198     addUrls( urls );
0199 }
0200 
0201 
0202 bool Interface::blocked() const
0203 {
0204     return k3bcore->jobsRunning();
0205 }
0206 
0207 } // namespace K3b
0208 
0209 #include "moc_k3binterface.cpp"