Browse Source

Add XZ tdeioslave

Based on KDE GIT commit bbe9e8f5
Francois Andriot 5 years ago
parent
commit
7f328ba699

+ 12
- 0
CMakeLists.txt View File

@@ -90,6 +90,7 @@ option( WITH_CONSOLEKIT "Enable ConsoleKit support" ${WITH_ALL_OPTIONS} )
90 90
 OPTION( WITH_NETWORK_MANAGER_BACKEND "Enable network-manager support" OFF )
91 91
 OPTION( WITH_SUDO_TDESU_BACKEND "Use sudo as backend for tdesu (default is su)" OFF )
92 92
 OPTION( WITH_OLD_XDG_STD "Use the pre R14.0.0 XDG standard where both TDE and KDE are recognized in desktop files" OFF )
93
+OPTION( WITH_LZMA "Enable support for LZMA/XZ" ${WITH_ALL_OPTIONS} )
93 94
 
94 95
 OPTION( WITH_ASPELL "Enable aspell support" ${WITH_ALL_OPTIONS} )
95 96
 OPTION( WITH_HSPELL "Enable hspell support" ${WITH_ALL_OPTIONS} )
@@ -493,6 +494,17 @@ if( BZIP2_NEED_PREFIX )
493 494
 endif( BZIP2_NEED_PREFIX )
494 495
 
495 496
 
497
+##### check for lzma/xz #########################
498
+
499
+if( WITH_LZMA )
500
+  pkg_search_module( LZMA liblzma )
501
+  if( NOT LZMA_FOUND )
502
+    tde_message_fatal( "LZMA are requested, but not found on your system" )
503
+  endif( NOT LZMA_FOUND )
504
+  set( HAVE_XZ_SUPPORT 1 )
505
+endif( WITH_LZMA )
506
+
507
+
496 508
 ##### check for jpeg ############################
497 509
 
498 510
 find_package( JPEG )

+ 3
- 0
config.h.cmake View File

@@ -62,6 +62,9 @@
62 62
 /* Defines if bzip2 is compiled */
63 63
 #cmakedefine HAVE_BZIP2_SUPPORT 1
64 64
 
65
+/* Defines if lzma/xz is compiled */
66
+#cmakedefine HAVE_XZ_SUPPORT 1
67
+
65 68
 /* Define to 1 if you have the <Carbon/Carbon.h> header file. */
66 69
 #cmakedefine HAVE_CARBON_CARBON_H 1
67 70
 

+ 1
- 0
tdecore/kdebug.areas View File

@@ -289,6 +289,7 @@
289 289
 7126        tdeio_devices
290 290
 7127        tdeio_fish
291 291
 7128        tdeio_svn
292
+7131        tdeio_xz
292 293
 
293 294
 # tdesdk
294 295
 8100        kompare

+ 4
- 0
tdecore/kurl.cpp View File

@@ -1482,6 +1482,10 @@ bool KURL::hasSubURL() const
1482 1482
      return true;
1483 1483
   if (m_strRef_encoded.startsWith("zip:"))
1484 1484
      return true;
1485
+  if (m_strRef_encoded.startsWith("lzma:"))
1486
+     return true;
1487
+  if (m_strRef_encoded.startsWith("xz:"))
1488
+     return true;
1485 1489
   if ( m_strProtocol == "error" ) // anything that starts with error: has suburls
1486 1490
      return true;
1487 1491
   return false;

+ 3
- 0
tdeio/magic View File

@@ -484,6 +484,9 @@
484 484
 # ACE archive
485 485
 7      string        **ACE**     application/x-ace
486 486
 
487
+# XZ
488
+0	string           \0fd\037\07a\058\05a\000             application/x-xz
489
+
487 490
 
488 491
 #------------------------------------------------------------------------------
489 492
 # frame:  file(1) magic for FrameMaker files

+ 10
- 0
tdeio/tests/kfiltertest.cpp View File

@@ -94,11 +94,14 @@ int main()
94 94
     getcwd( currentdir, PATH_MAX );
95 95
     TQString pathgz = TQFile::decodeName(currentdir) + "/test.gz";
