From ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kioslave/bzip2/Makefile.am | 11 +++ kioslave/bzip2/configure.in.in | 11 +++ kioslave/bzip2/kbzip2filter.cpp | 187 ++++++++++++++++++++++++++++++++++++ kioslave/bzip2/kbzip2filter.desktop | 86 +++++++++++++++++ kioslave/bzip2/kbzip2filter.h | 54 +++++++++++ 5 files changed, 349 insertions(+) create mode 100644 kioslave/bzip2/Makefile.am create mode 100644 kioslave/bzip2/configure.in.in create mode 100644 kioslave/bzip2/kbzip2filter.cpp create mode 100644 kioslave/bzip2/kbzip2filter.desktop create mode 100644 kioslave/bzip2/kbzip2filter.h (limited to 'kioslave/bzip2') diff --git a/kioslave/bzip2/Makefile.am b/kioslave/bzip2/Makefile.am new file mode 100644 index 000000000..bb5ca3dc5 --- /dev/null +++ b/kioslave/bzip2/Makefile.am @@ -0,0 +1,11 @@ +INCLUDES = -I$(top_srcdir)/kio $(all_includes) +METASOURCES = AUTO + +kde_module_LTLIBRARIES = kbzip2filter.la + +kbzip2filter_la_SOURCES = kbzip2filter.cpp +kbzip2filter_la_LIBADD = $(LIB_KIO) $(LIBBZ2) +kbzip2filter_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) + +kde_services_DATA = kbzip2filter.desktop + diff --git a/kioslave/bzip2/configure.in.in b/kioslave/bzip2/configure.in.in new file mode 100644 index 000000000..99392042d --- /dev/null +++ b/kioslave/bzip2/configure.in.in @@ -0,0 +1,11 @@ +AC_DEFUN([KIOBZIP2_CHECK_BZIP2], +[ +AC_REQUIRE([AC_FIND_BZIP2]) + +AM_CONDITIONAL(include_bzip2, test -n "$BZIP2DIR") +if test -n "$BZIP2DIR"; then + AC_DEFINE(HAVE_BZIP2_SUPPORT, 1, [Defines if bzip2 is compiled]) +fi +]) + +KIOBZIP2_CHECK_BZIP2 diff --git a/kioslave/bzip2/kbzip2filter.cpp b/kioslave/bzip2/kbzip2filter.cpp new file mode 100644 index 000000000..5ef6aaf5b --- /dev/null +++ b/kioslave/bzip2/kbzip2filter.cpp @@ -0,0 +1,187 @@ +/* This file is part of the KDE libraries + Copyright (C) 2000 David Faure + + $Id$ + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include + +#if defined( HAVE_BZIP2_SUPPORT ) + +// we don't need that +#define BZ_NO_STDIO +extern "C" { + #include +} + +#ifdef NEED_BZ2_PREFIX + #define bzDecompressInit(x,y,z) BZ2_bzDecompressInit(x,y,z) + #define bzDecompressEnd(x) BZ2_bzDecompressEnd(x) + #define bzCompressEnd(x) BZ2_bzCompressEnd(x) + #define bzDecompress(x) BZ2_bzDecompress(x) + #define bzCompress(x,y) BZ2_bzCompress(x, y) + #define bzCompressInit(x,y,z,a) BZ2_bzCompressInit(x, y, z, a); +#endif + +#include +#include + +#include "kbzip2filter.h" + +// For docu on this, see /usr/doc/bzip2-0.9.5d/bzip2-0.9.5d/manual_3.html + +class KBzip2FilterFactory : public KLibFactory +{ +public: + KBzip2FilterFactory() : KLibFactory() {} + virtual ~KBzip2FilterFactory(){} + QObject *createObject( QObject *, const char *, const char*, const QStringList & ) + { + return new KBzip2Filter; + } +}; + +K_EXPORT_COMPONENT_FACTORY( kbzip2filter, KBzip2FilterFactory ) + +// Not really useful anymore +class KBzip2Filter::KBzip2FilterPrivate +{ +public: + bz_stream zStream; +}; + +KBzip2Filter::KBzip2Filter() +{ + d = new KBzip2FilterPrivate; + d->zStream.bzalloc = 0; + d->zStream.bzfree = 0; + d->zStream.opaque = 0; + m_mode = 0; +} + + +KBzip2Filter::~KBzip2Filter() +{ + delete d; +} + +void KBzip2Filter::init( int mode ) +{ + d->zStream.next_in = 0; + d->zStream.avail_in = 0; + if ( mode == IO_ReadOnly ) + { + (void)bzDecompressInit(&d->zStream, 0, 0); + //kdDebug(7118) << "bzDecompressInit returned " << result << endl; + // No idea what to do with result :) + } else if ( mode == IO_WriteOnly ) { + (void)bzCompressInit(&d->zStream, 5, 0, 0); + //kdDebug(7118) << "bzDecompressInit returned " << result << endl; + } else + kdWarning(7118) << "Unsupported mode " << mode << ". Only IO_ReadOnly and IO_WriteOnly supported" << endl; + m_mode = mode; +} + +void KBzip2Filter::terminate() +{ + if ( m_mode == IO_ReadOnly ) + { + int result = bzDecompressEnd(&d->zStream); + kdDebug(7118) << "bzDecompressEnd returned " << result << endl; + } else if ( m_mode == IO_WriteOnly ) + { + int result = bzCompressEnd(&d->zStream); + kdDebug(7118) << "bzCompressEnd returned " << result << endl; + } else + kdWarning(7118) << "Unsupported mode " << m_mode << ". Only IO_ReadOnly and IO_WriteOnly supported" << endl; +} + + +void KBzip2Filter::reset() +{ + kdDebug(7118) << "KBzip2Filter::reset" << endl; + // bzip2 doesn't seem to have a reset call... + terminate(); + init( m_mode ); +} + +void KBzip2Filter::setOutBuffer( char * data, uint maxlen ) +{ + d->zStream.avail_out = maxlen; + d->zStream.next_out = data; +} + +void KBzip2Filter::setInBuffer( const char *data, unsigned int size ) +{ + d->zStream.avail_in = size; + d->zStream.next_in = const_cast(data); +} + +int KBzip2Filter::inBufferAvailable() const +{ + return d->zStream.avail_in; +} + +int KBzip2Filter::outBufferAvailable() const +{ + return d->zStream.avail_out; +} + +KBzip2Filter::Result KBzip2Filter::uncompress() +{ + //kdDebug(7118) << "Calling bzDecompress with avail_in=" << inBufferAvailable() << " avail_out=" << outBufferAvailable() << endl; + int result = bzDecompress(&d->zStream); + if ( result != BZ_OK ) + { + kdDebug(7118) << "bzDecompress returned " << result << endl; + kdDebug(7118) << "KBzip2Filter::uncompress " << ( result == BZ_OK ? OK : ( result == BZ_STREAM_END ? END : ERROR ) ) << endl; + } + + switch (result) { + case BZ_OK: + return OK; + case BZ_STREAM_END: + return END; + default: + return ERROR; + } +} + +KBzip2Filter::Result KBzip2Filter::compress( bool finish ) +{ + //kdDebug(7118) << "Calling bzCompress with avail_in=" << inBufferAvailable() << " avail_out=" << outBufferAvailable() << endl; + int result = bzCompress(&d->zStream, finish ? BZ_FINISH : BZ_RUN ); + + switch (result) { + case BZ_OK: + case BZ_FLUSH_OK: + case BZ_RUN_OK: + case BZ_FINISH_OK: + return OK; + break; + case BZ_STREAM_END: + kdDebug(7118) << " bzCompress returned " << result << endl; + return END; + break; + default: + kdDebug(7118) << " bzCompress returned " << result << endl; + return ERROR; + break; + } +} + +#endif diff --git a/kioslave/bzip2/kbzip2filter.desktop b/kioslave/bzip2/kbzip2filter.desktop new file mode 100644 index 000000000..d9d90ec88 --- /dev/null +++ b/kioslave/bzip2/kbzip2filter.desktop @@ -0,0 +1,86 @@ +[Desktop Entry] +Type=Service +Name=BZip2 Filter +Name[af]=Bzip2 Filter +Name[ar]=فلتر BZip2 +Name[az]=BZip2 Filtri +Name[be]=Фільтр BZip2 +Name[bg]=Филтър BZip2 +Name[bn]=বি-জিপ২ (BZip2) ফিল্টার +Name[br]=Sil BZip2 +Name[ca]=Filtre BZip2 +Name[cs]=Filtr BZip2 +Name[csb]=Filter BZip2 +Name[cy]=Hidl BZip2 +Name[da]=BZip2-filter +Name[de]=BZip2-Filter +Name[el]=Φίλτρο BZip2 +Name[eo]=Bzip2-filtrilo +Name[es]=Filtro BZip2 +Name[et]=BZip2 filter +Name[eu]=BZip2 iragazkia +Name[fa]=پالایۀ BZip2 +Name[fi]=BZip2-suodin +Name[fr]=Filtre Bzip2 +Name[fy]=BZip2-filter +Name[ga]=Scagaire bzip2 +Name[gl]=Filtro BZip2 +Name[he]=מסנן BZip2 +Name[hi]=BZip2 फ़िल्टर +Name[hr]=BZip2 filtar +Name[hu]=BZip2 szűrő +Name[id]=Filter BZip2 +Name[is]=BZip2 sía +Name[it]=Filtro Bzip2 +Name[ja]=BZip2 フィルタ +Name[ka]=Bzip2 ფილტრი +Name[kk]=BZip2 сүзгісі +Name[km]=តម្រង BZip2 +Name[ko]=BZip2 거르개 +Name[lb]=BZip2-Filter +Name[lt]=BZip2 filtras +Name[lv]=BZip2 Filtrs +Name[mk]=BZip2 филтер +Name[mn]=BZip2-Filter +Name[ms]=Penapis BZip2 +Name[mt]=Filtru BZip2 +Name[nb]=BZip2-filter +Name[nds]=BZip2-Filter +Name[ne]=BZip2 फिल्टर +Name[nl]=BZip2-filter +Name[nn]=BZip2-filter +Name[nso]=Sesekodi sa BZip2 +Name[pa]=BZip2 ਫਿਲਟਰ +Name[pl]=Filtr BZip2 +Name[pt]=Filtro do Bzip2 +Name[pt_BR]=Filtro BZip2 +Name[ro]=Filtru BZip2 +Name[ru]=Фильтр bzip2 +Name[rw]=Muyunguruzi BZipu2 +Name[se]=BZip2-filter +Name[sk]=BZip2 filter +Name[sl]=Filter za bzip2 +Name[sq]=Filteri BZip2 +Name[sr]=BZip2 филтер +Name[sr@Latn]=BZip2 filter +Name[ss]=Sisefo se BZip2 +Name[sv]=Bzip2-filter +Name[ta]=BZip2 வடிகட்டி +Name[te]=బిజిప్2 గలని +Name[tg]=Таровиши BZip2 +Name[th]=ตัวกรอง BZip2 +Name[tr]=BZip2 Filtresi +Name[tt]=BZip2 Sözgeçe +Name[uk]=Фільтр BZip2 +Name[uz]=BZip2-filter +Name[uz@cyrillic]=BZip2-филтер +Name[ven]=Filithara ya BZip2 +Name[vi]=Bộ lọc BZip2 +Name[wa]=Passete BZip2 +Name[xh]=Isihluzi se BZip2 +Name[zh_CN]=BZip2 过滤程序 +Name[zh_HK]=BZip2 過濾器 +Name[zh_TW]=BZip2 過濾器 +Name[zu]=Ihluzo le-BZip2 +X-KDE-Library=kbzip2filter +ServiceTypes=KDECompressionFilter,application/x-bzip2,application/x-tbz diff --git a/kioslave/bzip2/kbzip2filter.h b/kioslave/bzip2/kbzip2filter.h new file mode 100644 index 000000000..47ccef915 --- /dev/null +++ b/kioslave/bzip2/kbzip2filter.h @@ -0,0 +1,54 @@ +/* This file is part of the KDE libraries + Copyright (C) 2000 David Faure + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __kbzip2filter__h +#define __kbzip2filter__h + +#include + +#if defined( HAVE_BZIP2_SUPPORT ) + +#include "kfilterbase.h" + +class KBzip2Filter : public KFilterBase +{ +public: + KBzip2Filter(); + virtual ~KBzip2Filter(); + + virtual void init( int ); + virtual int mode() const { return m_mode; } + virtual void terminate(); + virtual void reset(); + virtual bool readHeader() { return true; } // bzip2 handles it by itself ! Cool ! + virtual bool writeHeader( const QCString & ) { return true; } + virtual void setOutBuffer( char * data, uint maxlen ); + virtual void setInBuffer( const char * data, uint size ); + virtual int inBufferAvailable() const; + virtual int outBufferAvailable() const; + virtual Result uncompress(); + virtual Result compress( bool finish ); +private: + class KBzip2FilterPrivate; + KBzip2FilterPrivate *d; + int m_mode; +}; + +#endif + +#endif -- cgit v1.2.1