~ubuntu-branches/ubuntu/trusty/kvirc/trusty-proposed

« back to all changes in this revision

Viewing changes to src/kvilib/file/KviPackageIOEngine.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=============================================================================
 
2
//
 
3
//   File : KviPackageIOEngine.cpp
 
4
//   Creation date : Tue 26 Dec 2006 05:33:33 by Szymon Stefanek
 
5
//
 
6
//   This file is part of the KVIrc IRC Client distribution
 
7
//   Copyright (C) 2006-2010 Szymon Stefanek <pragma at kvirc dot net>
 
8
//
 
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.
 
13
//
 
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.
 
18
//
 
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.
 
22
//
 
23
//=============================================================================
 
24
 
 
25
#include "KviPackageIOEngine.h"
 
26
#include "KviLocale.h"
 
27
 
 
28
#include <QApplication>
 
29
#include <QProgressDialog>
 
30
#include <QLabel>
 
31
 
 
32
 
 
33
//
 
34
// A KVIrc Package File is basically a simple zip file with some additional meta-data.
 
35
// The package file has the following format
 
36
//
 
37
 
 
38
// Field               Type       Bytes           Description
 
39
//-------------------------------------------------------------------------------
 
40
// Package:
 
41
//   PackageHeader
 
42
//   PackageInfo
 
43
//   PackageData
 
44
 
 
45
// PackageHeader:
 
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
 
49
//
 
50
 
 
51
// PackageInfo:
 
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
 
56
//   ....              ....       ....
 
57
 
 
58
// PackageData:
 
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
 
62
//   ....              ....       ....
 
63
 
 
64
// InfoField:
 
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
 
68
 
 
69
// ValueData for ValueType 1 (string field)
 
70
//   Value             UniString  Variable        The value element of type string of the the info field
 
71
 
 
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
 
75
 
 
76
 
 
77
// UniString:
 
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)
 
80
 
 
81
// Bytes:
 
82
//   Byte              uint8      1               A byte
 
83
//   Byte              uint8      1               A byte
 
84
//   ....              ....       ....
 
85
 
 
86
// DataField:
 
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
 
90
 
 
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
 
96
 
 
97
// Everything is stored in LITTLE ENDIAN byte order.
 
98
 
 
99
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
100
// Da Base Engine
 
101
 
 
102
KviPackageIOEngine::KviPackageIOEngine()
 
103
{
 
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);
 
109
}
 
110
 
 
111
KviPackageIOEngine::~KviPackageIOEngine()
 
112
{
 
113
        if(m_pProgressDialog)delete m_pProgressDialog;
 
114
        delete m_pStringInfoFields;
 
115
        delete m_pBinaryInfoFields;
 
116
}
 
117
 
 
118
bool KviPackageIOEngine::updateProgress(int iProgress,const QString &szLabel)
 
119
{
 
120
        if(!m_pProgressDialog)return true;
 
121
 
 
122
        m_pProgressDialog->setValue(iProgress);
 
123
        m_pProgressDialogLabel->setText(szLabel);
 
124
        qApp->processEvents();
 
125
        if(m_pProgressDialog->wasCanceled())
 
126
        {
 
127
                setLastError(__tr2qs("Operation cancelled"));
 
128
                return false;
 
129
        }
 
130
        return true;
 
131
}
 
132
 
 
133
void KviPackageIOEngine::showProgressDialog(const QString &szCaption,int iTotalSteps)
 
134
{
 
135
        m_pProgressDialog = new QProgressDialog(QString(""),__tr2qs("Cancel"),0,iTotalSteps,0);
 
136
        m_pProgressDialog->setModal(true);
 
137
        m_pProgressDialog->setWindowTitle(szCaption);
 
138
 
 
139
        m_pProgressDialogLabel = new QLabel(m_pProgressDialog);
 
140
        m_pProgressDialogLabel->setMaximumSize(500,300);
 
141
        m_pProgressDialog->setLabel(m_pProgressDialogLabel);
 
142
}
 
143
 
 
144
void KviPackageIOEngine::hideProgressDialog()
 
145
{
 
146
        if(!m_pProgressDialog)return;
 
147
        delete m_pProgressDialog;
 
148
        m_pProgressDialog = 0;
 
149
}
 
150
 
 
151
bool KviPackageIOEngine::writeError()
 
152
{
 
153
        setLastError(__tr2qs("File write error"));
 
154
        return false;
 
155
}
 
156
 
 
157
bool KviPackageIOEngine::readError()
 
158
{
 
159
        setLastError(__tr2qs("File read error"));
 
160
        return false;
 
161
}
 
162
 
 
163