Mercurial > hg > forks > UniversalIndentGUI
changeset 500:70e6985f83a2
Made it possible to start UiGUI with different command line parameters.
git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@740 59b1889a-e5ac-428c-b0c7-476e01d41282
author | thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282> |
---|---|
date | Wed, 25 Jun 2008 09:32:45 +0000 |
parents | 23ac99119d2c |
children | a4d67b117238 |
files | src/main.cpp |
diffstat | 1 files changed, 53 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main.cpp Mon Jun 23 13:08:02 2008 +0000 +++ b/src/main.cpp Wed Jun 25 09:32:45 2008 +0000 @@ -25,22 +25,69 @@ #include "uiguiIniFileParser.h" /*! - /brief Entry point to UniversalIndentGUI application. Does not evaluate any command line parameters. + /brief Entry point to UniversalIndentGUI application. + + Evaluates the following parameters: + No parameters starts without server and full gui. + -f filename --file filename : Opens the by filename defined file on start. + -p --plugin : Run as plugin. Server will be startet with a simplified gui. + -s --server : Run as server only without gui. + If -p and -s are set, -p will be used. */ int main(int argc, char *argv[]) { QApplication app(argc, argv); QString file2OpenOnStart = ""; + bool startAsPlugin = false; + bool startAsServer = false; UiguiIndentServer server; - server.startServer(); + MainWindow *mainWindow = NULL; + IndentHandler *indentHandler = NULL; - if ( argc > 1 ) { - file2OpenOnStart = argv[1]; + // Parse command line arguments. First parameter is the executable itself. + for ( int i = 1; i < argc; i++ ) { + QString currentArg = argv[i]; + // Open file parameters. + if ( currentArg == "-f" || currentArg == "--file" ) { + // Test whether a parameter follows the file parameter. + if ( i + 1 >= argc ) { + fprintf(stderr, "The parameter -f / --file needs a following parameter defining the file to be opened at start."); + exit(1); + } + // Set the file that shall be opened a start. + else { + i++; + file2OpenOnStart = argv[i]; + } + } + else if ( currentArg == "-p" || currentArg == "--plugin" ) { + startAsPlugin = true; + } + else if ( currentArg == "-s" || currentArg == "--server" ) { + startAsServer = true; + } + else { + fprintf(stderr, "Invalid parameter found. Allowed parameters are..."); + exit(1); + } } - MainWindow mainWindow(file2OpenOnStart); - mainWindow.show(); + // Start normal with full gui and without server. + if ( !startAsPlugin && !startAsServer ) { + mainWindow = new MainWindow(file2OpenOnStart); + mainWindow->show(); + } + // Start as plugin with server. + else if ( startAsPlugin ) { + server.startServer(); + indentHandler = new IndentHandler(0); + indentHandler->show(); + } + // Start as server only without any gui. + else if ( startAsServer ) { + server.startServer(); + } return app.exec(); }