Fixed UiGuiVersion and argument parsing

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
master
Michele Calgaro 2 years ago
parent 509cd0aa50
commit 2ba166d1f8
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -27,6 +27,7 @@ set( target universal-indent-gui-tqt )
set( ${target}_SRCS set( ${target}_SRCS
main.cpp main.cpp
UiGuiVersion.cpp
) )
tde_add_executable( ${target} AUTOMOC tde_add_executable( ${target} AUTOMOC

@ -19,9 +19,9 @@
#include "UiGuiVersion.h" #include "UiGuiVersion.h"
#include <tntqstring.h> #include <tqstring.h>
#include <tntqstringlist.h> #include <tqstringlist.h>
#include <tqdate.h> #include <tqdatetime.h>
namespace UiGuiVersion namespace UiGuiVersion
{ {
@ -32,19 +32,17 @@ namespace UiGuiVersion
TQString getBuildDate() TQString getBuildDate()
{ {
TQStringList monthNames; TQStringList monthNames;
TQString buildDateString = ""; monthNames << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"
<< "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
monthNames << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" <<
"Oct" << "Nov" << "Dez";
TQStringList buildDateStringList = TQString(__DATE__).simplified().split(' '); // __DATE__
// returns eg
// "Feb 4 2009"
TQString buildDateString = "";
// __DATE__ returns a string like "Feb 4 2009"
TQStringList buildDateStringList = TQStringList::split(' ', TQString(__DATE__).simplifyWhiteSpace());
if (buildDateStringList.count() == 3) if (buildDateStringList.count() == 3)
{ {
TQDate buildDate(buildDateStringList.last().toInt(), TQDate buildDate(buildDateStringList.last().toInt(),
monthNames.indexOf(buildDateStringList.first()) + 1, monthNames.findIndex(buildDateStringList.first()) + 1,
buildDateStringList.at(1).toInt()); buildDateStringList.at(1)->toInt());
buildDateString = buildDate.toString("d. MMMM yyyy"); buildDateString = buildDate.toString("d. MMMM yyyy");
} }
@ -58,13 +56,13 @@ namespace UiGuiVersion
TQString getBuildRevision() TQString getBuildRevision()
{ {
TQString buildRevision = ""; TQString buildRevision = "";
TQStringList buildRevisionStringList = TQString(PROGRAM_REVISION).simplified().split(' '); TQStringList buildRevisionStringList = TQStringList::split(' ', TQString(PROGRAM_REVISION).simplifyWhiteSpace());
if (buildRevisionStringList.count() == 3) if (buildRevisionStringList.count() == 3)
{ {
buildRevision = buildRevisionStringList.at(1); // PROGRAM_REVISION is eg "$Revision: 907 $" buildRevision = *buildRevisionStringList.at(1); // PROGRAM_REVISION is eg "$Revision: 907 $"
} }
return buildRevision; return buildRevision;
} }
} // namespace UiGuiVersion }

@ -23,7 +23,7 @@
class TQString; class TQString;
// Define the version number here. Update this as the last file before a release. // Define the version number here. Update this as the last file before a release.
#define PROGRAM_VERSION 1.2 .0 #define PROGRAM_VERSION 1.2.0
#define PROGRAM_VERSION_STRING "1.2.0" #define PROGRAM_VERSION_STRING "1.2.0"
#define RESOURCE_VERSION 1, 2, 0, 0 #define RESOURCE_VERSION 1, 2, 0, 0
#define RESOURCE_VERSION_STRING "1,2,0,0\0" #define RESOURCE_VERSION_STRING "1,2,0,0\0"
@ -35,4 +35,4 @@ namespace UiGuiVersion
TQString getBuildRevision(); TQString getBuildRevision();
} }
#endif // UIGUIVERSION_H #endif

@ -23,20 +23,23 @@
// -- #include "debugging/TSLogger.h" // -- #include "debugging/TSLogger.h"
// -- #include "UiGuiIniFileParser.h" // -- #include "UiGuiIniFileParser.h"
// -- #include "UiGuiSettings.h" // -- #include "UiGuiSettings.h"
// -- #include "UiGuiVersion.h"
// -- #include "UiGuiSystemInfo.h" // -- #include "UiGuiSystemInfo.h"
// -- #include "IndentHandler.h" // -- #include "IndentHandler.h"
// -- #include "SettingsPaths.h" // -- #include "SettingsPaths.h"
// -- // --
// -- #include <tntqapplication.h> // -- #include <tqapplication.h>
// -- #include <tntqtextcodec.h> // -- #include <tqtextcodec.h>
// -- #include <tqdebug.h> // -- #include <tqdebug.h>
// -- #include <string> // -- #include <string>
// -- #include <iostream>
// -- #include <algorithm> // -- #include <algorithm>
// -- #include <tclap/CmdLine.h>
#include "UiGuiVersion.h"
#include <tqstring.h>
#include <iostream>
#include <tclap/CmdLine.h>
// -- using namespace tschweitzer::debugging; // -- using namespace tschweitzer::debugging;
@ -47,134 +50,140 @@
No parameters starts without server and full gui. No parameters starts without server and full gui.
A string without any parameter prefix will be loaded as file on start. A string without any parameter prefix will be loaded as file on start.
-p --plugin : Run as plugin. Server will be started with a simplified gui. -p --plugin : Run as plugin. Server will be started with a simplified gui.
-s --server : Run as server only without gui. -s --server : Run as server only, without gui.
If -p and -s are set, -p will be used. If -p and -s are set, -p will be used.
-v --verbose needs a following parameter defining the verbose level as a number from 0 to 3. -v --verbose needs a following parameter defining the verbose level as a number from 0 to 3.
*/ */
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
TQString file2OpenOnStart = "";
int verboseLevel = 1;
bool startAsPlugin = false;
bool startAsServer = false;
bool tclapExitExceptionThrown = false;
int returnValue = 0;
return 0; return 0;
// -- TQString file2OpenOnStart = ""; // Wrap everything in a try block. Do this every time,
// -- int verboseLevel = 1; // because exceptions will be thrown for problems.
// -- bool startAsPlugin = false; try
// -- bool startAsServer = false; {
// -- bool tclapExitExceptionThrown = false; // Define the command line object.
// -- int returnValue = 0; TCLAP::CmdLine cmd("If -p and -s are set, -p will be used.\n"
// -- "Giving no parameters starts full gui without server.", ' ',
// -- // Wrap everything in a try block. Do this every time, "UiGUI version " PROGRAM_VERSION_STRING " " PROGRAM_REVISION);
// -- // because exceptions will be thrown for problems. cmd.setExceptionHandling(false);
// -- try {
// -- // Define the command line object. // Define a value argument and add it to the command line.
// -- TCLAP::CmdLine cmd("If -p and -s are set, -p will be used.\nGiving no parameters starts TCLAP::UnlabeledValueArg<std::string> filenameArg("file",
// full gui without server.", ' ', "UiGUI version " PROGRAM_VERSION_STRING " " PROGRAM_REVISION); "Opens the by filename defined file on start" , false, "", "filename");
// -- cmd.setExceptionHandling(false); cmd.add(filenameArg);
// --
// -- // Define a value argument and add it to the command line. // Define a switch and add it to the command line.
// -- TCLAP::UnlabeledValueArg<std::string> filenameArg("file", "Opens the by TCLAP::SwitchArg pluginSwitch("p", "plugin",
// filename defined file on start" , false, "", "filename"); "Run as plugin. Server will be started with a simplified gui", false);
// -- cmd.add( filenameArg ); cmd.add(pluginSwitch);
// --
// -- // Define a switch and add it to the command line. // Define a switch and add it to the command line.
// -- TCLAP::SwitchArg pluginSwitch("p", "plugin", "Run as plugin. Server will be started with TCLAP::SwitchArg serverSwitch("s", "server",
// a simplified gui", false); "Run as server only without gui", false);
// -- cmd.add( pluginSwitch ); cmd.add(serverSwitch);
// --
// -- // Define a switch and add it to the command line. // Define a value argument and add it to the command line.
// -- TCLAP::SwitchArg serverSwitch("s", "server", "Run as server only without gui", false); TCLAP::ValueArg<int> verboselevelArg("v", "verbose",
// -- cmd.add( serverSwitch ); "Sets how many info is written to the log. 0 means with debug info, "
// -- "3 means critical messages only" , false, 1, "int");
// -- // Define a value argument and add it to the command line. cmd.add(verboselevelArg);
// -- TCLAP::ValueArg<int> verboselevelArg("v", "verbose", "Sets how many info is written to
// the log. 0 means with debug info, 3 means critical messages only" , false, 1, "int"); // Parse the args.
// -- cmd.add( verboselevelArg ); cmd.parse(argc, argv);
// --
// -- // Parse the args. // Get the value parsed by each arg.
// -- cmd.parse( argc, argv ); file2OpenOnStart = filenameArg.getValue().c_str();
// -- startAsPlugin = pluginSwitch.getValue();
// -- // Get the value parsed by each arg. startAsServer = serverSwitch.getValue();
// -- file2OpenOnStart = filenameArg.getValue().c_str(); verboseLevel = verboselevelArg.getValue();
// -- startAsPlugin = pluginSwitch.getValue(); }
// -- startAsServer = serverSwitch.getValue(); catch (TCLAP::ArgException &e)
// -- verboseLevel = verboselevelArg.getValue(); {
// -- } // catch arg exceptions
// -- catch (TCLAP::ArgException &e) { // catch arg exceptions std::cerr << std::endl << "error: " << e.error() << ". " << e.argId() << std::endl;
// -- std::cerr << std::endl << "error: " << e.error() << ". " << e.argId() << std::endl; returnValue = 1;
// -- returnValue = 1; }
// -- } catch (TCLAP::ExitException &e)
// -- catch (TCLAP::ExitException &e) { // catch exit exceptions {
// -- tclapExitExceptionThrown = true; // catch exit exceptions
// -- returnValue = e.getExitStatus(); tclapExitExceptionThrown = true;
// -- } returnValue = e.getExitStatus();
// -- catch (...) { // catch any exceptions }
// -- std::cerr << std::endl << "There was an error! Maybe faulty command line arguments set. catch (...)
// See --help." << std::endl; {
// -- returnValue = 1; // catch any exceptions
// -- } std::cerr << std::endl << "There was an error! Maybe faulty "
// -- "command line arguments set. See --help." << std::endl;
// -- if ( returnValue != 0 || tclapExitExceptionThrown ) { returnValue = 1;
// -- return returnValue; }
// -- }
// -- if (returnValue != 0 || tclapExitExceptionThrown)
// -- TQApplication app(argc, argv); {
// -- UiGuiIndentServer server; return returnValue;
// -- MainWindow *mainWindow = NULL; }
// -- IndentHandler *indentHandler = NULL;
// -- // -- TQApplication app(argc, argv);
// -- // Init and install the logger function. // -- UiGuiIndentServer server;
// -- // Setting UTF-8 as default 8-Bit encoding to ensure that tqDebug does no false string // -- MainWindow *mainWindow = NULL;
// conversion. // -- IndentHandler *indentHandler = NULL;
// -- TQTextCodec::setCodecForCStrings( TQTextCodec::codecForName("UTF-8") ); // --
// -- TQTextCodec::setCodecForLocale( TQTextCodec::codecForName("UTF-8") ); // -- // Init and install the logger function.
// -- // Force creation of an TSLogger instance here, to avoid recursion with SettingsPaths // -- // Setting UTF-8 as default 8-Bit encoding to ensure that tqDebug does no false string conversion.
// init function. // -- TQTextCodec::setCodecForCStrings(TQTextCodec::codecForName("UTF-8"));
// -- #ifdef _DEBUG // -- TQTextCodec::setCodecForLocale(TQTextCodec::codecForName("UTF-8"));
// -- TSLogger::getInstance(0); // -- // Force creation of an TSLogger instance here, to avoid recursion with SettingsPaths init function.
// -- #else // -- #ifdef _DEBUG
// -- TSLogger::getInstance(verboseLevel); // -- TSLogger::getInstance(0);
// -- #endif // -- #else
// -- qInstallMsgHandler( TSLogger::messageHandler ); // -- TSLogger::getInstance(verboseLevel);
// -- TSLogger::messageHandler( TSLoggerInfoMsg, TQString("Starting UiGUI Version %1 // -- #endif
// %2").arg(PROGRAM_VERSION_STRING).arg(PROGRAM_REVISION).toAscii() ); // -- qInstallMsgHandler(TSLogger::messageHandler);
// -- TSLogger::messageHandler( TSLoggerInfoMsg, TQString("Running on // -- TSLogger::messageHandler(TSLoggerInfoMsg, TQString("Starting UiGUI Version %1 %2").arg(PROGRAM_VERSION_STRING).arg(PROGRAM_REVISION).toAscii());
// %1").arg(UiGuiSystemInfo::getOperatingSystem()).toAscii() ); // -- TSLogger::messageHandler(TSLoggerInfoMsg, TQString("Running on %1").arg(UiGuiSystemInfo::getOperatingSystem()).toAscii());
// -- // --
// -- // Set default values for all by UniversalIndentGUI used settings objects. // -- // Set default values for all by UniversalIndentGUI used settings objects.
// -- TQCoreApplication::setOrganizationName("UniversalIndentGUI"); // -- TQCoreApplication::setOrganizationName("UniversalIndentGUI");
// -- TQCoreApplication::setOrganizationDomain("universalindent.sf.net"); // -- TQCoreApplication::setOrganizationDomain("universalindent.sf.net");
// -- TQCoreApplication::setApplicationName("UniversalIndentGUI"); // -- TQCoreApplication::setApplicationName("UniversalIndentGUI");
// -- // --
// -- // Start normal with full gui and without server. // -- // Start normal with full gui and without server.
// -- if ( !startAsPlugin && !startAsServer ) { // -- if (!startAsPlugin && !startAsServer) {
// -- mainWindow = new MainWindow(file2OpenOnStart); // -- mainWindow = new MainWindow(file2OpenOnStart);
// -- mainWindow->show(); // -- mainWindow->show();
// -- } // -- }
// -- // Start as plugin with server. // -- // Start as plugin with server.
// -- else if ( startAsPlugin ) { // -- else if (startAsPlugin) {
// -- server.startServer(); // -- server.startServer();
// -- indentHandler = new IndentHandler(0); // -- indentHandler = new IndentHandler(0);
// -- indentHandler->show(); // -- indentHandler->show();
// -- } // -- }
// -- // Start as server only without any gui. // -- // Start as server only without any gui.
// -- else if ( startAsServer ) { // -- else if (startAsServer) {
// -- server.startServer(); // -- server.startServer();
// -- } // -- }
// -- // --
// -- try { // -- try {
// -- returnValue = app.exec(); // -- returnValue = app.exec();
// -- } // -- }
// -- catch (std::exception &ex) { // -- catch (std::exception &ex) {
// -- qCritical() << __LINE__ << " " << __FUNCTION__ << ": Something went terribly wrong:" // -- qCritical() << __LINE__ << " " << __FUNCTION__ << ": Something went terribly wrong:" << ex.what();
// << ex.what(); // -- }
// -- } // --
// -- // -- if (startAsPlugin || startAsServer)
// -- if ( startAsPlugin || startAsServer ) // -- server.stopServer();
// -- server.stopServer(); // --
// -- // -- delete indentHandler;
// -- delete indentHandler; // -- delete mainWindow;
// -- delete mainWindow; // --
// -- // -- SettingsPaths::cleanAndRemoveTempDir();
// -- SettingsPaths::cleanAndRemoveTempDir(); // -- TSLogger::deleteInstance();
// -- TSLogger::deleteInstance();
// -- return returnValue;
// -- return returnValue;
} }

Loading…
Cancel
Save