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
31 #include "gphoto2_i.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(twain
);
38 static char* GPHOTO2_StrDup(const char* str
)
40 char* dst
= HeapAlloc(GetProcessHeap(), 0, strlen(str
)+1);
47 load_filesystem(const char *folder
) {
52 ret
= gp_list_new (&list
);
55 ret
= gp_camera_folder_list_files (activeDS
.camera
, folder
, list
, activeDS
.context
);
60 count
= gp_list_count (list
);
65 for (i
= 0; i
< count
; i
++) {
67 struct gphoto2_file
*gpfile
;
69 ret
= gp_list_get_name (list
, i
, &name
);
72 gpfile
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct gphoto2_file
)); /* FIXME: Leaked */
75 TRACE("adding %s/%s\n", folder
, name
);
76 gpfile
->folder
= GPHOTO2_StrDup(folder
);
77 gpfile
->filename
= GPHOTO2_StrDup(name
);
78 gpfile
->download
= FALSE
;
79 list_add_tail( &activeDS
.files
, &gpfile
->entry
);
83 ret
= gp_camera_folder_list_folders (activeDS
.camera
, folder
, list
, activeDS
.context
);
85 FIXME("list_folders failed\n");
89 count
= gp_list_count (list
);
91 FIXME("list_folders failed\n");
95 for (i
= 0; i
< count
; i
++) {
98 ret
= gp_list_get_name (list
, i
, &name
);
101 TRACE("recursing into %s\n", name
);
102 newfolder
= HeapAlloc(GetProcessHeap(), 0, strlen(folder
)+1+strlen(name
)+1);
103 if (!strcmp(folder
,"/"))
104 sprintf (newfolder
, "/%s", name
);
106 sprintf (newfolder
, "%s/%s", folder
, name
);
107 load_filesystem (newfolder
); /* recurse ... happily */
113 /* DG_CONTROL/DAT_CAPABILITY/MSG_GET */
114 static TW_UINT16
GPHOTO2_CapabilityGet (pTW_IDENTITY pOrigin
, TW_MEMREF pData
)
116 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
118 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GET\n");
119 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7) {
120 activeDS
.twCC
= TWCC_SEQERROR
;
123 activeDS
.twCC
= GPHOTO2_SaneCapability (pCapability
, MSG_GET
);
124 return (activeDS
.twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
127 /* DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT */
128 static TW_UINT16
GPHOTO2_CapabilityGetCurrent (pTW_IDENTITY pOrigin
, TW_MEMREF pData
)
130 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
132 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT\n");
134 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7) {
135 activeDS
.twCC
= TWCC_SEQERROR
;
138 activeDS
.twCC
= GPHOTO2_SaneCapability (pCapability
, MSG_GETCURRENT
);
139 return (activeDS
.twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
142 /* DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT */
143 static TW_UINT16
GPHOTO2_CapabilityGetDefault (pTW_IDENTITY pOrigin
, TW_MEMREF pData
)
145 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
147 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT\n");
148 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7) {
149 activeDS
.twCC
= TWCC_SEQERROR
;
152 activeDS
.twCC
= GPHOTO2_SaneCapability (pCapability
, MSG_GETDEFAULT
);
153 return (activeDS
.twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
156 /* DG_CONTROL/DAT_CAPABILITY/MSG_QUERYSUPPORT */
157 static TW_UINT16
GPHOTO2_CapabilityQuerySupport (pTW_IDENTITY pOrigin
,
165 /* DG_CONTROL/DAT_CAPABILITY/MSG_RESET */
166 static TW_UINT16
GPHOTO2_CapabilityReset (pTW_IDENTITY pOrigin
,
169 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
171 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_RESET\n");
173 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7) {
174 activeDS
.twCC
= TWCC_SEQERROR
;
177 activeDS
.twCC
= GPHOTO2_SaneCapability (pCapability
, MSG_RESET
);
178 return (activeDS
.twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
181 /* DG_CONTROL/DAT_CAPABILITY/MSG_SET */
182 static TW_UINT16
GPHOTO2_CapabilitySet (pTW_IDENTITY pOrigin
,
185 pTW_CAPABILITY pCapability
= (pTW_CAPABILITY
) pData
;
187 TRACE ("DG_CONTROL/DAT_CAPABILITY/MSG_SET\n");
189 if (activeDS
.currentState
!= 4) {
190 activeDS
.twCC
= TWCC_SEQERROR
;
193 activeDS
.twCC
= GPHOTO2_SaneCapability (pCapability
, MSG_SET
);
194 return (activeDS
.twCC
== TWCC_SUCCESS
)?TWRC_SUCCESS
:TWRC_FAILURE
;
197 /* DG_CONTROL/DAT_CUSTOMDSDATA/MSG_GET */
198 static TW_UINT16
GPHOTO2_CustomDSDataGet (pTW_IDENTITY pOrigin
,
206 /* DG_CONTROL/DAT_CUSTOMDSDATA/MSG_SET */
207 static TW_UINT16
GPHOTO2_CustomDSDataSet (pTW_IDENTITY pOrigin
,
215 /* DG_CONTROL/DAT_FILESYSTEM/MSG_CHANGEDIRECTORY */
216 static TW_UINT16
GPHOTO2_ChangeDirectory (pTW_IDENTITY pOrigin
,
224 /* DG_CONTROL/DAT_FILESYSTEM/MSG_CREATEDIRECTORY */
225 static TW_UINT16
GPHOTO2_CreateDirectory (pTW_IDENTITY pOrigin
,
233 /* DG_CONTROL/DAT_FILESYSTEM/MSG_DELETE */
234 static TW_UINT16
GPHOTO2_FileSystemDelete (pTW_IDENTITY pOrigin
,
242 /* DG_CONTROL/DAT_FILESYSTEM/MSG_FORMATMEDIA */
243 static TW_UINT16
GPHOTO2_FormatMedia (pTW_IDENTITY pOrigin
,
251 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETCLOSE */
252 static TW_UINT16
GPHOTO2_FileSystemGetClose (pTW_IDENTITY pOrigin
,
260 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETFIRSTFILE */
261 static TW_UINT16
GPHOTO2_FileSystemGetFirstFile (pTW_IDENTITY pOrigin
,
270 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETINFO */
271 static TW_UINT16
GPHOTO2_FileSystemGetInfo (pTW_IDENTITY pOrigin
,
279 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETNEXTFILE */
280 static TW_UINT16
GPHOTO2_FileSystemGetNextFile (pTW_IDENTITY pOrigin
,
289 /* DG_CONTROL/DAT_FILESYSTEM/MSG_RENAME */
290 static TW_UINT16
GPHOTO2_FileSystemRename (pTW_IDENTITY pOrigin
,
298 /* DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT */
299 static TW_UINT16
GPHOTO2_ProcessEvent (pTW_IDENTITY pOrigin
,
302 TW_UINT16 twRC
= TWRC_SUCCESS
;
303 pTW_EVENT pEvent
= (pTW_EVENT
) pData
;
305 TRACE("DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT\n");
307 if (activeDS
.currentState
< 5 || activeDS
.currentState
> 7) {
308 activeDS
.twCC
= TWCC_SEQERROR
;
312 if (activeDS
.pendingEvent
.TWMessage
!= MSG_NULL
) {
313 pEvent
->TWMessage
= activeDS
.pendingEvent
.TWMessage
;
314 activeDS
.pendingEvent
.TWMessage
= MSG_NULL
;
317 pEvent
->TWMessage
= MSG_NULL
; /* no message to the application */
318 twRC
= TWRC_NOTDSEVENT
;
320 activeDS
.twCC
= TWCC_SUCCESS
;
324 /* DG_CONTROL/DAT_PASSTHRU/MSG_PASSTHRU */
325 static TW_UINT16
GPHOTO2_PassThrough (pTW_IDENTITY pOrigin
,
333 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER */
334 static TW_UINT16
GPHOTO2_PendingXfersEndXfer (pTW_IDENTITY pOrigin
,
338 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
339 struct gphoto2_file
*file
;
341 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER\n");
343 if (activeDS
.currentState
!= 6 && activeDS
.currentState
!= 7) {
344 activeDS
.twCC
= TWCC_SEQERROR
;
348 LIST_FOR_EACH_ENTRY( file
, &activeDS
.files
, struct gphoto2_file
, entry
) {
352 TRACE("count = %d\n", count
);
353 pPendingXfers
->Count
= count
;
354 if (pPendingXfers
->Count
!= 0) {
355 activeDS
.currentState
= 6;
357 activeDS
.currentState
= 5;
358 /* Notify the application that it can close the data source */
359 activeDS
.pendingEvent
.TWMessage
= MSG_CLOSEDSREQ
;
360 /* close any Transferring dialog */
361 TransferringDialogBox(activeDS
.progressWnd
,-1);
362 activeDS
.progressWnd
= 0;
364 activeDS
.twCC
= TWCC_SUCCESS
;
368 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_GET */
369 static TW_UINT16
GPHOTO2_PendingXfersGet (pTW_IDENTITY pOrigin
,
373 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
374 struct gphoto2_file
*file
;
376 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_GET\n");
378 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7) {
379 activeDS
.twCC
= TWCC_SEQERROR
;
384 LIST_FOR_EACH_ENTRY( file
, &activeDS
.files
, struct gphoto2_file
, entry
) {
388 TRACE("count = %d\n", count
);
389 pPendingXfers
->Count
= count
;
390 activeDS
.twCC
= TWCC_SUCCESS
;
394 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET */
395 static TW_UINT16
GPHOTO2_PendingXfersReset (pTW_IDENTITY pOrigin
,
398 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
400 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET\n");
402 if (activeDS
.currentState
!= 6) {
403 activeDS
.twCC
= TWCC_SEQERROR
;
406 pPendingXfers
->Count
= 0;
407 activeDS
.currentState
= 5;
408 activeDS
.twCC
= TWCC_SUCCESS
;
412 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_GET */
413 static TW_UINT16
GPHOTO2_SetupFileXferGet (pTW_IDENTITY pOrigin
,
421 /* DG_CONTROL/DAT_SETUPXFER/MSG_GETDEFAULT */
422 static TW_UINT16
GPHOTO2_SetupFileXferGetDefault (pTW_IDENTITY pOrigin
,
431 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_RESET */
432 static TW_UINT16
GPHOTO2_SetupFileXferReset (pTW_IDENTITY pOrigin
,
440 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_SET */
441 static TW_UINT16
GPHOTO2_SetupFileXferSet (pTW_IDENTITY pOrigin
,
449 /* DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET */
450 static TW_UINT16
GPHOTO2_SetupMemXferGet (pTW_IDENTITY pOrigin
,
453 pTW_SETUPMEMXFER pSetupMemXfer
= (pTW_SETUPMEMXFER
)pData
;
455 TRACE("DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET\n");
457 pSetupMemXfer
->MinBufSize
= 20000;
458 pSetupMemXfer
->MaxBufSize
= 80000;
459 pSetupMemXfer
->Preferred
= 40000;
463 /* DG_CONTROL/DAT_STATUS/MSG_GET */
464 static TW_UINT16
GPHOTO2_GetDSStatus (pTW_IDENTITY pOrigin
,
467 pTW_STATUS pSourceStatus
= (pTW_STATUS
) pData
;
469 TRACE ("DG_CONTROL/DAT_STATUS/MSG_GET\n");
470 pSourceStatus
->ConditionCode
= activeDS
.twCC
;
471 /* Reset the condition code */
472 activeDS
.twCC
= TWCC_SUCCESS
;
476 /* DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS */
477 static TW_UINT16
GPHOTO2_DisableDSUserInterface (pTW_IDENTITY pOrigin
,
480 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS\n");
482 if (activeDS
.currentState
!= 5) {
483 activeDS
.twCC
= TWCC_SEQERROR
;
486 activeDS
.currentState
= 4;
487 activeDS
.twCC
= TWCC_SUCCESS
;
491 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS */
492 static TW_UINT16
GPHOTO2_EnableDSUserInterface (pTW_IDENTITY pOrigin
,
495 pTW_USERINTERFACE pUserInterface
= (pTW_USERINTERFACE
) pData
;
497 load_filesystem("/");
499 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS\n");
500 if (activeDS
.currentState
!= 4) {
501 FIXME("Sequence error %d\n", activeDS
.currentState
);
502 activeDS
.twCC
= TWCC_SEQERROR
;
505 activeDS
.hwndOwner
= pUserInterface
->hParent
;
506 if (pUserInterface
->ShowUI
)
509 activeDS
.currentState
= 5; /* Transitions to state 5 */
512 activeDS
.pendingEvent
.TWMessage
= MSG_CLOSEDSREQ
;
514 /* FIXME: The GUI should have marked the files to download... */
515 activeDS
.pendingEvent
.TWMessage
= MSG_XFERREADY
;
516 activeDS
.currentState
= 6; /* Transitions to state 6 directly */
519 /* no UI will be displayed, so source is ready to transfer data */
520 activeDS
.pendingEvent
.TWMessage
= MSG_XFERREADY
;
521 activeDS
.currentState
= 6; /* Transitions to state 6 directly */
523 activeDS
.hwndOwner
= pUserInterface
->hParent
;
524 activeDS
.twCC
= TWCC_SUCCESS
;
528 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY */
529 static TW_UINT16
GPHOTO2_EnableDSUIOnly (pTW_IDENTITY pOrigin
,
532 TRACE("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY\n");
534 if (activeDS
.currentState
!= 4) {
535 activeDS
.twCC
= TWCC_SEQERROR
;
538 /* FIXME: we should replace xscanimage with our own UI */
539 FIXME ("not implemented!\n");
540 activeDS
.currentState
= 5;
541 activeDS
.twCC
= TWCC_SUCCESS
;
545 /* DG_CONTROL/DAT_XFERGROUP/MSG_GET */
546 static TW_UINT16
GPHOTO2_XferGroupGet (pTW_IDENTITY pOrigin
,
553 /* DG_CONTROL/DAT_XFERGROUP/MSG_SET */
554 static TW_UINT16
GPHOTO2_XferGroupSet (pTW_IDENTITY pOrigin
,
561 HINSTANCE GPHOTO2_instance
;
563 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
565 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
569 case DLL_PROCESS_ATTACH
:
570 GPHOTO2_instance
= hinstDLL
;
571 DisableThreadLibraryCalls(hinstDLL
);
573 activeDS
.context
= gp_context_new ();
577 case DLL_PROCESS_DETACH
:
578 GPHOTO2_instance
= NULL
;
586 static TW_UINT16
GPHOTO2_GetIdentity( pTW_IDENTITY
, pTW_IDENTITY
);
587 static TW_UINT16
GPHOTO2_OpenDS( pTW_IDENTITY
, pTW_IDENTITY
);
590 static TW_UINT16
GPHOTO2_SourceControlHandler (
591 pTW_IDENTITY pOrigin
,
596 TW_UINT16 twRC
= TWRC_SUCCESS
;
605 if (activeDS
.camera
) {
606 gp_camera_free (activeDS
.camera
);
607 activeDS
.camera
= NULL
;
613 twRC
= GPHOTO2_GetIdentity(pOrigin
,(pTW_IDENTITY
)pData
);
620 twRC
= GPHOTO2_OpenDS(pOrigin
,(pTW_IDENTITY
)pData
);
631 twRC
= GPHOTO2_CapabilityGet (pOrigin
, pData
);
634 twRC
= GPHOTO2_CapabilityGetCurrent (pOrigin
, pData
);
637 twRC
= GPHOTO2_CapabilityGetDefault (pOrigin
, pData
);
639 case MSG_QUERYSUPPORT
:
640 twRC
= GPHOTO2_CapabilityQuerySupport (pOrigin
, pData
);
643 twRC
= GPHOTO2_CapabilityReset (pOrigin
, pData
);
646 twRC
= GPHOTO2_CapabilitySet (pOrigin
, pData
);
650 FIXME("unrecognized opertion triplet\n");
654 case DAT_CUSTOMDSDATA
:
658 twRC
= GPHOTO2_CustomDSDataGet (pOrigin
, pData
);
661 twRC
= GPHOTO2_CustomDSDataSet (pOrigin
, pData
);
671 /*case MSG_AUTOMATICCAPTUREDIRECTORY:
672 twRC = GPHOTO2_AutomaticCaptureDirectory
675 case MSG_CHANGEDIRECTORY
:
676 twRC
= GPHOTO2_ChangeDirectory (pOrigin
, pData
);
679 twRC = GPHOTO2_FileSystemCopy (pOrigin, pData);
681 case MSG_CREATEDIRECTORY
:
682 twRC
= GPHOTO2_CreateDirectory (pOrigin
, pData
);
685 twRC
= GPHOTO2_FileSystemDelete (pOrigin
, pData
);
687 case MSG_FORMATMEDIA
:
688 twRC
= GPHOTO2_FormatMedia (pOrigin
, pData
);
691 twRC
= GPHOTO2_FileSystemGetClose (pOrigin
, pData
);
693 case MSG_GETFIRSTFILE
:
694 twRC
= GPHOTO2_FileSystemGetFirstFile (pOrigin
, pData
);
697 twRC
= GPHOTO2_FileSystemGetInfo (pOrigin
, pData
);
699 case MSG_GETNEXTFILE
:
700 twRC
= GPHOTO2_FileSystemGetNextFile (pOrigin
, pData
);
703 twRC
= GPHOTO2_FileSystemRename (pOrigin
, pData
);
712 if (MSG
== MSG_PROCESSEVENT
)
713 twRC
= GPHOTO2_ProcessEvent (pOrigin
, pData
);
719 if (MSG
== MSG_PASSTHRU
)
720 twRC
= GPHOTO2_PassThrough (pOrigin
, pData
);
725 case DAT_PENDINGXFERS
:
729 twRC
= GPHOTO2_PendingXfersEndXfer (pOrigin
, pData
);
732 twRC
= GPHOTO2_PendingXfersGet (pOrigin
, pData
);
735 twRC
= GPHOTO2_PendingXfersReset (pOrigin
, pData
);
737 /*case MSG_STOPFEEDER:
738 twRC = GPHOTO2_PendingXfersStopFeeder (pOrigin, pData);
745 case DAT_SETUPFILEXFER
:
749 twRC
= GPHOTO2_SetupFileXferGet (pOrigin
, pData
);
752 twRC
= GPHOTO2_SetupFileXferGetDefault (pOrigin
, pData
);
755 twRC
= GPHOTO2_SetupFileXferReset (pOrigin
, pData
);
758 twRC
= GPHOTO2_SetupFileXferSet (pOrigin
, pData
);
766 /*case DAT_SETUPFILEXFER2:
770 twRC = GPHOTO2_SetupFileXfer2Get (pOrigin, pData);
773 twRC = GPHOTO2_SetupFileXfer2GetDefault (pOrigin, pData);
776 twRC = GPHOTO2_SetupFileXfer2Reset (pOrigin, pData);
779 twRC = GPHOTO2_SetupFileXfer2Set (pOrigin, pData);
783 case DAT_SETUPMEMXFER
:
785 twRC
= GPHOTO2_SetupMemXferGet (pOrigin
, pData
);
792 twRC
= GPHOTO2_GetDSStatus (pOrigin
, pData
);
797 case DAT_USERINTERFACE
:
801 twRC
= GPHOTO2_DisableDSUserInterface (pOrigin
, pData
);
804 twRC
= GPHOTO2_EnableDSUserInterface (pOrigin
, pData
);
806 case MSG_ENABLEDSUIONLY
:
807 twRC
= GPHOTO2_EnableDSUIOnly (pOrigin
, pData
);
819 twRC
= GPHOTO2_XferGroupGet (pOrigin
, pData
);
822 twRC
= GPHOTO2_XferGroupSet (pOrigin
, pData
);
831 FIXME("code unknown: %d\n", DAT
);
840 static TW_UINT16
GPHOTO2_ImageGroupHandler (
841 pTW_IDENTITY pOrigin
,
846 TW_UINT16 twRC
= TWRC_SUCCESS
;
852 twRC
= GPHOTO2_CIEColorGet (pOrigin
, pData
);
857 case DAT_EXTIMAGEINFO
:
859 twRC
= GPHOTO2_ExtImageInfoGet (pOrigin
, pData
);
864 case DAT_GRAYRESPONSE
:
868 twRC
= GPHOTO2_GrayResponseReset (pOrigin
, pData
);
871 twRC
= GPHOTO2_GrayResponseSet (pOrigin
, pData
);
875 activeDS
.twCC
= TWCC_BADPROTOCOL
;
876 FIXME("unrecognized operation triplet\n");
880 case DAT_IMAGEFILEXFER
:
882 twRC
= GPHOTO2_ImageFileXferGet (pOrigin
, pData
);
889 twRC
= GPHOTO2_ImageInfoGet (pOrigin
, pData
);
894 case DAT_IMAGELAYOUT
:
898 twRC
= GPHOTO2_ImageLayoutGet (pOrigin
, pData
);
901 twRC
= GPHOTO2_ImageLayoutGetDefault (pOrigin
, pData
);
904 twRC
= GPHOTO2_ImageLayoutReset (pOrigin
, pData
);
907 twRC
= GPHOTO2_ImageLayoutSet (pOrigin
, pData
);
911 activeDS
.twCC
= TWCC_BADPROTOCOL
;
912 ERR("unrecognized operation triplet\n");
917 case DAT_IMAGEMEMXFER
:
919 twRC
= GPHOTO2_ImageMemXferGet (pOrigin
, pData
);
924 case DAT_IMAGENATIVEXFER
:
926 twRC
= GPHOTO2_ImageNativeXferGet (pOrigin
, pData
);
931 case DAT_JPEGCOMPRESSION
:
935 twRC
= GPHOTO2_JPEGCompressionGet (pOrigin
, pData
);
938 twRC
= GPHOTO2_JPEGCompressionGetDefault (pOrigin
, pData
);
941 twRC
= GPHOTO2_JPEGCompressionReset (pOrigin
, pData
);
944 twRC
= GPHOTO2_JPEGCompressionSet (pOrigin
, pData
);
948 activeDS
.twCC
= TWCC_BADPROTOCOL
;
949 WARN("unrecognized operation triplet\n");
958 twRC
= GPHOTO2_Palette8Get (pOrigin
, pData
);
961 twRC
= GPHOTO2_Palette8GetDefault (pOrigin
, pData
);
964 twRC
= GPHOTO2_Palette8Reset (pOrigin
, pData
);
967 twRC
= GPHOTO2_Palette8Set (pOrigin
, pData
);
971 activeDS
.twCC
= TWCC_BADPROTOCOL
;
972 WARN("unrecognized operation triplet\n");
976 case DAT_RGBRESPONSE
:
980 twRC
= GPHOTO2_RGBResponseReset (pOrigin
, pData
);
983 twRC
= GPHOTO2_RGBResponseSet (pOrigin
, pData
);
987 activeDS
.twCC
= TWCC_BADPROTOCOL
;
988 WARN("unrecognized operation triplet\n");
995 activeDS
.twCC
= TWCC_BADPROTOCOL
;
996 FIXME("unrecognized DG type %d\n", DAT
);
1001 /* Main entry point for the TWAIN library */
1003 DS_Entry ( pTW_IDENTITY pOrigin
,
1009 TW_UINT16 twRC
= TWRC_SUCCESS
; /* Return Code */
1011 TRACE("(DG=%d DAT=%d MSG=%d)\n", DG
, DAT
, MSG
);
1016 twRC
= GPHOTO2_SourceControlHandler (pOrigin
,DAT
,MSG
,pData
);
1019 twRC
= GPHOTO2_ImageGroupHandler (pOrigin
,DAT
,MSG
,pData
);
1022 FIXME("The audio group of entry codes is not implemented.\n");
1024 activeDS
.twCC
= TWCC_BADPROTOCOL
;
1025 twRC
= TWRC_FAILURE
;
1032 static GPPortInfoList
*port_list
;
1033 static int curcamera
;
1034 static CameraList
*detected_cameras
;
1035 static CameraAbilitiesList
*abilities_list
;
1038 gphoto2_auto_detect(void) {
1041 if (detected_cameras
&& (gp_list_count (detected_cameras
) == 0)) {
1042 /* Reload if previously no cameras, we might detect new ones. */
1043 TRACE("Reloading portlist trying to detect cameras.\n");
1045 gp_port_info_list_free (port_list
);
1050 TRACE("Auto detecting gphoto cameras.\n");
1051 TRACE("Loading ports...\n");
1052 if (gp_port_info_list_new (&port_list
) < GP_OK
)
1053 return TWRC_FAILURE
;
1054 result
= gp_port_info_list_load (port_list
);
1056 gp_port_info_list_free (port_list
);
1057 return TWRC_FAILURE
;
1059 count
= gp_port_info_list_count (port_list
);
1061 return TWRC_FAILURE
;
1062 if (gp_list_new (&detected_cameras
) < GP_OK
)
1063 return TWRC_FAILURE
;
1064 if (!abilities_list
) { /* Load only once per program start */
1065 gp_abilities_list_new (&abilities_list
);
1066 TRACE("Loading cameras...\n");
1067 gp_abilities_list_load (abilities_list
, NULL
);
1069 TRACE("Detecting cameras...\n");
1070 gp_abilities_list_detect (abilities_list
, port_list
, detected_cameras
, NULL
);
1072 TRACE("%d cameras detected\n", gp_list_count(detected_cameras
));
1074 return TWRC_SUCCESS
;
1078 GPHOTO2_GetIdentity( pTW_IDENTITY pOrigin
, pTW_IDENTITY self
) {
1080 const char *cname
, *pname
;
1082 if (TWRC_SUCCESS
!= gphoto2_auto_detect())
1083 return TWRC_FAILURE
;
1085 count
= gp_list_count (detected_cameras
);
1086 if (count
< GP_OK
) {
1087 gp_list_free (detected_cameras
);
1088 return TWRC_FAILURE
;
1090 TRACE("%d cameras detected.\n", count
);
1091 self
->ProtocolMajor
= TWON_PROTOCOLMAJOR
;
1092 self
->ProtocolMinor
= TWON_PROTOCOLMINOR
;
1093 lstrcpynA (self
->Manufacturer
, "The Wine Team", sizeof(self
->Manufacturer
) - 1);
1094 lstrcpynA (self
->ProductFamily
, "GPhoto2 Camera", sizeof(self
->ProductFamily
) - 1);
1096 if (!count
) { /* No camera detected. But we need to return an IDENTITY anyway. */
1097 lstrcpynA (self
->ProductName
, "GPhoto2 Camera", sizeof(self
->ProductName
) - 1);
1098 return TWRC_SUCCESS
;
1100 gp_list_get_name (detected_cameras
, curcamera
, &cname
);
1101 gp_list_get_value (detected_cameras
, curcamera
, &pname
);
1102 if (count
== 1) /* Normal case, only one camera. */
1103 snprintf (self
->ProductName
, sizeof(self
->ProductName
), "%s", cname
);
1105 snprintf (self
->ProductName
, sizeof(self
->ProductName
), "%s@%s", cname
, pname
);
1106 curcamera
= (curcamera
+1) % count
;
1107 return TWRC_SUCCESS
;
1111 GPHOTO2_OpenDS( pTW_IDENTITY pOrigin
, pTW_IDENTITY self
) {
1112 int ret
, m
, p
, count
, i
;
1115 const char *model
, *port
;
1117 if (TWRC_SUCCESS
!= gphoto2_auto_detect())
1118 return TWRC_FAILURE
;
1120 if (lstrcmpA(self
->ProductFamily
,"GPhoto2 Camera")) {
1121 FIXME("identity passed is not a gphoto camera, but %s!?!\n", self
->ProductFamily
);
1122 return TWRC_FAILURE
;
1124 count
= gp_list_count (detected_cameras
);
1126 ERR("No camera found by autodetection. Returning failure.\n");
1127 return TWRC_FAILURE
;
1130 if (!lstrcmpA (self
->ProductName
, "GPhoto2 Camera")) {
1131 TRACE("Potential undetected camera. Just using the first autodetected one.\n");
1134 for (i
=0;i
<count
;i
++) {
1135 const char *cname
, *pname
;
1138 gp_list_get_name (detected_cameras
, i
, &cname
);
1139 gp_list_get_value (detected_cameras
, i
, &pname
);
1140 if (!lstrcmpA(self
->ProductName
,cname
))
1142 snprintf(name
, sizeof(name
), "%s", cname
);
1143 if (!lstrcmpA(self
->ProductName
,name
))
1145 snprintf(name
, sizeof(name
), "%s@%s", cname
, pname
);
1146 if (!lstrcmpA(self
->ProductName
,name
))
1150 TRACE("Camera %s not found in autodetected list. Using first entry.\n", self
->ProductName
);
1154 gp_list_get_name (detected_cameras
, i
, &model
);
1155 gp_list_get_value (detected_cameras
, i
, &port
);
1156 TRACE("model %s, port %s\n", model
, port
);
1157 ret
= gp_camera_new (&activeDS
.camera
);
1159 ERR("gp_camera_new: %d\n", ret
);
1160 return TWRC_FAILURE
;
1162 m
= gp_abilities_list_lookup_model (abilities_list
, model
);
1164 FIXME("Model %s not found, %d!\n", model
, m
);
1165 return TWRC_FAILURE
;
1167 ret
= gp_abilities_list_get_abilities (abilities_list
, m
, &a
);
1169 FIXME("gp_camera_list_get_abilities failed? %d\n", ret
);
1170 return TWRC_FAILURE
;
1172 ret
= gp_camera_set_abilities (activeDS
.camera
, a
);
1174 FIXME("gp_camera_set_abilities failed? %d\n", ret
);
1175 return TWRC_FAILURE
;
1178 p
= gp_port_info_list_lookup_path (port_list
, port
);
1180 FIXME("port %s not in portlist?\n", port
);
1181 return TWRC_FAILURE
;
1183 ret
= gp_port_info_list_get_info (port_list
, p
, &info
);
1185 FIXME("could not get portinfo for port %s?\n", port
);
1186 return TWRC_FAILURE
;
1188 ret
= gp_camera_set_port_info (activeDS
.camera
, info
);
1190 FIXME("could not set portinfo for port %s to camera?\n", port
);
1191 return TWRC_FAILURE
;
1193 list_init( &(activeDS
.files
) );
1194 activeDS
.currentState
= 4;
1195 activeDS
.twCC
= TWRC_SUCCESS
;
1196 activeDS
.pixelflavor
= TWPF_CHOCOLATE
;
1197 activeDS
.pixeltype
= TWPT_RGB
;
1198 activeDS
.capXferMech
= TWSX_MEMORY
;
1200 return TWRC_SUCCESS
;