~canonical-dx-team/wncksync/trunk

« back to all changes in this revision

Viewing changes to src/windowmatcher.c

  • Committer: Jason Smith
  • Date: 2010-03-25 17:12:59 UTC
  • mfrom: (113.1.1 wncksync)
  • Revision ID: jason.smith@canonical.com-20100325171259-kc2blez40ang3e93
Merge prefer desktop-id branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
269
269
  GAppInfo *desktop_file;
270
270
  GString *exec;
271
271
  GString *filename;
 
272
  GString *existing;
272
273
  GString *desktop_id;
273
274
  
274
275
  g_return_if_fail (WNCKSYNC_IS_MATCHER (self));
289
290
    }
290
291
  
291
292
  filename = g_string_new (file);
292
 
  g_hash_table_insert (desktop_file_table, exec, filename);
293
 
 
294
293
  desktop_id = g_string_new (g_path_get_basename (filename->str));
295
294
  desktop_id = g_string_truncate (desktop_id, desktop_id->len - 8); /* remove last 8 characters for .desktop */
 
295
 
 
296
  existing = g_hash_table_lookup (desktop_file_table, exec);
 
297
 
 
298
  if (existing)
 
299
    {
 
300
      existing = g_string_new (g_path_get_basename (existing->str));
 
301
      existing = g_string_truncate (existing, existing->len - 8); /* remove last 8 characters for .desktop */
 
302
 
 
303
      if (g_strcmp0 (existing->str, exec->str) == 0)
 
304
        {
 
305
          existing = g_hash_table_lookup (desktop_file_table, exec);
 
306
          /* we prefer to have the desktop file where the desktop-id == exec */
 
307
          g_string_free (filename, TRUE);
 
308
          g_string_free (desktop_id, TRUE);
 
309
          g_string_free (existing, TRUE);
 
310
          return;
 
311
        }
 
312
      g_string_free (existing, TRUE);
 
313
    }
296
314
  
 
315
  g_hash_table_insert (desktop_file_table, exec, filename);
297
316
  g_hash_table_insert (desktop_id_table, desktop_id, filename); 
298
317
}
299
318
 
369
388
  directory = g_path_get_dirname (index_file);
370
389
  input = g_data_input_stream_new (G_INPUT_STREAM (stream));
371
390
  
372
 
  line = g_data_input_stream_read_line (input, &length, NULL, NULL);
373
 
  while (line)
 
391
  
 
392
  while ((line = g_data_input_stream_read_line (input, &length, NULL, NULL)) != NULL)
374
393
    {
375
394
      GString *exec;
376
395
      GString *desktop_id;
377
396
      GString *filename;
 
397
      GString *existing;
378
398
      
379
399
      gchar **parts = g_strsplit (line, "\t", 3);
380
400
      
389
409
      
390
410
      desktop_id = g_string_new (parts[0]);
391
411
      desktop_id = g_string_truncate (desktop_id, desktop_id->len - 8);
392
 
      
 
412
 
 
413
      existing = g_hash_table_lookup (desktop_file_table, exec);
 
414
 
 
415
      if (existing)
 
416
        {
 
417
          existing = g_string_new (g_path_get_basename (existing->str));
 
418
          existing = g_string_truncate (existing, existing->len - 8); /* remove last 8 characters for .desktop */
 
419
 
 
420
          if (g_strcmp0 (existing->str, exec->str) == 0)
 
421
            {
 
422
              existing = g_hash_table_lookup (desktop_file_table, exec);
 
423
              /* we prefer to have the desktop file where the desktop-id == exec */
 
424
              g_string_free (filename, TRUE);
 
425
              g_string_free (desktop_id, TRUE);
 
426
              continue;
 
427
            }
 
428
          g_string_free (existing, TRUE);
 
429
        }
 
430
        
393
431
      g_hash_table_insert (desktop_file_table, exec, filename);
394
432
      g_hash_table_insert (desktop_id_table, desktop_id, filename); 
395
433
      
396
434
      length = 0;
397
435
      g_strfreev (parts);
398
 
      
399
 
      line = g_data_input_stream_read_line (input, &length, NULL, NULL);
400
436
    }
401
437
  g_free ((gpointer) directory);
402
438
}