File indexing completed on 2024-04-14 04:29:48
0001 /* 0002 * This file is part of KDevelop 0003 * 0004 * Copyright 2007 Hamish Rodda <rodda@kde.org> 0005 * Copyright 2009 Niko Sams <niko.sams@gmail.com> 0006 * 0007 * This program is free software; you can redistribute it and/or modify 0008 * it under the terms of the GNU Library General Public License as 0009 * published by the Free Software Foundation; either version 2 of the 0010 * License, or (at your option) any later version. 0011 * 0012 * This program is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 * GNU General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU General Public 0018 * License along with this program; if not, write to the 0019 * Free Software Foundation, Inc., 0020 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0021 */ 0022 0023 #include "executebrowserplugin.h" 0024 0025 #include <QUrl> 0026 0027 #include <KPluginFactory> 0028 #include <KConfigGroup> 0029 0030 #include <interfaces/icore.h> 0031 #include <interfaces/iruncontroller.h> 0032 #include <interfaces/ilaunchconfiguration.h> 0033 0034 #include <debug.h> 0035 #include "browserappconfig.h" 0036 0037 QString ExecuteBrowserPlugin::_browserAppConfigTypeId = "Browser Application"; 0038 QString ExecuteBrowserPlugin::serverEntry = "Server"; 0039 QString ExecuteBrowserPlugin::pathEntry = "Path"; 0040 QString ExecuteBrowserPlugin::portEntry = "Port"; 0041 QString ExecuteBrowserPlugin::argumentsEntry = "Arguments"; 0042 QString ExecuteBrowserPlugin::browserEntry = "Browser"; 0043 0044 using namespace KDevelop; 0045 0046 //KPluginFactory stuff to load the plugin dynamically at runtime 0047 K_PLUGIN_FACTORY_WITH_JSON(KDevExecuteFactory, "kdevexecutebrowser.json", registerPlugin<ExecuteBrowserPlugin>();) 0048 0049 ExecuteBrowserPlugin::ExecuteBrowserPlugin(QObject *parent, const QVariantList&) 0050 : KDevelop::IPlugin("kdevexecutebrowser", parent) 0051 { 0052 BrowserAppConfigType* t = new BrowserAppConfigType(); 0053 t->addLauncher( new BrowserAppLauncher() ); 0054 qCDebug(KDEV_EXECUTEBROWSER) << "adding script launch config"; 0055 core()->runController()->addConfigurationType( t ); 0056 } 0057 0058 ExecuteBrowserPlugin::~ExecuteBrowserPlugin() 0059 { 0060 } 0061 0062 0063 void ExecuteBrowserPlugin::unload() 0064 { 0065 } 0066 0067 QUrl ExecuteBrowserPlugin::url( KDevelop::ILaunchConfiguration* cfg, QString& err_ ) const 0068 { 0069 QUrl url; 0070 0071 if( !cfg ) 0072 { 0073 return url; 0074 } 0075 KConfigGroup grp = cfg->config(); 0076 0077 QString host = grp.readEntry( ExecuteBrowserPlugin::serverEntry, "" ); 0078 if( host.isEmpty() ) 0079 { 0080 err_ = i18n("Empty server in launch configuration"); 0081 qCWarning(KDEV_EXECUTEBROWSER) << "Launch Configuration:" << cfg->name() << err_; 0082 return url; 0083 } 0084 0085 QString path(grp.readEntry( ExecuteBrowserPlugin::pathEntry, "" )); 0086 if( !host.endsWith("/") && !path.isEmpty() && !path.startsWith("/") ) { 0087 path.prepend("/"); 0088 } 0089 if( !host.contains(QStringLiteral("://")) ) 0090 { 0091 host.prepend(QStringLiteral("http://")); 0092 } 0093 0094 url.setUrl(host + path); 0095 url.setPort(grp.readEntry( ExecuteBrowserPlugin::portEntry, 80 )); 0096 { 0097 QString q = grp.readEntry( ExecuteBrowserPlugin::argumentsEntry, "" ); 0098 if (!q.isEmpty()) { 0099 url.setQuery(q); 0100 } 0101 } 0102 0103 if( url.toString().isEmpty() ) { 0104 err_ = i18n("Invalid launch configuration"); 0105 qCWarning(KDEV_EXECUTEBROWSER) << "Launch Configuration:" << cfg->name() << err_; 0106 return url; 0107 } 0108 qCDebug(KDEV_EXECUTEBROWSER) << "Url:" << url.toString(); 0109 return url; 0110 } 0111 0112 QString ExecuteBrowserPlugin::browser( ILaunchConfiguration* cfg ) const 0113 { 0114 return cfg->config().readEntry( ExecuteBrowserPlugin::browserEntry, "" ); 0115 } 0116 0117 QString ExecuteBrowserPlugin::browserAppConfigTypeId() const 0118 { 0119 return _browserAppConfigTypeId; 0120 } 0121 0122 0123 #include "executebrowserplugin.moc"