File indexing completed on 2021-12-21 13:14:18

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 #include "browserappconfig.h"
0021 
0022 #include <QIcon>
0023 
0024 #include <KConfigGroup>
0025 #include <KOpenWithDialog>
0026 
0027 #include <interfaces/icore.h>
0028 #include <interfaces/ilaunchconfiguration.h>
0029 #include <interfaces/iruncontroller.h>
0030 
0031 #include <debug.h>
0032 #include "browserappjob.h"
0033 #include "executebrowserplugin.h"
0034 
0035 QIcon BrowserAppConfigPage::icon() const
0036 {
0037     return QIcon::fromTheme("system-run");
0038 }
0039 
0040 void BrowserAppConfigPage::loadFromConfiguration(const KConfigGroup& cfg, KDevelop::IProject* project )
0041 {
0042     Q_UNUSED(project);
0043 
0044     bool b = blockSignals( true );
0045     server->setText( cfg.readEntry( ExecuteBrowserPlugin::serverEntry, "localhost" ) );
0046     path->setText( cfg.readEntry( ExecuteBrowserPlugin::pathEntry, "" ) );
0047     port->setValue( cfg.readEntry( ExecuteBrowserPlugin::portEntry, 80 ) );
0048     arguments->setText( cfg.readEntry( ExecuteBrowserPlugin::argumentsEntry, "" ) );
0049     browser->setText( cfg.readEntry( ExecuteBrowserPlugin::browserEntry, "" ) );
0050     blockSignals( b );
0051 }
0052 
0053 BrowserAppConfigPage::BrowserAppConfigPage( QWidget* parent )
0054     : LaunchConfigurationPage( parent )
0055 {
0056     setupUi(this);
0057 
0058     selectBrowserButton->setIcon(QIcon::fromTheme("system-run"));
0059 
0060     //connect signals to changed signal
0061     connect(server, &KLineEdit::textEdited, this, &BrowserAppConfigPage::changed); 
0062     connect(path, &KLineEdit::textEdited, this, &BrowserAppConfigPage::changed);
0063     connect(port, QOverload<int>::of(&QSpinBox::valueChanged), this, &BrowserAppConfigPage::changed);
0064     connect(arguments, &KLineEdit::textEdited, this, &BrowserAppConfigPage::changed); 
0065     connect(browser, &KLineEdit::textEdited, this, &BrowserAppConfigPage::changed); 
0066     connect(selectBrowserButton, &QPushButton::pressed, this, &BrowserAppConfigPage::selectDialog); 
0067 }
0068 
0069 void BrowserAppConfigPage::saveToConfiguration( KConfigGroup cfg, KDevelop::IProject* project ) const
0070 {
0071     Q_UNUSED( project );
0072     cfg.writeEntry( ExecuteBrowserPlugin::serverEntry, server->text() );
0073     cfg.writeEntry( ExecuteBrowserPlugin::pathEntry, path->text() );
0074     cfg.writeEntry( ExecuteBrowserPlugin::portEntry, port->value() );
0075     cfg.writeEntry( ExecuteBrowserPlugin::argumentsEntry, arguments->text() );
0076     cfg.writeEntry( ExecuteBrowserPlugin::browserEntry, browser->text() );
0077 }
0078 
0079 QString BrowserAppConfigPage::title() const
0080 {
0081     return i18n("Configure Browser Application");
0082 }
0083 
0084 void BrowserAppConfigPage::selectDialog()
0085 {
0086     KOpenWithDialog *dialog = new KOpenWithDialog();
0087     dialog->hideNoCloseOnExit();
0088     dialog->hideRunInTerminal();
0089     if(dialog->exec()) {
0090         browser->setText(dialog->text().replace(QStringLiteral(" %u"), QStringLiteral(""), Qt::CaseSensitivity::CaseInsensitive));
0091         dialog->deleteLater();
0092         emit changed();
0093     }
0094 }
0095 
0096 QList< KDevelop::LaunchConfigurationPageFactory* > BrowserAppLauncher::configPages() const
0097 {
0098     return QList<KDevelop::LaunchConfigurationPageFactory*>();
0099 }
0100 
0101 QString BrowserAppLauncher::description() const
0102 {
0103     return "Executes Browser Applications";
0104 }
0105 
0106 QString BrowserAppLauncher::id()
0107 {
0108     return "browserAppLauncher";
0109 }
0110 
0111 QString BrowserAppLauncher::name() const
0112 {
0113     return i18n("Browser Application");
0114 }
0115 
0116 BrowserAppLauncher::BrowserAppLauncher()
0117 {
0118 }
0119 
0120 KJob* BrowserAppLauncher::start(const QString& launchMode, KDevelop::ILaunchConfiguration* cfg)
0121 {
0122     Q_ASSERT(cfg);
0123     if( !cfg )
0124     {
0125         return nullptr;
0126     }
0127     if( launchMode == "execute" )
0128     {
0129         return new BrowserAppJob( KDevelop::ICore::self()->runController(), cfg );
0130         
0131     }
0132     qCWarning(KDEV_EXECUTEBROWSER) << "Unknown launch mode " << launchMode << "for config:" << cfg->name();
0133     return nullptr;
0134 }
0135 
0136 QStringList BrowserAppLauncher::supportedModes() const
0137 {
0138     return QStringList() << "execute";
0139 }
0140 
0141 KDevelop::LaunchConfigurationPage* BrowserAppPageFactory::createWidget(QWidget* parent)
0142 {
0143     return new BrowserAppConfigPage( parent );
0144 }
0145 
0146 BrowserAppPageFactory::BrowserAppPageFactory()
0147 {
0148 }
0149 
0150 BrowserAppConfigType::BrowserAppConfigType()
0151 {
0152     factoryList.append( new BrowserAppPageFactory() );
0153 }
0154 
0155 QString BrowserAppConfigType::name() const
0156 {
0157     return i18n("Browser Application");
0158 }
0159 
0160 
0161 QList<KDevelop::LaunchConfigurationPageFactory*> BrowserAppConfigType::configPages() const
0162 {
0163     return factoryList;
0164 }
0165 
0166 QString BrowserAppConfigType::id() const
0167 {
0168     return ExecuteBrowserPlugin::_browserAppConfigTypeId;
0169 }
0170 
0171 QIcon BrowserAppConfigType::icon() const
0172 {
0173     return QIcon::fromTheme("system-run");
0174 }
0175 
0176 bool BrowserAppConfigType::canLaunch(const QUrl& /*file*/) const
0177 {
0178     return false;
0179 }
0180 
0181 bool BrowserAppConfigType::canLaunch(KDevelop::ProjectBaseItem* /*item*/) const
0182 {
0183     return false;
0184 }
0185 
0186 void BrowserAppConfigType::configureLaunchFromItem(KConfigGroup /*config*/,
0187                                                    KDevelop::ProjectBaseItem* /*item*/) const
0188 {
0189 
0190 }
0191 
0192 void BrowserAppConfigType::configureLaunchFromCmdLineArguments(KConfigGroup /*config*/,
0193                                                                const QStringList &/*args*/) const
0194 {
0195 }