96 96
     TQString pathbz2 = TQFile::decodeName(currentdir) + "/test.bz2";
97
+    TQString pathxz = TQFile::decodeName(currentdir) + "/test.xz";
97 98
 
98 99
     kdDebug() << " -- test_block_write gzip -- " << endl;
99 100
     test_block_write(pathgz);
100 101
     kdDebug() << " -- test_block_write bzip2 -- " << endl;
101 102
     test_block_write(pathbz2);
103
+    kdDebug() << " -- test_block_write xz -- " << endl;
104
+    test_block_write(pathxz);
102 105
 
103 106
     kdDebug() << " -- test_block gzip -- " << endl;
104 107
     test_block(pathgz);
@@ -114,5 +117,12 @@ int main()
114 117
     kdDebug() << " -- test_textstream bzip2 -- " << endl;
115 118
     test_textstream(pathbz2);
116 119
 
120
+    kdDebug() << " -- test_block xz -- " << endl;
121
+    test_block(pathxz);
122
+    kdDebug() << " -- test_getch xz -- " << endl;
123
+    test_getch(pathxz);
124
+    kdDebug() << " -- test_textstream xz -- " << endl;
125
+    test_textstream(pathxz);
126
+
117 127
     return 0;
118 128
 }

+ 1
- 0
tdeioslave/CMakeLists.txt View File

@@ -14,5 +14,6 @@ add_subdirectory( http )
14 14
 add_subdirectory( ftp )
15 15
 add_subdirectory( gzip )
16 16
 add_subdirectory( bzip2 )
17
+tde_conditional_add_subdirectory( WITH_LZMA xz )
17 18
 add_subdirectory( metainfo )
18 19
 add_subdirectory( iso )

+ 42
- 0
tdeioslave/xz/CMakeLists.txt View File

