File: infofield.cpp

package info (click to toggle)
guymager 0.8.13-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,764 kB
  • sloc: cpp: 17,479; makefile: 30; sh: 22
file content (241 lines) | stat: -rw-r--r-- 9,964 bytes parent folder | download | duplicates (2)
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
// ****************************************************************************
//  Project:        GUYMAGER
// ****************************************************************************
//  Programmer:     Guy Voncken
//                  Police Grand-Ducale
//                  Service de Police Judiciaire
//                  Section Nouvelles Technologies
// ****************************************************************************
//  Module:         The info field area
// ****************************************************************************

// 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 "toolconstants.h"

#include "common.h"
#include "main.h"
#include "config.h"
#include "qtutil.h"
#include "infofield.h"

class t_InfoFieldLocal
{
   public:
      t_pDeviceList pDeviceList;
      QLabel       *pLabelParams;
      QLabel       *pLabelValues;
};

t_InfoField::t_InfoField ()
{
   CHK_EXIT (ERROR_INFOFIELD_CONSTRUCTOR_NOT_SUPPORTED)
} //lint !e1401 not initialised

t_InfoField::t_InfoField (QWidget *pParent, t_pDeviceList pDeviceList)
   :QFrame (pParent)
{
   CHK_EXIT (TOOL_ERROR_REGISTER_CODE (ERROR_INFOFIELD_CONSTRUCTOR_NOT_SUPPORTED))

   setFrameStyle ((int)QFrame::Panel | (int)QFrame::Sunken);
   pOwn = new t_InfoFieldLocal;
   pOwn->pDeviceList = pDeviceList;

   QHBoxLayout *pLayout = new QHBoxLayout (this);
   pOwn->pLabelValues = new QLabel (this);
   pOwn->pLabelParams = new QLabel (this);
   QTUTIL_SET_FONT (pOwn->pLabelValues, FONTOBJECT_INFOFIELD)
   QTUTIL_SET_FONT (pOwn->pLabelParams, FONTOBJECT_INFOFIELD)
   pLayout->addWidget (pOwn->pLabelParams);
   pLayout->addWidget (pOwn->pLabelValues);
   pLayout->addStretch();
}

t_InfoField::~t_InfoField ()
{
   delete pOwn->pLabelParams;
   delete pOwn->pLabelValues;
   delete pOwn;
}

QString t_InfoField::GetHashText (bool MD5, bool SHA1, bool SHA256)
{
   QString Str;

   if      (!MD5 && !SHA1 && !SHA256) Str = t_InfoField::tr("off"          , "Hash calculation is off");
   else if (!MD5 && !SHA1 &&  SHA256) Str = t_InfoField::tr("%1"           , "Show which hash values are in use, % value wll be replaced by MD5, SHA-1, ...") .arg("SHA-256");
   else if (!MD5 &&  SHA1 && !SHA256) Str = t_InfoField::tr("%1"           , "Show which hash values are in use, % value wll be replaced by MD5, SHA-1, ...") .arg("SHA-1");
   else if (!MD5 &&  SHA1 &&  SHA256) Str = t_InfoField::tr("%1 and %2"    , "Show which hash values are in use, % value wll be replaced by MD5, SHA-1, ...") .arg("SHA-1") .arg("SHA-256");
   else if ( MD5 && !SHA1 && !SHA256) Str = t_InfoField::tr("%1"           , "Show which hash values are in use, % value wll be replaced by MD5, SHA-1, ...") .arg("MD5");
   else if ( MD5 && !SHA1 &&  SHA256) Str = t_InfoField::tr("%1 and %2"    , "Show which hash values are in use, % value wll be replaced by MD5, SHA-1, ...") .arg("MD5") .arg("SHA-256");
   else if ( MD5 &&  SHA1 && !SHA256) Str = t_InfoField::tr("%1 and %2"    , "Show which hash values are in use, % value wll be replaced by MD5, SHA-1, ...") .arg("MD5") .arg("SHA-1");
   else                               Str = t_InfoField::tr("%1, %2 and %3", "Show which hash values are in use, % value wll be replaced by MD5, SHA-1, ...") .arg("MD5") .arg("SHA-1") .arg("SHA-256");
   return Str;
}

