File indexing completed on 2024-05-12 04:39:29

0001 /*
0002     SPDX-FileCopyrightText: 2013 Aleix Pol Gonzalez <aleixpol@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "kdevprojectopen.h"
0008 
0009 #include <tests/autotestshell.h>
0010 #include <tests/testcore.h>
0011 #include <interfaces/iprojectcontroller.h>
0012 #include "testhelpers.h"
0013 
0014 #include <KLocalizedString>
0015 #include <KAboutData>
0016 
0017 #include <QApplication>
0018 #include <QDebug>
0019 #include <QCommandLineParser>
0020 
0021 using namespace KDevelop;
0022 
0023 KDevProjectOpen::KDevProjectOpen(QObject* parent)
0024     : QObject(parent)
0025 {
0026     AutoTestShell::init();
0027     TestCore::initialize();
0028 
0029     cleanup();
0030     connect(ICore::self()->projectController(), &IProjectController::projectOpened, this, &KDevProjectOpen::projectDone);
0031 }
0032 
0033 void KDevProjectOpen::cleanup()
0034 {
0035     const auto projects = ICore::self()->projectController()->projects();
0036     for (IProject* p : projects) {
0037         ICore::self()->projectController()->closeProject(p);
0038     }
0039     Q_ASSERT(ICore::self()->projectController()->projects().isEmpty());
0040 }
0041 
0042 void KDevProjectOpen::openProject(const QUrl& path)
0043 {
0044     const TestProjectPaths paths = projectPaths(path.toLocalFile());
0045     defaultConfigure(paths);
0046 
0047     m_toOpen++;
0048     ICore::self()->projectController()->openProject(paths.projectFile.toUrl());
0049 }
0050 
0051 void KDevProjectOpen::projectDone(IProject* )
0052 {
0053     m_toOpen--;
0054     if(m_toOpen==0) {
0055         cleanup();
0056         qApp->exit();
0057     }
0058 }
0059 
0060 int main(int argc, char** argv)
0061 {
0062     QApplication app(argc, argv);
0063 
0064     KAboutData aboutData( QStringLiteral("kdevprojectopen"), i18n( "KDevelop" ), QStringLiteral("0.99"), i18n("opens a project then closes it, debugging tool"), KAboutLicense::GPL,
0065                           i18n( "Copyright 1999-2012, The KDevelop developers" ), QString(), QStringLiteral("https://www.kdevelop.org/") );
0066     aboutData.addAuthor( i18n("Aleix Pol Gonzalez"), i18n( "" ), QStringLiteral("aleixpol@kde.org") );
0067     KAboutData::setApplicationData(aboutData);
0068 
0069     QCommandLineParser parser;
0070     aboutData.setupCommandLine(&parser);
0071     parser.addPositionalArgument(QStringLiteral("projects"), i18n("Projects to load"));
0072 
0073     parser.process(app);
0074     aboutData.processCommandLine(&parser);
0075 
0076     if(parser.positionalArguments().isEmpty()) {
0077         parser.showHelp(1);
0078     }
0079 
0080     KDevProjectOpen opener;
0081     const auto args = parser.positionalArguments();
0082     for (const QString& arg : args) {
0083         opener.openProject(QUrl::fromUserInput(arg));
0084     }
0085     return app.exec();
0086 }
0087 
0088 #include "moc_kdevprojectopen.cpp"