File indexing completed on 2024-04-28 17:00:47
0001 /*************************************************************************** 0002 * Copyright (C) 2005-2009 by Rajko Albrecht * 0003 * ral@alwins-world.de * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program 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 * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 0019 ***************************************************************************/ 0020 #include "commandline.h" 0021 #include "kdesvn_part.h" 0022 #include "commandline_part.h" 0023 #include <KPluginFactory> 0024 #include <KPluginLoader> 0025 #include <KHelpClient> 0026 #include <QCommandLineParser> 0027 0028 CommandLine::CommandLine(const QCommandLineParser *parser) 0029 : m_parser(parser) 0030 {} 0031 0032 CommandLine::~CommandLine() 0033 {} 0034 0035 int CommandLine::exec() 0036 { 0037 if (m_parser->positionalArguments().isEmpty()) { 0038 return -1; 0039 } 0040 if (m_parser->positionalArguments().count() < 2) { 0041 cmd = QLatin1String("help"); 0042 } else { 0043 cmd = m_parser->positionalArguments().at(1); 0044 } 0045 if (cmd == QLatin1String("help")) { 0046 displayHelp(); 0047 return 0; 0048 } 0049 #ifdef EXTRA_KDE_LIBPATH 0050 QCoreApplication::addLibraryPath(QString::fromLocal8Bit(EXTRA_KDE_LIBPATH)); 0051 #endif 0052 KPluginLoader loader(QStringLiteral("kdesvnpart")); 0053 KPluginFactory *factory = loader.factory(); 0054 if (factory) { 0055 QObject *_p = (factory->create<QObject>(QStringLiteral("commandline_part"), nullptr)); 0056 if (!_p || QString::fromLatin1(_p->metaObject()->className()) != QLatin1String("commandline_part")) { 0057 return 0; 0058 } 0059 commandline_part *cpart = static_cast<commandline_part *>(_p); 0060 int res = cpart->exec(m_parser); 0061 return res; 0062 } 0063 return 0; 0064 } 0065 0066 void CommandLine::displayHelp() 0067 { 0068 KHelpClient::invokeHelp(QStringLiteral("kdesvn-commandline"), QStringLiteral("kdesvn")); 0069 }