void t_InfoField::SlotShowInfo (t_pDevice pDevice)
{
   QString StrValue, StrSpeed, Format;
   quint64 Size;
   QString LabelParams;
   bool    DuplicateImage=false;

   if (pDevice)
      if (pDevice->Duplicate)
         DuplicateImage = true;

   if (CONFIG (CommandGetAddStateInfo)[0])
      LabelParams = tr("Additional state info") + "\n";

   LabelParams +=        tr("Size")
               +  "\n" + tr("Sector size")
               +  "\n" + tr("Image file");  if (DuplicateImage) LabelParams += "\n";
   LabelParams += "\n" + tr("Info file" );  if (DuplicateImage) LabelParams += "\n";
   LabelParams += "\n" + tr("Current speed")
               +  "\n" + tr("Started", "Start timestamp and running time")
               +  "\n" + tr("Hash calculation")
               +  "\n" + tr("Source verification")
               +  "\n" + tr("Image verification")
               +  "\n" + tr("Overall speed (all acquisitions)");
   pOwn->pLabelParams->setText (LabelParams);

   if (pDevice)
   {
      // Additional state info
      // ---------------------
      if (CONFIG (CommandGetAddStateInfo)[0])
         StrValue = pDevice->AddStateInfo.Info + "\n";

      // Size
      // ----
      Size = t_Device::GetSize (pDevice).toULongLong();
      StrValue += MainGetpNumberLocale()->toString(Size) + " " + tr("bytes");
      StrValue += " ("  + t_Device::GetSizeHumanFrac (pDevice, false).toString();
      StrValue += " / " + t_Device::GetSizeHumanFrac (pDevice, true ).toString() + ")";

      // Sector size
      // -----------
      quint64 SectorSize     = t_Device::GetSectorSize    (pDevice).toULongLong();
      quint64 SectorSizePhys = t_Device::GetSectorSizePhys(pDevice).toULongLong();
      StrValue += "\n" + MainGetpNumberLocale()->toString(SectorSize);
      if (SectorSize != SectorSizePhys)
         StrValue += " / " + MainGetpNumberLocale()->toString(SectorSizePhys);

      // Image/Info file
      // ---------------
      QString ImagePaths;
      QString InfoPaths;

      if (pDevice->Acquisition1.Format != t_File::NotSet)
      {
         CHK_EXIT (t_File::GetFormatExtension   (pDevice->Acquisition1.Format, pDevice->Acquisition1.Clone, 0, nullptr, &Format))
         ImagePaths = pDevice->Acquisition1.ImagePath + pDevice->Acquisition1.ImageFilename + QSTR_TO_PSZ(Format);
         InfoPaths  = pDevice->Acquisition1.InfoPath  + pDevice->Acquisition1.InfoFilename  + t_File::pExtensionInfo;
         if (DuplicateImage)
         {
            ImagePaths += "\n" + pDevice->Acquisition2.ImagePath + pDevice->Acquisition2.ImageFilename + QSTR_TO_PSZ(Format);
            InfoPaths  += "\n" + pDevice->Acquisition2.InfoPath  + pDevice->Acquisition2.InfoFilename  + t_File::pExtensionInfo;
         }
      }
      StrValue += "\n" + ImagePaths;
      StrValue += "\n" + InfoPaths;

      // Speed
      // -----
      StrSpeed = t_Device::GetCurrentSpeed  (pDevice).toString();
      if (!StrSpeed.isEmpty())
         StrSpeed += " MB/s";
      StrValue += "\n" + StrSpeed;

      // Running time
      // ------------
      if (pDevice->Acquisition1.Format == t_File::NotSet)
      {
         StrValue += "\n";
      }
      else
      {
         int Hours, Minutes, Seconds;

         StrValue += "\n" + pDevice->StartTimestamp.toString ("d. MMMM hh:mm:ss");

         if ((pDevice->GetState() == t_Device::Acquire      ) ||  // Don't display anything if no acquisition is running
             (pDevice->GetState() == t_Device::AcquirePaused) ||
             (pDevice->GetState() == t_Device::Launch       ) ||
             (pDevice->GetState() == t_Device::LaunchPaused ) ||
             (pDevice->GetState() == t_Device::Verify       ) ||
             (pDevice->GetState() == t_Device::VerifyPaused ))
              Seconds = pDevice->StartTimestamp.secsTo (QDateTime::currentDateTime());
         else Seconds = pDevice->StartTimestamp.secsTo (pDevice->StopTimestamp);
         Hours    = Seconds / SECONDS_PER_HOUR  ; Seconds -= Hours   * SECONDS_PER_HOUR;
         Minutes  = Seconds / SECONDS_PER_MINUTE; Seconds -= Minutes * SECONDS_PER_MINUTE;

         StrValue += QString(" (%1:%2:%3)") .arg(Hours,2,10,QChar('0')) .arg(Minutes,2,10,QChar('0')) .arg(Seconds,2,10,QChar('0'));
      }

      // Hash
      // ----
      StrValue += "\n";
      if (!pDevice->StartTimestamp.isNull())
         StrValue += t_InfoField::GetHashText (pDevice->Acquisition1.CalcMD5,
                                               pDevice->Acquisition1.CalcSHA1,
                                               pDevice->Acquisition1.CalcSHA256);
      // Source verification
      // -------------------
      StrValue += "\n";
      if (!pDevice->StartTimestamp.isNull())
      {
         if (pDevice->Acquisition1.VerifySrc)
              StrValue += tr("on" , "Display that verification is on");
         else StrValue += tr("off", "Display that verification is off");
      }
      // Image verification
      // ------------------
      StrValue += "\n";
      if (!pDevice->StartTimestamp.isNull())
      {
         if (pDevice->Acquisition1.VerifyDst)
              StrValue += tr("on" , "Display that verification is on");
         else StrValue += tr("off", "Display that verification is off");
         if (DuplicateImage)
         {
            StrValue += " | ";
            if (pDevice->Acquisition2.VerifyDst)
                 StrValue += tr("on" , "Display that verification is on");
            else StrValue += tr("off", "Display that verification is off");
         }
      }

      // Overall acquisition speed
      // -------------------------
      StrValue += "\n";
      QString Speed = pOwn->pDeviceList->GetOverallAcquisitionSpeed();
      if (!Speed.isNull())
         StrValue += Speed + " MB/s";
   }
   pOwn->pLabelValues->setText (StrValue);
}