~ash1991/pantheon-files/pantheon-files-plugin-dropbox

« back to all changes in this revision

Viewing changes to plugin.c

  • Committer: am.monkeyd at gmail
  • Date: 2011-10-06 01:09:50 UTC
  • Revision ID: am.monkeyd@gmail.com-20111006010950-3ujuoy5cgzrh7bia
clean up and correctly trigger row change update

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
G_DEFINE_TYPE (MarlinDropbox, marlin_dropbox, MARLIN_PLUGINS_TYPE_BASE);
29
29
 
30
 
static char *db_emblems[] = {"dropbox-uptodate", "dropbox-syncing", "dropbox-unsyncable"};
31
 
static char *emblems[] = {"emblem-ubuntuone-synchronized", "emblem-ubuntuone-updating", "dropbox-unsyncable"};
 
30
static char *db_emblems[] = {"dropbox-uptodate", "dropbox-syncing", "dropbox-unsyncable", "web", "people", "photos", "star"};
 
31
static char *emblems[] = {"emblem-ubuntuone-synchronized", "emblem-ubuntuone-updating", "dropbox-unsyncable", "emblem-web", "emblem-people", "emblem-photos", "emblem-star"};
32
32
//gchar *DEFAULT_EMBLEM_PATHS[2] = { EMBLEMDIR , NULL };
33
33
 
34
34
static void marlin_dropbox_finalize (MarlinPluginsBase* obj);
69
69
}
70
70
 
71
71
static void
 
72
reset_file(GOFFile *file) {
 
73
    debug("resetting file %p", (void *) file);
 
74
    gof_file_update_emblem (file);
 
75
}
 
76
 
 
77
gboolean
 
78
reset_all_files(MarlinDropbox *cvs) {
 
79
    /* Only run this on the main loop or you'll cause problems. */
 
80
 
 
81
    /* this works because you can call a function pointer with
 
82
       more arguments than it takes */
 
83
    g_hash_table_foreach(cvs->obj2filename, (GHFunc) reset_file, NULL);
 
84
    return FALSE;
 
85
}
 
86
 
 
87
static void
72
88
when_file_dies(MarlinDropbox *cvs, GOFFile *file) {
73
89
    gchar *filename;
74
90
 
183
199
    g_mutex_unlock(cvs->emblem_paths_mutex);
184
200
 
185
201
    g_idle_add((GSourceFunc) add_emblem_paths, g_hash_table_ref(emblem_paths_response));
186
 
    //FIXME
187
 
    //g_idle_add((GSourceFunc) reset_all_files, cvs);
 
202
    g_idle_add((GSourceFunc) reset_all_files, cvs);
188
203
}
189
204
#endif
190
205
 
