Browse Source

Add support for gphoto 2.5

Based on KDE GIT commit cdcf4205
tags/r14.0.0
Slávek Banko 6 years ago
parent
commit
d4d1a5808b
4 changed files with 57 additions and 9 deletions
  1. 3
    0
      config.h.cmake
  2. 8
    0
      kamera/ConfigureChecks.cmake
  3. 10
    1
      kamera/kcontrol/kameradevice.cpp
  4. 36
    8
      kamera/tdeioslave/kamera.cpp

+ 3
- 0
config.h.cmake View File

@@ -45,3 +45,6 @@
45 45
 
46 46
 // ksnapshop
47 47
 #cmakedefine HAVE_X11_EXTENSIONS_SHAPE_H 1
48
+
49
+// kamera
50
+#cmakedefine HAVE_GPHOTO2_5 1

+ 8
- 0
kamera/ConfigureChecks.cmake View File

@@ -13,3 +13,11 @@ pkg_search_module( GPHOTO2 libgphoto2 )
13 13
 if( NOT GPHOTO2_FOUND )
14 14
   tde_message_fatal( "libgphoto2 is required, but was not found on your system" )
15 15
 endif( )
16
+
17
+check_library_exists(gphoto2_port gp_port_info_get_name "" GPHOTO2_5)
18
+if(GPHOTO2_5)
19
+  message(STATUS "  found libgphoto2 2.5")
20
+else(GPHOTO2_5)
21
+  message(STATUS "  assuming libgphoto2 2.4")
22
+endif(GPHOTO2_5)
23
+set(HAVE_GPHOTO2_5 ${GPHOTO2_5} CACHE FILEPATH "")

+ 10
- 1
kamera/kcontrol/kameradevice.cpp View File

@@ -37,6 +37,8 @@
37 37
 #include <kmessagebox.h>
38 38
 #include <kdebug.h>
39 39
 
40
+#include "config.h"
41
+
40 42
 extern "C" {
41 43
 	#include <gphoto2.h>
42 44
 }
@@ -118,9 +120,9 @@ bool KCamera::initCamera()
118 120
 		gp_port_info_list_new(&il);
119 121
 		gp_port_info_list_load(il);
120 122
 		gp_port_info_list_get_info(il, gp_port_info_list_lookup_path(il, m_path.local8Bit().data()), &info);
121
-		gp_port_info_list_free(il);
122 123
 		gp_camera_set_abilities(m_camera, m_abilities);
123 124
 		gp_camera_set_port_info(m_camera, info);
125
+		gp_port_info_list_free(il);
124 126
 
125 127
 		// this might take some time (esp. for non-existant camera) - better be done asynchronously
126 128
 		result = gp_camera_init(m_camera, glob_context);
@@ -346,8 +348,15 @@ KameraDeviceSelectDialog::KameraDeviceSelectDialog(TQWidget *parent, KCamera *de
346 348
 	}
347 349
 	for (int i = 0; i < gphoto_ports; i++) {
348 350
 		if (gp_port_info_list_get_info(list, i, &info) >= 0) {
351
+#ifdef HAVE_GPHOTO2_5
352
+			char *xpath;
353
+			gp_port_info_get_path (info, &xpath);
354
+			if (strncmp(xpath, "serial:", 7) == 0)
355
+				m_serialPortCombo->insertItem(TQString::fromLatin1(xpath).mid(7));
356
+#else
349 357
 			if (strncmp(info.path, "serial:", 7) == 0)
350 358
 				m_serialPortCombo->insertItem(TQString::fromLatin1(info.path).mid(7));
359
+#endif
351 360
 		}
352 361
 	}
353 362
 	gp_port_info_list_free(list);

+ 36
- 8
kamera/tdeioslave/kamera.cpp View File

