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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
/***************************************************************************
*
* Copyright (C) 2005 Elad Lahav (elad_lahav@users.sourceforge.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
***************************************************************************/
#include <tqregexp.h>
#include <tqpushbutton.h>
#include <tqspinbox.h>
#include <tqlabel.h>
#include <tqtextedit.h>
#include <kurlrequester.h>
#include <klineedit.h>
#include <tdemessagebox.h>
#include <tdelocale.h>
#include "newprojectdlg.h"
/**
* Class constructor.
* @param bNewProj true to create a new project dialog, false to display
* the properties of an existing project
* @param pParent The parent widget
* @param szName The widget's name
*/
NewProjectDlg::NewProjectDlg(bool bNewProj, TQWidget* pParent,
const char* szName) :
NewProjectLayout(pParent, szName),
m_bNewProj(bNewProj)
{
ProjectBase::Options opt;
// Create the auto-completion sub-dialogue
m_pAutoCompDlg = new AutoCompletionDlg(this);
// Restrict the path requester to existing directories.
m_pPathRequester->setMode(KFile::Directory | KFile::ExistingOnly |
KFile::LocalOnly);
m_pSrcRootRequester->setMode(KFile::Directory | KFile::ExistingOnly |
KFile::LocalOnly);
// Set up the Create/Cancel buttons
connect(m_pCreateButton, TQ_SIGNAL(clicked()), this, TQ_SLOT(accept()));
connect(m_pCancelButton, TQ_SIGNAL(clicked()), this, TQ_SLOT(reject()));
// Show the auto-completion properties dialogue
connect(m_pACButton, TQ_SIGNAL(clicked()), m_pAutoCompDlg, TQ_SLOT(exec()));
// Perform actions specific to the type of dialog (new project or
// project properties)
if (bNewProj) {
// Set default project properties
ProjectBase::getDefOptions(opt);
setProperties("", "", opt);
}
else {
// Give appropriate titles to the dialog and the accept button
setCaption(i18n("Project Properties"));
m_pCreateButton->setText(i18n("OK"));
// Disable the non-relevant widgets
m_pNameEdit->setEnabled(false);
m_pPathRequester->setEnabled(false);
}
}
/**
* Class destructor.
*/
NewProjectDlg::~NewProjectDlg()
{
}
/**
* Configures the dialog's widget to display the properties of the current
* project.
* @param sName The project's name
* @param sPath The project's path
* @param opt Project parameters configurable in this dialogue
*/
void NewProjectDlg::setProperties(const TQString& sName, const TQString& sPath,
const ProjectBase::Options& opt)
{
TQStringList::ConstIterator itr;
// Set values for current project
m_pNameEdit->setText(sName);
m_pPathRequester->setURL(sPath);
m_pSrcRootRequester->setURL(opt.sSrcRootPath);
m_pKernelCheck->setChecked(opt.bKernel);
m_pInvCheck->setChecked(opt.bInvIndex);
m_pNoCompCheck->setChecked(opt.bNoCompress);
m_pSlowPathCheck->setChecked(opt.bSlowPathDef);
if (opt.nAutoRebuildTime >= 0) {
m_pAutoRebuildCheck->setChecked(true);
m_pAutoRebuildSpin->setValue(opt.nAutoRebuildTime);
}
if (opt.bACEnabled) {
m_pACCheck->setChecked(true);
}
if (opt.nTabWidth > 0) {
m_pTabWidthCheck->setChecked(true);
m_pTabWidthSpin->setValue(opt.nTabWidth);
}
// Initialise the auto-completion sub-dialogue
m_pAutoCompDlg->m_nMinChars = opt.nACMinChars;
m_pAutoCompDlg->m_nDelay = opt.nACDelay;
m_pAutoCompDlg->m_nMaxEntries = opt.nACMaxEntries;
// Add type strings to the types list box
for (itr = opt.slFileTypes.begin(); itr != opt.slFileTypes.end(); ++itr)
m_pTypesList->insertItem(*itr);
m_pCtagsCmdEdit->setText(opt.sCtagsCmd);
}
/**
* Retrieves the text entered by the user in the dialog's "Project Name" edit
* box.
* @return The name of the new project
*/
TQString NewProjectDlg::getName()
{
return m_pNameEdit->text();
}
/**
* Retrieves the text entered by the user in the dialog's "Project Path" edit
* box.
* Note that the chosen path will be the parent of the new project's
* directory, created under it using the project's name.
* @return The full path of the parent directory for the new project
*/
TQString NewProjectDlg::getPath()
{
if (m_pHiddenDirCheck->isChecked())
return TQString(m_pSrcRootRequester->url()) + "/.cscope";
return m_pPathRequester->url();
}
/**
* Fills a structure with all user-configured project options.
* @param opt The structure to fill
*/
void NewProjectDlg::getOptions(ProjectBase::Options& opt)
{
opt.sSrcRootPath = m_pSrcRootRequester->url();
opt.slFileTypes = m_slTypes;
opt.bKernel = m_pKernelCheck->isChecked();
opt.bInvIndex = m_pInvCheck->isChecked();
opt.bNoCompress = m_pNoCompCheck->isChecked();
opt.bSlowPathDef = m_pSlowPathCheck->isChecked();
if (m_pAutoRebuildCheck->isChecked())
opt.nAutoRebuildTime = m_pAutoRebuildSpin->value();
else
opt.nAutoRebuildTime = -1;
if (m_pTabWidthCheck->isChecked())
opt.nTabWidth = m_pTabWidthSpin->value();
else
opt.nTabWidth = 0;
opt.bACEnabled = m_pACCheck->isChecked();
opt.nACMinChars = m_pAutoCompDlg->m_nMinChars;
opt.nACDelay = m_pAutoCompDlg->m_nDelay;
opt.nACMaxEntries = m_pAutoCompDlg->m_nMaxEntries;
opt.sCtagsCmd = m_pCtagsCmdEdit->text();
}
/**
* Ends the dialog after the user has clicked the "OK" button.
*/
void NewProjectDlg::accept()
{
int i, nCount;
// Validate the name of a new project
if (m_bNewProj) {
TQRegExp re("[^ \\t\\n]+");
if (!re.exactMatch(m_pNameEdit->text())) {
KMessageBox::error(0, i18n("Project names must not contain "
"whitespace."));
return;
}
}
// Fill the string list with all file types
nCount = (int)m_pTypesList->count();
for (i = 0; i < nCount; i++)
m_slTypes.append(m_pTypesList->text(i));
// Clean-up the source root
TQDir dir(m_pSrcRootRequester->url());
if (dir.exists())
m_pSrcRootRequester->setURL(dir.absPath());
else
m_pSrcRootRequester->setURL("/");
// Close the dialog
TQDialog::accept();
}
/**
* Adds the the file type string in the edit-box to the list of project types.
* This slot is called when the "Add.." button is clicked.
*/
void NewProjectDlg::slotAddType()
{
TQString sType;
// Try the custom type edit-box first.
sType = m_pTypesEdit->text();
sType.stripWhiteSpace();
if (sType.isEmpty())
return;
// Validate the type string
TQRegExp reg("[ \\t\\n\\|\\\\\\/]");
if (sType.contains(reg)) {
KMessageBox::error(0, i18n("This is not a valid file type!"));
return;
}
// Do not add an existing type.
if (m_pTypesList->findItem(sType, TQt::CaseSensitive | TQt::ExactMatch) !=
NULL) {
return;
}
// Add the file type to the list
m_pTypesList->insertItem(sType);
m_pTypesEdit->clear();
}
/**
* Removes the selected item from the list of file types.
* This slot is called when the "Remove" button is clicked.
*/
void NewProjectDlg::slotRemoveType()
{
int nItem;
TQString sType;
// Verify an item is selected
nItem = m_pTypesList->currentItem();
if (nItem == -1)
return;
// Remove the selected item
sType = m_pTypesList->currentText();
m_pTypesList->removeItem(nItem);
// Add to the list of available types.
if (m_pAvailTypesList->findItem(sType, TQt::CaseSensitive | TQt::ExactMatch)
== NULL) {
m_pAvailTypesList->insertItem(sType);
}
}
/**
* Changes the text in the types edit-box to reflect the current selection in
* the list of available types.
* This slot is called whenever a new item is highlighted in the list of
* available types.
* @param sType The newly selected type
*/
void NewProjectDlg::slotAvailTypesChanged(const TQString& sType)
{
m_pTypesEdit->setText(sType);
}
/**
* Class constructor.
* @param pParent The parent widget
* @param szName The widget's name
*/
AutoCompletionDlg::AutoCompletionDlg(TQWidget* pParent,
const char* szName ) :
AutoCompletionLayout(pParent, szName)
{
connect(m_pOKButton, TQ_SIGNAL(clicked()), this, TQ_SLOT(accept()));
connect(m_pCancelButton, TQ_SIGNAL(clicked()), this, TQ_SLOT(reject()));
}
/**
* Class destructor.
*/
AutoCompletionDlg::~AutoCompletionDlg()
{
}
/**
* Displays the dialogue, and waits for either the "OK" or "Cancel" button to
* be clicked.
* Before the dialogue is displayed, the stored values are set to the widgets.
* @return The dialogue's termination code
*/
int AutoCompletionDlg::exec()
{
// Set current values
m_pMinCharsSpin->setValue(m_nMinChars);
m_pDelaySpin->setValue(m_nDelay);
m_pMaxEntriesSpin->setValue(m_nMaxEntries);
// Show the dialogue
return TQDialog::exec();
}
/**
* Stores the values set by the user in the dialogue widgets, and terminates
* the dialogue.
* This slot is connected to the clicked() signal of the "OK" button.
*/
void AutoCompletionDlg::accept()
{
// Store widget values
m_nMinChars = m_pMinCharsSpin->value();
m_nDelay = m_pDelaySpin->value();
m_nMaxEntries = m_pMaxEntriesSpin->value();
// Close the dialogue, indicating acceptance
TQDialog::accept();
}
#include "newprojectdlg.moc"
|