~ubuntu-branches/ubuntu/natty/unity-place-applications/natty

« back to all changes in this revision

Viewing changes to src/utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2011-03-31 15:09:07 UTC
  • mfrom: (1.1.20 upstream)
  • Revision ID: james.westby@ubuntu.com-20110331150907-chmhoy92ufurusu3
Tags: 0.2.44-0ubuntu1
* New upstream release.
  - unity-applications-daemon crash when Software Center index is corrupted
    (LP: #620294)
  - Dash: Alt-F2 "nautilus ~/" errors to "Could not find '/~'" (LP: #734762)
  - unity-applications-daemon crash in unity_package_searcher_search()
    (LP: #739698)
  - unity-applications-daemon crash because of invalid docid 0 (LP: #744261)
  - Gnome-terminal doesn't start in user home directory when started from
    alt+F2 (LP: #736471)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include <gio/gio.h>
28
28
#include <unity.h>
29
29
#include <gee.h>
 
30
#include <pwd.h>
30
31
 
31
32
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
32
33
#define _g_free0(var) (var = (g_free (var), NULL))
38
39
gboolean unity_applications_place_utils_check_actor_has_category (const gchar* actor, GeeSet* categories);
39
40
gboolean unity_applications_place_utils_search_is_invalid (UnityPlaceSearch* search);
40
41
gboolean unity_applications_place_utils_search_has_really_changed (UnityPlaceSearch* old_search, UnityPlaceSearch* new_search);
 
42
gchar* unity_applications_place_utils_subst_tilde (const gchar* s);
41
43
 
42
44
 
43
45
GAppInfo* unity_applications_place_utils_get_app_info_for_actor (const gchar* actor) {
439
441
}
440
442
 
441
443
 
 
444
static gchar string_get (const gchar* self, glong index) {
 
445
        gchar result = '\0';
 
446
        g_return_val_if_fail (self != NULL, '\0');
 
447
        result = ((gchar*) self)[index];
 
448
        return result;
 
449
}
 
450
 
 
451
 
 
452
static gint string_index_of (const gchar* self, const gchar* needle, gint start_index) {
 
453
        gint result = 0;
 
454
        gchar* _tmp0_ = NULL;
 
455
        gchar* _result_;
 
456
        g_return_val_if_fail (self != NULL, 0);
 
457
        g_return_val_if_fail (needle != NULL, 0);
 
458
        _tmp0_ = strstr (((gchar*) self) + start_index, (gchar*) needle);
 
459
        _result_ = _tmp0_;
 
460
        if (_result_ != NULL) {
 
461
                result = (gint) (_result_ - ((gchar*) self));
 
462
                return result;
 
463
        } else {
 
464
                result = -1;
 
465
                return result;
 
466
        }
 
467
}
 
468
 
 
469
 
 
470
gchar* unity_applications_place_utils_subst_tilde (const gchar* s) {
 
471
        gchar* result = NULL;
 
472
        gint k = 0;
 
473
        gchar* name = NULL;
 
474
        struct passwd* pw = NULL;
 
475
        gchar _tmp0_;
 
476
        gboolean _tmp2_ = FALSE;
 
477
        gint _tmp3_;
 
478
        gint _tmp10_;
 
479
        struct passwd* _tmp13_ = NULL;
 
480
        g_return_val_if_fail (s != NULL, NULL);
 
481
        _tmp0_ = string_get (s, (glong) 0);
 
482
        if (_tmp0_ != '~') {
 
483
                gchar* _tmp1_;
 
484
                _tmp1_ = g_strdup (s);
 
485
                result = _tmp1_;
 
486
                _g_free0 (name);
 
487
                return result;
 
488
        }
 
489
        _tmp3_ = strlen (s);
 
490
        if (_tmp3_ == 1) {
 
491
                _tmp2_ = TRUE;
 
492
        } else {
 
493
                gchar _tmp4_;
 
494
                _tmp4_ = string_get (s, (glong) 1);
 
495
                _tmp2_ = _tmp4_ == '/';
 
496
        }
 
497
        if (_tmp2_) {
 
498
                const gchar* _tmp5_ = NULL;
 
499
                gchar* _tmp6_ = NULL;
 
500
                gchar* _tmp7_;
 
501
                gchar* _tmp8_;
 
502
                gchar* _tmp9_;
 
503
                _tmp5_ = g_get_home_dir ();
 
504
                _tmp6_ = string_substring (s, (glong) 1, (glong) (-1));
 
505
                _tmp7_ = _tmp6_;
 
506
                _tmp8_ = g_strconcat (_tmp5_, _tmp7_, NULL);
 
507
                _tmp9_ = _tmp8_;
 
508
                _g_free0 (_tmp7_);
 
509
                result = _tmp9_;
 
510
                _g_free0 (name);
 
511
                return result;
 
512
        }
 
513
        _tmp10_ = string_index_of (s, "/", 0);
 
514
        k = _tmp10_;
 
515
        if (k == (-1)) {
 
516
                gchar* _tmp11_ = NULL;
 
517
                _tmp11_ = string_substring (s, (glong) 1, (glong) (-1));
 
518
                _g_free0 (name);
 
519
                name = _tmp11_;
 
520
        } else {
 
521
                gchar* _tmp12_ = NULL;
 
522
                _tmp12_ = string_substring (s, (glong) 1, (glong) (k - 1));
 
523
                _g_free0 (name);
 
524
                name = _tmp12_;
 
525
        }
 
526
        _tmp13_ = getpwnam (name);
 
527
        pw = _tmp13_;
 
528
        if (pw == NULL) {
 
529
                gchar* _tmp14_;
 
530
                _tmp14_ = g_strdup (s);
 
531
                result = _tmp14_;
 
532
                _g_free0 (name);
 
533
                return result;
 
534
        }
 
535
        if (k == (-1)) {
 
536
                gchar* _tmp15_;
 
537
                _tmp15_ = g_strdup (pw->pw_dir);
 
538
                result = _tmp15_;
 
539
                _g_free0 (name);
 
540
                return result;
 
541
        } else {
 
542
                gchar* _tmp16_ = NULL;
 
543
                gchar* _tmp17_;
 
544
                gchar* _tmp18_;
 
545
                gchar* _tmp19_;
 
546
                _tmp16_ = string_substring (s, (glong) k, (glong) (-1));
 
547
                _tmp17_ = _tmp16_;
 
548
                _tmp18_ = g_strconcat (pw->pw_dir, _tmp17_, NULL);
 
549
                _tmp19_ = _tmp18_;
 
550
                _g_free0 (_tmp17_);
 
551
                result = _tmp19_;
 
552
                _g_free0 (name);
 
553
                return result;
 
554
        }
 
555
        _g_free0 (name);
 
556
}
 
557
 
 
558
 
442
559