@@ -55,11 +55,19 @@ extern "C"
55 55
 {
56 56
 	KDE_EXPORT int kdemain(int argc, char **argv);
57 57
 
58
+#ifdef HAVE_GPHOTO2_5
59
+	static void frontendCameraStatus(GPContext *context, const char *status, void *data);
60
+	static unsigned int frontendProgressStart(
61
+		GPContext *context, float totalsize, const char *status,
62
+		void *data
63
+	);
64
+#else
58 65
 	static void frontendCameraStatus(GPContext *context, const char *format, va_list args, void *data);
59 66
 	static unsigned int frontendProgressStart(
60 67
 		GPContext *context, float totalsize, const char *format,
61 68
 		va_list args, void *data
62 69
 	);
70
+#endif
63 71
 	static void frontendProgressUpdate(
64 72
 		GPContext *context, unsigned int id, float current, void *data
65 73
 	);
@@ -791,11 +799,11 @@ void KameraProtocol::setHost(const TQString& host, int port, const TQString& use
791 799
 			return;
792 800
 		}
793 801
 		gp_port_info_list_get_info(port_info_list, idx, &port_info);
794
-		gp_port_info_list_free(port_info_list);
795 802
 
796 803
 		// create a new camera object
797 804
 		gpr = gp_camera_new(&m_camera);
798 805
 		if(gpr != GP_OK) {
806
+			gp_port_info_list_free(port_info_list);
799 807
 			error(TDEIO::ERR_UNKNOWN, gp_result_as_string(gpr));
800 808
 			return;
801 809
 		}
@@ -813,6 +821,8 @@ void KameraProtocol::setHost(const TQString& host, int port, const TQString& use
813 821
 		gp_camera_set_port_speed(m_camera, 0); // TODO: the value needs to be configurable
814 822
 		kdDebug(7123) << "Opening camera model " << user << " at " << host << endl;
815 823
 
824
+		gp_port_info_list_free(port_info_list);
825
+
816 826
 		TQString errstr;
817 827
 		if (!openCamera(errstr)) {
818 828
 			kdDebug(7123) << "Unable to init camera: " << gp_result_as_string(gpr) << endl;
@@ -865,10 +875,7 @@ void KameraProtocol::translateFileToUDS(UDSEntry &udsEntry, const CameraFileInfo
865 875
 	udsEntry.append(atom);
866 876
 
867 877
 	atom.m_uds = UDS_NAME;
868
-	if (info.file.fields & GP_FILE_INFO_NAME)
869
-		atom.m_str = TQString::fromLocal8Bit(info.file.name);
870
-	else
871
-		atom.m_str = name;
878
+	atom.m_str = name;
872 879
 	udsEntry.append(atom);
873 880
 
874 881
 	if (info.file.fields & GP_FILE_INFO_SIZE) {
@@ -994,10 +1001,16 @@ void frontendProgressUpdate(
994 1001
 }
995 1002
 
996 1003
 unsigned int frontendProgressStart(
997
-	GPContext * /*context*/, float totalsize, const char *format, va_list args,
1004
+	GPContext * /*context*/, float totalsize,
1005
+#ifdef HAVE_GPHOTO2_5
1006
+	const char *status,
1007
+#else
1008
+	const char *format, va_list args,
1009
+#endif
998 1010
 	void *data
999 1011
 ) {
1000 1012
 	KameraProtocol *object = (KameraProtocol*)data;
1013
+#ifndef HAVE_GPHOTO2_5
1001 1014
 	char *status;
1002 1015
 
1003 1016
 	/* We must copy the va_list to walk it twice, or all hell 
@@ -1031,14 +1044,26 @@ unsigned int frontendProgressStart(
1031 1044
 
1032 1045
 	object->infoMessage(TQString::fromLocal8Bit(status));
1033 1046
 	delete [] status;
1047
+#else
1048
+	/* libgphoto2 2.5 has resolved this already, no need for print */
1049
+	object->infoMessage(TQString::fromLocal8Bit(status));
1050
+#endif
1034 1051
 	object->totalSize((int)totalsize); // hack: call slot directly
1035 1052
 	return GP_OK;
1036 1053
 }
1037 1054
 
1038 1055
 // this callback function is activated on every status message from gphoto2
1039
-static void frontendCameraStatus(GPContext * /*context*/, const char *format, va_list args, void *data)
1040
-{
1056
+static void frontendCameraStatus(
1057
+	GPContext * /*context*/,
1058
+#ifdef HAVE_GPHOTO2_5
1059
+	const char *status,
1060
+#else
1061
+	const char *format, va_list args,
1062
+#endif
1063
+	void *data
1064
+) {
1041 1065
 	KameraProtocol *object = (KameraProtocol*)data;
1066
+#ifndef HAVE_GPHOTO2_5
1042 1067
 	char *status;
1043 1068
 
1044 1069
 	/* We must copy the va_list to walk it twice, or all hell 
@@ -1071,4 +1096,7 @@ static void frontendCameraStatus(GPContext * /*context*/, const char *format, va
1071 1096
 #endif
1072 1097
 	object->infoMessage(TQString::fromLocal8Bit(status));
1073 1098
 	delete [] status;
1099
+#else
1100
+	object->infoMessage(TQString::fromLocal8Bit(status));
1101
+#endif
1074 1102
 }

Loading…
Cancel
Save