-
Notifications
You must be signed in to change notification settings - Fork 1
/
tarsnappathpage.cpp
97 lines (76 loc) · 2.4 KB
/
tarsnappathpage.cpp
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
// Copyright Arnt Gulbrandsen, [email protected].
#include "tarsnappathpage.h"
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QFileDialog>
#include <QFile>
#include <QDir>
#include <QTextStream>
#include <QDateTime>
#include <QMessageBox>
#include <QLabel>
#include <QProcess>
/*! \class TarsnapPathPage tarsnappathpage.h
The TarsnapPathPage class encompasses this program's knowledge of
one thing: Where tarsnap itself is to be found. With any luck, no
user will ever see this.
*/
/*! Constructs a wizard page to ask where the tarsnap executable may
perchance be located. The default should be good, but...
*/
TarsnapPathPage::TarsnapPathPage( BackupWizard * parent )
: QWizardPage( parent ),
tarsnapPath( new QLineEdit( this ) )
{
setDefaultPath();
registerField( "tarsnapPath", tarsnapPath );
QGridLayout * l = new QGridLayout( this );
QLabel * first = new QLabel(
tr( "<html>"
"This UI works by executing tarsnap and perhaps tarsnap-keygen, "
"so it needs to know where those programs are.</html>" ),
this );
first->setWordWrap( true );
l->addWidget( first,
0, 0, 1, 3 );
l->addWidget( new QLabel( tr( "Directory" ), this ),
1, 0, 1, 1, Qt::AlignLeft );
l->addWidget( tarsnapPath,
1, 1, 1, 1 );
}
/*! This private helper sets the path to tarsnap based on $PATH, or
does nothing if tarsnap cannot be found. isComplete() will ensure
that the user helps us if not, and isComplete() together with
BackupWizard will ensure that this entire wizard page generalyl
isn't shown.
*/
void TarsnapPathPage::setDefaultPath()
{
QStringList path = QString::fromUtf8( ::getenv( "PATH" ) )
.split( ':', QString::SkipEmptyParts );
auto dir = path.begin();
while ( dir != path.end() ) {
QFile candidate( *dir + "/tarsnap" );
if ( candidate.exists() ) {
tarsnapPath->setText( *dir );
return;
}
++dir;
}
}
/*! Returns true if we can proceed. Strictly speaking we could even
without, in some rare circumstances, but that's too odd. Best to
demand that we can find tarsnap. Simplicity is a feature.
*/
bool TarsnapPathPage::isComplete() const
{
QString path = tarsnapPath->text();
if ( path.isEmpty() )
return false;
if ( !path.endsWith( "/" ) )
path.append( "/" );
path.append( "tarsnap" );
QFile candidate( path );
return candidate.exists();
}