~ubuntu-branches/ubuntu/edgy/digikam/edgy-updates

« back to all changes in this revision

Viewing changes to digikam/utilities/cameragui/gpcamera.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Achim Bohnet
  • Date: 2005-03-10 02:39:02 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050310023902-023nymfst5mg696c
Tags: 0.7.2-2
* debian/TODO: clean
* digikam manpage: better --detect-camera description

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================
 
2
 * Author: Renchi Raju <renchi@pooh.tam.uiuc.edu>
 
3
 * Date  : 2003-01-21
 
4
 * Description : 
 
5
 * 
 
6
 * Copyright 2003 by Renchi Raju
 
7
 
 
8
 * This program is free software; you can redistribute it
 
9
 * and/or modify it under the terms of the GNU General
 
10
 * Public License as published by the Free Software Foundation;
 
11
 * either version 2, or (at your option)
 
12
 * 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.  See the
 
17
 * GNU General Public License for more details.
 
18
 * 
 
19
 * ============================================================ */
 
20
 
 
21
#include <qstring.h>
 
22
#include <qstringlist.h>
 
23
#include <qimage.h>
 
24
#include <qdom.h>
 
25
#include <qfile.h>
 
26
 
 
27
#include <iostream>
 
28
 
 
29
extern "C" {
 
30
#include <stdio.h>
 
31
#include <gphoto2.h>
 
32
}
 
33
 
 
34
#include "gpcamera.h"
 
35
 
 
36
class GPCameraPrivate
 
37
{
 
38
public:
 
39
 
 
40
    Camera *camera;
 
41
    CameraAbilities cameraAbilities;
 
42
 
 
43
    QString model;
 
44
    QString port;
 
45
    QString globalPath;
 
46
 
 
47
    bool cameraInitialized;
 
48
    
 
49
    bool thumbnailSupport;
 
50
    bool deleteSupport;
 
51
    bool uploadSupport;
 
52
    bool mkDirSupport;
 
53
    bool delDirSupport;
 
54
    
 
55
};
 
56
 
 
57
class GPStatus
 
58
{
 
59
public:
 
60
 
 
61
    GPStatus() {
 
62
        context = gp_context_new();
 
63
        cancel  = false;
 
64
        gp_context_set_cancel_func(context, cancel_func, 0);
 
65
    }
 
66
 
 
67
    ~GPStatus() {
 
68
        gp_context_unref(context);
 
69
        cancel = false;
 
70
    }
 
71
 
 
72
    GPContext*  context;
 
73
    static bool cancel;
 
74
 
 
75
    static GPContextFeedback cancel_func(GPContext *,
 
76
                                         void *) {
 
77
        return (cancel ? GP_CONTEXT_FEEDBACK_CANCEL :
 
78
                GP_CONTEXT_FEEDBACK_OK);
 
79
    }            
 
80
};
 
81
 
 
82
bool GPStatus::cancel = false;
 
83
 
 
84
GPCamera::GPCamera(const QString& model,
 
85
                   const QString& port,
 
86
                   const QString& path)
 
87
    : DKCamera(model, port, path)
 
88
{
 
89
    status = 0;
 
90
    
 
91
    d = new GPCameraPrivate;
 
92
    d->camera = 0;
 
93
 
 
94
    d->model = model;
 
95
    d->port  = port;
 
96
    d->globalPath = path;
 
97
               
 
98
    d->cameraInitialized = false;
 
99
 
 
100
    d->thumbnailSupport = false;
 
101
    d->deleteSupport    = false;
 
102
    d->uploadSupport    = false;
 
103
    d->mkDirSupport     = false;
 
104
    d->delDirSupport    = false;
 
105
}
 
106
 
 
107
GPCamera::~GPCamera()
 
108
{
 
109
    if (d->camera) {
 
110
        gp_camera_unref(d->camera);
 
111
        d->camera = 0;
 
112
    }
 
113
 
 
114
    delete d;
 
115
}
 
116
 
 
117
bool GPCamera::connect()
 
