• 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
  • core
  • io
  • filesystem
bytearrayrawfileloadthread.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 2008-2009,2011-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 "bytearrayrawfileloadthread.h"
24 
25 // lib
26 #include "bytearraydocument.h"
27 // Kasten core
28 #include <person.h>
29 // Okteta core
30 #include <piecetablebytearraymodel.h>
31 // KDE
32 #include <KLocale>
33 // Qt
34 #include <QtCore/QCoreApplication>
35 #include <QtCore/QDataStream>
36 #include <QtCore/QFile>
37 // C++
38 #include <limits>
39 
40 
41 namespace Kasten2
42 {
43 
44 void ByteArrayRawFileLoadThread::run()
45 {
46  const qint64 fileSize = mFile->size();
47 
48  // check if the file content can be addressed with Okteta::Address
49  const Okteta::Address maxAddress = std::numeric_limits<Okteta::Address>::max();
50 
51  bool success = ( fileSize <= maxAddress );
52 
53  if( success )
54  {
55  // allocate working memory
56  QByteArray data;
57  data.resize( fileSize );
58  bool success = ( data.size() == fileSize );
59 
60  if( success )
61  {
62  QDataStream inStream( mFile );
63  inStream.readRawData( data.data(), fileSize );
64 
65  success = ( inStream.status() == QDataStream::Ok );
66 
67  if( success )
68  {
69  Okteta::PieceTableByteArrayModel* byteArray = new Okteta::PieceTableByteArrayModel( data );
70  byteArray->setModified( false );
71 
72  mDocument = new ByteArrayDocument( byteArray, i18nc("destination of the byte array", "Loaded from file.") );
73  mDocument->setOwner( Person::createEgo() );
74  // TODO: make PieceTableByteArrayModel a child by constructor argument parent
75  byteArray->moveToThread( QCoreApplication::instance()->thread() );
76  mDocument->moveToThread( QCoreApplication::instance()->thread() );
77  }
78  else
79  mErrorString = mFile->errorString();
80  }
81  else
82  mErrorString = i18n( "There is not enough free working memory to load this file." );
83  }
84  else
85  mErrorString = i18n( "Support to load files larger than 2 GiB has not yet been implemented." );
86 
87  if( ! success )
88  mDocument = 0;
89 
90  emit documentRead( mDocument );
91 }
92 
93 ByteArrayRawFileLoadThread::~ByteArrayRawFileLoadThread() {}
94 
95 }
Okteta::Address
qint32 Address
Definition: address.h:34
Kasten2::Person::createEgo
static Person createEgo()
Definition: person.cpp:41
Okteta::PieceTableByteArrayModel::setModified
virtual void setModified(bool modified=true)
sets the modified flag for the buffer
Definition: piecetablebytearraymodel.cpp:49
person.h
piecetablebytearraymodel.h
Kasten2::ByteArrayRawFileLoadThread::documentRead
void documentRead(ByteArrayDocument *document)
bytearrayrawfileloadthread.h
Kasten2::ByteArrayRawFileLoadThread::mFile
QFile * mFile
Definition: bytearrayrawfileloadthread.h:58
Kasten2::Ok
Definition: kastencore.h:61
Kasten2::ByteArrayDocument::setOwner
void setOwner(const Person &owner)
Definition: bytearraydocument.cpp:114
Kasten2::ByteArrayRawFileLoadThread::mErrorString
QString mErrorString
Definition: bytearrayrawfileloadthread.h:61
Kasten2::ByteArrayRawFileLoadThread::~ByteArrayRawFileLoadThread
virtual ~ByteArrayRawFileLoadThread()
Definition: bytearrayrawfileloadthread.cpp:93
Kasten2::ByteArrayDocument
Definition: bytearraydocument.h:54
bytearraydocument.h
Okteta::PieceTableByteArrayModel
Definition: piecetablebytearraymodel.h:44
Kasten2::ByteArrayRawFileLoadThread::run
virtual void run()
Definition: bytearrayrawfileloadthread.cpp:44
Kasten2::ByteArrayRawFileLoadThread::mDocument
ByteArrayDocument * mDocument
Definition: bytearrayrawfileloadthread.h:60
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