~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/xpinstall/wizard/unix/src2/nsComponent.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/*
 
3
 * The contents of this file are subject to the Netscape Public
 
4
 * License Version 1.1 (the "License"); you may not use this file
 
5
 * except in compliance with the License. You may obtain a copy of
 
6
 * the License at http://www.mozilla.org/NPL/
 
7
 *
 
8
 * Software distributed under the License is distributed on an "AS
 
9
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
10
 * implied. See the License for the specific language governing
 
11
 * rights and limitations under the License.
 
12
 *
 
13
 * The Original Code is Mozilla Communicator client code, 
 
14
 * released March 31, 1998. 
 
15
 *
 
16
 * The Initial Developer of the Original Code is Netscape Communications 
 
17
 * Corporation.  Portions created by Netscape are
 
18
 * Copyright (C) 1998 Netscape Communications Corporation. All
 
19
 * Rights Reserved.
 
20
 *
 
21
 * Contributor(s): 
 
22
 *     Samir Gehani <sgehani@netscape.com>
 
23
 */
 
24
 
 
25
#include "nsComponent.h"
 
26
#include <sys/stat.h>
 
27
 
 
28
nsComponent::nsComponent() :
 
29
    mDescShort(NULL),
 
30
    mDescLong(NULL),
 
31
    mArchive(NULL),
 
32
    mInstallSize(0),
 
33
    mArchiveSize(0),
 
34
    mNextDependeeIdx(0),
 
35
    mAttributes(NO_ATTR),
 
36
    mNext(NULL),
 
37
    mIndex(-1),
 
38
    mRefCount(0),
 
39
    mDepRefCount(0),
 
40
    mResPos(0),
 
41
    mDownloaded(FALSE)
 
42
{
 
43
    int i;
 
44
 
 
45
    for (i = 0; i < MAX_URLS; i++)
 
46
        mURL[i] = NULL;
 
47
    for (i = 0; i < MAX_COMPONENTS; i++)
 
48
        mDependees[i] = NULL;
 
49
}
 
50
 
 
51
nsComponent::~nsComponent()
 
52
{
 
53
    int i;
 
54
 
 
55
    XI_IF_FREE(mDescShort);
 
56
    XI_IF_FREE(mDescLong);
 
57
    XI_IF_FREE(mArchive);
 
58
    for (i = 0; i < MAX_URLS; i++)
 
59
        XI_IF_FREE(mURL[i]);
 
60
    for (i = 0; i < MAX_COMPONENTS; i++)
 
61
        XI_IF_FREE(mDependees[i]);
 
62
}
 
63
 
 
64
nsComponent *
 
65
nsComponent::Duplicate()
 
66
{
 
67
    nsComponent *zdup = new nsComponent();
 
68
    *zdup = *this;
 
69
    zdup->InitRefCount();
 
70
    zdup->InitNext();
 
71
 
 
72
    return zdup;
 
73
}
 
74
 
 
75
int
 
76
nsComponent::SetDescShort(char *aDescShort)
 
77
{
 
78
    if (!aDescShort)
 
79
        return E_PARAM;
 
80
 
 
81
    mDescShort = aDescShort;
 
82
 
 
83
    return OK;
 
84
}
 
85
 
 
86
char *
 
87
nsComponent::GetDescShort()
 
88
{
 
89
    if (mDescShort)
 
90
        return mDescShort;
 
91
 
 
92
    return NULL;
 
93
}
 
94
 
 
95
int
 
96
nsComponent::SetDescLong(char *aDescLong)
 
97
{
 
98
    if (!aDescLong)
 
99
        return E_PARAM;
 
100
 
 
101
    mDescLong = aDescLong;
 
102
 
 
103
    return OK;
 
104
}
 
105
 
 
106
char *
 
107
nsComponent::GetDescLong()
 
108
{
 
109
    if (mDescLong)
 
110
        return mDescLong;
 
111
 
 
112
    return NULL;
 
113
}
 
114
 
 
115
int
 
116
nsComponent::SetArchive(char *aArchive)
 
117
{
 
118
    if (!aArchive)
 
119
        return E_PARAM;
 
120
 
 
121
    mArchive = aArchive;
 
122
 
 
123
    return OK;
 
124
}
 
125
 
 
126
char *
 
127
nsComponent::GetArchive()
 
128
{
 
129
    if (mArchive)
 
130
        return mArchive;
 
131
 
 
132
    return NULL;
 
133
}
 
134
 
 
135
int
 
136
nsComponent::SetInstallSize(int aInstallSize)
 
137
{
 
138
    mInstallSize = aInstallSize;
 
139
 
 
140
    return OK;
 
141
}
 
142
 
 
143
int
 
144
nsComponent::GetInstallSize()
 