118
{
 
119
    // -- first step - setup the camera --------------------
 
120
    
 
121
    if (d->camera) {
 
122
        gp_camera_unref(d->camera);
 
123
        d->camera = 0;
 
124
    }
 
125
    
 
126
    CameraAbilitiesList *abilList;
 
127
    GPPortInfoList      *infoList;
 
128
    GPPortInfo           info;
 
129
 
 
130
    gp_camera_new(&d->camera);
 
131
 
 
132
    if (status) {
 
133
        delete status;
 
134
        status = 0;
 
135
    }
 
136
            
 
137
    status = new GPStatus();
 
138
    
 
139
    gp_abilities_list_new(&abilList);
 
140
    gp_abilities_list_load(abilList, status->context);
 
141
    gp_port_info_list_new(&infoList);
 
142
    gp_port_info_list_load(infoList);
 
143
 
 
144
    delete status;
 
145
    status = 0;
 
146
 
 
147
    int modelNum = -1, portNum = -1;
 
148
    modelNum = gp_abilities_list_lookup_model(abilList,
 
149
                                              d->model.latin1());
 
150
    portNum = gp_port_info_list_lookup_path (infoList,
 
151
                                             d->port.latin1());
 
152
 
 
153
    gp_abilities_list_get_abilities(abilList, modelNum,
 
154
                                    &d->cameraAbilities);
 
155
    
 
156
    if (gp_camera_set_abilities(d->camera, d->cameraAbilities)
 
157
        != GP_OK) {
 
158
        gp_camera_unref(d->camera);
 
159
        d->camera = 0;
 
160
        gp_abilities_list_free(abilList);
 
161
        gp_port_info_list_free(infoList);
 
162
        return false;
 
163
    }
 
164
 
 
165
    if (d->model != "Directory Browse") {
 
166
        gp_port_info_list_get_info(infoList, portNum, &info);
 
167
        if (gp_camera_set_port_info(d->camera, info) != GP_OK) {
 
168
            gp_camera_unref(d->camera);
 
169
            d->camera = 0;
 
170
            gp_abilities_list_free (abilList);
 
171
            gp_port_info_list_free (infoList);
 
172
            return false;
 
173
        }
 
174
    }
 
175
 
 
176
    gp_abilities_list_free (abilList);
 
177
    gp_port_info_list_free (infoList);
 
178
 
 
179
    if (d->cameraAbilities.file_operations &
 
180
        GP_FILE_OPERATION_PREVIEW)
 
181
        d->thumbnailSupport = true;
 
182
 
 
183
    if (d->cameraAbilities.file_operations &
 
184
        GP_FILE_OPERATION_DELETE)
 
185
        d->deleteSupport = true;
 
186
 
 
187
    if (d->cameraAbilities.folder_operations &
 
188
        GP_FOLDER_OPERATION_PUT_FILE)
 
189
        d->uploadSupport = true;
 
190
 
 
191
    if (d->cameraAbilities.folder_operations &
 
192
        GP_FOLDER_OPERATION_MAKE_DIR)
 
193
        d->mkDirSupport = true;
 
194
 
 
195
    if (d->cameraAbilities.folder_operations &
 
196
        GP_FOLDER_OPERATION_REMOVE_DIR)
 
197
        d->delDirSupport = true;
 
198
 
 
199
    // -- Now try to initialize the camera -----------------
 
200
 
 
201
 
 
202
    status = new GPStatus();
 
203
 
 
204
    // Try and initialize the camera to see if its connected
 
205
    if (gp_camera_init(d->camera, status->context) != GP_OK) {
 
206
        gp_camera_unref(d->camera);
 
207
        d->camera = 0;
 
208
        delete status;
 
209
        status = 0;
 
210
        return false;
 
211
    }
 
212
 
 
213
    delete status;
 
214
    status = 0;
 
215
    
 
216
    d->cameraInitialized = true;    
 
217
    return true;
 
218
}
 
219
 
 
220
void GPCamera::cancel()
 
221
{
 
222
    if (!status)
 
223
        return;
 
224
    status->cancel = true;
 
225
}
 
226
 
 
227
bool GPCamera::thumbnailSupport()
 
228
{
 
229
    return d->thumbnailSupport;    
 
230
}
 
231
 
 
232
bool GPCamera::deleteSupport()
 