191
206
static void
192
207
on_connect(MarlinDropbox *cvs) {
193
 
    //reset_all_files(cvs);
 
208
    reset_all_files(cvs);
194
209
 
195
210
    g_message ("%s", G_STRFUNC);
196
211
    //amtest
202
217
 
203
218
static void
204
219
on_disconnect(MarlinDropbox *cvs) {
205
 
    //reset_all_files(cvs);
 
220
    reset_all_files(cvs);
206
221
 
207
222
    //FIXME
208
223
    g_message ("%s", G_STRFUNC);
216
231
#endif
217
232
}
218
233
 
 
234
static void
 
235
handle_shell_touch(GHashTable *args, MarlinDropbox *cvs) {
 
236
    gchar **path;
 
237
 
 
238
    //  debug_enter();
 
239
 
 
240
    if ((path = g_hash_table_lookup(args, "path")) != NULL &&
 
241
        path[0][0] == '/') {
 
242
        GOFFile *file;
 
243
        gchar *filename;
 
244
 
 
245
        filename = canonicalize_path(path[0]);
 
246
 
 
247
        debug("shell touch for %s", filename);
 
248
 
 
249
        file = g_hash_table_lookup(cvs->filename2obj, filename);
 
250
 
 
251
        if (file != NULL) {
 
252
            debug("gonna reset %s", filename);
 
253
            reset_file(file);
 
254
        }
 
255
        g_free(filename);
 
256
    }
 
257
 
 
258
    return;
 
259
}
 
260
 
219
261
static char *
220
262
translate_emblem (char *str)
221
263
{
222
264
    int i=0;
223
265
 
224
 
    for (i; i<3; i++) {
 
266
    for (i; i<sizeof(emblems); i++) {
225
267
        if (strcmp (str, db_emblems[i]) == 0) {
226
268
            return emblems[i];
227
269
        }
244
286
 
245
287
        isdir = dficr->dfic->file->is_directory;
246
288
 
247
 
        //amtest
248
 
        /*if (dficr->folder_tag_response != NULL)
249
 
            g_critical ("hummmmmmmmmmmmmmm");*/
250
 
 
251
289
        /* if we have emblems just use them. */
252
290
        if (dficr->emblems_response != NULL &&
253
291
            (status = g_hash_table_lookup(dficr->emblems_response, "emblems")) != NULL) {
254
292
            int i;
255
293
            for ( i = 0; status[i] != NULL; i++) {
256
294
                if (status[i][0]) {
 
295
                    g_message ("emblem %s", status[i]);
257
296
                    if ((str_emblem = translate_emblem (status[i])) != NULL)
258
297
                        gof_file_add_emblem(dficr->dfic->file, str_emblem);
 
298
                    else
 
299
                        g_warning ("emblem %s not found - %s", status[i], dficr->dfic->file->uri);
259
300
                }
260
301
            }
261
 
            //result = NAUTILUS_OPERATION_COMPLETE;
262
302
        }
263
303
        /* if the file status command went okay */
264
 
        //FIXME double check and clean this mess 
265
 
        /* icon_overlay_file_status and get_emblems seems to both provide the file status */
266
 
 
267
 
        //else if ((dficr->file_status_response != NULL &&
268
 
        /*if ((dficr->file_status_response != NULL &&
 
304
        else if ((dficr->file_status_response != NULL &&
269
305
                  (status =
270
306
                   g_hash_table_lookup(dficr->file_status_response, "status")) != NULL) &&
271
307
                 ((isdir == TRUE &&
272
 
                   dficr->folder_tag_response != NULL) || isdir == FALSE)) {*/
273
 
        if (isdir == TRUE && dficr->folder_tag_response != NULL) {
 
308
                   dficr->folder_tag_response != NULL) || isdir == FALSE)) {
 
309
            //FIXME
 
310
            g_critical ("grrrr %s", G_STRFUNC);
274
311
            gchar **tag = NULL;
275
312
 
276
313
            /* set the tag emblem */
277
 
            /*if (isdir &&
278
 
                (tag = g_hash_table_lookup(dficr->folder_tag_response, "tag")) != NULL) {*/
279
 
            if ((tag = g_hash_table_lookup(dficr->folder_tag_response, "tag")) != NULL) {
 
314
            if (isdir &&
 
315
                (tag = g_hash_table_lookup(dficr->folder_tag_response, "tag")) != NULL) {
280
316
                if (strcmp("public", tag[0]) == 0) {
281
317
                    gof_file_add_emblem(dficr->dfic->file, "emblem-web");
282
318
                }
291
327
                }
292
328
            }
293
329
 
294
 
#if 0
295
330
            /* set the status emblem */
296
331
            int emblem_code = 0;
297
332
 
311
346
                   g_filename_from_uri(dficr->dfic->file->uri,
312
347
                   NULL, NULL));
313
348
                   */
 
349
                //FIXME
314
350
                g_message ("emblem code %d", emblem_code);
315
351
                gof_file_add_emblem(dficr->dfic->file, emblems[emblem_code-1]);
316
352
            }
317
 
            //result = NAUTILUS_OPERATION_COMPLETE;
318
 
#endif
319
353
        }
320
354
    }
321
355
 
327
361
      (NautilusOperationHandle*) dficr->dfic,
328
362
      result);
329
363
      }*/
 
364
    //reset_file (dficr->dfic->file);
 
365
    gof_monitor_file_changed (dficr->dfic->file);
330
366
 
331
367
    /* destroy the objects we created */
332
368
    if (dficr->file_status_response != NULL)
393
429
            //g_signal_handlers_disconnect_by_func(file, G_CALLBACK(changed_cb), cvs);
394
430
        }
395
431
        //FIXME check
396
 
#if 0
 
432
        /*else if (stored_filename == NULL) {
 
433
            g_critical ("grrrrrrrrr");
 
434
        }*/
 
435
//#if 0
397
436
        else if (stored_filename == NULL) {
398
 
            NautilusFileInfo *f2;
 
437
            GOFFile *f2;
399
438
 
400
439
            if ((f2 = g_hash_table_lookup(cvs->filename2obj, filename)) != NULL) {
401
440
                /* if the filename exists in the filename2obj hash
407
446
                   just remove the association to the older file object, it's obsolete
408
447
                   */
409
448
                g_object_weak_unref(G_OBJECT(f2), (GWeakNotify) when_file_dies, cvs);
410
 
                g_signal_handlers_disconnect_by_func(f2, G_CALLBACK(changed_cb), cvs);
 
449
                //g_signal_handlers_disconnect_by_func(f2, G_CALLBACK(changed_cb), cvs);
411
450
                g_hash_table_remove(cvs->filename2obj, filename);
412
451
                g_hash_table_remove(cvs->obj2filename, f2);
413
452
            }
414
453
        }
415
 
#endif
 
454
//#endif
416
455
 
417
456
        /* too chatty */
418
457
        /* debug("adding %s <-> 0x%p", filename, file);*/
505
544
    dropbox_client_setup(&(cvs->dc));
506
545
 
507
546
    /* our hooks */
508
 
    //FIXME remove marlin monitor the directory too.
509
 
    /*nautilus_dropbox_hooks_add(&(cvs->dc.hookserv), "shell_touch",
510
 
      (DropboxUpdateHook) handle_shell_touch, cvs);*/
 
547
    /* tricky name: shell_touch signal is used for real time events too (like transfert done event) */
 
548
    marlin_dropbox_hooks_add(&(cvs->dc.hookserv), "shell_touch",
 
549
                             (DropboxUpdateHook) handle_shell_touch, cvs);
511
550
 
512
551
    /* add connection handlers */
513
552
    dropbox_client_add_on_connect_hook(&(cvs->dc),