File indexing completed on 2024-04-21 04:34:29

0001 /*  This file is part of KDevelop
0002     Copyright 2009 Andreas Pakulat <apaku@gmx.de>
0003     Copyright 2009 Niko Sams <niko.sams@gmail.com>
0004 
0005     This library is free software; you can redistribute it and/or
0006     modify it under the terms of the GNU Library General Public
0007     License as published by the Free Software Foundation; either
0008     version 2 of the License, or (at your option) any later version.
0009 
0010     This library is distributed in the hope that it will be useful,
0011     but WITHOUT ANY WARRANTY; without even the implied warranty of
0012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013     Library General Public License for more details.
0014 
0015     You should have received a copy of the GNU Library General Public License
0016     along with this library; see the file COPYING.LIB.  If not, write to
0017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018     Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #include "browserappjob.h"
0022 
0023 #include <QDesktopServices>
0024 
0025 #include <KProcess>
0026 
0027 #include <interfaces/ilaunchconfiguration.h>
0028 #include <interfaces/icore.h>
0029 #include <interfaces/iplugincontroller.h>
0030 
0031 #include <debug.h>
0032 #include "iexecutebrowserplugin.h"
0033 
0034 BrowserAppJob::BrowserAppJob(QObject* parent, KDevelop::ILaunchConfiguration* cfg)
0035     : KDevelop::OutputJob( parent )
0036 {
0037     qCDebug(KDEV_EXECUTEBROWSER) << "creating browser app job";
0038     setCapabilities(NoCapabilities);
0039 
0040     IExecuteBrowserPlugin* iface = KDevelop::ICore::self()->pluginController()->pluginForExtension("org.kdevelop.IExecuteBrowserPlugin")->extension<IExecuteBrowserPlugin>();
0041     Q_ASSERT(iface);
0042 
0043     QString err;
0044     m_url = iface->url(cfg, err);
0045     if (!err.isEmpty()) {
0046         m_url.clear();
0047         setError( -1 );
0048         setErrorText( err );
0049         return;
0050     }
0051     m_browser = iface->browser(cfg);
0052 
0053     setTitle(cfg->name());
0054 }
0055 
0056 
0057 void BrowserAppJob::start()
0058 {
0059     qCDebug(KDEV_EXECUTEBROWSER) << "launching?" << m_url;
0060     if (m_browser.isEmpty()) {
0061         if (!QDesktopServices::openUrl(m_url)) {
0062             qCWarning(KDEV_EXECUTEBROWSER) << "openUrl failed, something went wrong when creating the job";
0063         }
0064     } else {
0065     KProcess proc(this);
0066     proc << m_browser << m_url.url();
0067 
0068     proc.startDetached();
0069     }
0070     emitResult();
0071 }