File: main.cpp

package info (click to toggle)
kup-backup 0.7.1+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,480 kB
  • sloc: cpp: 7,263; sh: 51; makefile: 6
file content (110 lines) | stat: -rw-r--r-- 4,914 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
/***************************************************************************
 *   Copyright Simon Persson                                               *
 *   simonpersson1@gmail.com                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "filedigger.h"
#include "mergedvfs.h"

#if LIBGIT2_VER_MAJOR == 0 && LIBGIT2_VER_MINOR >= 24
#include <git2/global.h>
#else
#include <git2/threads.h>
#endif

#include <KAboutData>
#include <KLocalizedString>
#include <KMessageBox>

#include <QApplication>
#include <QDebug>
#include <QCommandLineOption>
#include <QCommandLineParser>
#include <QFile>
#include <QTextStream>

int main(int pArgCount, char **pArgArray) {
	QApplication lApp(pArgCount, pArgArray);
	lApp.setAttribute(Qt::AA_UseHighDpiPixmaps, true);

	KLocalizedString::setApplicationDomain("kup");

	KAboutData lAbout(QStringLiteral("kupfiledigger"), xi18nc("@title", "File Digger"), QStringLiteral("0.7.1"),
	                  i18n("Browser for bup archives."),
	                  KAboutLicense::GPL, i18n("Copyright (C) 2013-2015 Simon Persson"),
	                  QString(), QString(), "simonpersson1@gmail.com");
	lAbout.addAuthor(i18n("Simon Persson"), QString(), "simonpersson1@gmail.com");
	lAbout.setTranslator(xi18nc("NAME OF TRANSLATORS", "Your names"), xi18nc("EMAIL OF TRANSLATORS", "Your emails"));
	KAboutData::setApplicationData(lAbout); //this calls qApp.setApplicationName, setVersion, etc.

	QCommandLineParser lParser;
	lParser.addVersionOption();
	lParser.addHelpOption();
	lParser.addOption(QCommandLineOption(QStringList() << QStringLiteral("b") << QStringLiteral("branch"),
	                                     i18n("Name of the branch to be opened."),
	                                     QStringLiteral("branch name"), QStringLiteral("kup")));
	lParser.addPositionalArgument(QStringLiteral("<repository path>"), i18n("Path to the bup repository to be opened."));

	lAbout.setupCommandLine(&lParser);
	lParser.process(lApp);
	lAbout.processCommandLine(&lParser);

	if(lParser.positionalArguments().count() != 1) {
		// this very convoluted call is just to stop Qt from adding quotation marks around the text output
		qCritical("%s", i18nc("@info:shell Error message at startup",
		                     "You must supply the path to a bup or git repository that "
		                     "you wish to open for viewing.").toLocal8Bit().constData());
		return -1;
	}

	// This needs to be called first thing, before any other calls to libgit2.
	#if LIBGIT2_VER_MAJOR == 0 && LIBGIT2_VER_MINOR >= 24
	git_libgit2_init();
	#else
	git_threads_init();
	#endif
	MergedRepository *lRepository = new MergedRepository(NULL, lParser.positionalArguments().first(),
	                                                     lParser.value("branch"));
	if(!lRepository->open()) {
		KMessageBox::sorry(NULL, xi18nc("@info messagebox, %1 is a folder path",
		                               "The backup archive <filename>%1</filename> could not be opened. Check if the backups really are located there.",
		                               lParser.positionalArguments().first()));
		return 1;
	}
	if(!lRepository->readBranch()) {
		if(!lRepository->permissionsOk()) {
			KMessageBox::sorry(NULL, xi18nc("@info messagebox",
			                               "You do not have permission needed to read this backup archive."));
			return 2;
		} else {
			lRepository->askForIntegrityCheck();
			return 3;
		}
	}

	FileDigger *lFileDigger = new FileDigger(lRepository);
	lFileDigger->show();
	int lRetVal = lApp.exec();
	delete lRepository;
	#if LIBGIT2_VER_MAJOR == 0 && LIBGIT2_VER_MINOR >= 24
	git_libgit2_shutdown();
	#else
	git_threads_shutdown();
	#endif
	return lRetVal;
}