145
{
 
146
    if (mInstallSize >= 0)
 
147
        return mInstallSize;
 
148
 
 
149
    return 0;
 
150
}
 
151
 
 
152
int
 
153
nsComponent::SetArchiveSize(int aArchiveSize)
 
154
{
 
155
    mArchiveSize = aArchiveSize;
 
156
 
 
157
    return OK;
 
158
}
 
159
 
 
160
int
 
161
nsComponent::GetArchiveSize()
 
162
{
 
163
    if (mArchiveSize >= 0)
 
164
        return mArchiveSize;
 
165
 
 
166
    return 0;
 
167
}
 
168
 
 
169
int
 
170
nsComponent::GetCurrentSize()
 
171
{
 
172
    // assumes cwd is the same as the installer binary location
 
173
 
 
174
    char path[MAXPATHLEN];
 
175
    struct stat stbuf;
 
176
 
 
177
    if (!mArchive)
 
178
        return 0;
 
179
 
 
180
    sprintf(path, "./xpi/%s", mArchive);
 
181
    if (0 != stat(path, &stbuf))
 
182
        return 0;
 
183
 
 
184
    return (stbuf.st_size/1024); // return size in KB
 
185
}
 
186
 
 
187
int
 
188
nsComponent::SetURL(char *aURL, int aIndex)
 
189
{
 
190
    if (!aURL)
 
191
        return E_PARAM;
 
192
    if (mURL[aIndex])
 
193
        return E_URL_ALREADY;
 
194
 
 
195
    mURL[aIndex] = aURL;
 
196
    
 
197
    return OK;
 
198
}
 
199
 
 
200
char *
 
201
nsComponent::GetURL(int aIndex)
 
202
{
 
203
    if (aIndex < 0 || aIndex >= MAX_URLS)
 
204
        return NULL;
 
205
 
 
206
    return mURL[aIndex];
 
207
}
 
208
 
 
209
int
 
210
nsComponent::AddDependee(char *aDependee)
 
211
{
 
212
    if (!aDependee)
 
213
        return E_PARAM;
 
214
 
 
215
    mDependees[mNextDependeeIdx] = aDependee;
 
216
    mDependees[++mNextDependeeIdx] = NULL;
 
217
 
 
218
    return OK;
 
219
}
 
220
 
 
221
int 
 
222
nsComponent::ResolveDependees(int aBeingSelected, nsComponentList *aComps)
 
223
{
 
224
    int i;
 
225
    nsComponent *currComp = NULL;
 
226
    
 
227
    // param check
 
228
    if (!aComps)
 
229
        return E_PARAM;
 
230
 
 
231
    // loop over all dependees
 
232
    for (i = 0; i < mNextDependeeIdx; i++)
 
233
    {
 
234
        if (!mDependees[i])
 
235
            break;
 
236
 
 
237
        currComp = aComps->GetCompByShortDesc(mDependees[i]);
 
238
        if (!currComp)
 
239
            continue;
 
240
        
 
241
        if (aBeingSelected)
 
242
            currComp->DepAddRef();
 
243
        else    
 
244
            currComp->DepRelease();
 
245
    }
 
246
 
 
247
    return OK;
 
248
}
 
249
 
 
250
int
 
251
nsComponent::SetSelected()
 
252
{
 
253
    mAttributes |= nsComponent::SELECTED;
 
254
 
 
255
    return OK;
 
256
}
 
257
 
 
258
int
 
259
nsComponent::SetUnselected()
 
260
{
 
261
    if (IsSelected())
 
262
        mAttributes &= ~nsComponent::SELECTED;
 
263
    mDepRefCount = 0;
 
264
 
 
265
    return OK;
 
266
}
 
267
 
 
268
int
 
269
nsComponent::IsSelected()
 
270
{
 
271
    if (mAttributes & nsComponent::SELECTED)
 
272
        return TRUE;
 
273
 
 
274
    return FALSE;
 
275
}
 
276
 
 
277
int
 
278
nsComponent::SetInvisible()
 
279
{
 
280
    mAttributes |= nsComponent::INVISIBLE;
 
281
 
 
282
    return OK;
 
283
}
 
284
 
 
285
int
 
286
nsComponent::SetVisible()
 
287
{
 
288
    if (IsInvisible())
 
289
        mAttributes &= ~nsComponent::INVISIBLE;
 
290
 
 
291
    return OK;
 
292
}
 
293
 
 
294
int
 
295
nsComponent::IsInvisible()
 
296
{
 
297
    if (mAttributes & nsComponent::INVISIBLE)
 
298
        return TRUE;
 
299
 
 
300
    return FALSE;
 
301
}
 
302
 
 
303
int
 
304
nsComponent::SetLaunchApp()
 
