summaryrefslogtreecommitdiff
path: root/libpeas/peas-utils-osx.m
blob: 726c67c550fc49d459b81cbc4aa411e269d15f36 (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
/*
 * peas-utils-osx.m
 * This file is part of libpeas
 *
 * Copyright (C) 2008 Ignacio Casal Quinteiro
 *
 * libpeas is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * libpeas is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
 *
 * Author: Tom Schoonjans <Tom.Schoonjans@gmail.com>
 */

#include "config.h"

#include "peas-utils-osx.h"

#import <Foundation/Foundation.h>

#import <AppKit/AppKit.h>

void
peas_open_url_osx (const char *uri)
{
  [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithUTF8String:uri]]];
}

char *
peas_dirs_os_x_get_bundle_resource_dir (void)
{
  NSAutoreleasePool *pool;
  char *str = NULL;
  NSString *path;

  pool = [[NSAutoreleasePool alloc] init];

  if ([[NSBundle mainBundle] bundleIdentifier] == nil)
    {
      [pool release];
      return NULL;
    }

  path = [[NSBundle mainBundle] resourcePath];

  if (!path)
    {
      [pool release];
      return NULL;
    }

  str = g_strdup ([path UTF8String]);
  [pool release];
  return str;
}

char *
peas_dirs_os_x_get_resource_dir (const char *subdir,
                                 const char *default_dir)
{
  char *res_dir;
  char *ret;

  res_dir = peas_dirs_os_x_get_bundle_resource_dir ();

  if (res_dir == NULL)
    {
      ret = g_build_filename (default_dir, "libpeas-1.0", NULL);
    }
  else
    {
      ret = g_build_filename (res_dir, subdir, "libpeas-1.0", NULL);
      g_free (res_dir);
    }

  return ret;
}

char *
peas_dirs_os_x_get_data_dir (void)
{
  return peas_dirs_os_x_get_resource_dir ("share", DATADIR);
}

char *
peas_dirs_os_x_get_lib_dir (void)
{
  return peas_dirs_os_x_get_resource_dir ("lib", LIBDIR);
}

char *
peas_dirs_os_x_get_locale_dir (void)
{
  char *res_dir;
  char *ret;

  res_dir = peas_dirs_os_x_get_bundle_resource_dir ();

  if (res_dir == NULL)
    {
      ret = g_build_filename (DATADIR, "locale", NULL);
    }
  else
    {
      ret = g_build_filename (res_dir, "share", "locale", NULL);
      g_free (res_dir);
    }

  return ret;
}