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
);
36 struct tagActiveDS activeDS
;
38 DSMENTRYPROC GPHOTO2_dsmentry
;
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 static void GPHOTO2_Notify (TW_UINT16 message
)
303 GPHOTO2_dsmentry (&activeDS
.identity
, &activeDS
.appIdentity
, DG_CONTROL
, DAT_NULL
, message
, NULL
);
306 /* DG_CONTROL/DAT_ENTRYPOINT/MSG_SET */
307 static TW_UINT16
GPHOTO2_SetEntryPoint (pTW_IDENTITY pOrigin
, TW_MEMREF pData
)
309 TW_ENTRYPOINT
*entry
= (TW_ENTRYPOINT
*)pData
;
311 GPHOTO2_dsmentry
= entry
->DSM_Entry
;
316 /* DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT */
317 static TW_UINT16
GPHOTO2_ProcessEvent (pTW_IDENTITY pOrigin
,
320 pTW_EVENT pEvent
= (pTW_EVENT
) pData
;
322 TRACE("DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT\n");
324 if (activeDS
.currentState
< 5 || activeDS
.currentState
> 7) {
325 activeDS
.twCC
= TWCC_SEQERROR
;
329 pEvent
->TWMessage
= MSG_NULL
; /* no message to the application */
330 activeDS
.twCC
= TWCC_SUCCESS
;
331 return TWRC_NOTDSEVENT
;
334 /* DG_CONTROL/DAT_PASSTHRU/MSG_PASSTHRU */
335 static TW_UINT16
GPHOTO2_PassThrough (pTW_IDENTITY pOrigin
,
343 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER */
344 static TW_UINT16
GPHOTO2_PendingXfersEndXfer (pTW_IDENTITY pOrigin
,
348 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
349 struct gphoto2_file
*file
;
351 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER\n");
353 if (activeDS
.currentState
!= 6 && activeDS
.currentState
!= 7) {
354 activeDS
.twCC
= TWCC_SEQERROR
;
358 LIST_FOR_EACH_ENTRY( file
, &activeDS
.files
, struct gphoto2_file
, entry
) {
362 TRACE("count = %d\n", count
);
363 pPendingXfers
->Count
= count
;
364 if (pPendingXfers
->Count
!= 0) {
365 activeDS
.currentState
= 6;
367 activeDS
.currentState
= 5;
368 /* Notify the application that it can close the data source */
369 GPHOTO2_Notify(MSG_CLOSEDSREQ
);
370 /* close any Transferring dialog */
371 TransferringDialogBox(activeDS
.progressWnd
,-1);
372 activeDS
.progressWnd
= 0;
374 activeDS
.twCC
= TWCC_SUCCESS
;
378 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_GET */
379 static TW_UINT16
GPHOTO2_PendingXfersGet (pTW_IDENTITY pOrigin
,
383 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
384 struct gphoto2_file
*file
;
386 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_GET\n");
388 if (activeDS
.currentState
< 4 || activeDS
.currentState
> 7) {
389 activeDS
.twCC
= TWCC_SEQERROR
;
394 LIST_FOR_EACH_ENTRY( file
, &activeDS
.files
, struct gphoto2_file
, entry
) {
398 TRACE("count = %d\n", count
);
399 pPendingXfers
->Count
= count
;
400 activeDS
.twCC
= TWCC_SUCCESS
;
404 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET */
405 static TW_UINT16
GPHOTO2_PendingXfersReset (pTW_IDENTITY pOrigin
,
408 pTW_PENDINGXFERS pPendingXfers
= (pTW_PENDINGXFERS
) pData
;
410 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET\n");
412 if (activeDS
.currentState
!= 6) {
413 activeDS
.twCC
= TWCC_SEQERROR
;
416 pPendingXfers
->Count
= 0;
417 activeDS
.currentState
= 5;
418 activeDS
.twCC
= TWCC_SUCCESS
;
422 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_GET */
423 static TW_UINT16
GPHOTO2_SetupFileXferGet (pTW_IDENTITY pOrigin
,
431 /* DG_CONTROL/DAT_SETUPXFER/MSG_GETDEFAULT */
432 static TW_UINT16
GPHOTO2_SetupFileXferGetDefault (pTW_IDENTITY pOrigin
,
441 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_RESET */
442 static TW_UINT16
GPHOTO2_SetupFileXferReset (pTW_IDENTITY pOrigin
,
450 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_SET */
451 static TW_UINT16
GPHOTO2_SetupFileXferSet (pTW_IDENTITY pOrigin
,
459 /* DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET */
460 static TW_UINT16
GPHOTO2_SetupMemXferGet (pTW_IDENTITY pOrigin
,
463 pTW_SETUPMEMXFER pSetupMemXfer
= (pTW_SETUPMEMXFER
)pData
;
465 TRACE("DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET\n");
467 pSetupMemXfer
->MinBufSize
= 20000;
468 pSetupMemXfer
->MaxBufSize
= 80000;
469 pSetupMemXfer
->Preferred
= 40000;
473 /* DG_CONTROL/DAT_STATUS/MSG_GET */
474 static TW_UINT16
GPHOTO2_GetDSStatus (pTW_IDENTITY pOrigin
,
477 pTW_STATUS pSourceStatus
= (pTW_STATUS
) pData
;
479 TRACE ("DG_CONTROL/DAT_STATUS/MSG_GET\n");
480 pSourceStatus
->ConditionCode
= activeDS
.twCC
;
481 /* Reset the condition code */
482 activeDS
.twCC
= TWCC_SUCCESS
;
486 /* DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS */
487 static TW_UINT16
GPHOTO2_DisableDSUserInterface (pTW_IDENTITY pOrigin
,
490 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS\n");
492 if (activeDS
.currentState
!= 5) {
493 activeDS
.twCC
= TWCC_SEQERROR
;
496 activeDS
.currentState
= 4;
497 activeDS
.twCC
= TWCC_SUCCESS
;
501 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS */
502 static TW_UINT16
GPHOTO2_EnableDSUserInterface (pTW_IDENTITY pOrigin
,
505 pTW_USERINTERFACE pUserInterface
= (pTW_USERINTERFACE
) pData
;
507 load_filesystem("/");
509 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS\n");
510 if (activeDS
.currentState
!= 4) {
511 FIXME("Sequence error %d\n", activeDS
.currentState
);
512 activeDS
.twCC
= TWCC_SEQERROR
;
515 if (pUserInterface
->ShowUI
)
518 activeDS
.currentState
= 5; /* Transitions to state 5 */
521 GPHOTO2_Notify(MSG_CLOSEDSREQ
);
523 /* FIXME: The GUI should have marked the files to download... */
524 GPHOTO2_Notify(MSG_XFERREADY
);
525 activeDS
.currentState
= 6; /* Transitions to state 6 directly */
528 /* no UI will be displayed, so source is ready to transfer data */
529 GPHOTO2_Notify(MSG_XFERREADY
);
530 activeDS
.currentState
= 6; /* Transitions to state 6 directly */
532 activeDS
.twCC
= TWCC_SUCCESS
;
536 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY */
537 static TW_UINT16
GPHOTO2_EnableDSUIOnly (pTW_IDENTITY pOrigin
,
540 TRACE("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY\n");
542 if (activeDS
.currentState
!= 4) {
543 activeDS
.twCC
= TWCC_SEQERROR
;
546 /* FIXME: we should replace xscanimage with our own UI */
547 FIXME ("not implemented!\n");
548 activeDS
.currentState
= 5;
549 activeDS
.twCC
= TWCC_SUCCESS
;
553 /* DG_CONTROL/DAT_XFERGROUP/MSG_GET */
554 static TW_UINT16
GPHOTO2_XferGroupGet (pTW_IDENTITY pOrigin
,
561 /* DG_CONTROL/DAT_XFERGROUP/MSG_SET */
562 static TW_UINT16
GPHOTO2_XferGroupSet (pTW_IDENTITY pOrigin
,
569 HINSTANCE GPHOTO2_instance
;
571 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
573 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
577 case DLL_PROCESS_ATTACH
:
578 GPHOTO2_instance
= hinstDLL
;
579 DisableThreadLibraryCalls(hinstDLL
);
581 activeDS
.context
= gp_context_new ();
589 #if defined(HAVE_GPHOTO2) && defined(HAVE_GPHOTO2_PORT)
590 static TW_UINT16
GPHOTO2_GetIdentity( pTW_IDENTITY
, pTW_IDENTITY
);
591 static TW_UINT16
GPHOTO2_OpenDS( pTW_IDENTITY
, pTW_IDENTITY
);
594 static TW_UINT16
GPHOTO2_SourceControlHandler (
595 pTW_IDENTITY pOrigin
,
600 TW_UINT16 twRC
= TWRC_SUCCESS
;
608 #if defined(HAVE_GPHOTO2) && defined(HAVE_GPHOTO2_PORT)
609 if (activeDS
.camera
) {
610 gp_camera_free (activeDS
.camera
);
611 activeDS
.camera
= NULL
;
616 #if defined(HAVE_GPHOTO2) && defined(HAVE_GPHOTO2_PORT)
617 twRC
= GPHOTO2_GetIdentity(pOrigin
,(pTW_IDENTITY
)pData
);
623 #if defined(HAVE_GPHOTO2) && defined(HAVE_GPHOTO2_PORT)
624 twRC
= GPHOTO2_OpenDS(pOrigin
,(pTW_IDENTITY
)pData
);
635 twRC
= GPHOTO2_CapabilityGet (pOrigin
, pData
);
638 twRC
= GPHOTO2_CapabilityGetCurrent (pOrigin
, pData
);
641 twRC
= GPHOTO2_CapabilityGetDefault (pOrigin
, pData
);
643 case MSG_QUERYSUPPORT
:
644 twRC
= GPHOTO2_CapabilityQuerySupport (pOrigin
, pData
);
647 twRC
= GPHOTO2_CapabilityReset (pOrigin
, pData
);
650 twRC
= GPHOTO2_CapabilitySet (pOrigin
, pData
);
654 FIXME("unrecognized operation triplet\n");
658 case DAT_CUSTOMDSDATA
:
662 twRC
= GPHOTO2_CustomDSDataGet (pOrigin
, pData
);
665 twRC
= GPHOTO2_CustomDSDataSet (pOrigin
, pData
);
675 /*case MSG_AUTOMATICCAPTUREDIRECTORY:
676 twRC = GPHOTO2_AutomaticCaptureDirectory
679 case MSG_CHANGEDIRECTORY
:
680 twRC
= GPHOTO2_ChangeDirectory (pOrigin
, pData
);
683 twRC = GPHOTO2_FileSystemCopy (pOrigin, pData);
685 case MSG_CREATEDIRECTORY
:
686 twRC
= GPHOTO2_CreateDirectory (pOrigin
, pData
);
689 twRC
= GPHOTO2_FileSystemDelete (pOrigin
, pData
);
691 case MSG_FORMATMEDIA
:
692 twRC
= GPHOTO2_FormatMedia (pOrigin
, pData
);
695 twRC
= GPHOTO2_FileSystemGetClose (pOrigin
, pData
);
697 case MSG_GETFIRSTFILE
:
698 twRC
= GPHOTO2_FileSystemGetFirstFile (pOrigin
, pData
);
701 twRC
= GPHOTO2_FileSystemGetInfo (pOrigin
, pData
);
703 case MSG_GETNEXTFILE
:
704 twRC
= GPHOTO2_FileSystemGetNextFile (pOrigin
, pData
);
707 twRC
= GPHOTO2_FileSystemRename (pOrigin
, pData
);
717 twRC
= GPHOTO2_SetEntryPoint (pOrigin
, pData
);
723 if (MSG
== MSG_PROCESSEVENT
)
724 twRC
= GPHOTO2_ProcessEvent (pOrigin
, pData
);
730 if (MSG
== MSG_PASSTHRU
)
731 twRC
= GPHOTO2_PassThrough (pOrigin
, pData
);
736 case DAT_PENDINGXFERS
:
740 twRC
= GPHOTO2_PendingXfersEndXfer (pOrigin
, pData
);
743 twRC
= GPHOTO2_PendingXfersGet (pOrigin
, pData
);
746 twRC
= GPHOTO2_PendingXfersReset (pOrigin
, pData
);
748 /*case MSG_STOPFEEDER:
749 twRC = GPHOTO2_PendingXfersStopFeeder (pOrigin, pData);
756 case DAT_SETUPFILEXFER
:
760 twRC
= GPHOTO2_SetupFileXferGet (pOrigin
, pData
);
763 twRC
= GPHOTO2_SetupFileXferGetDefault (pOrigin
, pData
);
766 twRC
= GPHOTO2_SetupFileXferReset (pOrigin
, pData
);
769 twRC
= GPHOTO2_SetupFileXferSet (pOrigin
, pData
);
777 /*case DAT_SETUPFILEXFER2:
781 twRC = GPHOTO2_SetupFileXfer2Get (pOrigin, pData);
784 twRC = GPHOTO2_SetupFileXfer2GetDefault (pOrigin, pData);
787 twRC = GPHOTO2_SetupFileXfer2Reset (pOrigin, pData);
790 twRC = GPHOTO2_SetupFileXfer2Set (pOrigin, pData);
794 case DAT_SETUPMEMXFER
:
796 twRC
= GPHOTO2_SetupMemXferGet (pOrigin
, pData
);
803 twRC
= GPHOTO2_GetDSStatus (pOrigin
, pData
);
808 case DAT_USERINTERFACE
:
812 twRC
= GPHOTO2_DisableDSUserInterface (pOrigin
, pData
);
815 twRC
= GPHOTO2_EnableDSUserInterface (pOrigin
, pData
);
817 case MSG_ENABLEDSUIONLY
:
818 twRC
= GPHOTO2_EnableDSUIOnly (pOrigin
, pData
);
830 twRC
= GPHOTO2_XferGroupGet (pOrigin
, pData
);
833 twRC
= GPHOTO2_XferGroupSet (pOrigin
, pData
);
842 FIXME("code unknown: %d\n", DAT
);
851 static TW_UINT16
GPHOTO2_ImageGroupHandler (
852 pTW_IDENTITY pOrigin
,
857 TW_UINT16 twRC
= TWRC_SUCCESS
;
863 twRC
= GPHOTO2_CIEColorGet (pOrigin
, pData
);
868 case DAT_EXTIMAGEINFO
:
870 twRC
= GPHOTO2_ExtImageInfoGet (pOrigin
, pData
);
875 case DAT_GRAYRESPONSE
:
879 twRC
= GPHOTO2_GrayResponseReset (pOrigin
, pData
);
882 twRC
= GPHOTO2_GrayResponseSet (pOrigin
, pData
);
886 activeDS
.twCC
= TWCC_BADPROTOCOL
;
887 FIXME("unrecognized operation triplet\n");
891 case DAT_IMAGEFILEXFER
:
893 twRC
= GPHOTO2_ImageFileXferGet (pOrigin
, pData
);
900 twRC
= GPHOTO2_ImageInfoGet (pOrigin
, pData
);
905 case DAT_IMAGELAYOUT
:
909 twRC
= GPHOTO2_ImageLayoutGet (pOrigin
, pData
);
912 twRC
= GPHOTO2_ImageLayoutGetDefault (pOrigin
, pData
);
915 twRC
= GPHOTO2_ImageLayoutReset (pOrigin
, pData
);
918 twRC
= GPHOTO2_ImageLayoutSet (pOrigin
, pData
);
922 activeDS
.twCC
= TWCC_BADPROTOCOL
;
923 ERR("unrecognized operation triplet\n");
928 case DAT_IMAGEMEMXFER
:
930 twRC
= GPHOTO2_ImageMemXferGet (pOrigin
, pData
);
935 case DAT_IMAGENATIVEXFER
:
937 twRC
= GPHOTO2_ImageNativeXferGet (pOrigin
, pData
);
942 case DAT_JPEGCOMPRESSION
:
946 twRC
= GPHOTO2_JPEGCompressionGet (pOrigin
, pData
);
949 twRC
= GPHOTO2_JPEGCompressionGetDefault (pOrigin
, pData
);
952 twRC
= GPHOTO2_JPEGCompressionReset (pOrigin
, pData
);
955 twRC
= GPHOTO2_JPEGCompressionSet (pOrigin
, pData
);
959 activeDS
.twCC
= TWCC_BADPROTOCOL
;
960 WARN("unrecognized operation triplet\n");
969 twRC
= GPHOTO2_Palette8Get (pOrigin
, pData
);
972 twRC
= GPHOTO2_Palette8GetDefault (pOrigin
, pData
);
975 twRC
= GPHOTO2_Palette8Reset (pOrigin
, pData
);
978 twRC
= GPHOTO2_Palette8Set (pOrigin
, pData
);
982 activeDS
.twCC
= TWCC_BADPROTOCOL
;
983 WARN("unrecognized operation triplet\n");
987 case DAT_RGBRESPONSE
:
991 twRC
= GPHOTO2_RGBResponseReset (pOrigin
, pData
);
994 twRC
= GPHOTO2_RGBResponseSet (pOrigin
, pData
);
998 activeDS
.twCC
= TWCC_BADPROTOCOL
;
999 WARN("unrecognized operation triplet\n");
1005 twRC
= TWRC_FAILURE
;
1006 activeDS
.twCC
= TWCC_BADPROTOCOL
;
1007 FIXME("unrecognized DG type %d\n", DAT
);
1012 /* Main entry point for the TWAIN library */
1014 DS_Entry ( pTW_IDENTITY pOrigin
,
1020 TW_UINT16 twRC
= TWRC_SUCCESS
; /* Return Code */
1022 TRACE("(DG=%d DAT=%d MSG=%d)\n", DG
, DAT
, MSG
);
1027 twRC
= GPHOTO2_SourceControlHandler (pOrigin
,DAT
,MSG
,pData
);
1030 twRC
= GPHOTO2_ImageGroupHandler (pOrigin
,DAT
,MSG
,pData
);
1033 FIXME("The audio group of entry codes is not implemented.\n");
1035 activeDS
.twCC
= TWCC_BADPROTOCOL
;
1036 twRC
= TWRC_FAILURE
;
1042 #if defined(HAVE_GPHOTO2) && defined(HAVE_GPHOTO2_PORT)
1043 static GPPortInfoList
*port_list
;
1044 static int curcamera
;
1045 static CameraList
*detected_cameras
;
1046 static CameraAbilitiesList
*abilities_list
;
1049 gphoto2_auto_detect(void) {
1052 if (detected_cameras
&& (gp_list_count (detected_cameras
) == 0)) {
1053 /* Reload if previously no cameras, we might detect new ones. */
1054 TRACE("Reloading portlist trying to detect cameras.\n");
1056 gp_port_info_list_free (port_list
);
1061 TRACE("Auto detecting gphoto cameras.\n");
1062 TRACE("Loading ports...\n");
1063 if (gp_port_info_list_new (&port_list
) < GP_OK
)
1064 return TWRC_FAILURE
;
1065 result
= gp_port_info_list_load (port_list
);
1067 gp_port_info_list_free (port_list
);
1068 return TWRC_FAILURE
;
1070 count
= gp_port_info_list_count (port_list
);
1072 return TWRC_FAILURE
;
1073 if (gp_list_new (&detected_cameras
) < GP_OK
)
1074 return TWRC_FAILURE
;
1075 if (!abilities_list
) { /* Load only once per program start */
1076 gp_abilities_list_new (&abilities_list
);
1077 TRACE("Loading cameras...\n");
1078 gp_abilities_list_load (abilities_list
, NULL
);
1080 TRACE("Detecting cameras...\n");
1081 gp_abilities_list_detect (abilities_list
, port_list
, detected_cameras
, NULL
);
1083 TRACE("%d cameras detected\n", gp_list_count(detected_cameras
));
1085 return TWRC_SUCCESS
;
1089 GPHOTO2_GetIdentity( pTW_IDENTITY pOrigin
, pTW_IDENTITY self
) {
1091 const char *cname
, *pname
;
1093 if (TWRC_SUCCESS
!= gphoto2_auto_detect())
1094 return TWRC_FAILURE
;
1096 count
= gp_list_count (detected_cameras
);
1097 if (count
< GP_OK
) {
1098 gp_list_free (detected_cameras
);
1099 return TWRC_FAILURE
;
1101 TRACE("%d cameras detected.\n", count
);
1102 self
->ProtocolMajor
= TWON_PROTOCOLMAJOR
;
1103 self
->ProtocolMinor
= TWON_PROTOCOLMINOR
;
1104 self
->SupportedGroups
= DG_CONTROL
| DG_IMAGE
| DF_DS2
;
1105 lstrcpynA (self
->Manufacturer
, "The Wine Team", sizeof(self
->Manufacturer
) - 1);
1106 lstrcpynA (self
->ProductFamily
, "GPhoto2 Camera", sizeof(self
->ProductFamily
) - 1);
1108 if (!count
) { /* No camera detected. But we need to return an IDENTITY anyway. */
1109 lstrcpynA (self
->ProductName
, "GPhoto2 Camera", sizeof(self
->ProductName
) - 1);
1110 return TWRC_SUCCESS
;
1112 gp_list_get_name (detected_cameras
, curcamera
, &cname
);
1113 gp_list_get_value (detected_cameras
, curcamera
, &pname
);
1114 if (count
== 1) /* Normal case, only one camera. */
1115 snprintf (self
->ProductName
, sizeof(self
->ProductName
), "%s", cname
);
1117 snprintf (self
->ProductName
, sizeof(self
->ProductName
), "%s@%s", cname
, pname
);
1118 curcamera
= (curcamera
+1) % count
;
1119 return TWRC_SUCCESS
;
1123 GPHOTO2_OpenDS( pTW_IDENTITY pOrigin
, pTW_IDENTITY self
) {
1124 int ret
, m
, p
, count
, i
;
1127 const char *model
, *port
;
1129 if (GPHOTO2_dsmentry
== NULL
)
1131 static const WCHAR twain32W
[] = {'t','w','a','i','n','_','3','2',0};
1132 HMODULE moddsm
= GetModuleHandleW(twain32W
);
1135 GPHOTO2_dsmentry
= (void*)GetProcAddress(moddsm
, "DSM_Entry");
1137 if (!GPHOTO2_dsmentry
)
1139 ERR("can't find DSM entry point\n");
1140 return TWRC_FAILURE
;
1144 if (TWRC_SUCCESS
!= gphoto2_auto_detect())
1145 return TWRC_FAILURE
;
1147 if (lstrcmpA(self
->ProductFamily
,"GPhoto2 Camera")) {
1148 FIXME("identity passed is not a gphoto camera, but %s!?!\n", self
->ProductFamily
);
1149 return TWRC_FAILURE
;
1151 count
= gp_list_count (detected_cameras
);
1153 ERR("No camera found by autodetection. Returning failure.\n");
1154 return TWRC_FAILURE
;
1157 if (!lstrcmpA (self
->ProductName
, "GPhoto2 Camera")) {
1158 TRACE("Potential undetected camera. Just using the first autodetected one.\n");
1161 for (i
=0;i
<count
;i
++) {
1162 const char *cname
, *pname
;
1165 gp_list_get_name (detected_cameras
, i
, &cname
);
1166 gp_list_get_value (detected_cameras
, i
, &pname
);
1167 if (!lstrcmpA(self
->ProductName
,cname
))
1169 snprintf(name
, sizeof(name
), "%s", cname
);
1170 if (!lstrcmpA(self
->ProductName
,name
))
1172 snprintf(name
, sizeof(name
), "%s@%s", cname
, pname
);
1173 if (!lstrcmpA(self
->ProductName
,name
))
1177 TRACE("Camera %s not found in autodetected list. Using first entry.\n", self
->ProductName
);
1181 gp_list_get_name (detected_cameras
, i
, &model
);
1182 gp_list_get_value (detected_cameras
, i
, &port
);
1183 TRACE("model %s, port %s\n", model
, port
);
1184 ret
= gp_camera_new (&activeDS
.camera
);
1186 ERR("gp_camera_new: %d\n", ret
);
1187 return TWRC_FAILURE
;
1189 m
= gp_abilities_list_lookup_model (abilities_list
, model
);
1191 FIXME("Model %s not found, %d!\n", model
, m
);
1192 return TWRC_FAILURE
;
1194 ret
= gp_abilities_list_get_abilities (abilities_list
, m
, &a
);
1196 FIXME("gp_camera_list_get_abilities failed? %d\n", ret
);
1197 return TWRC_FAILURE
;
1199 ret
= gp_camera_set_abilities (activeDS
.camera
, a
);
1201 FIXME("gp_camera_set_abilities failed? %d\n", ret
);
1202 return TWRC_FAILURE
;
1205 p
= gp_port_info_list_lookup_path (port_list
, port
);
1207 FIXME("port %s not in portlist?\n", port
);
1208 return TWRC_FAILURE
;
1210 ret
= gp_port_info_list_get_info (port_list
, p
, &info
);
1212 FIXME("could not get portinfo for port %s?\n", port
);
1213 return TWRC_FAILURE
;
1215 ret
= gp_camera_set_port_info (activeDS
.camera
, info
);
1217 FIXME("could not set portinfo for port %s to camera?\n", port
);
1218 return TWRC_FAILURE
;
1220 list_init( &(activeDS
.files
) );
1221 activeDS
.currentState
= 4;
1222 activeDS
.twCC
= TWRC_SUCCESS
;
1223 activeDS
.pixelflavor
= TWPF_CHOCOLATE
;
1224 activeDS
.pixeltype
= TWPT_RGB
;
1225 activeDS
.capXferMech
= TWSX_MEMORY
;
1226 activeDS
.identity
.Id
= self
->Id
;
1227 activeDS
.appIdentity
= *pOrigin
;
1229 return TWRC_SUCCESS
;