233
{
 
234
    return d->deleteSupport;
 
235
}
 
236
 
 
237
bool GPCamera::uploadSupport()
 
238
{
 
239
    return d->uploadSupport;
 
240
}
 
241
 
 
242
bool GPCamera::mkDirSupport()
 
243
{
 
244
    return d->mkDirSupport;
 
245
}
 
246
 
 
247
bool GPCamera::delDirSupport()
 
248
{
 
249
    return d->delDirSupport;
 
250
}
 
251
 
 
252
void GPCamera::getAllFolders(const QString& rootFolder,
 
253
                             QStringList& folderList)
 
254
{
 
255
    QStringList subfolders;
 
256
    getSubFolders(rootFolder, subfolders);
 
257
 
 
258
    for (QStringList::iterator it = subfolders.begin();
 
259
         it != subfolders.end(); ++it)
 
260
    {
 
261
        *it = rootFolder + QString(rootFolder.endsWith("/") ? "" : "/")
 
262
              + (*it);
 
263
        folderList.append(*it);
 
264
    }
 
265
 
 
266
    for (QStringList::iterator it = subfolders.begin();
 
267
         it != subfolders.end(); ++it)
 
268
    {
 
269
        getAllFolders(*it, folderList);
 
270
    }
 
271
}
 
272
 
 
273
bool GPCamera::getSubFolders(const QString& folder,
 
274
                             QStringList& subFolderList)
 
275
{
 
276
    CameraList *clist;
 
277
    gp_list_new(&clist);
 
278
 
 
279
    if (status) {
 
280
        delete status;
 
281
        status = 0;
 
282
    }
 
283
    status = new GPStatus();
 
284
 
 
285
    if (gp_camera_folder_list_folders(d->camera,
 
286
                                      QFile::encodeName(folder),
 
287
                                      clist, status->context)
 
288
        != GP_OK) {
 
289
 
 
290
        gp_list_unref(clist);
 
291
        delete status;
 
292
        status = 0;
 
293
        return false;
 
294
    }
 
295
 
 
296
    delete status;
 
297
    status = 0;
 
298
 
 
299
    int count = gp_list_count(clist);
 
300
    for (int i=0; i<count; i++) {
 
301
 
 
302
        const char* subFolder;
 
303
 
 
304
        if (gp_list_get_name(clist, i, &subFolder) != GP_OK) {
 
305
            gp_list_unref(clist);
 
306
            return false;
 
307
        }
 
308
 
 
309
        subFolderList.append(QString(subFolder));
 
310
 
 
311
    }
 
312
 
 
313
    gp_list_unref(clist);
 
314
    return true;
 
315
}
 
316
 
 
317
bool GPCamera::getItemsList(const QString& folder, QStringList& itemsList)
 
318
{
 
319
    CameraList *clist;
 
320
    const char *cname;
 
321
 
 
322
    if (status) {
 
323
        delete status;
 
324
        status = 0;
 
325
    }
 
326
    status = new GPStatus;
 
327
    
 
328
    gp_list_new(&clist);
 
329
    if (gp_camera_folder_list_files(d->camera, QFile::encodeName(folder),
 
330
                                    clist,
 
331
                                    status->context) != GP_OK) {
 
332
        gp_list_unref(clist);
 
333
        delete status;
 
334
        status = 0;
 
335
        return false;
 
336
    }
 
337
 
 
338
    int count = gp_list_count(clist);
 
339
 
 
340
    for (int i=0; i<count; i++)
 
341
    {
 
342
        if (gp_list_get_name(clist, i, &cname) != GP_OK)
 
343
        {
 
344
            gp_list_unref(clist);
 
345
            delete status;
 
346
            status = 0;
 
347
            return false;
 
348
        }
 
349
 
 
350
        itemsList.append(cname);
 
351
    }
 
352
 
 
353
    gp_list_unref(clist);        
 
354
    
 
355
    delete status;
 
356
    status = 0;
 
357
 
 
358
    return true;
 
359
}
 
360
 
 
361
bool GPCamera::getItemsInfoList(const QString& folder, GPItemInfoList& items)
 
