1
//=============================================================================
3
// File : KviPackageIOEngine.cpp
4
// Creation date : Tue 26 Dec 2006 05:33:33 by Szymon Stefanek
6
// This file is part of the KVIrc IRC Client distribution
7
// Copyright (C) 2006-2010 Szymon Stefanek <pragma at kvirc dot net>
9
// This program is FREE software. You can redistribute it and/or
10
// modify it under the terms of the GNU General Public License
11
// as published by the Free Software Foundation; either version 2
12
// of the License, or (at your opinion) any later version.
14
// This program 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.
17
// See the GNU General Public License for more details.
19
// You should have received a copy of the GNU General Public License
20
// along with this program. If not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
//=============================================================================
25
#include "KviPackageIOEngine.h"
26
#include "KviLocale.h"
28
#include <QApplication>
29
#include <QProgressDialog>
34
// A KVIrc Package File is basically a simple zip file with some additional meta-data.
35
// The package file has the following format
38
// Field Type Bytes Description
39
//-------------------------------------------------------------------------------
46
// Magic Bytes 4 'KVPF': Signature for the Kvirc Package File
47
// Version uint32 4 0x00000001: Version of this package file
48
// Flags uint32 4 0x00000000: Flags, in version 1 is reserved and must be zero
52
// InfoFieldCount uint32 4 Number of package info fields
53
// InfoField InfoField Variable A list of informational name-value pairs
54
// InfoField InfoField Variable A list of informational name-value pairs
55
// InfoField InfoField Variable A list of informational name-value pairs
59
// DataField DataField Variable A list of data fields with format defined below
60
// DataField DataField Variable A list of data fields with format defined below
61
// DataField DataField Variable A list of data fields with format defined below
65
// Name UniString Variable The "name" element of the info field
66
// ValueType uint32 4 The type of the following ValueData field
67
// ValueData ValueData Variable
69
// ValueData for ValueType 1 (string field)
70
// Value UniString Variable The value element of type string of the the info field
72
// ValueData for ValueType 2 (binary buffer field)
73
// BufferLen uint32 4 The length of the binary buffer
74
// BufferData Bytes Variable The data for the binary buffer
78
// StringLen uint32 4 The length of the string data in BYTES (null terminator NOT included)
79
// StringData Bytes StringLen An utf8 encoded string (do NOT write the NULL terminator)
82
// Byte uint8 1 A byte
83
// Byte uint8 1 A byte
87
// FieldType uint32 4 The type of the field, see below for defined values
88
// FieldLen uint32 4 FieldData length in bytes (useful for skipping a field if unsupported)
89
// FieldData Variable FieldLen The data of the field, see below for defined values
91
// FieldData for FieldType 1 (file field)
92
// Flags uint32 4 Bitmask. Bits: 1=FileIsDeflated
93
// Path UniString Variable A relative path expressed as utf8 string. \ AND / are considered to be separators
94
// Size uint32 4 Size of the following file data
95
// FilePayload Bytes Variable
97
// Everything is stored in LITTLE ENDIAN byte order.
99
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
102
KviPackageIOEngine::KviPackageIOEngine()
104
m_pProgressDialog = 0;
105
m_pStringInfoFields = new KviPointerHashTable<QString,QString>();
106
m_pStringInfoFields->setAutoDelete(true);
107
m_pBinaryInfoFields = new KviPointerHashTable<QString,QByteArray>();
108
m_pBinaryInfoFields->setAutoDelete(true);
111
KviPackageIOEngine::~KviPackageIOEngine()
113
if(m_pProgressDialog)delete m_pProgressDialog;
114
delete m_pStringInfoFields;
115
delete m_pBinaryInfoFields;
118
bool KviPackageIOEngine::updateProgress(int iProgress,const QString &szLabel)
120
if(!m_pProgressDialog)return true;
122
m_pProgressDialog->setValue(iProgress);
123
m_pProgressDialogLabel->setText(szLabel);
124
qApp->processEvents();
125
if(m_pProgressDialog->wasCanceled())
127
setLastError(__tr2qs("Operation cancelled"));
133
void KviPackageIOEngine::showProgressDialog(const QString &szCaption,int iTotalSteps)
135
m_pProgressDialog = new QProgressDialog(QString(""),__tr2qs("Cancel"),0,iTotalSteps,0);
136
m_pProgressDialog->setModal(true);
137
m_pProgressDialog->setWindowTitle(szCaption);
139
m_pProgressDialogLabel = new QLabel(m_pProgressDialog);
140
m_pProgressDialogLabel->setMaximumSize(500,300);
141
m_pProgressDialog->setLabel(m_pProgressDialogLabel);
144
void KviPackageIOEngine::hideProgressDialog()
146
if(!m_pProgressDialog)return;
147
delete m_pProgressDialog;
148
m_pProgressDialog = 0;
151
bool KviPackageIOEngine::writeError()
153
setLastError(__tr2qs("File write error"));
157
bool KviPackageIOEngine::readError()
159
setLastError(__tr2qs("File read error"));