• 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
  • document
bytearraydocumentfactory.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 2006-2007 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 "bytearraydocumentfactory.h"
24 
25 // lib
26 #include "bytearraydocument.h"
27 // Okteta core
28 #include <piecetablebytearraymodel.h>
29 // Kasten core
30 #include <person.h>
31 // KDE
32 #include <KLocale>
33 // Qt
34 #include <QtCore/QMimeData>
35 
36 
37 namespace Kasten2
38 {
39 
40 static int newByteArrayDocumentCounter = 0;
41 static const char OctetStreamFormatName[] = "application/octet-stream";
42 
43 bool ByteArrayDocumentFactory::canCreateFromData( const QMimeData* mimeData )
44 {
45  Q_UNUSED( mimeData );
46 
47  // we currently take everything, see createFromData()
48  return true;
49 }
50 
51 AbstractDocument* ByteArrayDocumentFactory::create()
52 {
53  ByteArrayDocument* document = new ByteArrayDocument( i18nc("The byte array was new created.","New created.") );
54 
55  ++newByteArrayDocumentCounter;
56 
57  // TODO: use document->typeName() ?
58  document->setTitle(
59  i18ncp("numbered title for a created document without a filename",
60  "[New Byte Array]","[New Byte Array %1]",newByteArrayDocumentCounter) );
61 
62  document->setOwner( Person::createEgo() );
63 
64  return document;
65 }
66 
67 AbstractDocument* ByteArrayDocumentFactory::createFromData( const QMimeData* mimeData, bool setModified )
68 {
69  if( ! mimeData || mimeData->formats().isEmpty() )
70  return create();
71 
72  // SYNC: with abstractbytearrayview_p.cpp
73  // if there is a octet stream, use it, otherwise take the dump of the format
74  // with the highest priority
75  // TODO: this may not be, what is expected, think about it, if we just
76  // take byte array descriptions, like encodings in chars or values
77  // would need the movement of the encoders into the core library
78  const QString octetStreamFormatName = QString::fromLatin1( OctetStreamFormatName );
79  const QString dataFormatName = ( mimeData->hasFormat(octetStreamFormatName) ) ?
80  octetStreamFormatName :
81  mimeData->formats()[0];
82 
83  const QByteArray data = mimeData->data( dataFormatName );
84 
85  Okteta::PieceTableByteArrayModel* byteArray =
86  new Okteta::PieceTableByteArrayModel( data );
87  byteArray->setModified( setModified );
88 
89  // TODO: pass name of generator
90  ByteArrayDocument* document = new ByteArrayDocument( byteArray, i18nc("origin of the byte array", "Created from data.") );
91 
92  ++newByteArrayDocumentCounter;
93 
94  // TODO: use document->typeName() ?
95  document->setTitle(
96  i18ncp("numbered title for a created document without a filename",
97  "[New Byte Array]","[New Byte Array %1]",newByteArrayDocumentCounter) );
98 
99  document->setOwner( Person::createEgo() );
100 
101  return document;
102 }
103 
104 }
Kasten2::ByteArrayDocument::setTitle
void setTitle(const QString &title)
Definition: bytearraydocument.cpp:76
Kasten2::Person::createEgo
static Person createEgo()
Definition: person.cpp:41
Kasten2::newByteArrayDocumentCounter
static int newByteArrayDocumentCounter
Definition: bytearraydocumentfactory.cpp:40
Okteta::PieceTableByteArrayModel::setModified
virtual void setModified(bool modified=true)
sets the modified flag for the buffer
Definition: piecetablebytearraymodel.cpp:49
bytearraydocumentfactory.h
person.h
piecetablebytearraymodel.h
Kasten2::ByteArrayDocumentFactory::create
virtual AbstractDocument * create()
Definition: bytearraydocumentfactory.cpp:51
Kasten2::ByteArrayDocument::setOwner
void setOwner(const Person &owner)
Definition: bytearraydocument.cpp:114
Kasten2::AbstractDocument
Definition: abstractdocument.h:43
Kasten2::ByteArrayDocumentFactory::canCreateFromData
virtual bool canCreateFromData(const QMimeData *mimeData)
default returns false
Definition: bytearraydocumentfactory.cpp:43
Kasten2::ByteArrayDocumentFactory::createFromData
virtual AbstractDocument * createFromData(const QMimeData *mimeData, bool setModified)
default returns 0
Definition: bytearraydocumentfactory.cpp:67
Kasten2::ByteArrayDocument
Definition: bytearraydocument.h:54
Kasten2::OctetStreamFormatName
static const char OctetStreamFormatName[]
Definition: bytearraydocumentfactory.cpp:41
bytearraydocument.h
Okteta::PieceTableByteArrayModel
Definition: piecetablebytearraymodel.h:44
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