362
{
 
363
    CameraList *clist;
 
364
    const char *cname;
 
365
 
 
366
    if (status) {
 
367
        delete status;
 
368
        status = 0;
 
369
    }
 
370
    status = new GPStatus;
 
371
    
 
372
    gp_list_new(&clist);
 
373
    if (gp_camera_folder_list_files(d->camera, QFile::encodeName(folder),
 
374
                                    clist,
 
375
                                    status->context) != GP_OK) {
 
376
        gp_list_unref(clist);
 
377
        delete status;
 
378
        status = 0;
 
379
        return false;
 
380
    }
 
381
 
 
382
    int count = gp_list_count(clist);
 
383
 
 
384
    for (int i=0; i<count; i++)
 
385
    {
 
386
        if (gp_list_get_name(clist, i, &cname) != GP_OK)
 
387
        {
 
388
            gp_list_unref(clist);
 
389
            delete status;
 
390
            status = 0;
 
391
            return false;
 
392
        }
 
393
 
 
394
        GPItemInfo itemInfo;
 
395
 
 
396
        itemInfo.name   = cname;
 
397
        itemInfo.folder = folder;
 
398
 
 
399
        CameraFileInfo info;
 
400
        gp_camera_file_get_info(d->camera, QFile::encodeName(folder),
 
401
                                cname, &info, status->context);
 
402
 
 
403
        itemInfo.mtime            = -1;
 
404
        itemInfo.mime             = "";
 
405
        itemInfo.size             = -1;
 
406
        itemInfo.width            = -1;
 
407
        itemInfo.height           = -1;
 
408
        itemInfo.downloaded       = -1;
 
409
        itemInfo.readPermissions  = -1;
 
410
        itemInfo.writePermissions = -1;
 
411
        
 
412
        if (info.file.fields & GP_FILE_INFO_MTIME)
 
413
            itemInfo.mtime = info.file.mtime;
 
414
        
 
415
        if (info.file.fields & GP_FILE_INFO_TYPE)
 
416
            itemInfo.mime = info.file.type;
 
417
 
 
418
        if (info.file.fields & GP_FILE_INFO_SIZE)
 
419
            itemInfo.size = info.file.size;
 
420
 
 
421
        if (info.file.fields & GP_FILE_INFO_WIDTH)
 
422
            itemInfo.width = info.file.width;
 
423
 
 
424
        if (info.file.fields & GP_FILE_INFO_HEIGHT)
 
425
            itemInfo.height = info.file.height;
 
426
 
 
427
        if (info.file.fields & GP_FILE_INFO_STATUS) {
 
428
            if (info.file.status == GP_FILE_STATUS_DOWNLOADED)
 
429
                itemInfo.downloaded = 1;
 
430
            else
 
431
                itemInfo.downloaded = 0;
 
432
        }
 
433
        
 
434
        if (info.file.fields & GP_FILE_INFO_PERMISSIONS) {
 
435
            if (info.file.permissions & GP_FILE_PERM_READ)
 
436
                itemInfo.readPermissions = 1;
 
437
            else
 
438
                itemInfo.readPermissions = 0;
 
439
            if (info.file.permissions & GP_FILE_PERM_DELETE)
 
440
                itemInfo.writePermissions = 1;
 
441
            else
 
442
                itemInfo.writePermissions = 0;
 
443
        }
 
444
 
 
445
        items.append(itemInfo);
 
446
    }
 
447
 
 
448
    gp_list_unref(clist);        
 
449
    
 
450
    delete status;
 
451
    status = 0;
 
452
 
 
453
    return true;
 
454
}
 
455
 
 
456
bool GPCamera::getThumbnail(const QString& folder,
 
457
                            const QString& itemName,
 
458
                            QImage& thumbnail)
 
