-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpref_page2.cpp
163 lines (147 loc) · 5.14 KB
/
pref_page2.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*****************************************************************************
* ____ ____ _ _ _ *
* /# /_\_ | _ \ (_) __| | (_) ___ _ __ *
* | |/o\o\ | | | | | | / _` | | | / _ \ | '__| *
* | \\_/_/ | |_| | | | | (_| | | | | __/ | | *
* / |_ | |____/ |_| \__,_| |_| \___| |_| *
* | ||\_ ~| *
* | ||| \/ *
* | ||| Project : KFreeFlight : a KDE4 GUI frontend for FlightGear *
* \// | *
* || | Developper : Didier FABERT <[email protected]> *
* ||_ \ Date : 2009, April *
* \_| o| ,__, *
* \___/ Copyright (C) 2009 by didier fabert (oo)____ *
* ||||__ (__) )\ *
* (___)_) File : pref_page2.cpp ||--|| * *
* *
* 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. *
*****************************************************************************/
#include "pref_page2.h"
#include "settings.h"
#include "config.h"
#include <kmessagebox.h>
#include <kfiledialog.h>
#include <keditlistbox.h>
#include <QDebug>
#include <QDir>
KFFPref_page2::KFFPref_page2 ( QWidget *parent )
: QFrame ( parent )
{
ui_prefs2_base.setupUi ( this );
connect ( ui_prefs2_base.btn_rootSearch,
SIGNAL ( clicked() ),
SLOT ( chooseRootSlot() )
);
connect ( ui_prefs2_base.btn_dataSearch,
SIGNAL ( clicked() ),
SLOT ( chooseScenerySlot() )
);
connect ( ui_prefs2_base.btn_exeSearch,
SIGNAL ( clicked() ),
SLOT ( chooseExeSlot() )
);
}
KFFPref_page2::~KFFPref_page2()
{
}
void KFFPref_page2::chooseRootSlot()
{
QString buffer;
KUrl url = KUrl::fromPath ( Settings::fg_root() );
buffer = KFileDialog::getExistingDirectory ( url, this );
if ( !buffer.isEmpty() )
{
ui_prefs2_base.kcfg_fg_root->setText ( buffer );
}
}
void KFFPref_page2::chooseScenerySlot()
{
QStringList dirlist;
QStringList::Iterator it;
QString buffer = FG_SCENERY, dirname;
KUrl url;
QDir dir;
bool found = false;
if ( buffer.isEmpty() )
{
url = KUrl::fromPath ( Settings::fg_root() );
}
else
{
buffer = FG_SCENERY;
url = KUrl::fromPath ( buffer.section(',', 0, 0 ) );
}
//TODO Auto fill if selected directory contains more than one scenery dir
dirname = KFileDialog::getExistingDirectory ( url, this );
qDebug() << dirname;
if ( !dirname.isEmpty() )
{
dir.cd( dirname );
dirlist = dir.entryList( QDir::Dirs, QDir::Name );
for( it = dirlist.begin() ; it != dirlist.end() ; ++it )
{
qDebug() << *it;
if ( ( *it == "." ) || ( *it == ".." ) || ( it->toUpper() == "CVS" ) ) continue;
if ( isValid ( *it ) )
{
ui_prefs2_base.kcfg_fg_addon_sceneries->insertItem ( dirname + "/" + *it );
found = true;
}
}
if ( !found && isValid( dirname ) )
{
ui_prefs2_base.kcfg_fg_addon_sceneries->insertItem ( dirname + "/" + buffer );
}
}
}
bool KFFPref_page2::isValid( QString& dirname )
{
QString bufdirname, buffer;
bool valid = true;
bufdirname = dirname.toUpper();
buffer = bufdirname.left( 1 );
qDebug() << "buffer = " << buffer;
if ( ( buffer != "E" ) && ( buffer != "W" ) )
{
qDebug() << "first letter seem not good : " << buffer;
valid = false;
}
buffer = bufdirname.mid( 1, 3 );
if ( ( buffer != "000" ) && ( buffer.toUShort() == 0 ) )
{
qDebug() << "first number seem not good : " << buffer;
valid = false;
}
buffer = bufdirname.mid( 4, 1 );
if ( ( buffer.toUpper() != "N" ) && ( buffer.toUpper() != "S" ) )
{
qDebug() << "second letter seem not good : " << buffer;
valid = false;
}
buffer = bufdirname.mid( 5, 3 );
if ( ( buffer != "000" ) && ( buffer.toUShort() == 0 ) )
{
qDebug() << "second number seem not good : " << buffer;
valid = false;
}
return valid;
}
void KFFPref_page2::chooseExeSlot()
{
QString buffer;
KUrl url = KUrl::fromPath ( QDir::homePath() );
buffer = KFileDialog::getSaveFileName ( url, QString(), this );
if ( !buffer.isEmpty() )
{
ui_prefs2_base.kcfg_fg_exe->insertItem ( buffer );
}
}