4 * Copyright 2000 Shi Quan He <shiquan@cyberdude.com>
5 * Copyright 2006 Marcus Meissner
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
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 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include "gphoto2_i.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(twain
);
41 static char* GPHOTO2_StrDup(const char* str
)
43 char* dst
= HeapAlloc(GetProcessHeap(), 0, strlen(str
)+1);
50 load_filesystem(const char *folder
) {
55 ret
= gp_list_new (&list
);
58 ret
= gp_camera_folder_list_files (activeDS
.camera
, folder
, list
, activeDS
.context
);
63 count
= gp_list_count (list
);
68 for (i
= 0; i
< count
; i
++) {
70 struct gphoto2_file
*gpfile
;
72 ret
= gp_list_get_name (list
, i
, &name
);
75 gpfile
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct gphoto2_file
)); /* FIXME: Leaked */
78 TRACE("adding %s/%s\n", folder
, name
);
79 gpfile
->folder
= GPHOTO2_StrDup(folder
);
80 gpfile
->filename
= GPHOTO2_StrDup(name
);
81 gpfile
->download
= FALSE
;
82 list_add_tail( &activeDS
.files
, &gpfile
->entry
);
86 ret
= gp_camera_folder_list_folders (activeDS
.camera
, folder
, list
, activeDS
.context
);
88 FIXME("list_folders failed\n");
92 count
= gp_list_count (list
);
94 FIXME("list_folders failed\n");
98 for (i
= 0; i
< count
; i
++) {
101 ret
= gp_list_get_name (list
, i
, &name
);
104 TRACE("recursing into %s\n", name
);
105 newfolder
= HeapAlloc(GetProcessHeap(), 0, strlen(folder
)+1+strlen(name
)+1);
106 if (!strcmp(folder
,"/"))
107 sprintf (newfolder
, "/%s", name
);
109 sprintf (newfolder
, "%s/%s", folder
, name
);
110 load_filesystem (newfolder
); /* recurse ... happily */
116 /* DG_CONTROL/DAT_CAPABILITY/MSG_GET */
117 static TW_UINT16
GPHOTO2_CapabilityGet (pTW_IDENTITY pOrigin
, TW_MEMREF pData
)
119 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
121 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GET\n");
122 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7) {
123 activeDS
.twCC
= TWCC_SEQERROR
;
126 activeDS
.twCC
= GPHOTO2_SaneCapability (pCapability
, MSG_GET
);
127 return (activeDS
.twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
130 /* DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT */
131 static TW_UINT16
GPHOTO2_CapabilityGetCurrent (pTW_IDENTITY pOrigin
, TW_MEMREF pData
)
133 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
135 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT\n");
137 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7) {
138 activeDS
.twCC
= TWCC_SEQERROR
;
141 activeDS
.twCC
= GPHOTO2_SaneCapability (pCapability
, MSG_GETCURRENT
);
142 return (activeDS
.twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
145 /* DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT */
146 static TW_UINT16
GPHOTO2_CapabilityGetDefault (pTW_IDENTITY pOrigin
, TW_MEMREF pData
)
148 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
150 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT\n");
151 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7) {
152 activeDS
.twCC
= TWCC_SEQERROR
;
155 activeDS
.twCC
= GPHOTO2_SaneCapability (pCapability
, MSG_GETDEFAULT
);
156 return (activeDS
.twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
159 /* DG_CONTROL/DAT_CAPABILITY/MSG_QUERYSUPPORT */
160 static TW_UINT16
GPHOTO2_CapabilityQuerySupport (pTW_IDENTITY pOrigin
,
168 /* DG_CONTROL/DAT_CAPABILITY/MSG_RESET */
169 static TW_UINT16
GPHOTO2_CapabilityReset (pTW_IDENTITY pOrigin
,
172 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
174 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_RESET\n");
176 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7) {
177 activeDS
.twCC
= TWCC_SEQERROR
;
180 activeDS
.twCC
= GPHOTO2_SaneCapability (pCapability
, MSG_RESET
);
181 return (activeDS
.twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
184 /* DG_CONTROL/DAT_CAPABILITY/MSG_SET */
185 static TW_UINT16
GPHOTO2_CapabilitySet (pTW_IDENTITY pOrigin
,
188 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
190 TRACE ("DG_CONTROL/DAT_CAPABILITY/MSG_SET\n");
192 if (activeDS
.currentState
!= 4) {
193 activeDS
.twCC
= TWCC_SEQERROR
;
196 activeDS
.twCC
= GPHOTO2_SaneCapability (pCapability
, MSG_SET
);
197 return (activeDS
.twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
200 /* DG_CONTROL/DAT_CUSTOMDSDATA/MSG_GET */
201 static TW_UINT16
GPHOTO2_CustomDSDataGet (pTW_IDENTITY pOrigin
,
209 /* DG_CONTROL/DAT_CUSTOMDSDATA/MSG_SET */
210 static TW_UINT16
GPHOTO2_CustomDSDataSet (pTW_IDENTITY pOrigin
,
218 /* DG_CONTROL/DAT_FILESYSTEM/MSG_CHANGEDIRECTORY */
219 static TW_UINT16
GPHOTO2_ChangeDirectory (pTW_IDENTITY pOrigin
,
227 /* DG_CONTROL/DAT_FILESYSTEM/MSG_CREATEDIRECTORY */
228 static TW_UINT16
GPHOTO2_CreateDirectory (pTW_IDENTITY pOrigin
,
236 /* DG_CONTROL/DAT_FILESYSTEM/MSG_DELETE */
237 static TW_UINT16
GPHOTO2_FileSystemDelete (pTW_IDENTITY pOrigin
,
245 /* DG_CONTROL/DAT_FILESYSTEM/MSG_FORMATMEDIA */
246 static TW_UINT16
GPHOTO2_FormatMedia (pTW_IDENTITY pOrigin
,
254 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETCLOSE */
255 static TW_UINT16
GPHOTO2_FileSystemGetClose (pTW_IDENTITY pOrigin
,
263 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETFIRSTFILE */
264 static TW_UINT16
GPHOTO2_FileSystemGetFirstFile (pTW_IDENTITY pOrigin
,
273 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETINFO */
274 static TW_UINT16
GPHOTO2_FileSystemGetInfo (pTW_IDENTITY pOrigin
,
282 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETNEXTFILE */
283 static TW_UINT16
GPHOTO2_FileSystemGetNextFile (pTW_IDENTITY pOrigin
,
292 /* DG_CONTROL/DAT_FILESYSTEM/MSG_RENAME */
293 static TW_UINT16
GPHOTO2_FileSystemRename (pTW_IDENTITY pOrigin
,
301 /* DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT */
302 static TW_UINT16
GPHOTO2_ProcessEvent (pTW_IDENTITY pOrigin
,
305 TW_UINT16 twRC
= TWRC_SUCCESS
;
306 pTW_EVENT pEvent
= (pTW_EVENT
) pData
;
308 TRACE("DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT\n");
310 if (activeDS
.currentState
< 5 || activeDS
.currentState
> 7) {
311 activeDS
.twCC
= TWCC_SEQERROR
;
315 if (activeDS
.pendingEvent
.TWMessage
!= MSG_NULL
) {
316 pEvent
->TWMessage
= activeDS
.pendingEvent
.TWMessage
;
317 activeDS
.pendingEvent
.TWMessage
= MSG_NULL
;
320 pEvent
->TWMessage
= MSG_NULL
; /* no message to the application */
321 twRC
= TWRC_NOTDSEVENT
;
323 activeDS
.twCC
= TWCC_SUCCESS
;
327 /* DG_CONTROL/DAT_PASSTHRU/MSG_PASSTHRU */
328 static TW_UINT16
GPHOTO2_PassThrough (pTW_IDENTITY pOrigin
,
336 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER */
337 static TW_UINT16
GPHOTO2_PendingXfersEndXfer (pTW_IDENTITY pOrigin
,
341 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
342 struct gphoto2_file
*file
;
344 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER\n");
346 if (activeDS
.currentState
!= 6 && activeDS
.currentState
!= 7) {
347 activeDS
.twCC
= TWCC_SEQERROR
;
351 LIST_FOR_EACH_ENTRY( file
, &activeDS
.files
, struct gphoto2_file
, entry
) {
355 TRACE("count = %d\n", count
);
356 pPendingXfers
->Count
= count
;
357 if (pPendingXfers
->Count
!= 0) {
358 activeDS
.currentState
= 6;
360 activeDS
.currentState
= 5;
361 /* Notify the application that it can close the data source */
362 activeDS
.pendingEvent
.TWMessage
= MSG_CLOSEDSREQ
;
363 /* close any Transferring dialog */
364 TransferringDialogBox(activeDS
.progressWnd
,-1);
365 activeDS
.progressWnd
= 0;
367 activeDS
.twCC
= TWCC_SUCCESS
;
371 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_GET */
372 static TW_UINT16
GPHOTO2_PendingXfersGet (pTW_IDENTITY pOrigin
,
376 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
377 struct gphoto2_file
*file
;
379 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_GET\n");
381 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7) {
382 activeDS
.twCC
= TWCC_SEQERROR
;
387 LIST_FOR_EACH_ENTRY( file
, &activeDS
.files
, struct gphoto2_file
, entry
) {
391 TRACE("count = %d\n", count
);
392 pPendingXfers
->Count
= count
;
393 activeDS
.twCC
= TWCC_SUCCESS
;
397 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET */
398 static TW_UINT16
GPHOTO2_PendingXfersReset (pTW_IDENTITY pOrigin
,
401 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
403 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET\n");
405 if (activeDS
.currentState
!= 6) {
406 activeDS
.twCC
= TWCC_SEQERROR
;
409 pPendingXfers
->Count
= 0;
410 activeDS
.currentState
= 5;
411 activeDS
.twCC
= TWCC_SUCCESS
;
415 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_GET */
416 static TW_UINT16
GPHOTO2_SetupFileXferGet (pTW_IDENTITY pOrigin
,
424 /* DG_CONTROL/DAT_SETUPXFER/MSG_GETDEFAULT */
425 static TW_UINT16
GPHOTO2_SetupFileXferGetDefault (pTW_IDENTITY pOrigin
,
434 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_RESET */
435 static TW_UINT16
GPHOTO2_SetupFileXferReset (pTW_IDENTITY pOrigin
,
443 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_SET */
444 static TW_UINT16
GPHOTO2_SetupFileXferSet (pTW_IDENTITY pOrigin
,
452 /* DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET */
453 static TW_UINT16
GPHOTO2_SetupMemXferGet (pTW_IDENTITY pOrigin
,
456 pTW_SETUPMEMXFER pSetupMemXfer
= (pTW_SETUPMEMXFER
)pData
;
458 TRACE("DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET\n");
460 pSetupMemXfer
->MinBufSize
= 20000;
461 pSetupMemXfer
->MaxBufSize
= 80000;
462 pSetupMemXfer
->Preferred
= 40000;
466 /* DG_CONTROL/DAT_STATUS/MSG_GET */
467 static TW_UINT16
GPHOTO2_GetDSStatus (pTW_IDENTITY pOrigin
,
470 pTW_STATUS pSourceStatus
= (pTW_STATUS
) pData
;
472 TRACE ("DG_CONTROL/DAT_STATUS/MSG_GET\n");
473 pSourceStatus
->ConditionCode
= activeDS
.twCC
;
474 /* Reset the condition code */
475 activeDS
.twCC
= TWCC_SUCCESS
;
479 /* DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS */
480 static TW_UINT16
GPHOTO2_DisableDSUserInterface (pTW_IDENTITY pOrigin
,
483 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS\n");
485 if (activeDS
.currentState
!= 5) {
486 activeDS
.twCC
= TWCC_SEQERROR
;
489 activeDS
.currentState
= 4;
490 activeDS
.twCC
= TWCC_SUCCESS
;
494 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS */
495 static TW_UINT16
GPHOTO2_EnableDSUserInterface (pTW_IDENTITY pOrigin
,
498 pTW_USERINTERFACE pUserInterface
= (pTW_USERINTERFACE
) pData
;
500 load_filesystem("/");
502 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS\n");
503 if (activeDS
.currentState
!= 4) {
504 FIXME("Sequence error %d\n", activeDS
.currentState
);
505 activeDS
.twCC
= TWCC_SEQERROR
;
508 activeDS
.hwndOwner
= pUserInterface
->hParent
;
509 if (pUserInterface
->ShowUI
)
512 activeDS
.currentState
= 5; /* Transitions to state 5 */
515 activeDS
.pendingEvent
.TWMessage
= MSG_CLOSEDSREQ
;
517 /* FIXME: The GUI should have marked the files to download... */
518 activeDS
.pendingEvent
.TWMessage
= MSG_XFERREADY
;
519 activeDS
.currentState
= 6; /* Transitions to state 6 directly */
522 /* no UI will be displayed, so source is ready to transfer data */
523 activeDS
.pendingEvent
.TWMessage
= MSG_XFERREADY
;
524 activeDS
.currentState
= 6; /* Transitions to state 6 directly */
526 activeDS
.hwndOwner
= pUserInterface
->hParent
;
527 activeDS
.twCC
= TWCC_SUCCESS
;
531 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY */
532 static TW_UINT16
GPHOTO2_EnableDSUIOnly (pTW_IDENTITY pOrigin
,
535 TRACE("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY\n");
537 if (activeDS
.currentState
!= 4) {
538 activeDS
.twCC
= TWCC_SEQERROR
;
541 /* FIXME: we should replace xscanimage with our own UI */
542 FIXME ("not implemented!\n");
543 activeDS
.currentState
= 5;
544 activeDS
.twCC
= TWCC_SUCCESS
;
548 /* DG_CONTROL/DAT_XFERGROUP/MSG_GET */
549 static TW_UINT16
GPHOTO2_XferGroupGet (pTW_IDENTITY pOrigin
,
556 /* DG_CONTROL/DAT_XFERGROUP/MSG_SET */
557 static TW_UINT16
GPHOTO2_XferGroupSet (pTW_IDENTITY pOrigin
,
564 HINSTANCE GPHOTO2_instance
;
566 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
568 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
572 case DLL_PROCESS_ATTACH
:
573 GPHOTO2_instance
= hinstDLL
;
574 DisableThreadLibraryCalls(hinstDLL
);
576 activeDS
.context
= gp_context_new ();
580 case DLL_PROCESS_DETACH
:
581 GPHOTO2_instance
= NULL
;
589 static TW_UINT16
GPHOTO2_GetIdentity( pTW_IDENTITY
, pTW_IDENTITY
);
590 static TW_UINT16
GPHOTO2_OpenDS( pTW_IDENTITY
, pTW_IDENTITY
);
593 static TW_UINT16
GPHOTO2_SourceControlHandler (
594 pTW_IDENTITY pOrigin
,
599 TW_UINT16 twRC
= TWRC_SUCCESS
;
608 if (activeDS
.camera
) {
609 gp_camera_free (activeDS
.camera
);
610 activeDS
.camera
= NULL
;
616 twRC
= GPHOTO2_GetIdentity(pOrigin
,(pTW_IDENTITY
)pData
);
623 twRC
= GPHOTO2_OpenDS(pOrigin
,(pTW_IDENTITY
)pData
);
634 twRC
= GPHOTO2_CapabilityGet (pOrigin
, pData
);
637 twRC
= GPHOTO2_CapabilityGetCurrent (pOrigin
, pData
);
640 twRC
= GPHOTO2_CapabilityGetDefault (pOrigin
, pData
);
642 case MSG_QUERYSUPPORT
:
643 twRC
= GPHOTO2_CapabilityQuerySupport (pOrigin
, pData
);
646 twRC
= GPHOTO2_CapabilityReset (pOrigin
, pData
);
649 twRC
= GPHOTO2_CapabilitySet (pOrigin
, pData
);
653 FIXME("unrecognized opertion triplet\n");
657 case DAT_CUSTOMDSDATA
:
661 twRC
= GPHOTO2_CustomDSDataGet (pOrigin
, pData
);
664 twRC
= GPHOTO2_CustomDSDataSet (pOrigin
, pData
);
674 /*case MSG_AUTOMATICCAPTUREDIRECTORY:
675 twRC = GPHOTO2_AutomaticCaptureDirectory
678 case MSG_CHANGEDIRECTORY
:
679 twRC
= GPHOTO2_ChangeDirectory (pOrigin
, pData
);
682 twRC = GPHOTO2_FileSystemCopy (pOrigin, pData);
684 case MSG_CREATEDIRECTORY
:
685 twRC
= GPHOTO2_CreateDirectory (pOrigin
, pData
);
688 twRC
= GPHOTO2_FileSystemDelete (pOrigin
, pData
);
690 case MSG_FORMATMEDIA
:
691 twRC
= GPHOTO2_FormatMedia (pOrigin
, pData
);
694 twRC
= GPHOTO2_FileSystemGetClose (pOrigin
, pData
);
696 case MSG_GETFIRSTFILE
:
697 twRC
= GPHOTO2_FileSystemGetFirstFile (pOrigin
, pData
);
700 twRC
= GPHOTO2_FileSystemGetInfo (pOrigin
, pData
);
702 case MSG_GETNEXTFILE
:
703 twRC
= GPHOTO2_FileSystemGetNextFile (pOrigin
, pData
);
706 twRC
= GPHOTO2_FileSystemRename (pOrigin
, pData
);
715 if (MSG
== MSG_PROCESSEVENT
)
716 twRC
= GPHOTO2_ProcessEvent (pOrigin
, pData
);
722 if (MSG
== MSG_PASSTHRU
)
723 twRC
= GPHOTO2_PassThrough (pOrigin
, pData
);
728 case DAT_PENDINGXFERS
:
732 twRC
= GPHOTO2_PendingXfersEndXfer (pOrigin
, pData
);
735 twRC
= GPHOTO2_PendingXfersGet (pOrigin
, pData
);
738 twRC
= GPHOTO2_PendingXfersReset (pOrigin
, pData
);
740 /*case MSG_STOPFEEDER:
741 twRC = GPHOTO2_PendingXfersStopFeeder (pOrigin, pData);
748 case DAT_SETUPFILEXFER
:
752 twRC
= GPHOTO2_SetupFileXferGet (pOrigin
, pData
);
755 twRC
= GPHOTO2_SetupFileXferGetDefault (pOrigin
, pData
);
758 twRC
= GPHOTO2_SetupFileXferReset (pOrigin
, pData
);
761 twRC
= GPHOTO2_SetupFileXferSet (pOrigin
, pData
);
769 /*case DAT_SETUPFILEXFER2:
773 twRC = GPHOTO2_SetupFileXfer2Get (pOrigin, pData);
776 twRC = GPHOTO2_SetupFileXfer2GetDefault (pOrigin, pData);
779 twRC = GPHOTO2_SetupFileXfer2Reset (pOrigin, pData);
782 twRC = GPHOTO2_SetupFileXfer2Set (pOrigin, pData);
786 case DAT_SETUPMEMXFER
:
788 twRC
= GPHOTO2_SetupMemXferGet (pOrigin
, pData
);
795 twRC
= GPHOTO2_GetDSStatus (pOrigin
, pData
);
800 case DAT_USERINTERFACE
:
804 twRC
= GPHOTO2_DisableDSUserInterface (pOrigin
, pData
);
807 twRC
= GPHOTO2_EnableDSUserInterface (pOrigin
, pData
);
809 case MSG_ENABLEDSUIONLY
:
810 twRC
= GPHOTO2_EnableDSUIOnly (pOrigin
, pData
);
822 twRC
= GPHOTO2_XferGroupGet (pOrigin
, pData
);
825 twRC
= GPHOTO2_XferGroupSet (pOrigin
, pData
);
834 FIXME("code unknown: %d\n", DAT
);
843 static TW_UINT16
GPHOTO2_ImageGroupHandler (
844 pTW_IDENTITY pOrigin
,
849 TW_UINT16 twRC
= TWRC_SUCCESS
;
855 twRC
= GPHOTO2_CIEColorGet (pOrigin
, pData
);
860 case DAT_EXTIMAGEINFO
:
862 twRC
= GPHOTO2_ExtImageInfoGet (pOrigin
, pData
);
867 case DAT_GRAYRESPONSE
:
871 twRC
= GPHOTO2_GrayResponseReset (pOrigin
, pData
);
874 twRC
= GPHOTO2_GrayResponseSet (pOrigin
, pData
);
878 activeDS
.twCC
= TWCC_BADPROTOCOL
;
879 FIXME("unrecognized operation triplet\n");
883 case DAT_IMAGEFILEXFER
:
885 twRC
= GPHOTO2_ImageFileXferGet (pOrigin
, pData
);
892 twRC
= GPHOTO2_ImageInfoGet (pOrigin
, pData
);
897 case DAT_IMAGELAYOUT
:
901 twRC
= GPHOTO2_ImageLayoutGet (pOrigin
, pData
);
904 twRC
= GPHOTO2_ImageLayoutGetDefault (pOrigin
, pData
);
907 twRC
= GPHOTO2_ImageLayoutReset (pOrigin
, pData
);
910 twRC
= GPHOTO2_ImageLayoutSet (pOrigin
, pData
);
914 activeDS
.twCC
= TWCC_BADPROTOCOL
;
915 ERR("unrecognized operation triplet\n");
920 case DAT_IMAGEMEMXFER
:
922 twRC
= GPHOTO2_ImageMemXferGet (pOrigin
, pData
);
927 case DAT_IMAGENATIVEXFER
:
929 twRC
= GPHOTO2_ImageNativeXferGet (pOrigin
, pData
);
934 case DAT_JPEGCOMPRESSION
:
938 twRC
= GPHOTO2_JPEGCompressionGet (pOrigin
, pData
);
941 twRC
= GPHOTO2_JPEGCompressionGetDefault (pOrigin
, pData
);
944 twRC
= GPHOTO2_JPEGCompressionReset (pOrigin
, pData
);
947 twRC
= GPHOTO2_JPEGCompressionSet (pOrigin
, pData
);
951 activeDS
.twCC
= TWCC_BADPROTOCOL
;
952 WARN("unrecognized operation triplet\n");
961 twRC
= GPHOTO2_Palette8Get (pOrigin
, pData
);
964 twRC
= GPHOTO2_Palette8GetDefault (pOrigin
, pData
);
967 twRC
= GPHOTO2_Palette8Reset (pOrigin
, pData
);
970 twRC
= GPHOTO2_Palette8Set (pOrigin
, pData
);
974 activeDS
.twCC
= TWCC_BADPROTOCOL
;
975 WARN("unrecognized operation triplet\n");
979 case DAT_RGBRESPONSE
:
983 twRC
= GPHOTO2_RGBResponseReset (pOrigin
, pData
);
986 twRC
= GPHOTO2_RGBResponseSet (pOrigin
, pData
);
990 activeDS
.twCC
= TWCC_BADPROTOCOL
;
991 WARN("unrecognized operation triplet\n");
998 activeDS
.twCC
= TWCC_BADPROTOCOL
;
999 FIXME("unrecognized DG type %d\n", DAT
);
1004 /* Main entry point for the TWAIN library */
1006 DS_Entry ( pTW_IDENTITY pOrigin
,
1012 TW_UINT16 twRC
= TWRC_SUCCESS
; /* Return Code */
1014 TRACE("(DG=%d DAT=%d MSG=%d)\n", DG
, DAT
, MSG
);
1019 twRC
= GPHOTO2_SourceControlHandler (pOrigin
,DAT
,MSG
,pData
);
1022 twRC
= GPHOTO2_ImageGroupHandler (pOrigin
,DAT
,MSG
,pData
);
1025 FIXME("The audio group of entry codes is not implemented.\n");
1027 activeDS
.twCC
= TWCC_BADPROTOCOL
;
1028 twRC
= TWRC_FAILURE
;
1035 static GPPortInfoList
*port_list
;
1036 static int curcamera
;
1037 static CameraList
*detected_cameras
;
1038 static CameraAbilitiesList
*abilities_list
;
1041 gphoto2_auto_detect(void) {
1044 if (detected_cameras
&& (gp_list_count (detected_cameras
) == 0)) {
1045 /* Reload if previously no cameras, we might detect new ones. */
1046 TRACE("Reloading portlist trying to detect cameras.\n");
1048 gp_port_info_list_free (port_list
);
1053 TRACE("Auto detecting gphoto cameras.\n");
1054 TRACE("Loading ports...\n");
1055 if (gp_port_info_list_new (&port_list
) < GP_OK
)
1056 return TWRC_FAILURE
;
1057 result
= gp_port_info_list_load (port_list
);
1059 gp_port_info_list_free (port_list
);
1060 return TWRC_FAILURE
;
1062 count
= gp_port_info_list_count (port_list
);
1064 return TWRC_FAILURE
;
1065 if (gp_list_new (&detected_cameras
) < GP_OK
)
1066 return TWRC_FAILURE
;
1067 if (!abilities_list
) { /* Load only once per program start */
1068 gp_abilities_list_new (&abilities_list
);
1069 TRACE("Loading cameras...\n");
1070 gp_abilities_list_load (abilities_list
, NULL
);
1072 TRACE("Detecting cameras...\n");
1073 gp_abilities_list_detect (abilities_list
, port_list
, detected_cameras
, NULL
);
1075 TRACE("%d cameras detected\n", gp_list_count(detected_cameras
));
1077 return TWRC_SUCCESS
;
1081 GPHOTO2_GetIdentity( pTW_IDENTITY pOrigin
, pTW_IDENTITY self
) {
1083 const char *cname
, *pname
;
1085 if (TWRC_SUCCESS
!= gphoto2_auto_detect())
1086 return TWRC_FAILURE
;
1088 count
= gp_list_count (detected_cameras
);
1089 if (count
< GP_OK
) {
1090 gp_list_free (detected_cameras
);
1091 return TWRC_FAILURE
;
1093 TRACE("%d cameras detected.\n", count
);
1094 self
->ProtocolMajor
= TWON_PROTOCOLMAJOR
;
1095 self
->ProtocolMinor
= TWON_PROTOCOLMINOR
;
1096 lstrcpynA (self
->Manufacturer
, "The Wine Team", sizeof(self
->Manufacturer
) - 1);
1097 lstrcpynA (self
->ProductFamily
, "GPhoto2 Camera", sizeof(self
->ProductFamily
) - 1);
1099 if (!count
) { /* No camera detected. But we need to return an IDENTITY anyway. */
1100 lstrcpynA (self
->ProductName
, "GPhoto2 Camera", sizeof(self
->ProductName
) - 1);
1101 return TWRC_SUCCESS
;
1103 gp_list_get_name (detected_cameras
, curcamera
, &cname
);
1104 gp_list_get_value (detected_cameras
, curcamera
, &pname
);
1105 if (count
== 1) /* Normal case, only one camera. */
1106 snprintf (self
->ProductName
, sizeof(self
->ProductName
), "%s", cname
);
1108 snprintf (self
->ProductName
, sizeof(self
->ProductName
), "%s@%s", cname
, pname
);
1109 curcamera
= (curcamera
+1) % count
;
1110 return TWRC_SUCCESS
;
1114 GPHOTO2_OpenDS( pTW_IDENTITY pOrigin
, pTW_IDENTITY self
) {
1115 int ret
, m
, p
, count
, i
;
1118 const char *model
, *port
;
1120 if (TWRC_SUCCESS
!= gphoto2_auto_detect())
1121 return TWRC_FAILURE
;
1123 if (lstrcmpA(self
->ProductFamily
,"GPhoto2 Camera")) {
1124 FIXME("identity passed is not a gphoto camera, but %s!?!\n", self
->ProductFamily
);
1125 return TWRC_FAILURE
;
1127 count
= gp_list_count (detected_cameras
);
1129 ERR("No camera found by autodetection. Returning failure.\n");
1130 return TWRC_FAILURE
;
1133 if (!lstrcmpA (self
->ProductName
, "GPhoto2 Camera")) {
1134 TRACE("Potential undetected camera. Just using the first autodetected one.\n");
1137 for (i
=0;i
<count
;i
++) {
1138 const char *cname
, *pname
;
1141 gp_list_get_name (detected_cameras
, i
, &cname
);
1142 gp_list_get_value (detected_cameras
, i
, &pname
);
1143 if (!lstrcmpA(self
->ProductName
,cname
))
1145 snprintf(name
, sizeof(name
), "%s", cname
);
1146 if (!lstrcmpA(self
->ProductName
,name
))
1148 snprintf(name
, sizeof(name
), "%s@%s", cname
, pname
);
1149 if (!lstrcmpA(self
->ProductName
,name
))
1153 TRACE("Camera %s not found in autodetected list. Using first entry.\n", self
->ProductName
);
1157 gp_list_get_name (detected_cameras
, i
, &model
);
1158 gp_list_get_value (detected_cameras
, i
, &port
);
1159 TRACE("model %s, port %s\n", model
, port
);
1160 ret
= gp_camera_new (&activeDS
.camera
);
1162 ERR("gp_camera_new: %d\n", ret
);
1163 return TWRC_FAILURE
;
1165 m
= gp_abilities_list_lookup_model (abilities_list
, model
);
1167 FIXME("Model %s not found, %d!\n", model
, m
);
1168 return TWRC_FAILURE
;
1170 ret
= gp_abilities_list_get_abilities (abilities_list
, m
, &a
);
1172 FIXME("gp_camera_list_get_abilities failed? %d\n", ret
);
1173 return TWRC_FAILURE
;
1175 ret
= gp_camera_set_abilities (activeDS
.camera
, a
);
1177 FIXME("gp_camera_set_abilities failed? %d\n", ret
);
1178 return TWRC_FAILURE
;
1181 p
= gp_port_info_list_lookup_path (port_list
, port
);
1183 FIXME("port %s not in portlist?\n", port
);
1184 return TWRC_FAILURE
;
1186 ret
= gp_port_info_list_get_info (port_list
, p
, &info
);
1188 FIXME("could not get portinfo for port %s?\n", port
);
1189 return TWRC_FAILURE
;
1191 ret
= gp_camera_set_port_info (activeDS
.camera
, info
);
1193 FIXME("could not set portinfo for port %s to camera?\n", port
);
1194 return TWRC_FAILURE
;
1196 list_init( &(activeDS
.files
) );
1197 activeDS
.currentState
= 4;
1198 activeDS
.twCC
= TWRC_SUCCESS
;
1199 activeDS
.pixelflavor
= TWPF_CHOCOLATE
;
1200 activeDS
.pixeltype
= TWPT_RGB
;
1201 activeDS
.capXferMech
= TWSX_MEMORY
;
1203 return TWRC_SUCCESS
;