• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • controllers
  • view
  • checksum
checksumtool.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Kasten module, made within the KDE community.
3 
4  Copyright 2009 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 // QCA
24 // need to have this first, as QCA needs QT_NO_CAST_FROM_ASCII disabled when included
25 #include <config-qca2.h> //krazy:excludeall=includes
26 #ifdef HAVE_QCA2
27 // disable QT_NO_CAST_FROM_ASCII
28 #ifdef QT_NO_CAST_FROM_ASCII
29 #undef QT_NO_CAST_FROM_ASCII
30 #endif
31 #include <QtCrypto>
32 #endif
33 
34 #include "checksumtool.h"
35 
36 // lib
37 #include "checksumcalculatejob.h"
38 //
39 #include <bytearraychecksumalgorithmfactory.h>
40 #include <abstractbytearraychecksumalgorithm.h>
41 //
42 #include <bytearrayview.h>
43 #include <bytearraydocument.h>
44 // Okteta core
45 #include <abstractbytearraymodel.h>
46 // KDE
47 #include <KLocale>
48 // Qt
49 #include <QtGui/QApplication>
50 
51 #include <KDebug>
52 
53 
54 namespace Kasten2
55 {
56 
57 ChecksumTool::ChecksumTool()
58  : AbstractTool(),
59  mChecksumUptodate( false ),
60  mSourceByteArrayModelUptodate( false ),
61  mAlgorithmId( 0 ),
62  mByteArrayView( 0 ), mByteArrayModel( 0 ),
63  mSourceAlgorithmId( -1 ),
64  mSourceByteArrayModel( 0 )
65 {
66  setObjectName( QLatin1String( "Checksum" ) );
67 
68 // TODO: find a better place to do and store the initialization
69 #ifdef HAVE_QCA2
70  mQcaInitializer = new QCA::Initializer( QCA::Practical, 64 );
71 kDebug()<< QCA::supportedFeatures();//Hash::supportedTypes();
72 #endif
73 
74  mAlgorithmList = ByteArrayChecksumAlgorithmFactory::createAlgorithms();
75 }
76 
77 QList<AbstractByteArrayChecksumAlgorithm*> ChecksumTool::algorithmList() const { return mAlgorithmList; }
78 
79 bool ChecksumTool::isApplyable() const
80 {
81  return ( mByteArrayModel && mByteArrayView && mByteArrayView->hasSelectedData() );
82 }
83 
84 
85 QString ChecksumTool::title() const { return i18nc("@title:window of the tool to calculate checksums", "Checksum"); }
86 
87 
88 AbstractByteArrayChecksumParameterSet* ChecksumTool::parameterSet()
89 {
90  AbstractByteArrayChecksumAlgorithm* algorithm = mAlgorithmList.at( mAlgorithmId );
91 
92  return algorithm ? algorithm->parameterSet() : 0;
93 }
94 
95 void ChecksumTool::setTargetModel( AbstractModel* model )
96 {
97  if( mByteArrayView ) mByteArrayView->disconnect( this );
98 
99  mByteArrayView = model ? model->findBaseModel<ByteArrayView*>() : 0;
100 
101  ByteArrayDocument* document =
102  mByteArrayView ? qobject_cast<ByteArrayDocument*>( mByteArrayView->baseModel() ) : 0;
103  mByteArrayModel = document ? document->content() : 0;
104 
105  if( mByteArrayView && mByteArrayModel )
106  {
107  connect( mByteArrayView, SIGNAL(selectedDataChanged(const Kasten2::AbstractModelSelection*)),
108  SLOT(onSelectionChanged()) );
109  }
110 
111  // TODO: if there is no view, there is nothing calculate a checksum from
112  // or this could be the view where we did the checksum from and it did not change
113  checkUptoDate();
114  emit uptodateChanged( mChecksumUptodate );
115  emit isApplyableChanged( isApplyable() );
116 }
117 
118 
119 void ChecksumTool::checkUptoDate()
120 {
121  mChecksumUptodate =
122  ( mSourceByteArrayModel == mByteArrayModel
123  && mByteArrayView && mSourceSelection == mByteArrayView->selection()
124  && mSourceAlgorithmId == mAlgorithmId
125  && mSourceByteArrayModelUptodate );
126 }
127 
128 
129 void ChecksumTool::calculateChecksum()
130 {
131  AbstractByteArrayChecksumAlgorithm* algorithm = mAlgorithmList.at( mAlgorithmId );
132 
133  if( algorithm )
134  {
135  // forget old string source
136  if( mSourceByteArrayModel ) mSourceByteArrayModel->disconnect( this );
137 
138  QApplication::setOverrideCursor( Qt::WaitCursor );
139 
140  ChecksumCalculateJob* checksumCalculateJob =
141  new ChecksumCalculateJob( &mCheckSum, algorithm, mByteArrayModel, mByteArrayView->selection() );
142  checksumCalculateJob->exec();
143 
144  QApplication::restoreOverrideCursor();
145 
146  // remember checksum source
147  mSourceAlgorithmId = mAlgorithmId;
148  mSourceByteArrayModel = mByteArrayModel;
149  mSourceSelection = mByteArrayView->selection();
150  connect( mSourceByteArrayModel, SIGNAL(contentsChanged(Okteta::ArrayChangeMetricsList)),
151  SLOT(onSourceChanged()) );
152  connect( mSourceByteArrayModel, SIGNAL(destroyed()),
153  SLOT(onSourceDestroyed()) );
154 
155  mChecksumUptodate = true;
156  mSourceByteArrayModelUptodate = true;
157  emit checksumChanged( mCheckSum );
158  emit uptodateChanged( true );
159  }
160 }
161 
162 void ChecksumTool::setAlgorithm( int algorithmId )
163 {
164  mAlgorithmId = algorithmId;
165  checkUptoDate();
166  emit uptodateChanged( mChecksumUptodate );
167  emit isApplyableChanged( isApplyable() );
168 }
169 
170 // TODO: hack!
171 // better would be to store the parameter set used for the source and compare if equal
172 // this hack does the same, except for that the source will never be uptodate
173 void ChecksumTool::resetSourceTool()
174 {
175  mSourceAlgorithmId = -1;
176 
177  checkUptoDate();
178  emit uptodateChanged( mChecksumUptodate );
179  emit isApplyableChanged( isApplyable() );
180 }
181 
182 void ChecksumTool::onSelectionChanged()
183 {
184 // TODO: could be quicker using the selection data
185  checkUptoDate();
186  emit uptodateChanged( mChecksumUptodate );
187  emit isApplyableChanged( isApplyable() );
188 }
189 
190 void ChecksumTool::onSourceChanged()
191 {
192  mChecksumUptodate = false;
193  mSourceByteArrayModelUptodate = false;
194  emit uptodateChanged( false );
195 }
196 
197 void ChecksumTool::onSourceDestroyed()
198 {
199  mSourceByteArrayModel = 0;
200  onSourceChanged();
201 }
202 
203 ChecksumTool::~ChecksumTool()
204 {
205  qDeleteAll( mAlgorithmList );
206 #ifdef HAVE_QCA2
207  delete mQcaInitializer;
208 #endif
209 }
210 
211 }
Kasten2::ChecksumTool::setTargetModel
virtual void setTargetModel(AbstractModel *model)
Definition: checksumtool.cpp:95
Kasten2::ChecksumTool::isApplyableChanged
void isApplyableChanged(bool isApplyable)
AbstractByteArrayChecksumAlgorithm::parameterSet
virtual AbstractByteArrayChecksumParameterSet * parameterSet()=0
used by the editor to get write access to the parameters
abstractbytearraymodel.h
AbstractByteArrayChecksumAlgorithm
Definition: abstractbytearraychecksumalgorithm.h:38
Kasten2::ChecksumTool::parameterSet
AbstractByteArrayChecksumParameterSet * parameterSet()
Definition: checksumtool.cpp:88
abstractbytearraychecksumalgorithm.h
bytearraychecksumalgorithmfactory.h
Kasten2::ChecksumTool::uptodateChanged
void uptodateChanged(bool isUptodate)
Kasten2::ChecksumTool::checksumChanged
void checksumChanged(const QString &checksum)
Kasten2::ChecksumTool::calculateChecksum
void calculateChecksum()
Definition: checksumtool.cpp:129
Kasten2::ChecksumTool::resetSourceTool
void resetSourceTool()
Definition: checksumtool.cpp:173
Kasten2::ChecksumTool::ChecksumTool
ChecksumTool()
Definition: checksumtool.cpp:57
Kasten2::ByteArrayView::hasSelectedData
virtual bool hasSelectedData() const
Definition: bytearrayview.cpp:178
Kasten2::AbstractModel::baseModel
AbstractModel * baseModel() const
Definition: abstractmodel.cpp:40
Kasten2::ChecksumTool::setAlgorithm
void setAlgorithm(int algorithmId)
Definition: checksumtool.cpp:162
Kasten2::ByteArrayView::selection
Okteta::AddressRange selection() const
Definition: bytearrayview.cpp:271
Kasten2::ChecksumTool::algorithmList
QList< AbstractByteArrayChecksumAlgorithm * > algorithmList() const
Definition: checksumtool.cpp:77
Kasten2::ChecksumCalculateJob
Definition: checksumcalculatejob.h:41
checksumcalculatejob.h
Okteta::ArrayChangeMetricsList
Definition: arraychangemetricslist.h:36
Kasten2::ChecksumTool::isApplyable
bool isApplyable() const
Definition: checksumtool.cpp:79
Kasten2::AbstractModelSelection
Definition: abstractmodelselection.h:35
Kasten2::AbstractModel::findBaseModel
T findBaseModel() const
returns the first baseModel which is of type T, or null if none is found.
Definition: abstractmodel.h:93
checksumtool.h
Kasten2::ChecksumTool::~ChecksumTool
virtual ~ChecksumTool()
Definition: checksumtool.cpp:203
AbstractByteArrayChecksumParameterSet
Definition: abstractbytearraychecksumparameterset.h:27
Kasten2::ChecksumTool::algorithmId
int algorithmId() const
Definition: checksumtool.h:119
Kasten2::ChecksumTool::title
virtual QString title() const
Definition: checksumtool.cpp:85
Kasten2::ByteArrayDocument
Definition: bytearraydocument.h:54
Kasten2::AbstractTool
Definition: abstracttool.h:40
Kasten2::AbstractModel
Definition: abstractmodel.h:40
bytearraydocument.h
Kasten2::ByteArrayView
Definition: bytearrayview.h:51
Kasten2::ChecksumCalculateJob::exec
void exec()
Definition: checksumcalculatejob.cpp:39
ByteArrayChecksumAlgorithmFactory::createAlgorithms
static QList< AbstractByteArrayChecksumAlgorithm * > createAlgorithms()
Definition: bytearraychecksumalgorithmfactory.cpp:64
QList< AbstractByteArrayChecksumAlgorithm * >
bytearrayview.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:07 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal