[go: up one dir, main page]

File: qgit.cpp

package info (click to toggle)
qgit 2.12-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,364 kB
  • sloc: cpp: 13,251; xml: 47; sh: 25; javascript: 16; makefile: 3
file content (118 lines) | stat: -rw-r--r-- 3,264 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
	Author: Marco Costalba (C) 2005-2007
	Author: Sebastian Pipping (C) 2021

	Copyright: See COPYING file that comes with this distribution

*/

#include <QSettings>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
	#include <QCommandLineParser>
#else
	#include <QApplication>
	#include <QCoreApplication>
	#include <QStringList>
	#include <iostream>
#endif
#include "config.h" // defines PACKAGE_VERSION
#include "common.h"
#include "mainimpl.h"

#if defined(_MSC_VER) && defined(NDEBUG)
	#pragma comment(linker,"/entry:mainCRTStartup")
	#pragma comment(linker,"/subsystem:windows")
#endif

using namespace QGit;

int main(int argc, char* argv[]) {

	QApplication app(argc, argv);
#if QT_VERSION_CHECK(5, 6, 0) <= QT_VERSION && QT_VERSION < QT_VERSION_CHECK(6,0,0)
	app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
#endif
	QCoreApplication::setOrganizationName(ORG_KEY);
	QCoreApplication::setApplicationName(APP_KEY);

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
	QCommandLineParser parser;
	QCoreApplication::setApplicationVersion(PACKAGE_VERSION);
	parser.addHelpOption();
	parser.addVersionOption();
	parser.setApplicationDescription("QGit, a Git GUI viewer");
	parser.addPositionalArgument("git-log-args",
		"Arguments forwarded to \"git log\"; for example:\n"
		"   qgit --no-merges\n"
		"   qgit v2.6.18.. include/scsi \\\n"
		"                  drivers/scsi\n"
		"   qgit --since=\"2 weeks ago\" -- kernel/\n"
		"   qgit -r --name-status release..test\n"
		"See \"man git-log\" for details.",
		"[git-log-args]");

	parser.parse(app.arguments());

	if (parser.isSet("help")
			|| parser.isSet("help-all")
			|| parser.isSet("version")) {
		QCoreApplication::setApplicationName("QGit");
		parser.process(app.arguments());  // exits the process
	}
#else
	QStringList arguments = QCoreApplication::arguments();
	bool showHelp = false;
	bool showVersion = false;
	QStringList gitLogArgs;

	for (int i = 1; i < arguments.size(); ++i) {
		QString arg = arguments.at(i);
		if (arg == "--help" || arg == "-h") {
			showHelp = true;
		} else if (arg == "--version" || arg == "-v") {
			showVersion = true;
		} else {
			gitLogArgs.append(arg); // Collect positional arguments
		}
	}

	if (showHelp) {
		std::cout << "Usage: qgit [options] [git-log-args]\n"
			<< "Options:\n"
			<< "  --help, -h          Show this help message\n"
			<< "  --version, -v       Show application version\n"
			<< "\n"
			<< "Arguments:\n"
			<< "  git-log-args        Arguments forwarded to \"git log\"\n"
			<< "                      See \"man git-log\" for details.\n";
		return 0; // Exit after showing help
	}

	if (showVersion) {
		std::cout << "QGit version: " << PACKAGE_VERSION << "\n";
		return 0; // Exit after showing version
	}

	// Process git-log-args as needed
	foreach (const QString& arg, gitLogArgs) {
		std::cout << "Git log argument: " << arg.toStdString() << "\n";
	}
#endif

	/* On Windows msysgit exec directory is set up
	 * during installation so to always find git.exe
	 * also if not in PATH
	 */
	QSettings set;
	GIT_DIR = set.value(GIT_DIR_KEY).toString();

	initMimePix();

	MainImpl* mainWin = new MainImpl;
	mainWin->show();
	QObject::connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
	bool ret = app.exec();

	freeMimePix();
	return ret;
}