~elementary-apps/pantheon-files/trunk

« back to all changes in this revision

Viewing changes to libcore/gof-directory-async.vala

Merge trunk to r2319

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    private uint mount_timeout_id = 0;
30
30
    private const int ENUMERATE_TIMEOUT_SEC = 15;
31
31
    private const int QUERY_INFO_TIMEOUT_SEC = 5;
32
 
    private const int MOUNT_TIMEOUT_SEC = 5;
 
32
    private const int MOUNT_TIMEOUT_SEC = 10;
33
33
 
34
34
    public GLib.File location;
35
35
    public GLib.File? selected_file = null;
89
89
    public bool is_trash {get; private set;}
90
90
    public bool is_network {get; private set;}
91
91
    public bool is_recent {get; private set;}
 
92
    public bool is_no_info {get; private set;}
92
93
    public bool has_mounts {get; private set;}
93
94
    public bool has_trash_dirs {get; private set;}
94
95
    public bool can_load {get; private set;}
113
114
        scheme = location.get_uri_scheme ();
114
115
        is_trash = (scheme == "trash");
115
116
        is_recent = (scheme == "recent");
 
117
        is_no_info = ("cdda mtp".contains (scheme));
116
118
        is_local = is_trash || is_recent || (scheme == "file");
117
119
        is_network = !is_local && ("ftp sftp afp dav davs".contains (scheme));
118
120
        can_open_files = !("mtp".contains (scheme));
167
169
    private async void prepare_directory (GOFFileLoadedFunc? file_loaded_func) {
168
170
        bool success = yield get_file_info ();
169
171
        if (success) {
170
 
            if (!file.is_folder () && !file.is_root_network_folder ()) {
 
172
            if (!is_no_info && !file.is_folder () && !file.is_root_network_folder ()) {
171
173
                warning ("Trying to load a non-folder - finding parent");
172
174
                var parent = file.is_connected ? location.get_parent () : null;
173
175
                if (parent != null) {
179
181
                    warning ("Parent is null for file %s", file.uri);
180
182
                    success = false;
181
183
                }
182
 
            } else {
183
 
 
184
184
            }
185
185
        } else {
186
186
            warning ("Failed to get file info for file %s", file.uri);
187
187
        }
188
 
        yield make_ready (success, file_loaded_func); /* Only place that should call this function */
 
188
 
 
189
        yield make_ready (is_no_info || success, file_loaded_func); /* Only place that should call this function */
189
190
    }
190
191
 
 
192
    /*** Returns false if should be able to get info but were unable to ***/
191
193
    private async bool get_file_info () {
192
194
        /* Force info to be refreshed - the GOF.File may have been created already by another part of the program
193
195
         * that did not ensure the correct info Aync purposes, and retrieved from cache (bug 1511307).
194
196
         */
195
197
        file.info = null;
 
198
 
 
199
        if (is_network && !yield check_network ()) {
 
200
            file.is_connected = false;
 
201
            return false;
 
202
        }
 
203
 
 
204
        if (is_no_info) {
 
205
            /* Not a failure when not expected to get file info */
 
206
            return true;
 
207
        }
 
208
 
196
209
        if (is_local) {
197
210
            return file.ensure_query_info ();
198
211
        }
199
 
        /* Must be non-local */
200
 
        if (!yield check_network ()) {
201
 
            file.is_connected = false;
202
 
            return false;
203
 
        } else {
204
 
            if (!yield try_query_info ()) { /* may already be mounted */
205
 
                if (yield mount_mountable ()) {
206
 
                /* Previously mounted Samba servers still appear mounted even if disconnected
207
 
                 * e.g. by unplugging the network cable.  So the following function can block for
208
 
                 * a long time; we therefore use a timeout */
209
 
                    debug ("successful mount %s", file.uri);
210
 
                    return yield try_query_info ();
211
 
                } else {
212
 
                    return false;
213
 
                }
 
212
 
 
213
        if (!yield try_query_info ()) { /* may already be mounted */
 
214
            if (yield mount_mountable ()) {
 
215
            /* Previously mounted Samba servers still appear mounted even if disconnected
 
216
             * e.g. by unplugging the network cable.  So the following function can block for
 
217
             * a long time; we therefore use a timeout */
 
218
                debug ("successful mount %s", file.uri);
 
219
                return yield try_query_info ();
214
220
            } else {
215
 
                return true;
 
221
                return false;
216
222
            }
 
223
        } else {
 
224
            return true;
217
225
        }
218
226
    }
219
227
 
238
246
            file.is_connected = false;
239
247
            return false;
240
248
        }
 
249
 
241
250
        if (success) {
242
251
            debug ("got file info");
243
252
            file.update ();
253
262
            var mount_op = new Gtk.MountOperation (null);
254
263
            cancellable = new Cancellable ();
255
264
            bool mounting = true;
 
265
            bool asking_password = false;
256
266
            assert (mount_timeout_id == 0);
 
267
 
257
268
            mount_timeout_id = Timeout.add_seconds (MOUNT_TIMEOUT_SEC, () => {
258
 
                if (mounting) {
 
269
                if (mounting && !asking_password) {
259
270
                    warning ("Cancelled after timeout in mount mountable %s", file.uri);
260
271
                    cancellable.cancel ();
 
272
                    mount_timeout_id = 0;
 
273
                    return false;
 
274
                } else {
 
275
                    return true;
261
276
                }
262
 
                mount_timeout_id = 0;
263
 
                return false;
264
 
            });
 
277
            });
 
278
 
 
279
            mount_op.ask_password.connect (() => {
 
280
                asking_password = true;
 
281
            });
 
282
 
 
283
            mount_op.reply.connect (() => {
 
284
                asking_password = false;
 
285
            });
 
286
 
265
287
            yield location.mount_enclosing_volume (0, mount_op, cancellable);
266
288
            var mount = location.find_enclosing_mount ();
267
289
 
521
543
                        if (gof == null) {
522
544
                            gof = new GOF.File (loc, location); /*does not add to GOF file cache */
523
545
                        }
 
546
 
524
547
                        gof.info = file_info;
525
548
                        gof.update ();
526
549
 
1101
1124
        cancel_timeout (ref timeout_thumbsq);
1102
1125
        cancel_timeout (ref idle_consume_changes_id);
1103
1126
        cancel_timeout (ref load_timeout_id);
1104
 
        
 
1127
        cancel_timeout (ref mount_timeout_id);
1105
1128
    }
1106
1129
 
1107
1130
    private bool cancel_timeout (ref uint id) {