459
{
 
460
    CameraFile*       cfile;
 
461
    const char*       data;
 
462
    unsigned long int size;
 
463
 
 
464
    gp_file_new(&cfile);
 
465
 
 
466
    if (status) {
 
467
        delete status;
 
468
        status = 0;
 
469
    }
 
470
    
 
471
    status = new GPStatus;
 
472
 
 
473
    if (gp_camera_file_get(d->camera, QFile::encodeName(folder),
 
474
                           QFile::encodeName(itemName),
 
475
                           GP_FILE_TYPE_PREVIEW,
 
476
                           cfile, status->context) != GP_OK) {
 
477
        gp_file_unref(cfile);
 
478
        delete status;
 
479
        status = 0;
 
480
        return false;
 
481
    }
 
482
 
 
483
    delete status;
 
484
    status = 0;
 
485
 
 
486
    gp_file_get_data_and_size(cfile, &data, &size);
 
487
    thumbnail.loadFromData((const uchar*) data, (uint) size);
 
488
 
 
489
    gp_file_unref (cfile);
 
490
    return true;
 
491
}
 
492
 
 
493
bool GPCamera::getExif(const QString& folder,
 
494
                       const QString& itemName,
 
495
                       char **edata, int& esize)
 
496
{
 
497
    CameraFile *cfile;
 
498
    const char* data;
 
499
    unsigned long int size;
 
500
    
 
501
    gp_file_new(&cfile);
 
502
    
 
503
    if (status) {
 
504
        delete status;
 
505
        status = 0;
 
506
    }
 
507
    
 
508
    status = new GPStatus;
 
509
 
 
510
    if (gp_camera_file_get(d->camera, QFile::encodeName(folder),
 
511
                           QFile::encodeName(itemName),
 
512
                           GP_FILE_TYPE_EXIF,
 
513
                           cfile, status->context) != GP_OK) {
 
514
        gp_file_unref(cfile);
 
515
        delete status;
 
516
        status = 0;
 
517
        return false;
 
518
    }
 
519
 
 
520
    delete status;
 
521
    status = 0;
 
522
    
 
523
    gp_file_get_data_and_size(cfile, &data, &size);
 
524
 
 
525
    *edata = new char[size];
 
526
    esize = size;
 
527
 
 
528
    memcpy(*edata, data, size);
 
529
 
 
530
    gp_file_unref(cfile);
 
531
 
 
532
    return true;
 
533
}
 
534
 
 
535
bool GPCamera::downloadItem(const QString& folder,
 
536
                            const QString& itemName,
 
537
                            const QString& saveFile)
 
538
{
 
539
    CameraFile *cfile;
 
540
    gp_file_new(&cfile);
 
541
 
 
542
    if (status) {
 
543
        delete status;
 
544
        status = 0;
 
545
    }
 
546
    status = new GPStatus;
 
547
    
 
548
    if (gp_camera_file_get(d->camera, QFile::encodeName(folder),
 
549
                           QFile::encodeName(itemName),
 
550
                           GP_FILE_TYPE_NORMAL, cfile,
 
551
                           status->context) != GP_OK) {
 
552
        gp_file_unref(cfile);
 
553
        delete status;
 
554
        status = 0;
 
555
        return false;
 
556
    }
 
557
    delete status;
 
558
    status = 0;
 
559
 
 
560
    if (gp_file_save(cfile, QFile::encodeName(saveFile)) != GP_OK) {
 
561
        gp_file_unref(cfile);
 
562
        return false;
 
563
    }
 
564
    gp_file_unref(cfile);
 
565
 
 
566
    return true;
 
567
}
 
568
 
 
569
bool GPCamera::deleteItem(const QString& folder,
 
570
                          const QString& itemName)
 
571
{
 
572
    if (status) {
 
573
        delete status;
 
574
        status = 0;
 
575
    }
 
576
    status = new GPStatus;
 
577
 
 
578
    if (gp_camera_file_delete(d->camera, QFile::encodeName(folder),
 
579
                              QFile::encodeName(itemName),
 
580
                              status->context) != GP_OK) {
 
581
        delete status;
 
582
        status = 0;
 
583
        return false;
 
584
    }
 
585
 
 
586
    delete status;
 
587
    status = 0;
 
588
 
 
589
    return true;
 
590
}
 
591
 
 
592
// recursively delete all items
 
593
bool GPCamera::deleteAllItems(const QString& folder)
 
