mirror of
				https://github.com/Swordfish90/cool-retro-term.git
				synced 2025-11-04 00:52:11 +00:00 
			
		
		
		
	Added --workdir and --program flags.
This commit is contained in:
		
							
								
								
									
										16
									
								
								app/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								app/main.cpp
									
									
									
									
									
								
							@@ -1,12 +1,20 @@
 | 
				
			|||||||
#include <QtQml/QQmlApplicationEngine>
 | 
					#include <QtQml/QQmlApplicationEngine>
 | 
				
			||||||
#include <QtGui/QGuiApplication>
 | 
					#include <QtGui/QGuiApplication>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <QQmlContext>
 | 
				
			||||||
 | 
					#include <QStringList>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QtWidgets/QApplication>
 | 
					#include <QtWidgets/QApplication>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QDebug>
 | 
					#include <QDebug>
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QString getNamedArgument(QStringList args, QString name) {
 | 
				
			||||||
 | 
					    int index = args.indexOf(name);
 | 
				
			||||||
 | 
					    return (index != -1) ? args[index + 1] : QString("");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(int argc, char *argv[])
 | 
					int main(int argc, char *argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    setenv("QT_QPA_PLATFORMTHEME", "", 1);
 | 
					    setenv("QT_QPA_PLATFORMTHEME", "", 1);
 | 
				
			||||||
@@ -16,13 +24,18 @@ int main(int argc, char *argv[])
 | 
				
			|||||||
    // Manage command line arguments from the cpp side
 | 
					    // Manage command line arguments from the cpp side
 | 
				
			||||||
    QStringList args = app.arguments();
 | 
					    QStringList args = app.arguments();
 | 
				
			||||||
    if (args.contains("-h") || args.contains("--help")) {
 | 
					    if (args.contains("-h") || args.contains("--help")) {
 | 
				
			||||||
        qDebug() << "Usage: " + args.at(0) + " [--default-settings] [-h|--help]";
 | 
					        qDebug() << "Usage: " + args.at(0) + " [--default-settings] [--workdir <dir>] [--program <prog>] [-h|--help]";
 | 
				
			||||||
        qDebug() << "    --default-settings  Run cool-old-term with the default settings";
 | 
					        qDebug() << "    --default-settings  Run cool-old-term with the default settings";
 | 
				
			||||||
 | 
					        qDebug() << "    --workdir <dir>     Change working directory to 'dir'";
 | 
				
			||||||
 | 
					        qDebug() << "    --program <prog>    Run the 'prog' in the new terminal.";
 | 
				
			||||||
        qDebug() << "    -p|--profile        Run cool-old-term with the given profile.";
 | 
					        qDebug() << "    -p|--profile        Run cool-old-term with the given profile.";
 | 
				
			||||||
        qDebug() << "    -h|--help           Print this help.";
 | 
					        qDebug() << "    -h|--help           Print this help.";
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    engine.rootContext()->setContextProperty("workdir", getNamedArgument(args, "--workdir"));
 | 
				
			||||||
 | 
					    engine.rootContext()->setContextProperty("shellProgram", getNamedArgument(args, "--program"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Manage import paths
 | 
					    // Manage import paths
 | 
				
			||||||
    QStringList importPathList = engine.importPathList();
 | 
					    QStringList importPathList = engine.importPathList();
 | 
				
			||||||
    importPathList.prepend(QCoreApplication::applicationDirPath() + "/imports/");
 | 
					    importPathList.prepend(QCoreApplication::applicationDirPath() + "/imports/");
 | 
				
			||||||
@@ -32,4 +45,3 @@ int main(int argc, char *argv[])
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    return app.exec();
 | 
					    return app.exec();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -137,6 +137,13 @@ Item{
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        Component.onCompleted: {
 | 
					        Component.onCompleted: {
 | 
				
			||||||
            shadersettings.terminalFontChanged.connect(handleFontChange);
 | 
					            shadersettings.terminalFontChanged.connect(handleFontChange);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Retrieve the variable set in main.cpp if arguments are passed.
 | 
				
			||||||
 | 
					            if (shellProgram)
 | 
				
			||||||
 | 
					                ksession.setShellProgram(shellProgram);
 | 
				
			||||||
 | 
					            if (workdir)
 | 
				
			||||||
 | 
					                ksession.initialWorkingDirectory = workdir;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            ksession.startShellProgram();
 | 
					            ksession.startShellProgram();
 | 
				
			||||||
            forceActiveFocus();
 | 
					            forceActiveFocus();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user