@@ -0,0 +1,42 @@
1
+#################################################
2
+#
3
+#  (C) 2010 Serghei Amelian
4
+#  serghei (DOT) amelian (AT) gmail.com
5
+#
6
+#  Improvements and feedback are welcome
7
+#
8
+#  This file is released under GPL >= 2
9
+#
10
+#################################################
11
+
12
+include_directories(
13
+  ${TQT_INCLUDE_DIRS}
14
+  ${CMAKE_BINARY_DIR}
15
+  ${CMAKE_BINARY_DIR}/tdecore
16
+  ${CMAKE_SOURCE_DIR}/tdecore
17
+  ${CMAKE_SOURCE_DIR}/tdeio/tdeio
18
+)
19
+
20
+link_directories(
21
+  ${TQT_LIBRARY_DIRS}
22
+)
23
+
24
+
25
+##### other data ################################
26
+
27
+install( FILES kxzfilter.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
28
+
29
+
30
+##### kxzfilter ###############################
31
+
32
+set( target kxzfilter )
33
+
34
+set( ${target}_SRCS
35
+  kxzfilter.cpp
36
+)
37
+
38
+tde_add_kpart( ${target} AUTOMOC
39
+  SOURCES ${${target}_SRCS}
40
+  LINK tdeio-shared ${LZMA_LIBRARIES}
41
+  DESTINATION ${PLUGIN_INSTALL_DIR}
42
+)

+ 189
- 0
tdeioslave/xz/kxzfilter.cpp View File

@@ -0,0 +1,189 @@
1
+/* This file is part of the KDE libraries
2
+   Copyright (C) 2007-2008 Per Øyvind Karlsen <peroyvind@mandriva.org>
3
+
4
+   Based on kbzip2filter:
5
+   Copyright (C) 2000-2005 David Faure <faure@kde.org>
6
+
7
+   This library is free software; you can redistribute it and/or
8
+   modify it under the terms of the GNU Library General Public
9
+   License as published by the Free Software Foundation; either
10
+   version 2 of the License, or (at your option) any later version.
11
+
12
+   This library is distributed in the hope that it will be useful,
13
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+   Library General Public License for more details.
16
+
17
+   You should have received a copy of the GNU Library General Public License
18
+   along with this library; see the file COPYING.LIB.  If not, write to
19
+   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
+   Boston, MA 02110-1301, USA.
21
+*/
22
+
23
+#include "kxzfilter.h"
24
+#include <klibloader.h>
25
+
26
+#include <config.h>
27
+#if HAVE_XZ_SUPPORT
28
+extern "C" {
29
+	#include <lzma.h>
30
+}
31
+
32
+#include <kdebug.h>
33
+
34
+#include <tqiodevice.h>
35
+
36
+// #define DEBUG_XZ
37
+
38
+class KXzFilterFactory : public KLibFactory
39
+{
40
+public:
41
+    KXzFilterFactory() : KLibFactory() {}
42
+    virtual ~KXzFilterFactory(){}
43
+    TQObject *createObject( TQObject *, const char *, const char*, const TQStringList & )
44
+    {
45
+        return new KXzFilter;
46
+    }
47
+};
48
+
49
+K_EXPORT_COMPONENT_FACTORY( kxzfilter, KXzFilterFactory )
50
+
51
+
52
+class KXzFilter::Private
53
+{
54
+public:
55
+    Private()
56
+    : isInitialized(false)
57
+    {
58
+        memset(&zStream, 0, sizeof(zStream));
59
+        mode = 0;
60
+    }
61
+
62
+    lzma_stream zStream;
63
+    int mode;
64
+    bool isInitialized;
65
+};
66
+
67
+KXzFilter::KXzFilter()
68
+    :d(new Private)
69
+{
70
+}
71
+
72
+
73
+KXzFilter::~KXzFilter()
74
+{
75
+    delete d;
76
+}
77
+
78
+void KXzFilter::init( int mode )
79
+{
80
+    if (d->isInitialized) {
81
+        terminate();
82
+    }
83
+  
84
+    lzma_ret result;
85
+    d->zStream.next_in = 0;
86
+    d->zStream.avail_in = 0;
87
+    if ( mode == IO_ReadOnly )
88
+    {
89
+	/* We set the memlimit for decompression to 100MiB which should be
90
+	 * more than enough to be sufficient for level 9 which requires 65 MiB.
91
+	 */
92
+        result = lzma_auto_decoder(&d->zStream, 100<<20, 0);
93
+    	//kdDebug(7131) << "lzma_auto_decoder returned " << result;
94
+    } else if ( mode == IO_WriteOnly ) {
95
+        result = lzma_easy_encoder(&d->zStream, LZMA_PRESET_DEFAULT, LZMA_CHECK_CRC32);
96
+    	//kdDebug(7131) << "lzma_easy_encoder returned " << result;
97
+    } else
98
+        kdWarning(7131) << "Unsupported mode " << mode << ". Only IO_ReadOnly and IO_WriteOnly supported";
99
+    d->mode = mode;
100
+    d->isInitialized = true;
101
+}
102
+
103
+int KXzFilter::mode() const
104
+{
105
+    return d->mode;
106
+}
107
+
108
+void KXzFilter::terminate()
109
+{
110
+    if (d->mode == IO_ReadOnly || d->mode == IO_WriteOnly) {
111
+        lzma_end(&d->zStream);
112
+    } else {
113
+        kdWarning(7131) << "Unsupported mode " << d->mode << ". Only IO_ReadOnly and IO_WriteOnly supported";
114
+    }
115
+    d->isInitialized = false;
116
+}
117
+
118
+
119
+void KXzFilter::reset()
120
+{
121
+    //kdDebug(7131) << "KXzFilter::reset";
122
+    // liblzma doesn't have a reset call...
123
+    terminate();
124
+    init( d->mode );
125
+}
126
+
127
+void KXzFilter::setOutBuffer( char * data, uint maxlen )
128
+{
129
+    d->zStream.avail_out = maxlen;
130
+    d->zStream.next_out = (uint8_t *)data;
131
+}
132
+
133
+void KXzFilter::setInBuffer( const char *data, unsigned int size )
134
+{
135
+    d->zStream.avail_in = size;
136
+    d->zStream.next_in = (uint8_t *)const_cast<char *>(data);
137
+}
138
+
139
+int KXzFilter::inBufferAvailable() const
140
+{
141
+    return d->zStream.avail_in;
142
+}
143
+
144
+int KXzFilter::outBufferAvailable() const
145
+{
146
+    return d->zStream.avail_out;
147
+}
148
+
149
+KXzFilter::Result KXzFilter::uncompress()
150
+{
151
+    //kdDebug(7131) << "Calling lzma_code with avail_in=" << inBufferAvailable() << " avail_out =" << outBufferAvailable();
152
+    lzma_ret result = lzma_code(&d->zStream, LZMA_RUN);
153
+    if ( result != LZMA_OK )
154
+    {
155
+        kdDebug(7131) << "lzma_code returned " << result;
156
+        kdDebug(7131) << "KXzFilter::uncompress " << ( result == LZMA_STREAM_END ? END : ERROR );
157
+    }
158
+
159
+    switch (result) {
160
+        case LZMA_OK:
161
+                return OK;
162
+        case LZMA_STREAM_END:
163
+                return END;
164
+        default:
165
+                return ERROR;
166
+    }
167
+}
168
+
169
+KXzFilter::Result KXzFilter::compress( bool finish )
170
+{
171
+    //kdDebug(7131) << "Calling lzma_code with avail_in=" << inBufferAvailable() << " avail_out=" << outBufferAvailable();
172
+    lzma_ret result = lzma_code(&d->zStream, finish ? LZMA_FINISH : LZMA_RUN );
173
+
174
+    switch (result) {
175
+        case LZMA_OK:
176
+                return OK;
177
+                break;
178
+        case LZMA_STREAM_END:
179
+                kdDebug(7131) << "  lzma_code returned " << result;
180
+                return END;
181
+		break;
182
+        default:
183
+                kdDebug(7131) << "  lzma_code returned " << result;
184
+                return ERROR;
185
+                break;
186
+    }
187
+}
188
+
189
+#endif  /* HAVE_XZ_SUPPORT */

+ 86
- 0
tdeioslave/xz/kxzfilter.desktop View File

@@ -0,0 +1,86 @@
1
+[Desktop Entry]
2
+Type=Service
3
+Name=XZ Filter
4
+Name[af]=XZ Filter
5
+Name[ar]=فلتر XZ
6
+Name[az]=XZ Filtri
7
+Name[be]=Фільтр XZ
8
+Name[bg]=Филтър XZ
9
+Name[bn]=জি-জিপ (XZ) ফিল্টার
10
+Name[br]=Sil XZ
11
+Name[ca]=Filtre XZ
12
+Name[cs]=Filtr XZ
13
+Name[csb]=Filter XZ
14
+Name[cy]=Hidl XZ
15
+Name[da]=XZ-filter
16
+Name[de]=XZ-Filter
17
+Name[el]=Φίλτρο XZ
18
+Name[eo]=XZ-filtrilo
19
+Name[es]=Filtro XZ
20
+Name[et]=XZ filter
21
+Name[eu]=XZ iragazkia
22
+Name[fa]=پالایۀ XZ
23
+Name[fi]=XZ-suodin
24
+Name[fr]=Filtre XZ
25
+Name[fy]=XZ-filter
26
+Name[ga]=Scagaire XZ
27
+Name[gl]=Filtro XZ
28
+Name[he]=מסנן XZ
29
+Name[hi]=XZ फ़िल्टर
30
+Name[hr]=XZ filtar
31
+Name[hu]=XZ szűrő
32
+Name[id]=Filter XZ
33
+Name[is]=XZ sía
34
+Name[it]=Filtro XZ
35
+Name[ja]=XZ フィルタ
36
+Name[ka]=XZ ფილტრი
37
+Name[kk]=XZ сүзгісі
38
+Name[km]=តម្រង XZ
39
+Name[ko]=XZ 거르개
40
+Name[lb]=XZ-Filter
41
+Name[lt]=XZ filtras
42
+Name[lv]=XZ Filtrs
43
+Name[mk]=XZ филтер
44
+Name[mn]=XZ-Filter
45
+Name[ms]=Penapis XZ
46
+Name[mt]=Filtru XZ
47
+Name[nb]=XZ-filter
48
+Name[nds]=XZ-Filter
49
+Name[ne]=XZ फिल्टर
50
+Name[nl]=XZ-filter
51
+Name[nn]=XZ-filter
52
+Name[nso]=Sesekodi sa XZ
53
+Name[pa]=XZ ਫਿਲਟਰ
54
+Name[pl]=Filtr XZ
55
+Name[pt]=Filtro XZ
56
+Name[pt_BR]=Filtro XZ
57
+Name[ro]=Filtru XZ
58
+Name[ru]=Фильтр XZ
59
+Name[rw]=Muyunguruzi XZ 
60
+Name[se]=XZ-filter
61
+Name[sk]=XZ filter
62
+Name[sl]=Filter za XZ
63
+Name[sq]=Filteri XZ
64
+Name[sr]=XZ филтер
65
+Name[sr@Latn]=XZ filter
66
+Name[ss]=Sisefo se XZ 
67
+Name[sv]=XZ-filter
68
+Name[ta]=XZ வடிகட்டி
69
+Name[te]=జిజిప్ గలని
70
+Name[tg]=Таровиши XZ
71
+Name[th]=ตัวกรอง XZ
72
+Name[tr]=XZ Filtresi
73
+Name[tt]=XZ Sözgeçe
74
+Name[uk]=Фільтр XZ
75
+Name[uz]=XZ-filter
76
+Name[uz@cyrillic]=XZ-филтер
77
+Name[ven]=Filithara ya XZ
78
+Name[vi]=Bộ lọc XZ
79
+Name[wa]=Passete XZ
80
+Name[xh]=Isihluzi se XZ
81
+Name[zh_CN]=XZ 过滤程序
82
+Name[zh_HK]=XZ 過濾器
83
+Name[zh_TW]=XZ 過濾器
84
+Name[zu]=Ihluzo le-XZ
85
+X-TDE-Library=kxzfilter
86
+ServiceTypes=TDECompressionFilter,application/x-xz,application/x-txz,application/x-lzma

+ 60
- 0
tdeioslave/xz/kxzfilter.h View File

@@ -0,0 +1,60 @@
1
+/* This file is part of the KDE libraries
2
+   Copyright (C) 2007-2008 Per Øyvind Karlsen <peroyvind@mandriva.org>
3
+
4
+   Based on kbzip2filter:
5
+   Copyright (C) 2000 David Faure <faure@kde.org>
6
+
7
+   This library is free software; you can redistribute it and/or
8
+   modify it under the terms of the GNU Library General Public
9
+   License as published by the Free Software Foundation; either
10
+   version 2 of the License, or (at your option) any later version.
11
+
12
+   This library is distributed in the hope that it will be useful,
13
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+   Library General Public License for more details.
16
+
17
+   You should have received a copy of the GNU Library General Public License
18
+   along with this library; see the file COPYING.LIB.  If not, write to
19
+   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
+   Boston, MA 02110-1301, USA.
21
+*/
22
+
23
+#ifndef KXZFILTER_H
24
+#define KXZFILTER_H
25
+
26
+#include <config.h>
27
+#if HAVE_XZ_SUPPORT
28
+
29
+#include "kfilterbase.h"
30
+
31
+/**
32
+ * Internal class used by KFilterDev
33
+ * @internal
34
+ */
35
+class KXzFilter : public KFilterBase
36
+{
37
+public:
38
+    KXzFilter();
39
+    virtual ~KXzFilter();
40
+
41
+    virtual void init( int );
42
+    virtual int mode() const;
43
+    virtual void terminate();
44
+    virtual void reset();
45
+    virtual bool readHeader() { return true; } // lzma handles it by itself ! Cool !
46
+    virtual bool writeHeader( const TQCString & ) { return true; }
47
+    virtual void setOutBuffer( char * data, uint maxlen );
48
+    virtual void setInBuffer( const char * data, uint size );
49
+    virtual int  inBufferAvailable() const;
50
+    virtual int  outBufferAvailable() const;
51
+    virtual Result uncompress();
52
+    virtual Result compress( bool finish );
53
+private:
54
+    class Private;
55
+    Private* const d;
56
+};
57
+
58
+#endif
59
+
60
+#endif // KXZFILTER_H

Loading…
Cancel
Save