594
{
 
595
    QStringList folderList;
 
596
 
 
597
    // Get all subfolders in this folder
 
598
    getSubFolders(folder, folderList);
 
599
 
 
600
    if (folderList.count() > 0) {
 
601
        for (unsigned int i=0; i<folderList.count(); i++) {
 
602
            QString subFolder(folder);
 
603
            if (!subFolder.endsWith("/"))
 
604
                subFolder += "/";
 
605
            subFolder += folderList[i];
 
606
 
 
607
            deleteAllItems(subFolder);
 
608
        }
 
609
    }
 
610
    
 
611
   if (status) {
 
612
        delete status;
 
613
        status = 0;
 
614
    }
 
615
    status = new GPStatus;
 
616
    
 
617
    if (gp_camera_folder_delete_all(d->camera, QFile::encodeName(folder),
 
618
                                    status->context) != GP_OK) {
 
619
        delete status;
 
620
        status = 0;
 
621
        return false;
 
622
    }
 
623
    delete status;
 
624
    status = 0;
 
625
 
 
626
    return true;
 
627
}
 
628
 
 
629
bool GPCamera::uploadItem(const QString& folder,
 
630
                          const QString& itemName,
 
631
                          const QString& localFile)
 
632
{
 
633
    CameraFile *cfile;
 
634
    gp_file_new(&cfile);
 
635
 
 
636
    if (gp_file_open(cfile, QFile::encodeName(localFile)) != GP_OK) {
 
637
        gp_file_unref(cfile);
 
638
        return false;
 
639
    }
 
640
 
 
641
    gp_file_set_name(cfile, QFile::encodeName(itemName));
 
642
 
 
643
    if (status) {
 
644
        delete status;
 
645
        status = 0;
 
646
    }
 
647
    status = new GPStatus;
 
648
 
 
649
    if (gp_camera_folder_put_file(d->camera,
 
650
                                  QFile::encodeName(folder),
 
651
                                  cfile,
 
652
                                  status->context) != GP_OK) {
 
653
        gp_file_unref(cfile);
 
654
        delete status;
 
655
        status = 0;
 
656
        return false;
 
657
    }
 
658
 
 
659
    gp_file_unref(cfile);
 
660
    delete status;
 
661
    status = 0;
 
662
 
 
663
    return true;
 
664
}
 
665
 
 
666
void GPCamera::cameraSummary(QString& summary)
 
667
{
 
668
    CameraText sum;
 
669
 
 
670
    if (status) {
 
671
        delete status;
 
672
        status = 0;
 
673
    }
 
674
 
 
675
    status = new GPStatus;
 
676
    gp_camera_get_summary(d->camera, &sum, status->context);
 
677
    summary = QString(sum.text);
 
678
 
 
679
    delete status;
 
680
    status = 0;
 
681
}
 
682
 
 
683
void GPCamera::cameraManual(QString& manual)
 
684
{
 
685
    CameraText man;
 
686
 
 
687
    if (status) {
 
688
        delete status;
 
689
        status = 0;
 
690
    }
 
691
 
 
692
    status = new GPStatus;
 
693
    gp_camera_get_manual(d->camera, &man, status->context);
 
694
    manual = QString(man.text);
 
695
 
 
696
    delete status;
 
697
    status = 0;
 
698
}
 
699
 
 
700
void GPCamera::cameraAbout(QString& about)
 
701
{
 
702
    CameraText abt;
 
703
 
 
704
    if (status) {
 
705
        delete status;
 
706
        status = 0;
 
707
    }
 
708
 
 
709
    status = new GPStatus;
 
710
    gp_camera_get_about(d->camera, &abt, status->context);
 
711
    about = QString(abt.text);
 
712
 
 
713
    delete status;
 
714
    status = 0;
 
715
 
 
716
}
 
717
 
 
718
// Static functions
 
719
 
 
720
void GPCamera::getSupportedCameras(int& count, QStringList& clist)
 
