• 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
  • stringsextract
stringsextracttool.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 2007-2009,2012 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 "stringsextracttool.h"
24 
25 // lib
26 #include "extractstringsjob.h"
27 #include <bytearrayview.h>
28 #include <bytearraydocument.h>
29 // Okteta core
30 #include <charcodec.h>
31 #include <abstractbytearraymodel.h>
32 // KDE
33 #include <KLocale>
34 // Qt
35 #include <QtGui/QApplication>
36 
37 
38 namespace Kasten2
39 {
40 
41 static const int DefaultMinLength = 3;
42 
43 StringsExtractTool::StringsExtractTool()
44  : mExtractedStringsUptodate( false ),
45  mSourceByteArrayModelUptodate( false ),
46  mMinLength( DefaultMinLength ),
47  mByteArrayView( 0 ),
48  mByteArrayModel( 0 ),
49  mSourceByteArrayView( 0 ),
50  mSourceByteArrayModel( 0 ),
51  mSourceMinLength( 0 )
52 {
53  setObjectName( QLatin1String( "Strings" ) );
54 }
55 
56 bool StringsExtractTool::isApplyable() const
57 {
58  return ( mByteArrayModel && mByteArrayView && mByteArrayView->hasSelectedData() && mMinLength > 0 );
59 }
60 
61 bool StringsExtractTool::canHighlightString() const
62 {
63  return ( mSourceByteArrayModel == mByteArrayModel
64  && mByteArrayView && mSourceByteArrayModelUptodate );
65 }
66 
67 QString StringsExtractTool::title() const { return i18nc("@title:window of the tool to extract strings", "Strings"); }
68 
69 // TODO: add model with offset and string
70 // doubleclick moves cursor to offset
71 // filter für Suche, inkl. Regulärausdrücke
72 // groß/kleinschreibung
73 // voll strings, auch mit Leerzeichen
74 void StringsExtractTool::setTargetModel( AbstractModel* model )
75 {
76  if( mByteArrayView ) mByteArrayView->disconnect( this );
77 
78  mByteArrayView = model ? model->findBaseModel<ByteArrayView*>() : 0;
79 
80  ByteArrayDocument* document =
81  mByteArrayView ? qobject_cast<ByteArrayDocument*>( mByteArrayView->baseModel() ) : 0;
82  mByteArrayModel = document ? document->content() : 0;
83 
84  if( mByteArrayView && mByteArrayModel )
85  {
86  connect( mByteArrayView, SIGNAL(selectedDataChanged(const Kasten2::AbstractModelSelection*)),
87  SLOT(onSelectionChanged()) );
88 
89  // if strings are from same model, adapt offsetcoding
90  if( mSourceByteArrayModel == mByteArrayModel )
91  {
92  connect( mByteArrayView, SIGNAL(offsetCodingChanged(int)),
93  SIGNAL(offsetCodingChanged(int)) );
94  }
95  }
96 
97  // TODO: if there is no view, there is nothing to extract.
98  // or this could be the view where we got the strings from and it did not change
99  checkUptoDate();
100  emit uptodateChanged( mExtractedStringsUptodate );
101  emit isApplyableChanged( isApplyable() );
102  emit canHighlightStringChanged( canHighlightString() );
103  if( mSourceByteArrayModel == mByteArrayModel && mByteArrayView )
104  emit offsetCodingChanged( mByteArrayView->offsetCoding() );
105 }
106 
107 int StringsExtractTool::offsetCoding() const { return ( mByteArrayView ? mByteArrayView->offsetCoding() : 0 ); }
108 
109 
110 void StringsExtractTool::setMinLength( int minLength )
111 {
112  mMinLength = minLength;
113  checkUptoDate();
114  emit uptodateChanged( mExtractedStringsUptodate );
115 }
116 
117 void StringsExtractTool::setCharCodec( const QString & )
118 {
119  // noop, was one before, only kept for ABI stability
120 }
121 
122 void StringsExtractTool::checkUptoDate()
123 {
124  mExtractedStringsUptodate =
125  ( mSourceByteArrayModel == mByteArrayModel
126  && mByteArrayView && mSourceSelection == mByteArrayView->selection()
127  && mSourceMinLength == mMinLength
128  && mSourceByteArrayModelUptodate );
129 }
130 
131 void StringsExtractTool::markString( int stringId )
132 {
133  if( mSourceByteArrayView != mByteArrayView )
134  {
135  if( mSourceByteArrayView ) mSourceByteArrayView->disconnect( this );
136  mSourceByteArrayView = mByteArrayView;
137  connect( mSourceByteArrayView, SIGNAL(destroyed()),
138  SLOT(onSourceViewDestroyed()) );
139  }
140  const ContainedString &containedString = mContainedStringList.at( stringId );
141  const Okteta::Address offset = containedString.offset();
142  const int length = containedString.string().length();
143  const Okteta::AddressRange markingRange = Okteta::AddressRange::fromWidth( offset, length );
144  mSourceByteArrayView->setMarking( markingRange, true );
145 }
146 
147 void StringsExtractTool::unmarkString()
148 {
149 // TODO: marked region is property of document, not view?
150  if( mSourceByteArrayView )
151  mSourceByteArrayView->setMarking( Okteta::AddressRange() );
152 }
153 
154 void StringsExtractTool::onSelectionChanged()
155 {
156 // TODO: could be quicker using the selection data
157  checkUptoDate();
158  emit uptodateChanged( mExtractedStringsUptodate );
159  emit isApplyableChanged( isApplyable() );
160 }
161 
162 void StringsExtractTool::onSourceChanged()
163 {
164  mExtractedStringsUptodate = false;
165  mSourceByteArrayModelUptodate = false;
166  emit uptodateChanged( false );
167  emit canHighlightStringChanged( false );
168 }
169 
170 void StringsExtractTool::onSourceDestroyed()
171 {
172  mSourceByteArrayModel = 0;
173  onSourceChanged();
174 }
175 
176 void StringsExtractTool::onSourceViewDestroyed()
177 {
178  mSourceByteArrayView = 0;
179 }
180 
181 
182 // TODO: use WordByteArrayService
183 void StringsExtractTool::extractStrings()
184 {
185  // forget old string source
186  if( mSourceByteArrayModel ) mSourceByteArrayModel->disconnect( this );
187 
188  QApplication::setOverrideCursor( Qt::WaitCursor );
189 
190  Okteta::CharCodec* charCodec = Okteta::CharCodec::createCodec( mByteArrayView->charCodingName() );
191  ExtractStringsJob *extractStringsJob =
192  new ExtractStringsJob( mByteArrayModel, mByteArrayView->selection(), charCodec, mMinLength,
193  &mContainedStringList );
194  extractStringsJob->exec();
195  delete charCodec;
196 
197  QApplication::restoreOverrideCursor();
198 
199  // remember new string source
200  mSourceByteArrayModel = mByteArrayModel;
201  mSourceSelection = mByteArrayView->selection();
202  mSourceMinLength = mMinLength;
203  connect( mSourceByteArrayModel, SIGNAL(contentsChanged(Okteta::ArrayChangeMetricsList)),
204  SLOT(onSourceChanged()) );
205  connect( mSourceByteArrayModel, SIGNAL(destroyed()),
206  SLOT(onSourceDestroyed()) );
207  connect( mByteArrayView, SIGNAL(offsetCodingChanged(int)),
208  SIGNAL(offsetCodingChanged(int)) );
209 
210  mExtractedStringsUptodate = true;
211  mSourceByteArrayModelUptodate = true;
212  emit uptodateChanged( true );
213  emit canHighlightStringChanged( true );
214  emit offsetCodingChanged( mByteArrayView->offsetCoding() );
215 }
216 
217 
218 StringsExtractTool::~StringsExtractTool()
219 {
220 }
221 
222 }
Okteta::Address
qint32 Address
Definition: address.h:34
ContainedString::offset
Okteta::Address offset() const
Definition: containedstring.h:58
abstractbytearraymodel.h
extractstringsjob.h
ContainedString::string
const QString & string() const
Definition: containedstring.h:57
Kasten2::StringsExtractTool::setTargetModel
virtual void setTargetModel(AbstractModel *model)
Definition: stringsextracttool.cpp:74
Kasten2::ByteArrayView::charCodingName
QString charCodingName() const
Definition: bytearrayview.cpp:255
KDE::NumberRange< Address, Size >
Kasten2::StringsExtractTool::markString
void markString(int stringId)
Definition: stringsextracttool.cpp:131
Kasten2::DefaultMinLength
static const int DefaultMinLength
Definition: stringsextracttool.cpp:41
Kasten2::StringsExtractTool::uptodateChanged
void uptodateChanged(bool isUptodate)
stringsextracttool.h
Kasten2::ByteArrayView::hasSelectedData
virtual bool hasSelectedData() const
Definition: bytearrayview.cpp:178
Kasten2::AbstractModel::baseModel
AbstractModel * baseModel() const
Definition: abstractmodel.cpp:40
Kasten2::StringsExtractTool::offsetCodingChanged
void offsetCodingChanged(int offsetCoding)
Kasten2::ByteArrayView::selection
Okteta::AddressRange selection() const
Definition: bytearrayview.cpp:271
Kasten2::StringsExtractTool::offsetCoding
int offsetCoding() const
Definition: stringsextracttool.cpp:107
Kasten2::StringsExtractTool::StringsExtractTool
StringsExtractTool()
Definition: stringsextracttool.cpp:43
Kasten2::StringsExtractTool::isApplyable
bool isApplyable() const
Definition: stringsextracttool.cpp:56
Okteta::CharCodec
Definition: charcodec.h:42
KDE::NumberRange< Address, Size >::fromWidth
static NumberRange fromWidth(AddressstartIndex, Sizewidth)
constructs a range by width
Kasten2::StringsExtractTool::title
virtual QString title() const
Definition: stringsextracttool.cpp:67
Okteta::ArrayChangeMetricsList
Definition: arraychangemetricslist.h:36
Kasten2::StringsExtractTool::extractStrings
void extractStrings()
Definition: stringsextracttool.cpp:183
Kasten2::ByteArrayView::setMarking
void setMarking(const Okteta::AddressRange &range, bool ensureVisible=false)
Definition: bytearrayview.cpp:351
Kasten2::ExtractStringsJob
Definition: extractstringsjob.h:43
Okteta::CharCodec::createCodec
static CharCodec * createCodec(CharCoding charCoding)
Definition: charcodec.cpp:68
Kasten2::AbstractModelSelection
Definition: abstractmodelselection.h:35
Kasten2::StringsExtractTool::minLength
int minLength() const
Definition: stringsextracttool.h:122
Kasten2::StringsExtractTool::canHighlightString
bool canHighlightString() const
Definition: stringsextracttool.cpp:61
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
charcodec.h
ContainedString
Definition: containedstring.h:33
Kasten2::StringsExtractTool::setCharCodec
KDE_DEPRECATED void setCharCodec(const QString &codecName)
Definition: stringsextracttool.cpp:117
Kasten2::StringsExtractTool::setMinLength
void setMinLength(int minLength)
Definition: stringsextracttool.cpp:110
Kasten2::ByteArrayDocument
Definition: bytearraydocument.h:54
Kasten2::AbstractModel
Definition: abstractmodel.h:40
Kasten2::ByteArrayView::offsetCoding
int offsetCoding() const
Definition: bytearrayview.cpp:296
bytearraydocument.h
Kasten2::ExtractStringsJob::exec
void exec()
Definition: extractstringsjob.cpp:38
Kasten2::StringsExtractTool::~StringsExtractTool
virtual ~StringsExtractTool()
Definition: stringsextracttool.cpp:218
Kasten2::ByteArrayView
Definition: bytearrayview.h:51
Kasten2::StringsExtractTool::canHighlightStringChanged
void canHighlightStringChanged(bool canHighlightString)
Kasten2::StringsExtractTool::unmarkString
void unmarkString()
Definition: stringsextracttool.cpp:147
Kasten2::StringsExtractTool::isApplyableChanged
void isApplyableChanged(bool isApplyable)
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:09 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