@@ -133,8 +133,21 @@ void GPhotoCameraWorker::startCamera(const QString &cameraName) {
133133
134134 // Initialize camera connection
135135 int ret = gp_camera_init (mCamera .get (), mContext .get ());
136+
136137 if (ret < GP_OK) {
137- emit errorOccurred (tr (" Failed to initialize camera: %1" ).arg (ret));
138+ // Translate gPhoto2 result code to a human-readable string and report it
139+ const char *gphotoErrStr = nullptr ;
140+
141+ // gp_result_as_string is available in libgphoto2 and translates result
142+ // codes
143+ gphotoErrStr = gp_result_as_string (ret);
144+
145+ QString initErrorString = QString::fromLocal8Bit (
146+ gphotoErrStr ? gphotoErrStr : " Unknown gPhoto2 error" );
147+
148+ emit errorOccurred (tr (" Failed to initialize camera: (Code %1) - %2" )
149+ .arg (ret)
150+ .arg (initErrorString));
138151 mCamera .reset ();
139152 return ;
140153 }
@@ -190,7 +203,17 @@ void GPhotoCameraWorker::captureImage() {
190203 int ret = gp_camera_capture (mCamera .get (), GP_CAPTURE_IMAGE,
191204 &camera_file_path, mContext .get ());
192205 if (ret < GP_OK) {
193- emit captureError (tr (" Failed to capture image: %1" ).arg (ret));
206+ // Translate gPhoto2 result code to a human-readable string and report it
207+ const char *gphotoErrStr = nullptr ;
208+
209+ // gp_result_as_string is available in libgphoto2 and translates result
210+ // codes
211+ gphotoErrStr = gp_result_as_string (ret);
212+
213+ QString captureErrorString = QString::fromLocal8Bit (
214+ gphotoErrStr ? gphotoErrStr : " Unknown gPhoto2 error" );
215+
216+ emit captureError (tr (" Failed to capture image: (Code %1) - $2" ).arg (ret).arg (captureErrorString));
194217 return ;
195218 }
196219
@@ -199,7 +222,17 @@ void GPhotoCameraWorker::captureImage() {
199222 camera_file_path.name , GP_FILE_TYPE_NORMAL,
200223 captureFile.get (), mContext .get ());
201224 if (ret < GP_OK) {
202- emit captureError (tr (" Failed to download image: %1" ).arg (ret));
225+ // Translate gPhoto2 result code to a human-readable string and report it
226+ const char *gphotoErrStr = nullptr ;
227+
228+ // gp_result_as_string is available in libgphoto2 and translates result
229+ // codes
230+ gphotoErrStr = gp_result_as_string (ret);
231+
232+ QString captureErrorString = QString::fromLocal8Bit (
233+ gphotoErrStr ? gphotoErrStr : " Unknown gPhoto2 error" );
234+
235+ emit captureError (tr (" Failed to download image: (Code %1) - %2" ).arg (ret).arg (captureErrorString));
203236 return ;
204237 }
205238
@@ -208,7 +241,17 @@ void GPhotoCameraWorker::captureImage() {
208241 unsigned long int size = 0 ;
209242 ret = gp_file_get_data_and_size (captureFile.get (), &data, &size);
210243 if (ret < GP_OK) {
211- emit captureError (tr (" Failed to get image data: %1" ).arg (ret));
244+ // Translate gPhoto2 result code to a human-readable string and report it
245+ const char *gphotoErrStr = nullptr ;
246+
247+ // gp_result_as_string is available in libgphoto2 and translates result
248+ // codes
249+ gphotoErrStr = gp_result_as_string (ret);
250+
251+ QString captureErrorString = QString::fromLocal8Bit (
252+ gphotoErrStr ? gphotoErrStr : " Unknown gPhoto2 error" );
253+
254+ emit captureError (tr (" Failed to get image data: (Code %1) - %2" ).arg (ret).arg (captureErrorString));
212255 return ;
213256 }
214257
0 commit comments