721
{
 
722
    clist.clear();
 
723
    count = 0;
 
724
 
 
725
    CameraAbilitiesList *abilList;
 
726
    CameraAbilities abil;
 
727
    GPContext *context;
 
728
 
 
729
    context = gp_context_new ();
 
730
 
 
731
    gp_abilities_list_new( &abilList );
 
732
    gp_abilities_list_load( abilList, context );
 
733
 
 
734
    count = gp_abilities_list_count( abilList );
 
735
    if ( count < 0) {
 
736
        gp_context_unref( context );
 
737
        qWarning("failed to get list of cameras");
 
738
        return;
 
739
    }
 
740
    else {
 
741
        for (int i=0; i<count; i++) {
 
742
            const char *cname;
 
743
            gp_abilities_list_get_abilities( abilList, i, &abil );
 
744
            cname = abil.model;
 
745
            clist.append( QString( cname ) );
 
746
        }
 
747
    }
 
748
 
 
749
    gp_abilities_list_free( abilList );
 
750
    gp_context_unref( context );
 
751
 
 
752
}
 
753
 
 
754
void GPCamera::getSupportedPorts(QStringList& plist)
 
755
{
 
756
    GPPortInfoList *list;
 
757
    GPPortInfo info;
 
758
 
 
759
    plist.clear();
 
760
 
 
761
    gp_port_info_list_new( &list );
 
762
    gp_port_info_list_load( list );
 
763
 
 
764
    int numPorts = gp_port_info_list_count( list );
 
765
 
 
766
    for (int i = 0; i < numPorts; i++) {
 
767
        gp_port_info_list_get_info( list, i, &info );
 
768
        plist.append( info.path );
 
769
    }
 
770
 
 
771
    gp_port_info_list_free( list );
 
772
 
 
773
}
 
774
 
 
775
void GPCamera::getCameraSupportedPorts(const QString& model,
 
776
                                       QStringList& plist)
 
777
{
 
778
    int i = 0;
 
779
    plist.clear();
 
780
 
 
781
    CameraAbilities abilities;
 
782
    CameraAbilitiesList *abilList;
 
783
    GPContext *context;
 
784
 
 
785
    context = gp_context_new ();
 
786
 
 
787
    gp_abilities_list_new (&abilList);
 
788
    gp_abilities_list_load (abilList, context);
 
789
    i = gp_abilities_list_lookup_model (abilList,
 
790
                                        model.local8Bit().data());
 
791
    gp_abilities_list_get_abilities (abilList, i, &abilities);
 
792
    gp_abilities_list_free (abilList);
 
793
 
 
794
    if (abilities.port & GP_PORT_SERIAL)
 
795
        plist.append("serial");
 
796
    if (abilities.port & GP_PORT_USB)
 
797
        plist.append("usb");
 
798
 
 
799
    gp_context_unref( context );
 
800
 
 
801
}
 
802
 
 
803
int GPCamera::autoDetect(QString& model, QString& port)
 
804
{
 
805
    CameraList camList;
 
806
    CameraAbilitiesList *abilList;
 
807
    GPPortInfoList *infoList;
 
808
    const char *camModel_, *camPort_;
 
809
    GPContext *context;
 
810
 
 
811
    context = gp_context_new ();
 
812
 
 
813
    gp_abilities_list_new (&abilList);
 
814
    gp_abilities_list_load (abilList, context);
 
815
    gp_port_info_list_new (&infoList);
 
816
    gp_port_info_list_load (infoList);
 
817
    gp_abilities_list_detect (abilList, infoList,
 
818
                              &camList, context);
 
819
    gp_abilities_list_free (abilList);
 
820
    gp_port_info_list_free (infoList);
 
821
 
 
822
    gp_context_unref( context );
 
823
 
 
824
    int count = gp_list_count (&camList);
 
825
 
 
826
    if (count<=0) {
 
827
        return -1;
 
828
    }
 
829
 
 
830
    for (int i = 0; i < count; i++) {
 
831
        gp_list_get_name  (&camList, i, &camModel_);
 
832
        gp_list_get_value (&camList, i, &camPort_);
 
833
    }
 
834
 
 
835
    model = camModel_;
 
836
    port  = camPort_;
 
837
 
 
838
    return 0;
 
839
}
 
840
 
 
841
QString GPCamera::model() const
 
842
{
 
843
    return d->model;    
 
844
}
 
845
 
 
846
QString GPCamera::port() const
 
847
{
 
848
    return d->port;
 
849
}
 
850
 
 
851
QString GPCamera::path() const
 
852
{
 
853
    return d->globalPath;   
 
854
}