-
Notifications
You must be signed in to change notification settings - Fork 1
/
dlgacquire.cpp
1677 lines (1470 loc) · 71.2 KB
/
dlgacquire.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
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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ****************************************************************************
// Project: GUYMAGER
// ****************************************************************************
// Programmer: Guy Voncken
// Police Grand-Ducale
// Service de Police Judiciaire
// Section Nouvelles Technologies
// ****************************************************************************
// Module: Acquisition dialog
// ****************************************************************************
// Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
// 2018, 2019, 2020
// Guy Voncken
//
// This file is part of Guymager.
//
// Guymager 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.
//
// Guymager 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.
//
// You should have received a copy of the GNU General Public License
// along with Guymager. If not, see <http://www.gnu.org/licenses/>.
#if (QT_VERSION >= 0x050000)
#include <QtWidgets> //lint !e537 Repeated include
#else
#include <QtGui> //lint !e537 Repeated include
#endif
#include <QDesktopWidget>
#include "toolconstants.h"
#include "common.h"
#include "compileinfo.h"
#include "config.h"
#include "util.h"
#include "qtutil.h"
#include "dlgdirsel.h"
#include "devicelistmodel.h"
#include "dlgacquire.h"
#include "dlgacquire_private.h"
#include "dlgmessage.h"
#include "main.h"
#include "mainwindow.h"
// -----------------------------
// Constants
// -----------------------------
static const char *DLGACQUIRE_DEFAULT_EMPTY_FILENAME = "Out"; // Default image file name if - after removing special chars - the file name is empty.
static const char *DLGACQUIRE_PROPERTY_SENDER_LINEEDIT = "SenderLineEdit";
// -----------------------------
// Classes
// -----------------------------
class t_DlgAcquireLocal
{
public:
bool Clone;
bool Duplicate;
QRadioButton *pRadioButtonFormatDD;
QRadioButton *pRadioButtonFormatEWF;
QRadioButton *pRadioButtonFormatAFF;
QList<QWidget*> EwfWidgetsList; // Used to comfortably enable / disable EWF related entry fields and labels
QTableWidget *pDeviceTable; // Only created and displayed when cloning a device
QPushButton *pButtonOk;
QPushButton *pButtonDuplicate;
QPushButton *pButtonBack;
QPushButton *pButtonCancel;
t_pDevice pDevice;
t_pDeviceList pDeviceList;
t_pAcquisition pAcquisition1; // Contains the values entered in the first acquisition dialog in case this dialog is the duplicate dialog. Used
// for checking consistency of values entered in both acquisition dialogs (cross check info and image filenames)
bool OldSplitFileSwitch; // Required to remember SplitFileSwitch when chaging forth and back
// between formats that support split files and not.
};
class t_DlgAcquireTableWidgetItem : public QTableWidgetItem // t_DlgAcquireTableWidgetItem contains a pointer to the coreesponding
{ // device in order to be able to find out the device when clicking on a
public: // line in the clone dialog device table.
t_DlgAcquireTableWidgetItem (t_pcDevice pDevice, const QString &Text) :
QTableWidgetItem (Text),
poDevice (pDevice)
{
}
t_pcDevice GetpDevice (void)
{
return poDevice;
}
private:
t_pcDevice poDevice;
};
static t_File::Format DlgAcquireLastUsedFormat = t_File::NotSet; // For remembering the format that was used for the last acquisition
// -----------------------------
// Unit conversion
// -----------------------------
const QStringList UnitStrings = QStringList() << "MiB" << "GiB" << "TiB" << "PiB" << "EiB";
static int UnitStringToIndex (QString &Str)
{
if (Str.contains ('M', Qt::CaseInsensitive)) return 0;
else if (Str.contains ('G', Qt::CaseInsensitive)) return 1;
else if (Str.contains ('T', Qt::CaseInsensitive)) return 2;
else if (Str.contains ('P', Qt::CaseInsensitive)) return 3;
else if (Str.contains ('E', Qt::CaseInsensitive)) return 4;
LOG_ERROR ("Unknown Unit %s", QSTR_TO_PSZ(Str))
return 0;
}
static unsigned long long UnitIndexToMultiplier (int Index)
{
unsigned long long Mul = 1024*1024;
if ((Index < 0) || (Index > 4))
LOG_ERROR ("Unit index out of range: %d", Index)
else Mul <<= (Index*10);
return Mul;
}
// -----------------------------
// Field utility functions
// -----------------------------
static t_pCfgDlgAcquireField DlgAcquireGetField (const QString &Name)
{
t_pCfgDlgAcquireFields pDlgAcquireFields;
t_pCfgDlgAcquireField pDlgAcquireField;
int i;
CHK_EXIT (CfgGetDlgAcquireFields (&pDlgAcquireFields))
for (i=0; i<pDlgAcquireFields->count(); i++)
{
pDlgAcquireField = pDlgAcquireFields->at(i);
if (pDlgAcquireField->FieldName.compare(Name, Qt::CaseInsensitive)==0)
return pDlgAcquireField;
}
LOG_ERROR ("DlgAcquire field %s not found", QSTR_TO_PSZ(Name))
return nullptr;
}
static t_pDlgAcquireLineEdit DlgAcquireGetLineEdit (const QString &Name)
{
return DlgAcquireGetField(Name)->pLineEdit;
}
static APIRET DlgAcquireResolveSpecialSequences (t_pDevice pDevice, bool ConsiderFields, const QString &In, QString &Out)
{
t_pCfgDlgAcquireFields pDlgAcquireFields;
t_pCfgDlgAcquireField pDlgAcquireField;
QDateTime Now = QDateTime::currentDateTime();
int i;
QString Search;
// Replace tokens
// --------------
Out = In;
t_Device::ProcessTokenString (Out, pDevice);
// Replace field values
// --------------------
if (ConsiderFields)
{
CHK_EXIT (CfgGetDlgAcquireFields (&pDlgAcquireFields))
for (i=0; i<pDlgAcquireFields->count(); i++)
{
pDlgAcquireField = pDlgAcquireFields->at(i);
if (pDlgAcquireField->pLineEdit)
{
Search = "%" + pDlgAcquireField->FieldName + "%";
Out.replace (Search, pDlgAcquireField->pLineEdit->text());
}
}
}
return NO_ERROR;
}
static APIRET DlgAcquireGetFieldValue (t_pDevice pDevice, bool Clone, t_pCfgDlgAcquireField pDlgAcquireField, bool ForceLastEnteredValues, QString &Set)
{
t_CfgEntryMode EntryMode;
if (Clone && ((pDlgAcquireField->FieldName == CFG_DLGACQUIRE_DEST_IMAGEDIRECTORY) ||
(pDlgAcquireField->FieldName == CFG_DLGACQUIRE_DEST_IMAGEFILENAME )))
{
Set = QString();
return NO_ERROR;
}
if (ForceLastEnteredValues)
{
EntryMode = CFG_ENTRYMODE_SHOWLAST;
}
else
{
if (Clone)
EntryMode = pDlgAcquireField->EntryModeClone;
else EntryMode = pDlgAcquireField->EntryModeImage;
}
switch (EntryMode)
{
case CFG_ENTRYMODE_HIDE:
case CFG_ENTRYMODE_SHOWLAST:
Set = pDlgAcquireField->LastEnteredValue;
if (Set.isNull())
{
Set = pDlgAcquireField->DefaultValue;
CHK (DlgAcquireResolveSpecialSequences (pDevice, false, pDlgAcquireField->DefaultValue, Set))
}
break;
case CFG_ENTRYMODE_SHOWDEFAULT:
Set = pDlgAcquireField->DefaultValue;
CHK (DlgAcquireResolveSpecialSequences (pDevice, false, pDlgAcquireField->DefaultValue, Set))
break;
default:
CHK (ERROR_DLGACQUIRE_INVALID_ENTRYMODE)
}
return NO_ERROR;
}
// -----------------------------
// t_DlgAcquire
// -----------------------------
static bool DlgAcquireStrToBool (const QString &Set)
{
return !Set.isEmpty() && (Set.compare ("NO" , Qt::CaseInsensitive) != 0) &&
!Set.isNull () && (Set.compare ("OFF" , Qt::CaseInsensitive) != 0) &&
(Set.compare ("FALSE" , Qt::CaseInsensitive) != 0) &&
(Set.compare ("0" , Qt::CaseInsensitive) != 0) &&
(Set.compare ("DISABLED" , Qt::CaseInsensitive) != 0) &&
(Set.compare ("DEACTIVATED", Qt::CaseInsensitive) != 0);
}
t_CfgEntryMode t_DlgAcquire::EntryMode (t_pCfgDlgAcquireField pField)
{
return pOwn->Clone ? pField->EntryModeClone : pField->EntryModeImage;
}
APIRET t_DlgAcquire::AddField (t_pDevice pDevice, t_pCfgDlgAcquireField pField, QGridLayout *pLayout, int *pRow, int *pCol, bool ForceLastEnteredValues)
{
t_pDlgAcquireLineEdit pLineEdit = nullptr;
QCheckBox *pCheckBox = nullptr;
QComboBox *pComboBox = nullptr;
QLabel *pLabel = nullptr;
QWidget *pEntryWidget = nullptr;
QToolButton *pButtonBrowse = nullptr;
QString Set;
bool Ok;
// Create field
// ------------
if (pField->HashField || pField->FieldName == CFG_DLGACQUIRE_SPLITFILESWITCH)
{
pEntryWidget = pCheckBox = new QCheckBox (tr(QSTR_TO_PSZ(pField->FieldName)), this);
}
else if (pField->FieldName == CFG_DLGACQUIRE_SPLITFILEUNIT)
{
pEntryWidget = pComboBox = new QComboBox (this);
pComboBox->addItems (UnitStrings);
}
else
{
pEntryWidget = pLineEdit = new t_DlgAcquireLineEdit (this, pField->FieldName);
pLabel = new QLabel (tr(QSTR_TO_PSZ(pField->FieldName)), this);
}
if ((pField->DirField) && (EntryMode(pField) != CFG_ENTRYMODE_HIDE))
{
pButtonBrowse = new QToolButton (this);
QSize MaximumSize = pButtonBrowse->maximumSize();
MaximumSize.setWidth (USHRT_MAX);
pButtonBrowse->setMaximumSize (MaximumSize);
pButtonBrowse->setText (tr("...", "The directory browse button"));
}
// Position field
// --------------
pField->pLineEdit = pLineEdit;
pField->pCheckBox = pCheckBox;
pField->pComboBox = pComboBox;
pField->pLabel = pLabel;
if (EntryMode(pField) == CFG_ENTRYMODE_HIDE)
{
if (pLabel)
pLabel->hide();
pEntryWidget->hide();
}
else
{
if (pField->FieldName == CFG_DLGACQUIRE_SPLITFILESIZE)
{
pLayout->addWidget (pLabel , *pRow, *pCol );
pLayout->addWidget (pLineEdit, *pRow, *pCol+1);
}
else
{
if (pButtonBrowse)
{
pLayout->addWidget (pLabel , *pRow, 0);
pLayout->addWidget (pButtonBrowse, *pRow, 1);
}
else if (pLabel)
{
pLayout->addWidget (pLabel, *pRow, 0, 1, 2); // if there's no button then use the first 2 columns for the label
}
if (pLineEdit)
{
pLayout->addWidget (pLineEdit, *pRow, 2);
if (pField->EwfField)
{
pOwn->EwfWidgetsList.append (pLabel );
pOwn->EwfWidgetsList.append (pLineEdit);
}
(*pRow)++;
}
if (pCheckBox)
{
if (pField->FieldName == CFG_DLGACQUIRE_SPLITFILESWITCH)
{
pLayout->addWidget (pCheckBox, *pRow, *pCol, 1, 2);
(*pRow)++;
}
else if (pField->FieldName.startsWith (CFG_DLGACQUIRE_HASHCALC_FIELDID))
{
pLayout->addWidget (pCheckBox, 0, *pCol); // Put all HashCalc field in the first row
(*pCol)++;
}
else
{
pLayout->addWidget (pCheckBox, (*pRow)+1, 0, 1, 2); // Put each verification field in an own row below
(*pRow)++;
}
}
if (pComboBox)
{
pLayout->addWidget (pComboBox, *pRow, 3);
}
}
}
// Set field value
// ---------------
CHK_EXIT (DlgAcquireGetFieldValue (pDevice, pOwn->Clone, pField, ForceLastEnteredValues, Set))
if (pField->DirField)
{
if (!CONFIG(DirectoryFieldEditing))
pLineEdit->setReadOnly (true);
if (!Set.endsWith ("/"))
Set += "/";
}
if (pLineEdit)
{
pLineEdit->setText (Set);
CHK_QT_EXIT (connect (pLineEdit, SIGNAL (SignalTextEdited (t_DlgAcquireLineEdit *, const QString &)),
this, SLOT (SlotTextEdited (t_DlgAcquireLineEdit *, const QString &))))
}
if (pField->DstField)
CHK_QT_EXIT (connect (pLineEdit, SIGNAL (textChanged(const QString &)), this, SLOT(UpdateDialogState(const QString &))))
if (pCheckBox)
pCheckBox->setChecked (DlgAcquireStrToBool(Set));
if (pComboBox)
{
pComboBox->setCurrentIndex(Set.toInt(&Ok));
if (!Ok)
LOG_ERROR ("Invalid set value for ComboBox: %s", QSTR_TO_PSZ(Set));
}
if (pButtonBrowse)
{
(void) pButtonBrowse->setProperty (DLGACQUIRE_PROPERTY_SENDER_LINEEDIT, qVariantFromValue ((void *)pLineEdit));
CHK_QT_EXIT (connect (pButtonBrowse, SIGNAL (released()), this, SLOT(SlotBrowse())))
}
return NO_ERROR;
}
static APIRET DlgAcquireGetCol (int i, t_pcCfgColumn *ppColCfg, t_pMainWindowColumn *ppColDef)
{
*ppColCfg = CfgGetColumn (i);
if ((*ppColCfg)->ShowInCloneTable)
{
*ppColDef = MainWindowGetColumn ((*ppColCfg)->Name);
if (*ppColDef == nullptr)
CHK(ERROR_DLGACQUIRE_UNKNOWN_COLUMN)
}
else
{
*ppColCfg = nullptr;
*ppColDef = nullptr;
}
return NO_ERROR;
}
APIRET t_DlgAcquire::InsertDeviceTableRow (QTableWidget *pTable, int Row, t_pDeviceList pDeviceList, t_pDevice pDevSrc, t_pDevice pDevDst)
{
t_DlgAcquireTableWidgetItem *pItem;
t_pcCfgColumn pColCfg;
t_pMainWindowColumn pColDef;
QString Remark;
QString Str;
bool Selectable = false;
int Cols;
int Col;
int i;
Cols = CfgGetColumnCount();
// Build header row on 1st call
// ----------------------------
if (Row == 0)
{
for (i=0, Col=0; i<Cols; i++)
if (CfgGetColumn(i)->ShowInCloneTable)
Col++;
pTable->setColumnCount (Col+1); // +1 for column "remark"
for (i=0, Col=0; i<Cols; i++)
{
CHK (DlgAcquireGetCol (i, &pColCfg, &pColDef))
if (pColCfg)
pTable->setHorizontalHeaderItem (Col++, new QTableWidgetItem(t_DeviceListModel::tr(pColCfg->Name)));
}
pTable->setHorizontalHeaderItem (Col, new QTableWidgetItem(t_DeviceListModel::tr("Remark")));
}
// Insert row data
// ---------------
bool InUse = (pDevDst->GetState() != t_Device::Idle ) &&
(pDevDst->GetState() != t_Device::Finished) &&
(pDevDst->GetState() != t_Device::Aborted );
if (pDevDst->Local) Remark = tr("Local device, cannot be written");
else if (pDevDst == pDevSrc) Remark = tr("Device to be cloned");
else if (pDevDst->Size < pDevSrc->Size) Remark = tr("Too small");
else if (InUse) Remark = tr("In use");
else if (pOwn->Duplicate && ((pOwn->pAcquisition1->ImagePath +
pOwn->pAcquisition1->ImageFilename) == pDevDst->LinuxDevice))
Remark = tr("Selected for first acquisition");
else if (pDeviceList->UsedAsCloneDestination(pDevDst)) Remark = tr("Used in another clone operation");
else { Remark = tr("Ok for cloning"); Selectable = true;}
#define ADD_ITEM(Str) \
{ \
pItem = new t_DlgAcquireTableWidgetItem (pDevDst, Str); \
pTable->setItem (Row, Col++, pItem); \
pItem->setFlags (Selectable ? (Qt::ItemIsSelectable | Qt::ItemIsEnabled) : Qt::NoItemFlags); \
}
for (i=0, Col=0; i<Cols; i++)
{
CHK (DlgAcquireGetCol (i, &pColCfg, &pColDef))
if (pColCfg)
ADD_ITEM ((pColDef->pGetDataFn)(pDevDst).toString())
}
ADD_ITEM (Remark);
return NO_ERROR;
}
APIRET t_DlgAcquire::CreateDeviceTable (t_pDeviceList pDeviceList, t_pDevice pDeviceSrc, QTableWidget **ppTable)
{
QTableWidget *pTable;
t_pDevice pDev;
int i=0;
int ColWidth=0;
int ExtraWidth;
int ScreenWidth;
int Width=0;
pTable = new QTableWidget(0, 0, this);
*ppTable = pTable;
pOwn->pDeviceTable = pTable;
QTUTIL_SET_FONT (pTable, FONTOBJECT_TABLE)
pTable->setSelectionBehavior (QAbstractItemView::SelectRows );
pTable->setSelectionMode (QAbstractItemView::SingleSelection);
pTable->setRowCount(pDeviceList->count());
for (i=0; i<pDeviceList->count(); i++)
{
pDev = pDeviceList->at (i);
CHK (InsertDeviceTableRow (pTable, i, pDeviceList, pDeviceSrc, pDev))
}
ExtraWidth = pTable->columnWidth(0); // Somehow, the table widget always gets this value larger when calling setMinimumWidth...
pTable->resizeColumnsToContents();
pTable->resizeRowsToContents ();
pTable->verticalHeader ()->hide ();
// pTable->horizontalHeader()->setClickable (true);
// pTable->horizontalHeader()->setSortIndicatorShown (true);
pTable->setHorizontalScrollMode (QAbstractItemView::ScrollPerPixel);
pTable->setVerticalScrollMode (QAbstractItemView::ScrollPerPixel);
for (i=0; i<pTable->columnCount(); i++)
ColWidth += pTable->columnWidth(i);
ScreenWidth = QApplication::desktop()->availableGeometry().width();
Width = GETMIN ((int)(0.8 * ScreenWidth), ColWidth - ExtraWidth); // Do not use more than 80% of the screen width
pTable->setMinimumWidth (Width);
pTable->setMinimumHeight (130);
CHK_QT (connect (pTable, SIGNAL(itemSelectionChanged ()), this, SLOT(SlotDeviceTableSelectionChanged())))
return NO_ERROR;
}
t_DlgAcquire::t_DlgAcquire ()
{
CHK_EXIT (ERROR_DLGACQUIRE_CONSTRUCTOR_NOT_SUPPORTED)
} //lint !e1401 pOwn not initialised
class t_DlgAcquireLayoutScroller: public QScrollArea // This class makes layouts scrollable.
{
public:
t_DlgAcquireLayoutScroller (QWidget *pParent, QLayout *pLayout)
: QScrollArea (pParent)
{
setFrameStyle (QFrame::NoFrame); // We do not want any frames
setLineWidth (0); // nor margins
setMidLineWidth (0);
setContentsMargins (0,0,0,0);
setWidgetResizable (true); // necessary to have the layout inside the ScrollArea follow the dialog's resizing
QWidget *pWidget = new QWidget (this); // we need an intermediate widget, as QScrollArea only accepts
setWidget (pWidget); // a widget and does ont allow for setting a layout directly
pWidget->setLayout (pLayout); // We then put the layout in the widget
setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff); // Only scroll vertically
}
~t_DlgAcquireLayoutScroller ()
{
}
virtual QSize sizeHint () const
{
QWidget *pWidget;
QLayout *pLayout;
pWidget = widget();
if (pWidget)
{
pLayout = pWidget->layout();
if (pLayout) // Give the layout's minimal size as size hint. So, when putting the whole
return pLayout->minimumSize (); // scroll area in a layout, it should be displayed just big enough to have
} // the scroll bar hidden.
return QScrollArea::sizeHint();
}
virtual QSize minimumSizeHint () const // In hor. direction, the area must never be smaller then
{ // the minimum required by the layout inside (as we do not
return QSize (sizeHint().width(), // want a hor. scrollbar and thus switched it off, see
QScrollArea::minimumSizeHint().height()); // constructor above). Vertically, the default minimum
} // of QScrollArea is used (whatever this might be).
};
// t_DlgAcquire::t_DlgAcquire: Duplicate is false for the 1st acquisition dialog and true for the 2nd one.
t_DlgAcquire::t_DlgAcquire (t_pDevice pDevice, bool Clone, t_pDeviceList pDeviceList, bool Duplicate, QWidget *pParent, Qt::WindowFlags Flags, bool ForceLastEnteredValues, t_pAcquisition pAcquisition1)
:QDialog (pParent, Flags)
{
static bool Initialised = false;
t_pCfgDlgAcquireFields pDlgAcquireFields;
t_pCfgDlgAcquireField pDlgAcquireField;
t_DlgAcquireLayoutScroller *pLayoutScroller;
QVBoxLayout *pTopLayout;
QVBoxLayout *pLayout;
QLabel *pLabel;
QString DefaultFilename;
QString Path;
QString Str, StrAlt;
QString ButtonTextDD;
QString ButtonTextEWF;
QString ButtonTextAFF;
QString Set;
int Row, Col;
int i;
if (!Initialised)
{
Initialised = true;
CHK_EXIT (TOOL_ERROR_REGISTER_CODE (ERROR_DLGACQUIRE_CONSTRUCTOR_NOT_SUPPORTED))
CHK_EXIT (TOOL_ERROR_REGISTER_CODE (ERROR_DLGACQUIRE_UNKNOWN_FILEDIALOG_SIZE))
CHK_EXIT (TOOL_ERROR_REGISTER_CODE (ERROR_DLGACQUIRE_INVALID_ENTRYMODE))
CHK_EXIT (TOOL_ERROR_REGISTER_CODE (ERROR_DLGACQUIRE_INVALID_FORMAT))
CHK_EXIT (TOOL_ERROR_REGISTER_CODE (ERROR_DLGACQUIRE_INVALID_SELECTION))
CHK_EXIT (TOOL_ERROR_REGISTER_CODE (ERROR_DLGACQUIRE_UNKNOWN_COLUMN))
pDlgAcquireField = DlgAcquireGetField (CFG_DLGACQUIRE_SPLITFILEUNIT); // This initialisation needs to be done only once, as the user writes text (MiB, GiB, ...)
pDlgAcquireField->DefaultValue = QString::number (UnitStringToIndex(pDlgAcquireField->DefaultValue)); // in the configuration file, but we internally work with the ComboBox index numbers
}
QTUTIL_SET_FONT (this, FONTOBJECT_ACQUISITION_DIALOGS)
if (!Duplicate && !Clone) setWindowTitle (tr ("Acquire image of %1" , "Dialog title, %1 is the device (for instance /dev/hdc)") .arg(pDevice->LinuxDevice));
else if (!Duplicate && Clone) setWindowTitle (tr ("Clone %1" , "Dialog title, %1 is the device (for instance /dev/hdc)") .arg(pDevice->LinuxDevice));
else if ( Duplicate && !Clone) setWindowTitle (tr ("Duplicate image of %1", "Dialog title, %1 is the device (for instance /dev/hdc)") .arg(pDevice->LinuxDevice));
else /*( Duplicate && Clone) */ setWindowTitle (tr ("Duplicate Clone %1" , "Dialog title, %1 is the device (for instance /dev/hdc)") .arg(pDevice->LinuxDevice));
pOwn = new t_DlgAcquireLocal;
pOwn->pDevice = pDevice;
pOwn->Clone = Clone;
pOwn->pDeviceTable = nullptr;
pOwn->Duplicate = Duplicate;
pOwn->pAcquisition1 = pAcquisition1;
pOwn->pDeviceList = pDeviceList;
// Organisation of the whole dialog
// Dialog
// TopLayout
// ScrollArea - t_DlgAcquireLayoutScroller
// Widget - see t_DlgAcquireLayoutScroller
// Layout - see t_DlgAcquireLayoutScroller
// LayoutButtons
pTopLayout = new QVBoxLayout(this);
pTopLayout->setSpacing(0); // We do not want extra margins everywhere (see t_DlgAcquireScrollArea as well)
pTopLayout->setMargin (0);
pLayout = new QVBoxLayout();
pLayout->setSizeConstraint (QLayout::SetMinAndMaxSize);
pLayoutScroller = new t_DlgAcquireLayoutScroller (this, pLayout);
pTopLayout->addWidget(pLayoutScroller);
CHK_EXIT (CfgGetDlgAcquireFields (&pDlgAcquireFields))
if (Duplicate)
pLayout->addWidget (new QLabel(("<b><font color=\"blue\"><center>" + tr("Duplicate image settings") + "</center></font></b>"), this));
if (!Clone)
{
// Format box (with EWF fields)
// ----------------------------
QGroupBox *pGroupBoxFormat = new QGroupBox (tr("File format"), this);
QVBoxLayout *pLayoutGroupBox = new QVBoxLayout;
QHBoxLayout *pLayoutFormatSplit = new QHBoxLayout;
QGridLayout *pLayoutFormat = new QGridLayout;
QGridLayout *pLayoutSplit = new QGridLayout;
QGridLayout *pLayoutEwf = new QGridLayout;
QFrame *pSeparator = new QFrame(this); // vertical separator line between format and split fields
pSeparator->setFrameShape (QFrame::VLine);
pLayout ->addWidget (pGroupBoxFormat);
pGroupBoxFormat ->setLayout (pLayoutGroupBox);
pLayoutGroupBox ->addLayout (pLayoutFormatSplit);
pLayoutFormatSplit->addLayout (pLayoutFormat);
pLayoutFormatSplit->addWidget (pSeparator);
pLayoutFormatSplit->addLayout (pLayoutSplit);
pLayoutGroupBox ->addLayout (pLayoutEwf);
CHK_EXIT (t_File::GetFormatDescription (t_File::DD , false, 0, Str)) ButtonTextDD = "&" + Str;
CHK_EXIT (t_File::GetFormatDescription (t_File::EWF , false, 0, Str)) ButtonTextEWF = "&" + Str;
CHK_EXIT (t_File::GetFormatDescription (t_File::AAFF, false, 0, Str)) ButtonTextAFF = "&" + Str;
CHK_EXIT (t_File::GetFormatExtension (t_File::DD , false, 0, nullptr, &Str))
CHK_EXIT (t_File::GetFormatExtension (t_File::DD , false, 3, nullptr, &StrAlt)) ButtonTextDD += " " + tr("(file extension %1 or %2)") .arg (Str) .arg (StrAlt);
CHK_EXIT (t_File::GetFormatExtension (t_File::EWF , false, 0, nullptr, &Str)) ButtonTextEWF+= " " + tr("(file extension %1)") .arg (Str);
CHK_EXIT (t_File::GetFormatExtension (t_File::AAFF, false, 0, nullptr, &Str)) ButtonTextAFF+= " " + tr("(file extension %1)") .arg (Str);
pOwn->pRadioButtonFormatDD = new QRadioButton (ButtonTextDD , this);
pOwn->pRadioButtonFormatEWF = new QRadioButton (ButtonTextEWF, this);
pOwn->pRadioButtonFormatAFF = new QRadioButton (ButtonTextAFF, this);
pLayoutFormat->addWidget (pOwn->pRadioButtonFormatDD );
pLayoutFormat->addWidget (pOwn->pRadioButtonFormatEWF);
if (CONFIG(AffEnabled))
{
pLayoutFormat->addWidget (pOwn->pRadioButtonFormatAFF);
}
else
{
pOwn->pRadioButtonFormatAFF->hide();
pOwn->pRadioButtonFormatAFF->setEnabled(false);
pOwn->pRadioButtonFormatAFF->setChecked(false);
}
if (Duplicate)
{
pOwn->pRadioButtonFormatDD ->setEnabled(false);
pOwn->pRadioButtonFormatEWF->setEnabled(false);
pOwn->pRadioButtonFormatAFF->setEnabled(false);
}
// Split file controls
// -------------------
t_pCfgDlgAcquireField pFieldSplitFileSwitch = DlgAcquireGetField ("SplitFileSwitch");
t_pCfgDlgAcquireField pFieldSplitFileSize = DlgAcquireGetField ("SplitFileSize" );
t_pCfgDlgAcquireField pFieldSplitFileUnit = DlgAcquireGetField ("SplitFileUnit" );
if ((EntryMode(pFieldSplitFileSwitch) == CFG_ENTRYMODE_HIDE) &&
(EntryMode(pFieldSplitFileSize ) == CFG_ENTRYMODE_HIDE) &&
(EntryMode(pFieldSplitFileUnit ) == CFG_ENTRYMODE_HIDE))
pSeparator->hide();
Row = 0;
Col = 1;
CHK_EXIT (AddField (pDevice, pFieldSplitFileSwitch, pLayoutSplit, &Row, &Col, ForceLastEnteredValues))
CHK_EXIT (AddField (pDevice, pFieldSplitFileSize , pLayoutSplit, &Row, &Col, ForceLastEnteredValues))
CHK_EXIT (AddField (pDevice, pFieldSplitFileUnit , pLayoutSplit, &Row, &Col, ForceLastEnteredValues))
pOwn->OldSplitFileSwitch = pFieldSplitFileSwitch->pCheckBox->isChecked();
if (Duplicate)
{
pFieldSplitFileSwitch->pCheckBox->setEnabled(false);
pFieldSplitFileSize ->pLineEdit->setEnabled(false);
pFieldSplitFileUnit ->pComboBox->setEnabled(false);
}
Row = Col = 0;
for (i=0; i<pDlgAcquireFields->count(); i++)
{
pDlgAcquireField = pDlgAcquireFields->at(i);
if (pDlgAcquireField->EwfField)
CHK_EXIT (AddField (pDevice, pDlgAcquireField, pLayoutEwf, &Row, &Col, ForceLastEnteredValues))
}
pLayoutEwf->setColumnMinimumWidth (0, 20);
}
// Other Fields (Userfield)
// ------------------------
QGridLayout *pLayoutOther = new QGridLayout ();
pLayout->addLayout (pLayoutOther);
Row = Col = 0;
CHK_EXIT (AddField (pDevice, DlgAcquireGetField(CFG_DLGACQUIRE_USERFIELD), pLayoutOther, &Row, &Col, ForceLastEnteredValues))
// Destination box
// ---------------
QGroupBox *pGroupBoxDest = new QGroupBox(tr("Destination"), this);
QGridLayout *pLayoutDest = new QGridLayout ();
pGroupBoxDest->setLayout (pLayoutDest);
pLayout->addWidget (pGroupBoxDest);
Row = Col = 0;
if (Clone)
{
CHK_EXIT (CreateDeviceTable (pDeviceList, pDevice, &pOwn->pDeviceTable))
pLayoutDest->addWidget (pOwn->pDeviceTable, Row++, 0, 1, 3);
}
if (CONFIG(WriteToDevNull))
{
pLabel = new QLabel(QString("<font color='red'>") + tr("Configuration flag WriteToDevNull is set!") + "</font>", this);
pLayoutDest->addWidget (pLabel, Row++, 0, 1, 3);
}
//lint -restore
for (i=0; i<pDlgAcquireFields->count(); i++)
{
pDlgAcquireField = pDlgAcquireFields->at(i);
if (pDlgAcquireField->DstField)
CHK_EXIT (AddField (pDevice, pDlgAcquireField, pLayoutDest, &Row, &Col, ForceLastEnteredValues))
}
// Hash box
// --------
Row = Col = 0;
QGroupBox *pGroupBoxHash = new QGroupBox(tr("Hash calculation / verification"), this);
QGridLayout *pLayoutHash = new QGridLayout ();
pGroupBoxHash->setLayout (pLayoutHash);
pLayout->addWidget (pGroupBoxHash);
for (i=0; i<pDlgAcquireFields->count(); i++)
{
pDlgAcquireField = pDlgAcquireFields->at(i);
if (pDlgAcquireField->HashField)
{
CHK_EXIT (AddField (pDevice, pDlgAcquireField, pLayoutHash, &Row, &Col, ForceLastEnteredValues))
if (pDlgAcquireField->FieldName.startsWith (CFG_DLGACQUIRE_HASHCALC_FIELDID))
CHK_QT_EXIT (connect (pDlgAcquireField->pCheckBox, SIGNAL (stateChanged(int)), this, SLOT(UpdateHashState(int))))
if (Duplicate && (pDlgAcquireField->FieldName.startsWith(CFG_DLGACQUIRE_HASHCALC_FIELDID)))
pDlgAcquireField->pCheckBox->setEnabled(false); // Thas hash calculation fields may not be changed in the duplicate dialog
}
}
// Dialog buttons
// --------------
QHBoxLayout *pLayoutButtons = new QHBoxLayout (); // The new layout would normally use the margin of its parent layout
pLayoutButtons->setMargin (pLayout->margin ()); // (TopLayout), but those have been set to set zero. Instead, we tell
pLayoutButtons->setSpacing (pLayout->spacing()); // the button layout top use the same margins as the main layout in
pTopLayout->addLayout (pLayoutButtons); // order to have everything appear nicely and the same way on the screen).
#ifdef OLD_BUTTON_POSITIONING
#define ADD_BUTTON(pButton, Text) \
{ \
pButton = new QPushButton (Text, this); \
pLayoutButtons->addWidget (pButton); \
}
ADD_BUTTON (pOwn->pButtonOk, QObject::tr("Ok"))
pOwn->pButtonDuplicate = nullptr;
pOwn->pButtonBack = nullptr;
if (Duplicate)
ADD_BUTTON (pOwn->pButtonBack, tr("Back..."))
else if (CONFIG(DuplicateImage))
ADD_BUTTON (pOwn->pButtonDuplicate , tr("Duplicate image..."))
ADD_BUTTON (pOwn->pButtonCancel, QObject::tr("Cancel"))
#undef ADD_BUTTON
#endif
#define ADD_BUTTON(pButton, Text) \
{ \
pButton = new QPushButton (Text, this); \
pLayoutButtons->addWidget (pButton, 2); \
}
pOwn->pButtonDuplicate = nullptr;
pOwn->pButtonBack = nullptr;
ADD_BUTTON (pOwn->pButtonCancel, QObject::tr("Cancel"))
pLayoutButtons->addStretch(1);
if (CONFIG(DuplicateImage))
{
if (Duplicate)
ADD_BUTTON (pOwn->pButtonBack , tr("Back..."))
else ADD_BUTTON (pOwn->pButtonDuplicate , tr("Duplicate image..."))
}
ADD_BUTTON (pOwn->pButtonOk, QObject::tr("Start"))
pOwn->pButtonOk->setDefault (true);
// Set other defaults
// ------------------
if (!Clone)
{
if (DlgAcquireLastUsedFormat == t_File::NotSet)
DlgAcquireLastUsedFormat = (t_File::Format) CONFIG (DefaultFormat);
switch (DlgAcquireLastUsedFormat)
{
case t_File::DD : pOwn->pRadioButtonFormatDD ->setChecked (true); break;
case t_File::EWF : pOwn->pRadioButtonFormatEWF->setChecked (true); break;
case t_File::AAFF: pOwn->pRadioButtonFormatAFF->setChecked (true); break;
default : CHK_EXIT (ERROR_DLGACQUIRE_INVALID_FORMAT)
}
}
UpdateHashState ();
UpdateDialogState();
// Adjust size
// -----------
// Qt limits dialogs to 2/3 of the screen height and width. That's why we adjust it with
// the following code if the dialog is smaller then its size hint.
adjustSize(); // Let Qt calculate the size (limited to 2/3 of the screen)
QRect DialogRect = geometry ();
if (DialogRect.height() < sizeHint().height())
{
QDesktopWidget *pDesktop;
pDesktop = QApplication::desktop();
QRect ScreenRect = pDesktop->screenGeometry(pDesktop->screenNumber(this));
int NewHeight = GETMIN (ScreenRect.height()*0.9, sizeHint().height());
DialogRect.setX ((ScreenRect.width () - DialogRect.width())/2);
DialogRect.setY ((ScreenRect.height() - NewHeight )/2);
DialogRect.setHeight (NewHeight); // Must be done after setY!
setGeometry(DialogRect);
}
// Connections
// -----------
if (!Clone)
{
CHK_QT_EXIT (connect (pOwn->pRadioButtonFormatDD , SIGNAL (released()), this, SLOT(UpdateFieldState())))
CHK_QT_EXIT (connect (pOwn->pRadioButtonFormatEWF, SIGNAL (released()), this, SLOT(UpdateFieldState())))
CHK_QT_EXIT (connect (pOwn->pRadioButtonFormatAFF, SIGNAL (released()), this, SLOT(UpdateFieldState())))
CHK_QT_EXIT (connect (DlgAcquireGetField ("SplitFileSwitch")->pCheckBox, SIGNAL (released()), this, SLOT(UpdateFileSplitState())))
UpdateFieldState();
}
CHK_QT_EXIT (connect (pOwn->pButtonOk , SIGNAL (released()), this, SLOT(SlotOk ())))
CHK_QT_EXIT (connect (pOwn->pButtonCancel, SIGNAL (released()), this, SLOT(SlotCancel())))
if (pOwn->pButtonDuplicate) CHK_QT_EXIT (connect (pOwn->pButtonDuplicate, SIGNAL (released()), this, SLOT(SlotDuplicate())))
if (pOwn->pButtonBack) CHK_QT_EXIT (connect (pOwn->pButtonBack , SIGNAL (released()), this, SLOT(SlotBack ())))
}
void t_DlgAcquire::UpdateHashState (int /*State*/)
{
t_pCfgDlgAcquireFields pDlgAcquireFields;
t_pCfgDlgAcquireField pDlgAcquireField;
bool Hash = false;
int i;
CHK_EXIT (CfgGetDlgAcquireFields (&pDlgAcquireFields))
for (i=0; i<pDlgAcquireFields->count(); i++)
{
pDlgAcquireField = pDlgAcquireFields->at(i);
if (pDlgAcquireField->FieldName.startsWith (CFG_DLGACQUIRE_HASHCALC_FIELDID))
Hash = Hash || pDlgAcquireField->pCheckBox->isChecked();
}
for (i=0; i<pDlgAcquireFields->count(); i++)
{
pDlgAcquireField = pDlgAcquireFields->at(i);
if (pDlgAcquireField->FieldName.startsWith (CFG_DLGACQUIRE_HASHVERIFY_FIELDID))
{
if (!Hash)
pDlgAcquireField->pCheckBox->setChecked (false);
if (pDlgAcquireField->FieldName == CFG_DLGACQUIRE_HASH_VERIFY_DST) // The VerifyDest flag may be changed by the user in the duplicate
pDlgAcquireField->pCheckBox->setEnabled (Hash); // acquisition dialog, the VerifySrc flag not.
else pDlgAcquireField->pCheckBox->setEnabled (Hash && !pOwn->Duplicate);
}
}
}
void t_DlgAcquire::UpdateDialogState (const QString & /*NewText*/)
{
t_pCfgDlgAcquireFields pFields;
t_pCfgDlgAcquireField pField;
bool Enabled=true;
int i;
CHK_EXIT (CfgGetDlgAcquireFields (&pFields))
for (i=0; i<pFields->count() && Enabled; i++)
{
pField = pFields->at(i);
if (pField->DstField)
Enabled = Enabled && !pField->pLineEdit->text().isEmpty();
}
pOwn->pButtonOk->setEnabled (Enabled);
if (pOwn->pButtonDuplicate)
pOwn->pButtonDuplicate->setEnabled (Enabled);
}
void t_DlgAcquire::SlotDeviceTableSelectionChanged (void)
{
t_pDlgAcquireLineEdit pLineEditDirectory;
t_pDlgAcquireLineEdit pLineEditFilename;
t_DlgAcquireTableWidgetItem *pItem;
QList<QTableWidgetItem*> SelectedItemsList = pOwn->pDeviceTable->selectedItems();
QFileInfo FileInfo;
int Row;
int Selected;
QString Directory;
pLineEditDirectory = DlgAcquireGetField (CFG_DLGACQUIRE_DEST_IMAGEDIRECTORY)->pLineEdit;
pLineEditFilename = DlgAcquireGetField (CFG_DLGACQUIRE_DEST_IMAGEFILENAME )->pLineEdit;
Selected = SelectedItemsList.count();
if (Selected == 0)
{
pLineEditDirectory->setText (QString());
pLineEditFilename ->setText (QString());
}
else
{
if (Selected != pOwn->pDeviceTable->columnCount()) // every single item is selected and thus, selected must correspond to the number of columns
{
LOG_ERROR ("Clone dialog selection: %d / %d", Selected, pOwn->pDeviceTable->columnCount())
CHK_EXIT (ERROR_DLGACQUIRE_INVALID_SELECTION)
}
Row = SelectedItemsList[0]->row();
pItem = dynamic_cast<t_DlgAcquireTableWidgetItem *>(pOwn->pDeviceTable->item (Row, 0)); // Any field contains a pointer to the Device, so simply take the 1st one
FileInfo.setFile (pItem->GetpDevice()->LinuxDevice);
Directory = FileInfo.dir().absolutePath();
if (!Directory.endsWith ("/"))
Directory += "/";
pLineEditDirectory->setText (Directory);
pLineEditFilename ->setText (FileInfo.fileName());
}
// No need to call UpdateDialogState, as the LineEdit widget will emit a textChanged signal which is connected to UpdateDialogState.
}
void t_DlgAcquire::UpdateFieldState (void)
{
QWidget *pWidget;
bool Enabled;
int i;
// EWF fields
// ----------
Enabled = pOwn->pRadioButtonFormatEWF->isChecked() ||
pOwn->pRadioButtonFormatAFF->isChecked() ||