-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckOut.cpp
More file actions
423 lines (363 loc) · 11.1 KB
/
CheckOut.cpp
File metadata and controls
423 lines (363 loc) · 11.1 KB
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
/*
Project: DocMan
Module: CheckOut.cpp
Description: Check out a file and dialog
Author: Martin Gäckler
Address: Hofmannsthalweg 14, A-4030 Linz
Web: https://www.gaeckler.at/
Copyright: (c) 1988-2026 Martin Gäckler
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, version 3.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
THIS SOFTWARE IS PROVIDED BY Martin Gäckler, Linz, Austria ``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 OR
CONTRIBUTORS 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 <vcl.h>
#include <vcl/registry.hpp>
#pragma hdrstop
#include "DocManDM.h"
#include "ActionManager.h"
#include "File.h"
#include "Folder.h"
#include "PermissionsFrm.h"
#include "CheckOut.h"
//---------------------------------------------------------------------------
using namespace gak;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TCheckOutForm *CheckOutForm;
//---------------------------------------------------------------------------
class ACTION_CHECK_OUT : public ACTION_BASE_CHECK
{
virtual bool acceptItem( THE_ITEM *theItem );
virtual const char *getLabel() const;
virtual RefhreshType perform( PTR_ITEM theItem );
};
class ACTION_CHECK_OUT_TREE : public ACTION_BASE_CHECK
{
virtual bool acceptItem( THE_ITEM *theItem );
virtual const char *getLabel() const;
virtual RefhreshType perform( PTR_ITEM theItem );
};
class ACTION_ASSIGNED_TASK : public ACTION_BASE_CHECK
{
virtual bool acceptItem( THE_ITEM *theItem );
virtual const char *getLabel() const;
virtual RefhreshType perform( PTR_ITEM theItem );
};
class ACTION_CANCEL_CHECK_OUT : public ACTION_BASE_CHECK
{
virtual bool acceptItem( THE_ITEM *theItem );
virtual const char *getLabel() const;
virtual RefhreshType perform( PTR_ITEM theItem );
};
#pragma option -RT-
class THREAD_CHECK_OUT_TREE : public ThreadDocMan
{
int m_taskID;
bool m_changedOnly;
virtual const char *getTitle() const;
virtual void perform();
public:
THREAD_CHECK_OUT_TREE( const PTR_ITEM &theItemToHandle, int taskID, bool changedOnly )
: ThreadDocMan(theItemToHandle), m_taskID(taskID), m_changedOnly(changedOnly)
{
}
};
#pragma option -RT.
//---------------------------------------------------------------------------
static ACTION_CHECK_OUT theCheckOutAction;
static ACTION_CHECK_OUT_TREE theCheckOutTreeAction;
static ACTION_ASSIGNED_TASK theAssignedTaskAction;
static ACTION_CANCEL_CHECK_OUT theCancelAction;
//---------------------------------------------------------------------------
bool ACTION_CHECK_OUT::acceptItem( THE_ITEM *theItem )
{
const THE_FILE_BASE *theFile = dynamic_cast<const THE_FILE_BASE *>(theItem);
if( theFile )
{
return theFile->canReserve() && ACTION_BASE::acceptItem( theItem );
}
return false;
}
const char *ACTION_CHECK_OUT::getLabel() const
{
return "Check Out...";
}
inline CI_STRING splitFname( CI_STRING &fname )
{
CI_STRING fext;
size_t dotPos = fname.searchChar( '.' );
if( dotPos != fname.no_index )
{
fext = fname.subString( dotPos );
fname.cut( dotPos );
}
return fext;
}
RefhreshType ACTION_CHECK_OUT::perform( PTR_ITEM theItem )
{
PTR_FILE_BASE theFile = theItem;
if( theFile )
{
CI_STRING baseName = theItem->getName();
CI_STRING baseExt = splitFname(baseName);
if( CheckOutForm->ShowModal(CHECKOUT_FILE, baseExt) == mrOk )
{
theFile->reserve( CheckOutForm->getSelectedTaskID() );
theFile->updateDatabase();
bool otherExt = CheckOutForm->CheckBoxFlag1->Checked;
bool otherNames = CheckOutForm->CheckBoxFlag2->Checked;
if( otherExt || otherNames )
{
PTR_ITEM parent = theItem->getParent();
if( parent )
{
Array<CI_STRING> goodNames;
ITEM_CONTENT *theContent = parent->getContent();
if(otherExt && otherNames)
{
for( size_t i=0; i<theContent->size(); i++ )
{
theFile = parent->getContentItem( i );
if( theFile )
{
CI_STRING childName = theFile->getName();
CI_STRING childExt = splitFname(childName);
if( childExt == baseExt )
goodNames.addElement( childName );
}
}
}
for( size_t i=0; i<theContent->size(); i++ )
{
theFile = parent->getContentItem( i );
if( theFile && theFile->canReserve() )
{
CI_STRING childName = theFile->getName();
CI_STRING childExt = splitFname(childName);
if( (
otherExt && childName == baseName
)
|| (
otherNames && childExt == baseExt
)
|| goodNames.findElement(childName) != goodNames.no_index )
{
theFile->reserve(
CheckOutForm->getSelectedTaskID()
);
theFile->updateDatabase();
}
}
}
}
}
/***/ return rtREDRAW;
}
}
return rtNONE;
}
//---------------------------------------------------------------------------
bool ACTION_CHECK_OUT_TREE::acceptItem( THE_ITEM *theItem )
{
THE_SOURCE_FOLDER *theFolder = dynamic_cast<THE_SOURCE_FOLDER *>(theItem);
return theFolder ? ACTION_BASE::acceptItem( theItem ) : false;
}
const char *ACTION_CHECK_OUT_TREE::getLabel() const
{
return "Check Out...";
}
const char *THREAD_CHECK_OUT_TREE::getTitle() const
{
return "Check Out";
}
void THREAD_CHECK_OUT_TREE::perform()
{
PTR_SOURCE_FOLDER theFolder = theItemToHandle;
if( theFolder )
{
theFolder->reserve( m_taskID, m_changedOnly );
}
}
RefhreshType ACTION_CHECK_OUT_TREE::perform( PTR_ITEM theItem )
{
PTR_SOURCE_FOLDER theFolder = theItem;
if( theFolder )
{
STRING localPath = theFolder->getDownloadPath();
if( localPath.isEmpty() )
/*@*/ throw Exception( "Don't know local path" );
if( CheckOutForm->ShowModal(CHECKOUT_TREE) == mrOk )
{
THREAD_CHECK_OUT_TREE *theThread = new THREAD_CHECK_OUT_TREE(
theFolder,
CheckOutForm->getSelectedTaskID(),
CheckOutForm->CheckBoxFlag1->Checked
);
theThread->StartThread();
return rtRELOAD;
}
}
return rtNONE;
}
//---------------------------------------------------------------------------
bool ACTION_ASSIGNED_TASK::acceptItem( THE_ITEM *theItem )
{
const THE_FILE_BASE *theFile = dynamic_cast<const THE_FILE_BASE *>(theItem);
if( theFile )
return theFile->canUnreserve( true ) && ACTION_BASE::acceptItem( theItem );
return false;
}
const char *ACTION_ASSIGNED_TASK::getLabel() const
{
return "Assinged Task...";
}
RefhreshType ACTION_ASSIGNED_TASK::perform( PTR_ITEM theItem )
{
PTR_FILE_BASE theFile = theItem;
if( theFile )
{
CheckOutForm->setLastTask( theFile->getTask() );
if( CheckOutForm->ShowModal(CHANGE_TASK) == mrOk )
{
theFile->setTask( CheckOutForm->getSelectedTaskID() );
theFile->updateDatabase();
}
}
return rtNONE;
}
//---------------------------------------------------------------------------
bool ACTION_CANCEL_CHECK_OUT::acceptItem( THE_ITEM *theItem )
{
const THE_FILE_BASE *theFile = dynamic_cast<const THE_FILE_BASE *>(theItem);
if( theFile )
return theFile->canUnreserve( true ) && ACTION_BASE::acceptItem( theItem );
return false;
}
const char *ACTION_CANCEL_CHECK_OUT::getLabel() const
{
return "Cancel";
}
RefhreshType ACTION_CANCEL_CHECK_OUT::perform( PTR_ITEM theItem )
{
PTR_FILE_BASE theFile = theItem;
if( theFile )
{
theFile->cancelReserve();
theFile->updateDatabase();
return rtREDRAW;
}
return rtNONE;
}
//---------------------------------------------------------------------------
__fastcall TCheckOutForm::TCheckOutForm(TComponent* Owner)
: TForm(Owner), m_lastTaskID( 0 ), m_regKey1(NULL)
{
}
int TCheckOutForm::ShowModal( FormMode mode, const STRING &extension )
{
if( mode == CHECKOUT_FILE )
{
Caption = "Check Out";
CheckBoxFlag1->Visible = true;
CheckBoxFlag1->Caption = "Include Other File Extensions";
CheckBoxFlag2->Visible = true;
m_regKey1 = "CheckBoxIncludeExtensions";
m_regKey2 = STRING("CheckBoxIncludeNames") + extension;
}
else if( mode == CHECKOUT_TREE )
{
Caption = "Check Out";
CheckBoxFlag1->Visible = true;
CheckBoxFlag1->Caption = "Changed Files, only";
CheckBoxFlag2->Visible = false;
m_regKey1 = "CheckBoxChangedOnly";
m_regKey2.release();
}
else if( mode == CHANGE_TASK )
{
Caption = "Assigned Task";
CheckBoxFlag1->Visible = false;
CheckBoxFlag2->Visible = false;
m_regKey1 = NULL;
m_regKey2.release();
}
return TForm::ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TCheckOutForm::FormShow(TObject *)
{
int lastItemIndex = 0;
AnsiString taskTitle;
if( !m_lastTaskID )
{
std::auto_ptr<TRegistry> reg( new TRegistry );
if( reg->OpenKey( registryKey, false ) )
{
if( reg->ValueExists( "lastTaskID" ) )
m_lastTaskID = reg->ReadInteger( "lastTaskID" );
if( m_regKey1 && reg->ValueExists( m_regKey1 ) )
CheckBoxFlag1->Checked = reg->ReadBool( m_regKey1 );
if( !m_regKey2.isEmpty() && reg->ValueExists( m_regKey2 ) )
CheckBoxFlag2->Checked = reg->ReadBool( m_regKey2 );
reg->CloseKey();
}
}
ComboBoxTasks->Items->Clear();
m_ids.clear();
m_ids.addElement( 0 );
ComboBoxTasks->Items->Add( "None" );
QueryOpenTasks->ParamByName( "actUser" )->AsInteger = vcl::getActUserID();
for(
QueryOpenTasks->Open();
!QueryOpenTasks->Eof;
QueryOpenTasks->Next()
)
{
taskTitle = QueryOpenTasks->FieldByName( "Name" )->AsString;
taskTitle += " (";
taskTitle += QueryOpenTasks->FieldByName( "Task_Status" )->AsString;
taskTitle += ')';
ComboBoxTasks->Items->Add( taskTitle );
m_ids.addElement( QueryOpenTasks->FieldByName( "ID" )->AsInteger );
if( QueryOpenTasks->FieldByName( "ID" )->AsInteger == m_lastTaskID )
lastItemIndex = ComboBoxTasks->Items->Count -1;
}
ComboBoxTasks->ItemIndex = lastItemIndex;
QueryOpenTasks->Close();
ActiveControl = ComboBoxTasks;
vcl::bringWindowToFront( this );
}
//---------------------------------------------------------------------------
void __fastcall TCheckOutForm::ButtonOKClick(TObject *)
{
m_lastTaskID = m_ids[ComboBoxTasks->ItemIndex];
std::auto_ptr<TRegistry> reg( new TRegistry );
reg->OpenKey( registryKey, true );
reg->WriteInteger( "lastTaskID", m_lastTaskID );
if( m_regKey1 )
{
reg->WriteBool( m_regKey1, CheckBoxFlag1->Checked );
}
if( !m_regKey2.isEmpty() )
{
reg->WriteBool( m_regKey2, CheckBoxFlag2->Checked );
}
reg->CloseKey();
}
//---------------------------------------------------------------------------