kamera: require Gphoto2 v2.5+

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-07-14 21:33:42 +03:00
parent 2c056213e8
commit c6324fa767
5 changed files with 4 additions and 181 deletions

View file

@ -9,32 +9,13 @@ include(KDE4Defaults)
include(MacroLibrary) include(MacroLibrary)
include(MacroOptionalAddSubdirectory) include(MacroOptionalAddSubdirectory)
find_package(Gphoto2) find_package(Gphoto2 2.5)
set_package_properties(Gphoto2 PROPERTIES set_package_properties(Gphoto2 PROPERTIES
URL "http://heanet.dl.sourceforge.net/sourceforge/gphoto" URL "http://heanet.dl.sourceforge.net/sourceforge/gphoto"
PURPOSE "Required to build kamera" PURPOSE "Required to build kamera"
TYPE REQUIRED TYPE REQUIRED
) )
cmake_reset_check_state()
set(CMAKE_REQUIRED_INCLUDES "${GPHOTO2_INCLUDE_DIR}")
set(CMAKE_REQUIRED_LIBRARIES "${GPHOTO2_LIBRARIES}")
check_symbol_exists(gp_port_info_get_name "gphoto2/gphoto2.h" HAVE_GPHOTO2_5)
cmake_reset_check_state()
if(HAVE_GPHOTO2_5)
message(STATUS "Detected libgphoto2 2.5.0 or newer")
else()
message(STATUS "Detected libgphoto2 2.4 or older")
endif()
include(ConfigureChecks.cmake)
configure_file(
config-kamera.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/config-kamera.h
)
add_definitions( add_definitions(
${QT_DEFINITIONS} ${QT_DEFINITIONS}
${KDE4_DEFINITIONS} ${KDE4_DEFINITIONS}

View file

@ -1,49 +0,0 @@
include(CheckCXXSourceCompiles)
set(VA_COPY_TEST_SOURCE
"
#include <stdarg.h>
#include <stdlib.h>
void f (int i, ...) {
va_list args1, args2;
va_start (args1, i);
va_copy (args2, args1);
if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
exit (1);
va_end (args1); va_end (args2);
}
int main() {
f (0, 42);
return 0;
}
")
set(__VA_COPY_TEST_SOURCE
"
#include <stdarg.h>
#include <stdlib.h>
void f (int i, ...) {
va_list args1, args2;
va_start (args1, i);
__va_copy (args2, args1);
if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
exit (1);
va_end (args1); va_end (args2);
}
int main() {
f (0, 42);
return 0;
}
")
check_cxx_source_compiles("${VA_COPY_TEST_SOURCE}" HAVE_VA_COPY)
if(HAVE_VA_COPY)
set(VA_COPY va_copy CACHE STRING "va_copy function")
else(HAVE_VA_COPY)
check_cxx_source_compiles("${__VA_COPY_TEST_SOURCE}" HAVE___VA_COPY)
if(HAVE___VA_COPY)
set(VA_COPY __va_copy CACHE STRING "__va_copy function")
else(HAVE___VA_COPY)
message(FATAL_ERROR "Either va_copy or __va_copy must be present. Please check your libc.")
endif(HAVE___VA_COPY)
endif(HAVE_VA_COPY)

View file

@ -1,8 +0,0 @@
/* Define if we have va_copy */
#cmakedefine HAVE_VA_COPY 1
/* Define if we have __va_copy */
#cmakedefine HAVE___VA_COPY 1
/* Define if we have gp_port_info_get_name (trigger for 2.5) */
#cmakedefine HAVE_GPHOTO2_5 1

View file

@ -35,8 +35,6 @@
#include <KConfig> #include <KConfig>
#include <KMessageBox> #include <KMessageBox>
#include "config-kamera.h"
extern "C" { extern "C" {
#include <gphoto2.h> #include <gphoto2.h>
} }
@ -386,17 +384,11 @@ KameraDeviceSelectDialog::KameraDeviceSelectDialog(QWidget *parent, KCamera *dev
} }
for (int i = 0; i < gphoto_ports; i++) { for (int i = 0; i < gphoto_ports; i++) {
if (gp_port_info_list_get_info(list, i, &info) >= 0) { if (gp_port_info_list_get_info(list, i, &info) >= 0) {
#ifdef HAVE_GPHOTO2_5
char *xpath; char *xpath;
gp_port_info_get_path (info, &xpath); gp_port_info_get_path(info, &xpath);
if (strncmp(xpath, "serial:", 7) == 0) { if (strncmp(xpath, "serial:", 7) == 0) {
m_serialPortCombo->addItem(QString::fromLocal8Bit(xpath).mid(7)); m_serialPortCombo->addItem(QString::fromLocal8Bit(xpath).mid(7));
} }
#else
if (strncmp(info.path, "serial:", 7) == 0) {
m_serialPortCombo->addItem(QString::fromLocal8Bit(info.path).mid(7));
}
#endif
} }
} }
gp_port_info_list_free(list); gp_port_info_list_free(list);

View file

@ -46,8 +46,6 @@
#include <kio/slaveconfig.h> #include <kio/slaveconfig.h>
#include <kconfiggroup.h> #include <kconfiggroup.h>
#include "config-kamera.h"
#include "kamera.h" #include "kamera.h"
#define tocstr(x) ((x).toLocal8Bit()) #define tocstr(x) ((x).toLocal8Bit())
@ -60,13 +58,8 @@ extern "C"
{ {
Q_DECL_EXPORT int kdemain(int argc, char **argv); Q_DECL_EXPORT int kdemain(int argc, char **argv);
#ifdef HAVE_GPHOTO2_5
static void frontendCameraStatus(GPContext *context, const char *status, void *data); static void frontendCameraStatus(GPContext *context, const char *status, void *data);
static unsigned int frontendProgressStart(GPContext *context, float totalsize, const char *status, void *data); static unsigned int frontendProgressStart(GPContext *context, float totalsize, const char *status, void *data);
#else
static void frontendCameraStatus(GPContext *context, const char *format, va_list args, void *data);
static unsigned int frontendProgressStart(GPContext *context, float totalsize, const char *format, va_list args, void *data);
#endif
static void frontendProgressUpdate(GPContext *context, unsigned int id, float current, void *data); static void frontendProgressUpdate(GPContext *context, unsigned int id, float current, void *data);
} }
@ -993,103 +986,17 @@ void frontendProgressUpdate(GPContext * /*context*/, unsigned int /*id*/, float
} }
} }
unsigned int frontendProgressStart(GPContext * /*context*/, float totalsize, unsigned int frontendProgressStart(GPContext * /*context*/, float totalsize, const char *status, void *data)
#ifdef HAVE_GPHOTO2_5
const char *status,
#else
const char *format, va_list args,
#endif
void *data)
{ {
KameraProtocol *object = (KameraProtocol*)data; KameraProtocol *object = (KameraProtocol*)data;
#ifndef HAVE_GPHOTO2_5
char *status;
/* We must copy the va_list to walk it twice, or all hell
* breaks loose on non-i386 platforms.
*/
#if defined(HAVE_VA_COPY) || defined(HAVE___VA_COPY)
va_list xvalist;
# ifdef HAVE_VA_COPY
va_copy(xvalist, args);
# elif HAVE___VA_COPY
__va_copy(xvalist, args);
# endif
int size=vsnprintf(NULL, 0, format, xvalist);
if (size<=0) {
return GP_OK; // vsnprintf is broken, better don't do anything.
}
status=new char[size+1];
# ifdef HAVE_VA_COPY
va_copy(xvalist, args);
# elif HAVE___VA_COPY
__va_copy(xvalist, args);
# endif
vsnprintf(status, size+1, format, xvalist);
#else
/* We cannot copy the va_list, so make sure we
* walk it just _once_.
*/
status=new char[300];
vsnprintf(status, 300, format, args);
#endif
object->infoMessage(QString::fromLocal8Bit(status)); object->infoMessage(QString::fromLocal8Bit(status));
delete [] status;
#else
/* libgphoto2 2.5 has resolved this already, no need for print */
object->infoMessage(QString::fromLocal8Bit(status));
#endif
object->totalSize((KIO::filesize_t)totalsize); // hack: call slot directly object->totalSize((KIO::filesize_t)totalsize); // hack: call slot directly
return GP_OK; return GP_OK;
} }
// this callback function is activated on every status message from gphoto2 // this callback function is activated on every status message from gphoto2
static void frontendCameraStatus(GPContext * /*context*/, static void frontendCameraStatus(GPContext * /*context*/, const char *status, void *data)
#ifdef HAVE_GPHOTO2_5
const char *status,
#else
const char *format, va_list args,
#endif
void *data)
{ {
KameraProtocol *object = (KameraProtocol*)data; KameraProtocol *object = (KameraProtocol*)data;
#ifndef HAVE_GPHOTO2_5
char *status;
/* We must copy the va_list to walk it twice, or all hell
* breaks loose on non-i386 platforms.
*/
#if defined(HAVE_VA_COPY) || defined(HAVE___VA_COPY)
va_list xvalist;
# ifdef HAVE_VA_COPY
va_copy(xvalist, args);
# elif HAVE___VA_COPY
__va_copy(xvalist, args);
# endif
int size=vsnprintf(NULL, 0, format, xvalist);
if (size<=0) {
return; // vsnprintf is broken, better don't do anything.
}
status=new char[size+1];
# ifdef HAVE_VA_COPY
va_copy(xvalist, args);
# elif HAVE___VA_COPY
__va_copy(xvalist, args);
# endif
vsnprintf(status, size+1, format, xvalist);
#else
/* We cannot copy the va_list, so make sure we
* walk it just _once_.
*/
status=new char[300];
vsnprintf(status, 300, format, args);
#endif
object->infoMessage(QString::fromLocal8Bit(status)); object->infoMessage(QString::fromLocal8Bit(status));
delete [] status;
#else
object->infoMessage(QString::fromLocal8Bit(status));
#endif
} }