File: infofield.cpp

package info (click to toggle)
guymager 0.6.7-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,500 kB
  • sloc: cpp: 13,963; makefile: 50; sh: 17
file content (191 lines) | stat: -rw-r--r-- 6,932 bytes parent folder | download
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
// ****************************************************************************
//  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 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/>.

#include <QtGui>

#include "toolconstants.h"

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

class t_InfoFieldLocal
{
   public:
      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)
   :QFrame (pParent)
{
   QString LabelParams;
   
   CHK_EXIT (TOOL_ERROR_REGISTER_CODE (ERROR_INFOFIELD_CONSTRUCTOR_NOT_SUPPORTED))

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

   QHBoxLayout *pLayout = new QHBoxLayout (this);
   pOwn->pLabelParams = new QLabel (this);
   pOwn->pLabelValues = new QLabel (this);
   pLayout->addWidget (pOwn->pLabelParams);
   pLayout->addWidget (pOwn->pLabelValues);
   pLayout->addStretch();
   
   if (CONFIG (CommandGetAddStateInfo)[0])
      LabelParams = tr("Additional state info") + "\n";
      
   LabelParams +=       tr("Size")
               + "\n" + tr("Sector size")
               + "\n" + tr("Image file")
               + "\n" + tr("Info file")
               + "\n" + tr("Current speed")
               + "\n" + tr("Started", "Start timestamp and running time")
               + "\n" + tr("Hash calculation")
               + "\n" + tr("Source verification")
               + "\n" + tr("Image verification");
   pOwn->pLabelParams->setText (LabelParams);
}

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

void t_InfoField::SlotShowInfo (t_pDevice pDevice)
{
   QString StrValue, StrSpeed, Format;
   quint64 Size;

   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
      // ---------------
      if (pDevice->Acquisition.Format == t_File::NotSet)
      {
         StrValue += "\n\n";
      }
      else
      {
         CHK_EXIT (t_File::GetFormatExtension   (pDevice->Acquisition.Format, pDevice->Acquisition.Clone, 0, NULL, &Format))
         StrValue += "\n" + pDevice->Acquisition.ImagePath + pDevice->Acquisition.ImageFilename + QSTR_TO_PSZ(Format);
         StrValue += "\n" + pDevice->Acquisition.InfoPath  + pDevice->Acquisition.InfoFilename  + t_File::pExtensionInfo;
      }

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

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

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

         if ((pDevice->State == t_Device::Acquire      ) ||  // Don't display anything if no acquisition is running
             (pDevice->State == t_Device::AcquirePaused) ||
             (pDevice->State == t_Device::Verify       ) ||
             (pDevice->State == 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())
      {   
         if     ((pDevice->Acquisition.CalcMD5) &&
                 (pDevice->Acquisition.CalcSHA256)) StrValue += tr("MD5 and SHA-256" , "Both hashes are calculated");
         else if (pDevice->Acquisition.CalcMD5)     StrValue += tr("MD5"    );
         else if (pDevice->Acquisition.CalcSHA256)  StrValue += tr("SHA-256");
         else                                       StrValue += tr("off", "Hash calculation is off");
      }
      // Source verification
      // -------------------
      StrValue += "\n";
      if (!pDevice->StartTimestamp.isNull())
      {   
         if (pDevice->Acquisition.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->Acquisition.VerifyDst)
              StrValue += tr("on" , "Display that verification is on");
         else StrValue += tr("off", "Display that verification is off");
      }
}
   pOwn->pLabelValues->setText (StrValue);
}