~ubuntu-branches/debian/squeeze/stellarium/squeeze

« back to all changes in this revision

Viewing changes to src/external/kfilter/klimitediodevice.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cédric Delfosse
  • Date: 2010-07-31 15:44:02 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100731154402-511dojtyt5ycuizd
Tags: 0.10.5-1
* New upstream release (Closes: #586804)
* Remove 01_fix_pow10_function_check.diff, now applied upstream
* Remove 02_remove_unknown_locale_code.diff, no more needed
* Rendering of `old_style' landscapes fixed by upstream (Closes: #581657)
* Update debian/control:
  - Bump Standards-Version from 3.8.4 to 3.9.0
  - Add libqt4-sql-sqlite to Depends (Closes: #582726)
* Update debian/copyright:
  - Fix FSF address

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE libraries
2
 
   Copyright (C) 2001, 2002, 2007 David Faure <faure@kde.org>
3
 
 
4
 
   This library is free software; you can redistribute it and/or
5
 
   modify it under the terms of the GNU Library General Public
6
 
   License version 2 as published by the Free Software Foundation.
7
 
 
8
 
   This library is distributed in the hope that it will be useful,
9
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
 
   Library General Public License for more details.
12
 
 
13
 
   You should have received a copy of the GNU Library General Public License
14
 
   along with this library; see the file COPYING.LIB.  If not, write to
15
 
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
 
   Boston, MA 02110-1301, USA.
17
 
*/
18
 
 
19
 
#include "klimitediodevice.h"
20
 
#include <QDebug>
21
 
 
22
 
KLimitedIODevice::KLimitedIODevice( QIODevice *dev, int start, int length )
23
 
    : m_dev( dev ), m_start( start ), m_length( length )
24
 
{
25
 
    //kDebug(7005) << "start=" << start << "length=" << length;
26
 
    open( QIODevice::ReadOnly ); //krazy:exclude=syscalls
27
 
}
28
 
 
29
 
bool KLimitedIODevice::open( QIODevice::OpenMode m )
30
 
{
31
 
    //kDebug(7005) << "m=" << m;
32
 
    if ( m & QIODevice::ReadOnly ) {
33
 
        /*bool ok = false;
34
 
          if ( m_dev->isOpen() )
35
 
          ok = ( m_dev->mode() == QIODevice::ReadOnly );
36
 
          else
37
 
          ok = m_dev->open( m );
38
 
          if ( ok )*/
39
 
        m_dev->seek( m_start ); // No concurrent access !
40
 
    }
41
 
    else
42
 
        qWarning() << "KLimitedIODevice::open only supports QIODevice::ReadOnly!";
43
 
    setOpenMode( QIODevice::ReadOnly );
44
 
    return true;
45
 
}
46
 
 
47
 
void KLimitedIODevice::close()
48
 
{
49
 
}
50
 
 
51
 
qint64 KLimitedIODevice::size() const
52
 
{
53
 
    return m_length;
54
 
}
55
 
 
56
 
qint64 KLimitedIODevice::readData( char * data, qint64 maxlen )
57
 
{
58
 
    maxlen = qMin( maxlen, m_length - pos() ); // Apply upper limit
59
 
    return m_dev->read( data, maxlen );
60
 
}
61
 
 
62
 
bool KLimitedIODevice::seek( qint64 pos )
63
 
{
64
 
    Q_ASSERT( pos <= m_length );
65
 
    pos = qMin( pos, m_length ); // Apply upper limit
66
 
    return m_dev->seek( m_start + pos );
67
 
}
68
 
 
69
 
qint64 KLimitedIODevice::bytesAvailable() const
70
 
{
71
 
     return m_length + QIODevice::bytesAvailable();
72
 
}
73
 
 
74
 
bool KLimitedIODevice::isSequential() const
75
 
{
76
 
    return m_dev->isSequential();
77
 
}