summaryrefslogtreecommitdiff
path: root/graphics/shotwell/patches/patch-ab
blob: 665f09890d791d546271fa3efa279a055f725cb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
$NetBSD: patch-ab,v 1.2 2011/01/11 20:46:16 gls Exp $

--- src/CameraTable.vala.orig	2010-12-23 23:01:46.000000000 +0000
+++ src/CameraTable.vala
@@ -24,7 +24,6 @@ public class CameraTable {
     
     private static CameraTable instance = null;
     
-    private GUdev.Client client = new GUdev.Client(SUBSYSTEMS);
     private OneShotScheduler camera_update_scheduler = null;
     private GPhoto.Context null_context = new GPhoto.Context();
     private GPhoto.CameraAbilitiesList abilities_list;
@@ -42,7 +41,6 @@ public class CameraTable {
             on_update_cameras);
         
         // listen for interesting events on the specified subsystems
-        client.uevent.connect(on_udev_event);
         volume_monitor = VolumeMonitor.get();
         volume_monitor.volume_changed.connect(on_volume_changed);
         volume_monitor.volume_added.connect(on_volume_changed);
@@ -94,43 +92,18 @@ public class CameraTable {
         if (res != GPhoto.Result.OK)
             throw new GPhotoError.LIBRARY("[%d] Unable to %s: %s", (int) res, op, res.as_string());
     }
-    
+
     private void init_camera_table() throws GPhotoError {
         do_op(GPhoto.CameraAbilitiesList.create(out abilities_list), "create camera abilities list");
         do_op(abilities_list.load(null_context), "load camera abilities list");
     }
-    
+
     private string[] get_all_usb_cameras() {
         string[] cameras = new string[0];
-        
-        GLib.List<GUdev.Device> device_list = client.query_by_subsystem(null);
-        foreach (GUdev.Device device in device_list) {
-            string device_file = device.get_device_file();
-            if(
-                // only keep devices that have a non-null device file and that
-                // have both the ID_GPHOTO2 and GPHOTO2_DRIVER properties set
-                (device_file != null) &&
-                (device.has_property("ID_GPHOTO2")) &&
-                (device.has_property("GPHOTO2_DRIVER"))
-            ) {
-                int camera_bus, camera_device;
-                // extract the bus and device IDs from the device file string
-                // TODO: is it safe to parse the absolute path or should we be
-                // smarter and use a regex to only pick up the end of the path?
-                if (device_file.scanf("/dev/bus/usb/%d/%d", out camera_bus, out camera_device) < 2) {
-                    critical("get_all_usb_cameras: Failed to scanf device file %s", device_file);
-                    
-                    continue;
-                }
-                string camera = "usb:%.3d,%.3d".printf(camera_bus, camera_device);
-                debug("USB camera detected at %s", camera);
-                cameras += camera;
-            }
-        }
-        
+
         return cameras;
     }
-    
+
     // USB (or libusb) is a funny beast; if only one USB device is present (i.e. the camera),
     // then a single camera is detected at port usb:.  However, if multiple USB devices are
     // present (including non-cameras), then the first attached camera will be listed twice,
@@ -139,59 +112,59 @@ public class CameraTable {
     //
     // This function gleans the full port name of a particular port, even if it's the unadorned
     // "usb:", by using GUdev.
-    private bool usb_esp(int current_camera_count, string[] usb_cameras, string port, 
+    private bool usb_esp(int current_camera_count, string[] usb_cameras, string port,
         out string full_port) {
         // sanity
         assert(current_camera_count > 0);
-        
+
         debug("USB ESP: current_camera_count=%d port=%s", current_camera_count, port);
-        
+
         // if GPhoto detects one camera, and USB reports one camera, all is swell
         if (current_camera_count == 1 && usb_cameras.length == 1) {
             full_port = usb_cameras[0];
-            
+
             debug("USB ESP: port=%s full_port=%s", port, full_port);
-            
+
             return true;
         }
 
         // with more than one camera, skip the mirrored "usb:" port
         if (port == "usb:") {
             debug("USB ESP: Skipping %s", port);
-            
+
             return false;
         }
-        
+
         // parse out the bus and device ID
         int bus, device;
         if (port.scanf("usb:%d,%d", out bus, out device) < 2) {
             critical("USB ESP: Failed to scanf %s", port);
-            
+
             return false;
         }
-        
+
         foreach (string usb_camera in usb_cameras) {
             int camera_bus, camera_device;
             if (usb_camera.scanf("usb:%d,%d", out camera_bus, out camera_device) < 2) {
                 critical("USB ESP: Failed to scanf %s", usb_camera);
-                
+
                 continue;
             }
-            
+
             if ((bus == camera_bus) && (device == camera_device)) {
                 full_port = port;
-                
+
                 debug("USB ESP: port=%s full_port=%s", port, full_port);
 
                 return true;
             }
         }
-        
+
         debug("USB ESP: No matching bus/device found for port=%s", port);
-        
+
         return false;
     }
-    
+
     public static string get_port_uri(string port) {
         return "gphoto2://[%s]/".printf(port);
     }
@@ -220,13 +193,13 @@ public class CameraTable {
         GPhoto.CameraList camera_list;
         do_op(GPhoto.CameraList.create(out camera_list), "create camera list");
         do_op(abilities_list.detect(port_info_list, camera_list, null_context), "detect cameras");
-        
+
         Gee.HashMap<string, string> detected_map = new Gee.HashMap<string, string>(str_hash, str_equal,
             str_equal);
-        
+
         // walk the USB chain and find all PTP cameras; this is necessary for usb_esp
         string[] usb_cameras = get_all_usb_cameras();
-        
+
         // go through the detected camera list and glean their ports
         for (int ctr = 0; ctr < camera_list.count(); ctr++) {
             string name;
@@ -234,55 +207,55 @@ public class CameraTable {
 
             string port;
             do_op(camera_list.get_value(ctr, out port), "get detected camera port");
-            
+
             debug("Detected %d/%d %s @ %s", ctr + 1, camera_list.count(), name, port);
-            
+
             // do some USB ESP, skipping ports that cannot be deduced
             if (port.has_prefix("usb:")) {
                 string full_port;
                 if (!usb_esp(camera_list.count(), usb_cameras, port, out full_port))
                     continue;
-                
+
                 port = full_port;
             }
 
             detected_map.set(port, name);
         }
-        
+
         // find cameras that have disappeared
         DiscoveredCamera[] missing = new DiscoveredCamera[0];
         foreach (DiscoveredCamera camera in camera_map.values) {
             GPhoto.PortInfo port_info;
-            do_op(camera.gcamera.get_port_info(out port_info), 
+            do_op(camera.gcamera.get_port_info(out port_info),
                 "retrieve missing camera port information");
-            
+
             GPhoto.CameraAbilities abilities;
             do_op(camera.gcamera.get_abilities(out abilities), "retrieve camera abilities");
-            
+
             if (detected_map.has_key(port_info.path)) {
                 debug("Found camera for %s @ %s in detected map", abilities.model, port_info.path);
-                
+
                 continue;
             }
-            
+
             debug("%s @ %s missing", abilities.model, port_info.path);
-            
+
             missing += camera;
         }
-        
+
         // have to remove from hash map outside of iterator
         foreach (DiscoveredCamera camera in missing) {
             GPhoto.PortInfo port_info;
             do_op(camera.gcamera.get_port_info(out port_info),
                 "retrieve missing camera port information");
-            
+
             GPhoto.CameraAbilities abilities;
             do_op(camera.gcamera.get_abilities(out abilities), "retrieve missing camera abilities");
 
             debug("Removing from camera table: %s @ %s", abilities.model, port_info.path);
 
             camera_map.unset(get_port_uri(port_info.path));
-            
+
             camera_removed(camera);
         }
 
@@ -299,21 +272,6 @@ public class CameraTable {
                 continue;
             }
             
-            // Get display name for camera.
-            string path = get_port_path(port);
-            if (null != path) {
-                GUdev.Device device = client.query_by_device_file(path);
-                string serial = device.get_property("ID_SERIAL_SHORT");
-                if (null != serial) {
-                    display_name = get_name_for_uuid(serial);
-                }
-                if (null == display_name) {
-                    display_name = device.get_sysfs_attr("product");
-                } 
-                if (null == display_name) {
-                    display_name = device.get_property("ID_MODEL");
-                }
-            }
             if (null == display_name) {
                 // Default to GPhoto detected name.
                 display_name = name;
@@ -351,13 +309,6 @@ public class CameraTable {
         }
     }
     
-    private void on_udev_event(string action, GUdev.Device device) {
-        debug("udev event: %s on %s", action, device.get_name());
-        
-        // Device add/removes often arrive in pairs; this allows for a single
-        // update to occur when they come in all at once
-        camera_update_scheduler.after_timeout(UPDATE_DELAY_MSEC, true);
-    }
     
     public void on_volume_changed(Volume volume) {
         camera_update_scheduler.after_timeout(UPDATE_DELAY_MSEC, true);