~robertcarr/libunity-webapps/fix-1059846-happy-october

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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
 * unity-webapps-preinstalled-application-info.c
 * Copyright (C) Canonical LTD 2011
 *
 * Author: Robert Carr <racarr@canonical.com>
 * 
 unity-webapps 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 3 of the License, or
 * (at your option) any later version.
 * 
 * unity-webapps 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 program.  If not, see <http://www.gnu.org/licenses/>.";
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gstdio.h>
#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>

#include "unity-webapps-preinstalled-application-info.h"

#include "../unity-webapps-debug.h"

G_DEFINE_TYPE(UnityWebappsPreinstalledApplicationInfo, unity_webapps_preinstalled_application_info, UNITY_WEBAPPS_TYPE_APPLICATION_INFO);

enum {
  PROP_0,
  PROP_DESKTOP_NAME
};


#define UNITY_WEBAPPS_PREINSTALLED_APPLICATION_INFO_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), UNITY_WEBAPPS_TYPE_PREINSTALLED_APPLICATION_INFO, UnityWebappsPreinstalledApplicationInfoPrivate))

struct _UnityWebappsPreinstalledApplicationInfoPrivate {
  gchar *desktop_name;
};


static void
unity_webapps_preinstalled_application_info_finalize (GObject *object)
{
  UnityWebappsPreinstalledApplicationInfo *info;
  
  info = UNITY_WEBAPPS_PREINSTALLED_APPLICATION_INFO (object);
    
  g_free (info->priv->desktop_name);
}

static void
unity_webapps_preinstalled_application_info_set_property (GObject *object, guint property_id,
							  const GValue *value, GParamSpec *pspec)
{
  UnityWebappsPreinstalledApplicationInfo *self;
  
  self = UNITY_WEBAPPS_PREINSTALLED_APPLICATION_INFO (object);
  
  switch (property_id)
    {
    case PROP_DESKTOP_NAME:
      g_return_if_fail (self->priv->desktop_name == NULL);
      self->priv->desktop_name = g_value_dup_string (value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    }

}

static void
unity_webapps_preinstalled_application_info_get_property (GObject *object, guint property_id,
							  GValue *value, GParamSpec *pspec)
{
  UnityWebappsPreinstalledApplicationInfo *self;
  
  self = UNITY_WEBAPPS_PREINSTALLED_APPLICATION_INFO (object);
  
  switch (property_id)
    {
    case PROP_DESKTOP_NAME:
      g_value_set_string (value, self->priv->desktop_name);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    }
}

static gchar *
unity_webapps_preinstalled_application_info_get_desktop_file_name (UnityWebappsApplicationInfo *application_info)
{
  UnityWebappsPreinstalledApplicationInfo *info;
  
  info = UNITY_WEBAPPS_PREINSTALLED_APPLICATION_INFO (application_info);
  
  return g_strdup (info->priv->desktop_name);
}

static gchar *
unity_webapps_preinstalled_application_info_get_desktop_file_path (UnityWebappsApplicationInfo *application_info)
{
  UnityWebappsPreinstalledApplicationInfo *info;
  GDesktopAppInfo *desktop_app_info;
  gchar *desktop_file_path;
  
  info = UNITY_WEBAPPS_PREINSTALLED_APPLICATION_INFO (application_info);
  
  // TODO: Cache GDesktopAppInfo for lifetime of object? Not without implications
  desktop_app_info = g_desktop_app_info_new (info->priv->desktop_name);
  desktop_file_path = g_strdup (g_desktop_app_info_get_filename (desktop_app_info));
  
  g_object_unref (G_OBJECT (desktop_app_info));
  
  return desktop_file_path;
}

static gboolean
unity_webapps_preinstalled_application_info_ensure_desktop_file (UnityWebappsApplicationInfo *application_info,
								 GError **error)
{
  // TODO: This could actually ensure the desktop file exists...not much point in the current usage of the object.
  return TRUE;
}

static void
unity_webapps_preinstalled_application_info_class_init (UnityWebappsPreinstalledApplicationInfoClass *klass)
{
  GParamSpec *pspec;
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  UnityWebappsApplicationInfoClass *application_info_class = UNITY_WEBAPPS_APPLICATION_INFO_CLASS (klass);
  
  object_class->finalize = unity_webapps_preinstalled_application_info_finalize;
  object_class->get_property = unity_webapps_preinstalled_application_info_get_property;
  object_class->set_property = unity_webapps_preinstalled_application_info_set_property;
  
  application_info_class->get_desktop_file_name = unity_webapps_preinstalled_application_info_get_desktop_file_name;
  application_info_class->get_desktop_file_path = unity_webapps_preinstalled_application_info_get_desktop_file_path;
  application_info_class->ensure_desktop_file = unity_webapps_preinstalled_application_info_ensure_desktop_file;
  
  pspec = g_param_spec_string ("desktop-name", "Desktop Name", "Desktop Name for the Preinstalled .desktop file",
			       NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
  g_object_class_install_property (object_class, PROP_DESKTOP_NAME, pspec);

  g_type_class_add_private (object_class, sizeof(UnityWebappsPreinstalledApplicationInfoPrivate));
}

static void
unity_webapps_preinstalled_application_info_init (UnityWebappsPreinstalledApplicationInfo *info)
{
  info->priv = UNITY_WEBAPPS_PREINSTALLED_APPLICATION_INFO_GET_PRIVATE (info);
}


UnityWebappsApplicationInfo *
unity_webapps_preinstalled_application_info_new (const gchar *name,
						 const gchar *domain,
						 const gchar *icon_url,
						 const gchar *mime_types,
						 const gchar *desktop_name)
{
  return g_object_new (UNITY_WEBAPPS_TYPE_PREINSTALLED_APPLICATION_INFO,
		       "name", name,
		       "domain", domain,
		       "icon-url", icon_url,
		       "mime-types", mime_types,
		       "desktop-name", desktop_name,
		       NULL);
}