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);
40 static char* GPHOTO2_StrDup(const char* str)
42 char* dst = HeapAlloc(GetProcessHeap(), 0, strlen(str)+1);
48 load_filesystem(const char *folder) {
53 ret = gp_list_new (&list);
56 ret = gp_camera_folder_list_files (activeDS.camera, folder, list, activeDS.context);
61 count = gp_list_count (list);
66 for (i = 0; i < count; i++) {
68 struct gphoto2_file *gpfile;
70 ret = gp_list_get_name (list, i, &name);
73 gpfile = HeapAlloc(GetProcessHeap(), 0, sizeof(struct gphoto2_file)); /* FIXME: Leaked */
76 TRACE("adding %s/%s\n", folder, name);
77 gpfile->folder = GPHOTO2_StrDup(folder);
78 gpfile->filename = GPHOTO2_StrDup(name);
79 gpfile->download = FALSE;
80 list_add_tail( &activeDS.files, &gpfile->entry );
84 ret = gp_camera_folder_list_folders (activeDS.camera, folder, list, activeDS.context);
86 FIXME("list_folders failed\n");
90 count = gp_list_count (list);
92 FIXME("list_folders failed\n");
96 for (i = 0; i < count; i++) {
99 ret = gp_list_get_name (list, i, &name);
102 TRACE("recursing into %s\n", name);
103 newfolder = HeapAlloc(GetProcessHeap(), 0, strlen(folder)+1+strlen(name)+1);
104 if (!strcmp(folder,"/"))
105 sprintf (newfolder, "/%s", name);
107 sprintf (newfolder, "%s/%s", folder, name);
108 load_filesystem (newfolder); /* recurse ... happily */
114 /* DG_CONTROL/DAT_CAPABILITY/MSG_GET */
115 static TW_UINT16 GPHOTO2_CapabilityGet (pTW_IDENTITY pOrigin, TW_MEMREF pData)
117 pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
119 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GET\n");
120 if (activeDS.currentState < 4 || activeDS.currentState > 7) {
121 activeDS.twCC = TWCC_SEQERROR;
124 activeDS.twCC = GPHOTO2_SaneCapability (pCapability, MSG_GET);
125 return (activeDS.twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
128 /* DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT */
129 static TW_UINT16 GPHOTO2_CapabilityGetCurrent (pTW_IDENTITY pOrigin, TW_MEMREF pData)
131 pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
133 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT\n");
135 if (activeDS.currentState < 4 || activeDS.currentState > 7) {
136 activeDS.twCC = TWCC_SEQERROR;
139 activeDS.twCC = GPHOTO2_SaneCapability (pCapability, MSG_GETCURRENT);
140 return (activeDS.twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
143 /* DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT */
144 static TW_UINT16 GPHOTO2_CapabilityGetDefault (pTW_IDENTITY pOrigin, TW_MEMREF pData)
146 pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
148 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_GETDEFAULT\n");
149 if (activeDS.currentState < 4 || activeDS.currentState > 7) {
150 activeDS.twCC = TWCC_SEQERROR;
153 activeDS.twCC = GPHOTO2_SaneCapability (pCapability, MSG_GETDEFAULT);
154 return (activeDS.twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
157 /* DG_CONTROL/DAT_CAPABILITY/MSG_QUERYSUPPORT */
158 static TW_UINT16 GPHOTO2_CapabilityQuerySupport (pTW_IDENTITY pOrigin,
166 /* DG_CONTROL/DAT_CAPABILITY/MSG_RESET */
167 static TW_UINT16 GPHOTO2_CapabilityReset (pTW_IDENTITY pOrigin,
170 pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
172 TRACE("DG_CONTROL/DAT_CAPABILITY/MSG_RESET\n");
174 if (activeDS.currentState < 4 || activeDS.currentState > 7) {
175 activeDS.twCC = TWCC_SEQERROR;
178 activeDS.twCC = GPHOTO2_SaneCapability (pCapability, MSG_RESET);
179 return (activeDS.twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
182 /* DG_CONTROL/DAT_CAPABILITY/MSG_SET */
183 static TW_UINT16 GPHOTO2_CapabilitySet (pTW_IDENTITY pOrigin,
186 pTW_CAPABILITY pCapability = (pTW_CAPABILITY) pData;
188 TRACE ("DG_CONTROL/DAT_CAPABILITY/MSG_SET\n");
190 if (activeDS.currentState != 4) {
191 activeDS.twCC = TWCC_SEQERROR;
194 activeDS.twCC = GPHOTO2_SaneCapability (pCapability, MSG_SET);
195 return (activeDS.twCC == TWCC_SUCCESS)?TWRC_SUCCESS:TWRC_FAILURE;
198 /* DG_CONTROL/DAT_CUSTOMDSDATA/MSG_GET */
199 static TW_UINT16 GPHOTO2_CustomDSDataGet (pTW_IDENTITY pOrigin,
207 /* DG_CONTROL/DAT_CUSTOMDSDATA/MSG_SET */
208 static TW_UINT16 GPHOTO2_CustomDSDataSet (pTW_IDENTITY pOrigin,
216 /* DG_CONTROL/DAT_FILESYSTEM/MSG_CHANGEDIRECTORY */
217 static TW_UINT16 GPHOTO2_ChangeDirectory (pTW_IDENTITY pOrigin,
225 /* DG_CONTROL/DAT_FILESYSTEM/MSG_CREATEDIRECTORY */
226 static TW_UINT16 GPHOTO2_CreateDirectory (pTW_IDENTITY pOrigin,
234 /* DG_CONTROL/DAT_FILESYSTEM/MSG_DELETE */
235 static TW_UINT16 GPHOTO2_FileSystemDelete (pTW_IDENTITY pOrigin,
243 /* DG_CONTROL/DAT_FILESYSTEM/MSG_FORMATMEDIA */
244 static TW_UINT16 GPHOTO2_FormatMedia (pTW_IDENTITY pOrigin,
252 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETCLOSE */
253 static TW_UINT16 GPHOTO2_FileSystemGetClose (pTW_IDENTITY pOrigin,
261 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETFIRSTFILE */
262 static TW_UINT16 GPHOTO2_FileSystemGetFirstFile (pTW_IDENTITY pOrigin,
271 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETINFO */
272 static TW_UINT16 GPHOTO2_FileSystemGetInfo (pTW_IDENTITY pOrigin,
280 /* DG_CONTROL/DAT_FILESYSTEM/MSG_GETNEXTFILE */
281 static TW_UINT16 GPHOTO2_FileSystemGetNextFile (pTW_IDENTITY pOrigin,
290 /* DG_CONTROL/DAT_FILESYSTEM/MSG_RENAME */
291 static TW_UINT16 GPHOTO2_FileSystemRename (pTW_IDENTITY pOrigin,
299 /* DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT */
300 static TW_UINT16 GPHOTO2_ProcessEvent (pTW_IDENTITY pOrigin,
303 TW_UINT16 twRC = TWRC_SUCCESS;
304 pTW_EVENT pEvent = (pTW_EVENT) pData;
306 TRACE("DG_CONTROL/DAT_EVENT/MSG_PROCESSEVENT\n");
308 if (activeDS.currentState < 5 || activeDS.currentState > 7) {
309 activeDS.twCC = TWCC_SEQERROR;
313 if (activeDS.pendingEvent.TWMessage != MSG_NULL) {
314 pEvent->TWMessage = activeDS.pendingEvent.TWMessage;
315 activeDS.pendingEvent.TWMessage = MSG_NULL;
318 pEvent->TWMessage = MSG_NULL; /* no message to the application */
319 twRC = TWRC_NOTDSEVENT;
321 activeDS.twCC = TWCC_SUCCESS;
325 /* DG_CONTROL/DAT_PASSTHRU/MSG_PASSTHRU */
326 static TW_UINT16 GPHOTO2_PassThrough (pTW_IDENTITY pOrigin,
334 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER */
335 static TW_UINT16 GPHOTO2_PendingXfersEndXfer (pTW_IDENTITY pOrigin,
339 pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
340 struct gphoto2_file *file;
342 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER\n");
344 if (activeDS.currentState != 6 && activeDS.currentState != 7) {
345 activeDS.twCC = TWCC_SEQERROR;
349 LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry ) {
353 TRACE("count = %d\n", count);
354 pPendingXfers->Count = count;
355 if (pPendingXfers->Count != 0) {
356 activeDS.currentState = 6;
358 activeDS.currentState = 5;
359 /* Notify the application that it can close the data source */
360 activeDS.pendingEvent.TWMessage = MSG_CLOSEDSREQ;
361 /* close any Transferring dialog */
362 TransferringDialogBox(activeDS.progressWnd,-1);
363 activeDS.progressWnd = 0;
365 activeDS.twCC = TWCC_SUCCESS;
369 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_GET */
370 static TW_UINT16 GPHOTO2_PendingXfersGet (pTW_IDENTITY pOrigin,
374 pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
375 struct gphoto2_file *file;
377 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_GET\n");
379 if (activeDS.currentState < 4 || activeDS.currentState > 7) {
380 activeDS.twCC = TWCC_SEQERROR;
385 LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry ) {
389 TRACE("count = %d\n", count);
390 pPendingXfers->Count = count;
391 activeDS.twCC = TWCC_SUCCESS;
395 /* DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET */
396 static TW_UINT16 GPHOTO2_PendingXfersReset (pTW_IDENTITY pOrigin,
399 pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
401 TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET\n");
403 if (activeDS.currentState != 6) {
404 activeDS.twCC = TWCC_SEQERROR;
407 pPendingXfers->Count = 0;
408 activeDS.currentState = 5;
409 activeDS.twCC = TWCC_SUCCESS;
413 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_GET */
414 static TW_UINT16 GPHOTO2_SetupFileXferGet (pTW_IDENTITY pOrigin,
422 /* DG_CONTROL/DAT_SETUPXFER/MSG_GETDEFAULT */
423 static TW_UINT16 GPHOTO2_SetupFileXferGetDefault (pTW_IDENTITY pOrigin,
432 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_RESET */
433 static TW_UINT16 GPHOTO2_SetupFileXferReset (pTW_IDENTITY pOrigin,
441 /* DG_CONTROL/DAT_SETUPFILEXFER/MSG_SET */
442 static TW_UINT16 GPHOTO2_SetupFileXferSet (pTW_IDENTITY pOrigin,
450 /* DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET */
451 static TW_UINT16 GPHOTO2_SetupMemXferGet (pTW_IDENTITY pOrigin,
454 pTW_SETUPMEMXFER pSetupMemXfer = (pTW_SETUPMEMXFER)pData;
456 TRACE("DG_CONTROL/DAT_SETUPMEMXFER/MSG_GET\n");
458 pSetupMemXfer->MinBufSize = 20000;
459 pSetupMemXfer->MaxBufSize = 80000;
460 pSetupMemXfer->Preferred = 40000;
464 /* DG_CONTROL/DAT_STATUS/MSG_GET */
465 static TW_UINT16 GPHOTO2_GetDSStatus (pTW_IDENTITY pOrigin,
468 pTW_STATUS pSourceStatus = (pTW_STATUS) pData;
470 TRACE ("DG_CONTROL/DAT_STATUS/MSG_GET\n");
471 pSourceStatus->ConditionCode = activeDS.twCC;
472 /* Reset the condition code */
473 activeDS.twCC = TWCC_SUCCESS;
477 /* DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS */
478 static TW_UINT16 GPHOTO2_DisableDSUserInterface (pTW_IDENTITY pOrigin,
481 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_DISABLEDS\n");
483 if (activeDS.currentState != 5) {
484 activeDS.twCC = TWCC_SEQERROR;
487 activeDS.currentState = 4;
488 activeDS.twCC = TWCC_SUCCESS;
492 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS */
493 static TW_UINT16 GPHOTO2_EnableDSUserInterface (pTW_IDENTITY pOrigin,
496 pTW_USERINTERFACE pUserInterface = (pTW_USERINTERFACE) pData;
498 load_filesystem("/");
500 TRACE ("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS\n");
501 if (activeDS.currentState != 4) {
502 FIXME("Sequence error %d\n", activeDS.currentState);
503 activeDS.twCC = TWCC_SEQERROR;
506 activeDS.hwndOwner = pUserInterface->hParent;
507 if (pUserInterface->ShowUI)
510 activeDS.currentState = 5; /* Transitions to state 5 */
513 activeDS.pendingEvent.TWMessage = MSG_CLOSEDSREQ;
515 /* FIXME: The GUI should have marked the files to download... */
516 activeDS.pendingEvent.TWMessage = MSG_XFERREADY;
517 activeDS.currentState = 6; /* Transitions to state 6 directly */
520 /* no UI will be displayed, so source is ready to transfer data */
521 activeDS.pendingEvent.TWMessage = MSG_XFERREADY;
522 activeDS.currentState = 6; /* Transitions to state 6 directly */
524 activeDS.hwndOwner = pUserInterface->hParent;
525 activeDS.twCC = TWCC_SUCCESS;
529 /* DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY */
530 static TW_UINT16 GPHOTO2_EnableDSUIOnly (pTW_IDENTITY pOrigin,
533 TRACE("DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDSUIONLY\n");
535 if (activeDS.currentState != 4) {
536 activeDS.twCC = TWCC_SEQERROR;
539 /* FIXME: we should replace xscanimage with our own UI */
540 FIXME ("not implemented!\n");
541 activeDS.currentState = 5;
542 activeDS.twCC = TWCC_SUCCESS;
546 /* DG_CONTROL/DAT_XFERGROUP/MSG_GET */
547 static TW_UINT16 GPHOTO2_XferGroupGet (pTW_IDENTITY pOrigin,
554 /* DG_CONTROL/DAT_XFERGROUP/MSG_SET */
555 static TW_UINT16 GPHOTO2_XferGroupSet (pTW_IDENTITY pOrigin,
562 HINSTANCE GPHOTO2_instance;
564 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
566 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
570 case DLL_PROCESS_ATTACH:
571 GPHOTO2_instance = hinstDLL;
572 DisableThreadLibraryCalls(hinstDLL);
574 activeDS.context = gp_context_new ();
578 case DLL_PROCESS_DETACH:
579 GPHOTO2_instance = NULL;
587 static TW_UINT16 GPHOTO2_GetIdentity( pTW_IDENTITY, pTW_IDENTITY);
588 static TW_UINT16 GPHOTO2_OpenDS( pTW_IDENTITY, pTW_IDENTITY);
591 static TW_UINT16 GPHOTO2_SourceControlHandler (
592 pTW_IDENTITY pOrigin,
597 TW_UINT16 twRC = TWRC_SUCCESS;
606 if (activeDS.camera) {
607 gp_camera_free (activeDS.camera);
608 activeDS.camera = NULL;
614 twRC = GPHOTO2_GetIdentity(pOrigin,(pTW_IDENTITY)pData);
621 twRC = GPHOTO2_OpenDS(pOrigin,(pTW_IDENTITY)pData);
632 twRC = GPHOTO2_CapabilityGet (pOrigin, pData);
635 twRC = GPHOTO2_CapabilityGetCurrent (pOrigin, pData);
638 twRC = GPHOTO2_CapabilityGetDefault (pOrigin, pData);
640 case MSG_QUERYSUPPORT:
641 twRC = GPHOTO2_CapabilityQuerySupport (pOrigin, pData);
644 twRC = GPHOTO2_CapabilityReset (pOrigin, pData);
647 twRC = GPHOTO2_CapabilitySet (pOrigin, pData);
651 FIXME("unrecognized opertion triplet\n");
655 case DAT_CUSTOMDSDATA:
659 twRC = GPHOTO2_CustomDSDataGet (pOrigin, pData);
662 twRC = GPHOTO2_CustomDSDataSet (pOrigin, pData);
672 /*case MSG_AUTOMATICCAPTUREDIRECTORY:
673 twRC = GPHOTO2_AutomaticCaptureDirectory
676 case MSG_CHANGEDIRECTORY:
677 twRC = GPHOTO2_ChangeDirectory (pOrigin, pData);
680 twRC = GPHOTO2_FileSystemCopy (pOrigin, pData);
682 case MSG_CREATEDIRECTORY:
683 twRC = GPHOTO2_CreateDirectory (pOrigin, pData);
686 twRC = GPHOTO2_FileSystemDelete (pOrigin, pData);
688 case MSG_FORMATMEDIA:
689 twRC = GPHOTO2_FormatMedia (pOrigin, pData);
692 twRC = GPHOTO2_FileSystemGetClose (pOrigin, pData);
694 case MSG_GETFIRSTFILE:
695 twRC = GPHOTO2_FileSystemGetFirstFile (pOrigin, pData);
698 twRC = GPHOTO2_FileSystemGetInfo (pOrigin, pData);
700 case MSG_GETNEXTFILE:
701 twRC = GPHOTO2_FileSystemGetNextFile (pOrigin, pData);
704 twRC = GPHOTO2_FileSystemRename (pOrigin, pData);
713 if (MSG == MSG_PROCESSEVENT)
714 twRC = GPHOTO2_ProcessEvent (pOrigin, pData);
720 if (MSG == MSG_PASSTHRU)
721 twRC = GPHOTO2_PassThrough (pOrigin, pData);
726 case DAT_PENDINGXFERS:
730 twRC = GPHOTO2_PendingXfersEndXfer (pOrigin, pData);
733 twRC = GPHOTO2_PendingXfersGet (pOrigin, pData);
736 twRC = GPHOTO2_PendingXfersReset (pOrigin, pData);
738 /*case MSG_STOPFEEDER:
739 twRC = GPHOTO2_PendingXfersStopFeeder (pOrigin, pData);
746 case DAT_SETUPFILEXFER:
750 twRC = GPHOTO2_SetupFileXferGet (pOrigin, pData);
753 twRC = GPHOTO2_SetupFileXferGetDefault (pOrigin, pData);
756 twRC = GPHOTO2_SetupFileXferReset (pOrigin, pData);
759 twRC = GPHOTO2_SetupFileXferSet (pOrigin, pData);
767 /*case DAT_SETUPFILEXFER2:
771 twRC = GPHOTO2_SetupFileXfer2Get (pOrigin, pData);
774 twRC = GPHOTO2_SetupFileXfer2GetDefault (pOrigin, pData);
777 twRC = GPHOTO2_SetupFileXfer2Reset (pOrigin, pData);
780 twRC = GPHOTO2_SetupFileXfer2Set (pOrigin, pData);
784 case DAT_SETUPMEMXFER:
786 twRC = GPHOTO2_SetupMemXferGet (pOrigin, pData);
793 twRC = GPHOTO2_GetDSStatus (pOrigin, pData);
798 case DAT_USERINTERFACE:
802 twRC = GPHOTO2_DisableDSUserInterface (pOrigin, pData);
805 twRC = GPHOTO2_EnableDSUserInterface (pOrigin, pData);
807 case MSG_ENABLEDSUIONLY:
808 twRC = GPHOTO2_EnableDSUIOnly (pOrigin, pData);
820 twRC = GPHOTO2_XferGroupGet (pOrigin, pData);
823 twRC = GPHOTO2_XferGroupSet (pOrigin, pData);
832 FIXME("code unknown: %d\n", DAT);
841 static TW_UINT16 GPHOTO2_ImageGroupHandler (
842 pTW_IDENTITY pOrigin,
847 TW_UINT16 twRC = TWRC_SUCCESS;
853 twRC = GPHOTO2_CIEColorGet (pOrigin, pData);
858 case DAT_EXTIMAGEINFO:
860 twRC = GPHOTO2_ExtImageInfoGet (pOrigin, pData);
865 case DAT_GRAYRESPONSE:
869 twRC = GPHOTO2_GrayResponseReset (pOrigin, pData);
872 twRC = GPHOTO2_GrayResponseSet (pOrigin, pData);
876 activeDS.twCC = TWCC_BADPROTOCOL;
877 FIXME("unrecognized operation triplet\n");
881 case DAT_IMAGEFILEXFER:
883 twRC = GPHOTO2_ImageFileXferGet (pOrigin, pData);
890 twRC = GPHOTO2_ImageInfoGet (pOrigin, pData);
895 case DAT_IMAGELAYOUT:
899 twRC = GPHOTO2_ImageLayoutGet (pOrigin, pData);
902 twRC = GPHOTO2_ImageLayoutGetDefault (pOrigin, pData);
905 twRC = GPHOTO2_ImageLayoutReset (pOrigin, pData);
908 twRC = GPHOTO2_ImageLayoutSet (pOrigin, pData);
912 activeDS.twCC = TWCC_BADPROTOCOL;
913 ERR("unrecognized operation triplet\n");
918 case DAT_IMAGEMEMXFER:
920 twRC = GPHOTO2_ImageMemXferGet (pOrigin, pData);
925 case DAT_IMAGENATIVEXFER:
927 twRC = GPHOTO2_ImageNativeXferGet (pOrigin, pData);
932 case DAT_JPEGCOMPRESSION:
936 twRC = GPHOTO2_JPEGCompressionGet (pOrigin, pData);
939 twRC = GPHOTO2_JPEGCompressionGetDefault (pOrigin, pData);
942 twRC = GPHOTO2_JPEGCompressionReset (pOrigin, pData);
945 twRC = GPHOTO2_JPEGCompressionSet (pOrigin, pData);
949 activeDS.twCC = TWCC_BADPROTOCOL;
950 WARN("unrecognized operation triplet\n");
959 twRC = GPHOTO2_Palette8Get (pOrigin, pData);
962 twRC = GPHOTO2_Palette8GetDefault (pOrigin, pData);
965 twRC = GPHOTO2_Palette8Reset (pOrigin, pData);
968 twRC = GPHOTO2_Palette8Set (pOrigin, pData);
972 activeDS.twCC = TWCC_BADPROTOCOL;
973 WARN("unrecognized operation triplet\n");
977 case DAT_RGBRESPONSE:
981 twRC = GPHOTO2_RGBResponseReset (pOrigin, pData);
984 twRC = GPHOTO2_RGBResponseSet (pOrigin, pData);
988 activeDS.twCC = TWCC_BADPROTOCOL;
989 WARN("unrecognized operation triplet\n");
996 activeDS.twCC = TWCC_BADPROTOCOL;
997 FIXME("unrecognized DG type %d\n", DAT);
1002 /* Main entry point for the TWAIN library */
1004 DS_Entry ( pTW_IDENTITY pOrigin,
1010 TW_UINT16 twRC = TWRC_SUCCESS; /* Return Code */
1012 TRACE("(DG=%d DAT=%d MSG=%d)\n", DG, DAT, MSG);
1017 twRC = GPHOTO2_SourceControlHandler (pOrigin,DAT,MSG,pData);
1020 twRC = GPHOTO2_ImageGroupHandler (pOrigin,DAT,MSG,pData);
1023 FIXME("The audio group of entry codes is not implemented.\n");
1025 activeDS.twCC = TWCC_BADPROTOCOL;
1026 twRC = TWRC_FAILURE;
1033 static GPPortInfoList *port_list;
1034 static int curcamera;
1035 static CameraList *detected_cameras;
1036 static CameraAbilitiesList *abilities_list;
1039 gphoto2_auto_detect(void) {
1042 if (detected_cameras && (gp_list_count (detected_cameras) == 0)) {
1043 /* Reload if previously no cameras, we might detect new ones. */
1044 TRACE("Reloading portlist trying to detect cameras.\n");
1046 gp_port_info_list_free (port_list);
1051 TRACE("Auto detecting gphoto cameras.\n");
1052 TRACE("Loading ports...\n");
1053 if (gp_port_info_list_new (&port_list) < GP_OK)
1054 return TWRC_FAILURE;
1055 result = gp_port_info_list_load (port_list);
1057 gp_port_info_list_free (port_list);
1058 return TWRC_FAILURE;
1060 count = gp_port_info_list_count (port_list);
1062 return TWRC_FAILURE;
1063 if (gp_list_new (&detected_cameras) < GP_OK)
1064 return TWRC_FAILURE;
1065 if (!abilities_list) { /* Load only once per program start */
1066 gp_abilities_list_new (&abilities_list);
1067 TRACE("Loading cameras...\n");
1068 gp_abilities_list_load (abilities_list, NULL);
1070 TRACE("Detecting cameras...\n");
1071 gp_abilities_list_detect (abilities_list, port_list, detected_cameras, NULL);
1073 TRACE("%d cameras detected\n", gp_list_count(detected_cameras));
1075 return TWRC_SUCCESS;
1079 GPHOTO2_GetIdentity( pTW_IDENTITY pOrigin, pTW_IDENTITY self) {
1081 const char *cname, *pname;
1083 if (TWRC_SUCCESS != gphoto2_auto_detect())
1084 return TWRC_FAILURE;
1086 count = gp_list_count (detected_cameras);
1087 if (count < GP_OK) {
1088 gp_list_free (detected_cameras);
1089 return TWRC_FAILURE;
1091 TRACE("%d cameras detected.\n", count);
1092 self->ProtocolMajor = TWON_PROTOCOLMAJOR;
1093 self->ProtocolMinor = TWON_PROTOCOLMINOR;
1094 lstrcpynA (self->Manufacturer, "The Wine Team", sizeof(self->Manufacturer) - 1);
1095 lstrcpynA (self->ProductFamily, "GPhoto2 Camera", sizeof(self->ProductFamily) - 1);
1097 if (!count) { /* No camera detected. But we need to return an IDENTITY anyway. */
1098 lstrcpynA (self->ProductName, "GPhoto2 Camera", sizeof(self->ProductName) - 1);
1099 return TWRC_SUCCESS;
1101 gp_list_get_name (detected_cameras, curcamera, &cname);
1102 gp_list_get_value (detected_cameras, curcamera, &pname);
1103 if (count == 1) /* Normal case, only one camera. */
1104 snprintf (self->ProductName, sizeof(self->ProductName), "%s", cname);
1106 snprintf (self->ProductName, sizeof(self->ProductName), "%s@%s", cname, pname);
1107 curcamera = (curcamera+1) % count;
1108 return TWRC_SUCCESS;
1112 GPHOTO2_OpenDS( pTW_IDENTITY pOrigin, pTW_IDENTITY self) {
1113 int ret, m, p, count, i;
1116 const char *model, *port;
1118 if (TWRC_SUCCESS != gphoto2_auto_detect())
1119 return TWRC_FAILURE;
1121 if (lstrcmpA(self->ProductFamily,"GPhoto2 Camera")) {
1122 FIXME("identity passed is not a gphoto camera, but %s!?!\n", self->ProductFamily);
1123 return TWRC_FAILURE;
1125 count = gp_list_count (detected_cameras);
1127 ERR("No camera found by autodetection. Returning failure.\n");
1128 return TWRC_FAILURE;
1131 if (!lstrcmpA (self->ProductName, "GPhoto2 Camera")) {
1132 TRACE("Potential undetected camera. Just using the first autodetected one.\n");
1135 for (i=0;i<count;i++) {
1136 const char *cname, *pname;
1139 gp_list_get_name (detected_cameras, i, &cname);
1140 gp_list_get_value (detected_cameras, i, &pname);
1141 if (!lstrcmpA(self->ProductName,cname))
1143 snprintf(name, sizeof(name), "%s", cname);
1144 if (!lstrcmpA(self->ProductName,name))
1146 snprintf(name, sizeof(name), "%s@%s", cname, pname);
1147 if (!lstrcmpA(self->ProductName,name))
1151 TRACE("Camera %s not found in autodetected list. Using first entry.\n", self->ProductName);
1155 gp_list_get_name (detected_cameras, i, &model);
1156 gp_list_get_value (detected_cameras, i, &port);
1157 TRACE("model %s, port %s\n", model, port);
1158 ret = gp_camera_new (&activeDS.camera);
1160 ERR("gp_camera_new: %d\n", ret);
1161 return TWRC_FAILURE;
1163 m = gp_abilities_list_lookup_model (abilities_list, model);
1165 FIXME("Model %s not found, %d!\n", model, m);
1166 return TWRC_FAILURE;
1168 ret = gp_abilities_list_get_abilities (abilities_list, m, &a);
1170 FIXME("gp_camera_list_get_abilities failed? %d\n", ret);
1171 return TWRC_FAILURE;
1173 ret = gp_camera_set_abilities (activeDS.camera, a);
1175 FIXME("gp_camera_set_abilities failed? %d\n", ret);
1176 return TWRC_FAILURE;
1179 p = gp_port_info_list_lookup_path (port_list, port);
1181 FIXME("port %s not in portlist?\n", port);
1182 return TWRC_FAILURE;
1184 ret = gp_port_info_list_get_info (port_list, p, &info);
1186 FIXME("could not get portinfo for port %s?\n", port);
1187 return TWRC_FAILURE;
1189 ret = gp_camera_set_port_info (activeDS.camera, info);
1191 FIXME("could not set portinfo for port %s to camera?\n", port);
1192 return TWRC_FAILURE;
1194 list_init( &(activeDS.files) );
1195 activeDS.currentState = 4;
1196 activeDS.twCC = TWRC_SUCCESS;
1197 activeDS.pixelflavor = TWPF_CHOCOLATE;
1198 activeDS.pixeltype = TWPT_RGB;
1199 activeDS.capXferMech = TWSX_MEMORY;
1201 return TWRC_SUCCESS;