• 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
checksumview.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 #include "checksumview.h"
24 
25 // tool
26 #include "checksumtool.h"
27 // lib
28 #include <bytearraychecksumparameterseteditfactory.h>
29 #include <abstractbytearraychecksumparametersetedit.h>
30 #include <abstractbytearraychecksumparameterset.h>
31 #include <abstractbytearraychecksumalgorithm.h>
32 // KDE
33 #include <KComboBox>
34 #include <KPushButton>
35 #include <KLineEdit>
36 #include <KGuiItem>
37 #include <KLocale>
38 #include <KGlobalSettings>
39 // Qt
40 #include <QtGui/QLabel>
41 #include <QtGui/QGroupBox>
42 #include <QtGui/QStackedWidget>
43 #include <QtGui/QLayout>
44 #include <QtGui/QClipboard>
45 #include <QtGui/QApplication>
46 #include <QtGui/QAbstractItemView>
47 
48 
49 namespace Kasten2
50 {
51 
52 ChecksumView::ChecksumView( ChecksumTool* tool, QWidget* parent )
53  : AbstractToolWidget( parent ),
54  mTool( tool )
55 {
56  QVBoxLayout* baseLayout = new QVBoxLayout( this );
57  baseLayout->setMargin( 0 );
58 
59  // algorithm
60  QHBoxLayout* algorithmLayout = new QHBoxLayout();
61  QLabel* label = new QLabel( i18nc("@label:listbox algorithm to use for the checksum","Algorithm:"), this );
62  mAlgorithmComboBox = new KComboBox( this );
63  connect( mAlgorithmComboBox, SIGNAL(activated(int)),
64  SLOT(onOperationChange(int)) );
65 
66  label->setBuddy( mAlgorithmComboBox );
67  const QString algorithmWhatsThis =
68  i18nc("@info:whatsthis","Select the algorithm to use for the checksum.");
69  label->setWhatsThis( algorithmWhatsThis );
70  mAlgorithmComboBox->setWhatsThis( algorithmWhatsThis );
71 
72  algorithmLayout->addWidget( label );
73  algorithmLayout->addWidget( mAlgorithmComboBox, 10 );
74  baseLayout->addLayout( algorithmLayout );
75 
76  // parameter
77  QGroupBox* parameterSetBox = new QGroupBox( i18nc("@title:group","Parameters"), this );
78  baseLayout->addWidget( parameterSetBox );
79 
80  QVBoxLayout* parameterSetLayout = new QVBoxLayout( parameterSetBox );
81 
82  mParameterSetEditStack = new QStackedWidget( parameterSetBox );
83  parameterSetLayout->addWidget( mParameterSetEditStack );
84 
85  // calculate
86  QHBoxLayout* calculateLayout = new QHBoxLayout();
87 
88  calculateLayout->addStretch();
89  const KGuiItem updateGuiItem =
90  KGuiItem( i18nc("@action:button calculate the checksum","&Calculate"),
91  QLatin1String("run-build"),
92  i18nc("@info:tooltip",
93  "Calculate the checksum for the bytes in the selected range."),
94  i18nc("@info:whatsthis",
95  "If you press the <interface>Calculate</interface> button, the list will be updated "
96  "to all strings which are contained in the selected range and have the set minimum length.") );
97  mCalculateButton = new KPushButton( updateGuiItem, this );
98  mCalculateButton->setEnabled( mTool->isApplyable() );
99  connect( mCalculateButton, SIGNAL(clicked(bool)), SLOT(onCalculateClicked()) );
100  addButton( mCalculateButton, AbstractToolWidget::Default );
101  calculateLayout->addWidget( mCalculateButton );
102  baseLayout->addLayout( calculateLayout );
103 
104  mChecksumLabel = new KLineEdit( this );
105  mChecksumLabel->setReadOnly( true );
106  mChecksumLabel->setText( mTool->checkSum() );
107  connect( mTool, SIGNAL(checksumChanged(QString)), mChecksumLabel, SLOT(setText(QString)) );
108  baseLayout->addWidget( mChecksumLabel, 10 );
109 
110  baseLayout->addStretch( 10 );
111 
112  connect( mTool, SIGNAL(uptodateChanged(bool)), SLOT(onChecksumUptodateChanged(bool)) );
113  connect( mTool, SIGNAL(isApplyableChanged(bool)), SLOT(onApplyableChanged(bool)) );
114 
115  // automatically set focus to the parameters if a operation has been selected
116  QAbstractItemView* algorithmComboBoxListView = mAlgorithmComboBox->view();
117  QObject::connect( algorithmComboBoxListView, SIGNAL(activated(QModelIndex)),
118  mParameterSetEditStack, SLOT(setFocus()) );
119  // TODO: is a workaround for Qt 4.5.1 which doesn't emit activated() for mouse clicks
120  QObject::connect( algorithmComboBoxListView, SIGNAL(pressed(QModelIndex)),
121  mParameterSetEditStack, SLOT(setFocus()) );
122  // TODO: goto filter button if there are no parameters
123 
124  addAlgorithms();
125 }
126 
127 void ChecksumView::addAlgorithms()
128 {
129  //
130  const QList<AbstractByteArrayChecksumAlgorithm*> algorithmList = mTool->algorithmList();
131  foreach( AbstractByteArrayChecksumAlgorithm* algorithm, algorithmList )
132  {
133  mAlgorithmComboBox->addItem( algorithm->name() );
134 
135  const char* const parameterSetId = algorithm->parameterSet()->id();
136  AbstractByteArrayChecksumParameterSetEdit* parameterEdit =
137  ByteArrayChecksumParameterSetEditFactory::createEdit( parameterSetId );
138 
139  mParameterSetEditStack->addWidget( parameterEdit );
140  }
141 
142  onOperationChange( mTool->algorithmId() );
143 }
144 
145 void ChecksumView::getParameterSet( AbstractByteArrayChecksumParameterSet* parameterSet ) const
146 {
147  AbstractByteArrayChecksumParameterSetEdit* parametersetEdit =
148  qobject_cast<AbstractByteArrayChecksumParameterSetEdit*>( mParameterSetEditStack->currentWidget() );
149  if( parametersetEdit )
150  parametersetEdit->getParameterSet( parameterSet );
151 }
152 
153 void ChecksumView::onCalculateClicked()
154 {
155  AbstractByteArrayChecksumParameterSet* parameterSet = mTool->parameterSet();
156  if( parameterSet )
157  getParameterSet( parameterSet );
158 
159  mTool->calculateChecksum();
160 }
161 
162 void ChecksumView::onOperationChange( int index )
163 {
164  QWidget* oldWidget = mParameterSetEditStack->currentWidget();
165  if( oldWidget )
166  {
167  oldWidget->disconnect( this );
168  oldWidget->disconnect( mTool );
169  }
170 
171  mTool->setAlgorithm( index );
172  mParameterSetEditStack->setCurrentIndex( index );
173 
174  AbstractByteArrayChecksumParameterSetEdit* parametersetEdit =
175  qobject_cast<AbstractByteArrayChecksumParameterSetEdit*>( mParameterSetEditStack->currentWidget() );
176  if( parametersetEdit )
177  {
178  connect( parametersetEdit, SIGNAL(validityChanged(bool)),
179  SLOT(onValidityChanged(bool)) );
180  // TODO: hack, see checksum source
181  connect( parametersetEdit, SIGNAL(valuesChanged()),
182  mTool, SLOT(resetSourceTool()) );
183  onValidityChanged( parametersetEdit->isValid() );
184  }
185 }
186 
187 
188 void ChecksumView::onChecksumUptodateChanged( bool checksumUptodate )
189 {
190  const bool isApplyable = mTool->isApplyable();
191  mCalculateButton->setEnabled( ! checksumUptodate && isApplyable );
192 }
193 
194 void ChecksumView::onApplyableChanged( bool isApplyable )
195 {
196  mCalculateButton->setEnabled( !mTool->isUptodate() && isApplyable );
197 }
198 
199 void ChecksumView::onValidityChanged( bool isValid )
200 {
201  mCalculateButton->setEnabled( mTool->isApplyable() && isValid );
202 }
203 
204 ChecksumView::~ChecksumView() {}
205 
206 }
AbstractByteArrayChecksumAlgorithm::parameterSet
virtual AbstractByteArrayChecksumParameterSet * parameterSet()=0
used by the editor to get write access to the parameters
AbstractByteArrayChecksumAlgorithm
Definition: abstractbytearraychecksumalgorithm.h:38
Kasten2::ChecksumTool::parameterSet
AbstractByteArrayChecksumParameterSet * parameterSet()
Definition: checksumtool.cpp:88
Kasten2::AbstractToolWidget::addButton
void addButton(QPushButton *button, DefaultType defaultType=AutoDefault)
Definition: abstracttoolwidget.cpp:37
abstractbytearraychecksumalgorithm.h
ByteArrayChecksumParameterSetEditFactory::createEdit
static AbstractByteArrayChecksumParameterSetEdit * createEdit(const char *id)
Definition: bytearraychecksumparameterseteditfactory.cpp:35
AbstractByteArrayChecksumAlgorithm::name
QString name() const
Definition: abstractbytearraychecksumalgorithm.cpp:51
QWidget
AbstractByteArrayChecksumParameterSetEdit
Definition: abstractbytearraychecksumparametersetedit.h:32
abstractbytearraychecksumparametersetedit.h
Kasten2::AbstractToolWidget
Definition: abstracttoolwidget.h:41
Kasten2::ChecksumTool::calculateChecksum
void calculateChecksum()
Definition: checksumtool.cpp:129
Kasten2::ChecksumTool::isUptodate
bool isUptodate() const
Definition: checksumtool.h:121
Kasten2::ChecksumTool::setAlgorithm
void setAlgorithm(int algorithmId)
Definition: checksumtool.cpp:162
Kasten2::ChecksumTool::algorithmList
QList< AbstractByteArrayChecksumAlgorithm * > algorithmList() const
Definition: checksumtool.cpp:77
abstractbytearraychecksumparameterset.h
Kasten2::AbstractToolWidget::Default
Definition: abstracttoolwidget.h:46
bytearraychecksumparameterseteditfactory.h
AbstractByteArrayChecksumParameterSetEdit::isValid
virtual bool isValid() const
default returns true
Definition: abstractbytearraychecksumparametersetedit.cpp:35
Kasten2::ChecksumView::~ChecksumView
virtual ~ChecksumView()
Definition: checksumview.cpp:204
checksumview.h
Kasten2::ChecksumTool
Definition: checksumtool.h:51
Kasten2::ChecksumTool::isApplyable
bool isApplyable() const
Definition: checksumtool.cpp:79
KLineEdit
checksumtool.h
AbstractByteArrayChecksumParameterSet
Definition: abstractbytearraychecksumparameterset.h:27
Kasten2::ChecksumTool::algorithmId
int algorithmId() const
Definition: checksumtool.h:119
Kasten2::ChecksumView::ChecksumView
ChecksumView(ChecksumTool *tool, QWidget *parent=0)
Definition: checksumview.cpp:52
AbstractByteArrayChecksumParameterSet::id
virtual const char * id() const =0
AbstractByteArrayChecksumParameterSetEdit::getParameterSet
virtual void getParameterSet(AbstractByteArrayChecksumParameterSet *parameterSet) const =0
default does nothing
QList< AbstractByteArrayChecksumAlgorithm * >
Kasten2::ChecksumTool::checkSum
QString checkSum() const
Definition: checksumtool.h:120
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