27
37
bool sEditDBInfoDialog::Modify (psDB_Info info)
29
sEditDBInfoDialog * D = new sEditDBInfoDialog(info);
39
sEditDBInfoDialog * D = new sEditDBInfoDialog(info
40
,tr("Select database"));
30
41
D->setAttribute(Qt::WA_DeleteOnClose);
31
42
return D->exec() == QDialog::Accepted;
35
46
sEditDBInfoDialog::sEditDBInfoDialog (psDB_Info info
40
setWindowTitle(tr("Select database"));
52
setWindowTitle(title);
42
Layout = new QVBoxLayout();
45
FLayout = new QFormLayout();
46
// FLayout->setLabelAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
47
Layout->addLayout(FLayout);
49
FLayout->setWidget(20,QFormLayout::LabelRole,new QLabel(tr("Type")));
54
setLayout(new QVBoxLayout());
56
URLLabel = new QLabel(tr("URL: "),this);
57
URLField = new QLabel(this);
50
59
TypeField = new QComboBox(this);
51
FLayout->setWidget(20,QFormLayout::FieldRole,TypeField);
53
61
HostLabel = new QLabel(tr("Host"),this);
54
FLayout->setWidget(21,QFormLayout::LabelRole,HostLabel);
55
62
HostField = new QLineEdit(this);
56
FLayout->setWidget(21,QFormLayout::FieldRole,HostField);
58
64
PortLabel = new QLabel(tr("Port"),this);
59
FLayout->setWidget(22,QFormLayout::LabelRole,PortLabel);
60
65
PortField = new QSpinBox(this);
61
FLayout->setWidget(22,QFormLayout::FieldRole,PortField);
63
NameLabel = new QLabel(tr("Name"),this);
64
FLayout->setWidget(23,QFormLayout::LabelRole,NameLabel);
65
NameField = new QLineEdit(this);
66
FLayout->setWidget(23,QFormLayout::FieldRole,NameField);
68
FLayout->setWidget(24,QFormLayout::LabelRole,new QLabel(tr("Login")));
66
PortField->setRange(-1,0xffff);
67
PortField->setSpecialValueText(tr("auto"));
69
LoginLabel = new QLabel(tr("Login"),this);
69
70
LoginField = new QLineEdit(this);
70
FLayout->setWidget(24,QFormLayout::FieldRole,LoginField);
72
FLayout->setWidget(25,QFormLayout::LabelRole,new QLabel(tr("Password")));
72
PasswordLabel = new QLabel(tr("Password"),this);
73
73
PasswordField = new QLineEdit(this);
74
PasswordField->setEchoMode(QLineEdit::PasswordEchoOnEdit);
75
FLayout->setWidget(25,QFormLayout::FieldRole,PasswordField);
74
PasswordField->setEchoMode(QLineEdit::Password);
76
ShowPasswordButton = new QToolButton(this);
77
ShowPasswordButton->setIcon(QIcon(":/RAGUI/icons/eye.png"));
79
DBNameLabel = new QLabel("",this);
80
DBNameField = new QLineEdit(this);
81
BrowseButton = new QPushButton(tr("Browse"),this);
82
RelativeCheckBox = new QCheckBox(tr("relative to the current folder:"),this);
83
CurrentDirField = new QLabel(QDir::currentPath(),this);
84
DBNameValidator = new QRegExpValidator(DBNameRegExpr,this);
86
SchemaLabel = new QLabel(tr("Schema name"),this);
87
SchemaField = new QLineEdit(this);
89
PrefixLabel = new QLabel(tr("Table naming prefix"),this);
90
PrefixField = new QLineEdit(this);
92
OptionsLabel = new QLabel(tr("Connection options"),this);
93
OptionsField = new QLineEdit(this);
77
95
QDialogButtonBox * ButtonBox = new QDialogButtonBox(this);
78
96
ButtonBox->setOrientation(Qt::Horizontal);
79
97
ButtonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
80
// ButtonBox->setStandardButtons(QDialogButtonBox::Cancel
81
// |QDialogButtonBox::Ok
82
// |QDialogButtonBox::Help);
83
Layout->addWidget(ButtonBox);
85
// QStringList drivers = QSqlDatabase::drivers();
86
// // remove compat names
87
// drivers.removeAll("QMYSQL3");
88
// drivers.removeAll("QOCI8");
89
// drivers.removeAll("QODBC3");
90
// drivers.removeAll("QPSQL7");
91
// drivers.removeAll("QTDS7");
92
// TypeField->addItems(drivers);
102
(L = new QHBoxLayout())->setAlignment(Qt::AlignLeft);
103
((QVBoxLayout*)layout())->addItem(L);
104
L->addWidget(URLLabel);
105
L->addWidget(URLField);
107
(L = new QHBoxLayout())->setAlignment(Qt::AlignLeft);
108
((QVBoxLayout*)layout())->addItem(L);
109
L->addWidget(new QLabel(tr("Type"),this));
110
L->addWidget(TypeField);
112
(L = new QHBoxLayout())->setAlignment(Qt::AlignLeft);
113
((QVBoxLayout*)layout())->addItem(L);
114
L->addWidget(HostLabel);
115
L->addWidget(HostField);
116
L->addWidget(PortLabel);
117
L->addWidget(PortField);
119
(L = new QHBoxLayout())->setAlignment(Qt::AlignLeft);
120
((QVBoxLayout*)layout())->addItem(L);
121
L->addWidget(LoginLabel);
122
L->addWidget(LoginField);
123
L->addWidget(PasswordLabel);
124
L->addWidget(PasswordField);
125
L->addWidget(ShowPasswordButton);
127
(L = new QHBoxLayout())->setAlignment(Qt::AlignLeft);
128
((QVBoxLayout*)layout())->addItem(L);
129
L->addWidget(DBNameLabel);
130
L->addWidget(DBNameField);
131
L->addWidget(BrowseButton);
133
(L = new QHBoxLayout())->setAlignment(Qt::AlignLeft);
134
((QVBoxLayout*)layout())->addItem(L);
135
L->addWidget(RelativeCheckBox);
137
(L = new QHBoxLayout())->setAlignment(Qt::AlignLeft);
138
((QVBoxLayout*)layout())->addItem(L);
139
L->addWidget(CurrentDirField);
141
(L = new QHBoxLayout())->setAlignment(Qt::AlignLeft);
142
((QVBoxLayout*)layout())->addItem(L);
143
L->addWidget(SchemaLabel);
144
L->addWidget(SchemaField);
145
L->addWidget(PrefixLabel);
146
L->addWidget(PrefixField);
148
layout()->addWidget(OptionsLabel);
149
layout()->addWidget(OptionsField);
151
((QVBoxLayout*)layout())->addStretch(1);
152
layout()->addWidget(ButtonBox);
155
PrefixField->setValidator(new QRegExpValidator(PrefixRegExpr));
156
SchemaField->setValidator(new QRegExpValidator(SchemaRegExpr));
94
158
TypeField->addItem(ToQString( sDB_Info::TypeName[sDB_Info::cSQLite] ));
95
159
TypeField->addItem(ToQString( sDB_Info::TypeName[sDB_Info::cMySQL ] ));
97
NameField->setText(ToQString( Info->Name ));
98
HostField->setText(ToQString( Info->Host ));
99
PortField->setValue(Info->Port);
100
LoginField->setText(ToQString( Info->Login ));
101
PasswordField->setText(ToQString( Info->Password ));
160
TypeField->addItem(ToQString( sDB_Info::TypeName[sDB_Info::cPostgreSQL ] ));
161
TypeField->setCurrentIndex( Info->Type );
162
RelativeCheckBox->setChecked(true);
103
164
OnTypeChanged(TypeField->currentIndex());
105
166
connect(TypeField ,SIGNAL(currentIndexChanged(int))
106
167
,this ,SLOT(OnTypeChanged(int)));
168
connect(RelativeCheckBox ,SIGNAL(clicked())
169
,this ,SLOT(OnRelativeCheckBoxChange()));
170
connect(BrowseButton ,SIGNAL(clicked())
171
,this ,SLOT(Browse()));
172
connect(HostField ,SIGNAL(textChanged(QString))
173
,this ,SLOT(ShowURL()));
174
connect(PortField ,SIGNAL(valueChanged(int))
175
,this ,SLOT(ShowURL()));
176
connect(LoginField ,SIGNAL(textChanged(QString))
177
,this ,SLOT(ShowURL()));
178
connect(PasswordField ,SIGNAL(textChanged(QString))
179
,this ,SLOT(ShowURL()));
180
connect(ShowPasswordButton ,SIGNAL(pressed())
181
,this ,SLOT(ShowPassword()) );
182
connect(ShowPasswordButton ,SIGNAL(released())
183
,this ,SLOT(MaskPassword()) );
184
connect(DBNameField ,SIGNAL(textChanged(QString))
185
,this ,SLOT(ShowURL()));
186
connect(SchemaField ,SIGNAL(textChanged(QString))
187
,this ,SLOT(ShowURL()));
188
connect(PrefixField ,SIGNAL(textChanged(QString))
189
,this ,SLOT(ShowURL()));
190
connect(OptionsField ,SIGNAL(textChanged(QString))
191
,this ,SLOT(ShowURL()));
107
192
connect(ButtonBox ,SIGNAL(accepted()) ,this ,SLOT(OnOK()));
108
193
connect(ButtonBox ,SIGNAL(rejected()) ,this ,SLOT(reject()));
109
194
// connect(ButtonBox,SIGNAL(helpRequested()),this,SLOT(ShowHelp()));
119
204
void sEditDBInfoDialog::OnTypeChanged (int type)
121
207
switch( sDB_Info::eType(type) ){
122
208
case sDB_Info::cSQLite:
209
HostLabel->setVisible( false );
123
210
HostField->setVisible( false );
211
PortLabel->setVisible( false );
124
212
PortField->setVisible( false );
125
NameLabel->setText(tr("File name"));
213
LoginLabel->setVisible( false );
214
LoginField->setVisible( false );
215
PasswordLabel->setVisible( false );
216
PasswordField->setVisible( false );
217
ShowPasswordButton->setVisible( false );
218
RelativeCheckBox->setVisible( true );
219
CurrentDirField->setVisible( true );
220
DBNameLabel->setText(tr("SQLite file"));
221
DBNameField->setValidator(NULL);
222
BrowseButton->setVisible( true );
223
SchemaLabel->setVisible( false );
224
SchemaField->setVisible( false );
127
case sDB_Info::cMySQL:
227
HostLabel->setVisible( true );
128
228
HostField->setVisible( true );
229
PortLabel->setVisible( true );
129
230
PortField->setVisible( true );
130
NameLabel->setText(tr("Database name"));
231
LoginLabel->setVisible( true );
232
LoginField->setVisible( true );
233
PasswordLabel->setVisible( true );
234
PasswordField->setVisible( true );
235
ShowPasswordButton->setVisible( true );
236
RelativeCheckBox->setVisible( false );
237
CurrentDirField->setVisible( false );
238
DBNameLabel->setText(tr("Database name"));
239
DBNameField->setValidator(DBNameValidator);
240
BrowseButton->setVisible( false );
241
SchemaLabel->setVisible( true );
242
SchemaField->setVisible( true );
133
HostLabel->setVisible( HostField->isVisible() );
134
PortLabel->setVisible( PortLabel->isVisible() );
245
if( sDB_Info::eType(type) == Info->Type ){
246
HostField->setText(ToQString( Info->Host ));
247
PortField->setValue(Info->Port);
248
LoginField->setText(ToQString( Info->Login ));
249
PasswordField->setText(ToQString( Info->Password ));
250
DBNameField->setText(ToQString( Info->DBName ));
251
SchemaField->setText(ToQString( Info->SchemaName ));
252
PrefixField->setText(ToQString( Info->TableNamePrefix ));
253
OptionsField->setText(ToQString( Info->ConnectOptions ));
255
sDB_Info I( (sDB_Info::eType) type );
256
HostField->setText(ToQString( I.Host ));
257
PortField->setValue(I.Port);
258
LoginField->setText(ToQString( I.Login ));
259
PasswordField->setText(ToQString( I.Password ));
260
DBNameField->setText(ToQString( I.DBName ));
261
SchemaField->setText(ToQString( I.SchemaName ));
262
PrefixField->setText(ToQString( I.TableNamePrefix ));
263
OptionsField->setText(ToQString( I.ConnectOptions ));
269
void sEditDBInfoDialog::OnRelativeCheckBoxChange ()
271
if( RelativeCheckBox->isChecked() ){
272
DBNameField->setText( QDir::current().relativeFilePath(DBNameField->text()) );
274
DBNameField->setText( QFileInfo(DBNameField->text()).absoluteFilePath() );
279
void sEditDBInfoDialog::ShowURL ()
281
TempInfo.Type = sDB_Info::eType( TypeField->currentIndex() );
282
TempInfo.DBName = FromQString( DBNameField->text() );
283
TempInfo.SchemaName = FromQString( SchemaField->text() );
284
TempInfo.TableNamePrefix = FromQString( PrefixField->text() );
285
TempInfo.Host = FromQString( HostField->text() );
286
TempInfo.Port = PortField->value();
287
TempInfo.Login = FromQString( LoginField->text() );
288
TempInfo.Password = FromQString( PasswordField->text() );
289
TempInfo.ConnectOptions = FromQString( OptionsField->text() );
290
URLField->setText(ToQString(sString("<b>")+TempInfo.URL())+"</b>");
294
// TempInfo.SetByURL(TempInfo.URL());
295
// URLField->setText(URLField->text()
297
// +"<br/> type="+ToQString(sDB_Info::TypeName[TempInfo.Type])
298
// +"<br/> login="+ToQString(TempInfo.Login)
299
// +"<br/> password="+ToQString(TempInfo.Password)
300
// +"<br/> host="+ToQString(TempInfo.Host)
301
// +"<br/> port="+QString().setNum(TempInfo.Port)
302
// +"<br/> dbname="+ToQString(TempInfo.DBName)
303
// +"<br/> schema="+ToQString(TempInfo.SchemaName)
304
// +"<br/> prefix="+ToQString(TempInfo.TableNamePrefix)
305
// +"<br/> options="+ToQString(TempInfo.ConnectOptions)
312
void sEditDBInfoDialog::Browse ()
314
QString Name = DBNameField->text();
316
Name = QFileDialog::getOpenFileName(DBNameField
318
,QFileInfo(Name).path()
319
,"RANet sqlite files (*.RANet.sqlite);;All files (*)"
321
,QFileDialog::DontUseCustomDirectoryIcons
324
//!@todo{UI} There should be different dialog styles:
325
//! - when setting a link to related part
326
//! - as is, but the file must exist;
327
//! - when selecting a root part to open
328
//! - RelativeCheckBox is senseless,
329
//! - file must exist;
330
//! - when creating new root part
331
//! - RelativeCheckBox is senseless,
332
//! - file should not exist,
333
//! - and it should be possible to create a folder.
335
// Dir = QFileDialog::getExistingDirectory(NameField
337
// ,QFileInfo(Name).path()
340
// Name = QFileDialog::getSaveFileName(NameField
343
// ,"RANet sqlite files (*.RANet.sqlite);;All files (*)"
345
// ,QFileDialog::DontUseCustomDirectoryIcons
348
if( ! Name.isEmpty() ){
349
if( RelativeCheckBox->isChecked() ){
350
Name = QDir::current().relativeFilePath(Name);
352
DBNameField->setText(Name);
357
void sEditDBInfoDialog::ShowPassword ()
359
PasswordField->setEchoMode(QLineEdit::Normal);
363
void sEditDBInfoDialog::MaskPassword ()
365
PasswordField->setEchoMode(QLineEdit::Password);
161
394
void sEditDBInfoDialog::AcceptChanges ()
163
396
Info->Type = sDB_Info::eType( TypeField->currentIndex() );
164
Info->Name = FromQString( NameField->text() );
397
Info->DBName = FromQString( DBNameField->text() );
398
Info->SchemaName = FromQString( SchemaField->text() );
399
Info->TableNamePrefix = FromQString( PrefixField->text() );
165
400
Info->Host = FromQString( HostField->text() );
166
401
Info->Port = PortField->value();
167
402
Info->Login = FromQString( LoginField->text() );
168
403
Info->Password = FromQString( PasswordField->text() );
404
Info->ConnectOptions = FromQString( OptionsField->text() );
171
407
//-------------------------------------------------------- sEditDBLinkDialog ---
173
409
sEditDBLinkDialog::sEditDBLinkDialog (psDB_Link link
174
411
,QWidget * parent)
175
:sEditDBInfoDialog(link,parent)
412
:sEditDBInfoDialog(link,title,parent)
178
setWindowTitle(tr("Edit link to a database"));
180
416
if( ! Link->Id.Undefined() ){
181
IdDisplay = new QLabel(ToQString(Link->Id.ToString()),this);
182
FLayout->setWidget(10,QFormLayout::LabelRole,new QLabel(tr("DB Id")));
183
FLayout->setWidget(10,QFormLayout::FieldRole,IdDisplay);
186
NicknameField = new QLineEdit(ToQString( Link->Nickname ),this);
187
FLayout->setWidget(11,QFormLayout::LabelRole,new QLabel(tr("Link nickname")));
188
FLayout->setWidget(11,QFormLayout::FieldRole,NicknameField);
190
CommentField = new QLineEdit(ToQString( Link->Comment ),this);
191
FLayout->setWidget(12,QFormLayout::LabelRole,new QLabel(tr("Link comment")));
192
FLayout->setWidget(12,QFormLayout::FieldRole,CommentField);
196
bool sEditDBLinkDialog::Validate ()
198
if( ! sEditDBInfoDialog::Validate() ){
201
QString Nickname = NicknameField->text();
202
//... analyse and transform Nickname
203
if( Nickname.isEmpty() ){
204
QMessageBox::information(this, tr("No database link nickname given")
205
,tr("Please fill up the nickname field"));
206
NicknameField->setFocus();
213
void sEditDBLinkDialog::AcceptChanges ()
215
sEditDBInfoDialog::AcceptChanges();
216
Link->Nickname = FromQString( NicknameField->text() );
217
Link->Comment = FromQString( CommentField->text() );
417
IdDisplay = new QLabel(ToQString(Link->Id.ToString()
418
+" v."+Link->Version.Text()
429
(L = new QHBoxLayout())->setAlignment(Qt::AlignLeft);
430
((QVBoxLayout*)layout())->insertItem(I++,L);
431
L->addWidget(new QLabel(tr("DB Id "),this));
432
L->addWidget(IdDisplay);
220
437
//------------------------------------------------------------------------------