305
{
 
306
    mAttributes |= nsComponent::LAUNCHAPP;
 
307
 
 
308
    return OK;
 
309
}
 
310
 
 
311
int
 
312
nsComponent::SetDontLaunchApp()
 
313
{
 
314
    if (IsLaunchApp())
 
315
        mAttributes &= ~nsComponent::LAUNCHAPP;
 
316
 
 
317
    return OK;
 
318
}
 
319
 
 
320
int
 
321
nsComponent::IsLaunchApp()
 
322
{
 
323
    if (mAttributes & nsComponent::LAUNCHAPP)
 
324
        return TRUE;
 
325
 
 
326
    return FALSE;
 
327
}
 
328
 
 
329
int 
 
330
nsComponent::SetDownloadOnly()
 
331
{
 
332
    mAttributes |= nsComponent::DOWNLOAD_ONLY;
 
333
 
 
334
    return OK;
 
335
}
 
336
 
 
337
int
 
338
nsComponent::IsDownloadOnly()
 
339
{
 
340
    if (mAttributes & nsComponent::DOWNLOAD_ONLY)
 
341
        return TRUE;
 
342
 
 
343
    return FALSE;
 
344
}
 
345
 
 
346
int
 
347
nsComponent::SetNext(nsComponent *aComponent)
 
348
{
 
349
    if (!aComponent)
 
350
        return E_PARAM;
 
351
 
 
352
    mNext = aComponent;
 
353
    
 
354
    return OK;
 
355
}
 
356
 
 
357
int
 
358
nsComponent::InitNext()
 
359
{
 
360
    mNext = NULL;
 
361
 
 
362
    return OK;
 
363
}
 
364
 
 
365
nsComponent *
 
366
nsComponent::GetNext()
 
367
{
 
368
    if (mNext)
 
369
        return mNext;
 
370
 
 
371
    return NULL;
 
372
}
 
373
 
 
374
int
 
375
nsComponent::SetIndex(int aIndex)
 
376
{
 
377
    if (aIndex < 0 || aIndex > MAX_COMPONENTS)
 
378
        return E_OUT_OF_BOUNDS;
 
379
 
 
380
    mIndex = aIndex;
 
381
        
 
382
    return OK;
 
383
}
 
384
 
 
385
int
 
386
nsComponent::GetIndex()
 
387
{
 
388
    if (mIndex < 0 || mIndex > MAX_COMPONENTS)
 
389
        return E_OUT_OF_BOUNDS;
 
390
    
 
391
    return mIndex;
 
392
}
 
393
 
 
394
int
 
395
nsComponent::AddRef()
 
396
{
 
397
    mRefCount++;
 
398
    
 
399
    return OK;
 
400
}
 
401
 
 
402
int
 
403
nsComponent::Release()
 
404
{
 
405
    mRefCount--;
 
406
 
 
407
    if (mRefCount < 0)
 
408
        return E_REF_COUNT;
 
409
 
 
410
    if (mRefCount == 0)
 
411
        delete this;
 
412
 
 
413
    return OK;
 
414
}
 
415
 
 
416
int
 
417
nsComponent::InitRefCount()
 
418
{
 
419
    mRefCount = 1;
 
420
 
 
421
    return OK;
 
422
}
 
423
 
 
424
int 
 
425
nsComponent::DepAddRef()
 
426
{
 
427
    if (mDepRefCount == 0)
 
428
        SetSelected();
 
429
 
 
430
    mDepRefCount++;
 
431
        
 
432
    return OK;
 
433
}
 
434
 
 
435
int
 
436
nsComponent::DepRelease()
 
437
{
 
438
    mDepRefCount--;
 
439
 
 
440
    if (mDepRefCount < 0)
 
441
        mDepRefCount = 0;
 
442
 
 
443
    if (mDepRefCount == 0)
 
444
        SetUnselected();
 
445
 
 
446
    return OK;
 
447
}
 
448
 
 
449
int
 
450
nsComponent::DepGetRefCount()
 
451
{
 
452
    return mDepRefCount;
 
453
}
 
454
 
 
455
int
 
456
nsComponent::SetResumePos(int aResPos)
 
457
{
 
458
    mResPos = aResPos;
 
459
 
 
460
    return OK;
 
461
}
 
462
 
 
463
int
 
464
nsComponent::GetResumePos()
 
465
{
 
466
    if (mResPos > 0)
 
467
        return mResPos;
 
468
 
 
469
    return 0;
 
470
}
 
471
 
 
472
int
 
473
nsComponent::SetDownloaded( int which )
 
474
{
 
475
    mDownloaded = which;
 
476
 
 
477
    return OK;
 
478
}
 
479
 
 
480
int
 
481
nsComponent::IsDownloaded()
 
482
{
 
483
    return mDownloaded;
 
484
}