13
type ConnectivityStatus int
16
ConnectivityStatusUnknown ConnectivityStatus = 0
17
ConnectivityStatusConnected ConnectivityStatus = 1
18
ConnectivityStatusDisconnected ConnectivityStatus = 2
21
// queryMetadata is the base class for extra metadata passed to scopes as a part of a request.
22
// This base class is not exported
23
type queryMetadata struct {
27
// Locale returns the expected locale for the search request.
28
func (metadata *queryMetadata) Locale() string {
29
locale := C.query_metadata_get_locale(metadata.m)
30
defer C.free(unsafe.Pointer(locale))
31
return C.GoString(locale)
34
// FormFactor returns the form factor for the search request.
35
func (metadata *queryMetadata) FormFactor() string {
36
formFactor := C.query_metadata_get_form_factor(metadata.m)
37
defer C.free(unsafe.Pointer(formFactor))
38
return C.GoString(formFactor)
41
// SetInternetConnectivity indicates the internet connectivity status.
42
func (metadata *queryMetadata) SetInternetConnectivity(status ConnectivityStatus) {
43
C.query_metadata_set_internet_connectivity(metadata.m, C.int(status))
46
// InternetConnectivity gets internet connectivity status.
47
func (metadata *queryMetadata) InternetConnectivity() ConnectivityStatus {
48
return ConnectivityStatus(C.query_metadata_get_internet_connectivity(metadata.m))
51
// SearchMetadata holds additional metadata about the search request.
52
type SearchMetadata struct {
56
func finalizeSearchMetadata(metadata *SearchMetadata) {
57
if metadata.m != nil {
58
C.destroy_search_metadata((*C._SearchMetadata)(metadata.m))
63
func makeSearchMetadata(m *C._SearchMetadata) *SearchMetadata {
64
metadata := new(SearchMetadata)
65
runtime.SetFinalizer(metadata, finalizeSearchMetadata)
66
metadata.m = (*C._QueryMetadata)(m)
70
// NewSearchMetadata creates a new SearchMetadata with the given locale and
72
func NewSearchMetadata(cardinality int, locale, form_factor string) *SearchMetadata {
73
return makeSearchMetadata(C.new_search_metadata(C.int(cardinality),
74
unsafe.Pointer(&locale),
75
unsafe.Pointer(&form_factor)))
78
// Cardinality returns the desired number of results for the search request.
79
func (metadata *SearchMetadata) Cardinality() int {
80
return int(C.search_metadata_get_cardinality((*C._SearchMetadata)(metadata.m)))
83
type Location struct {
84
Latitude float64 `json:"latitude"`
85
Longitude float64 `json:"longitude"`
86
Altitude float64 `json:"altitude"`
87
AreaCode string `json:"area_code"`
88
City string `json:"city"`
89
CountryCode string `json:"country_code"`
90
CountryName string `json:"country_name"`
91
HorizontalAccuracy float64 `json:"horizontal_accuracy"`
92
VerticalAccuracy float64 `json:"vertical_accuracy"`
93
RegionCode string `json:"region_code"`
94
RegionName string `json:"region_name"`
95
ZipPostalCode string `json:"zip_postal_code"`
98
func (metadata *SearchMetadata) Location() *Location {
100
locData := C.search_metadata_get_location((*C._SearchMetadata)(metadata.m), &length)
104
defer C.free(locData)
105
var location Location
106
if err := json.Unmarshal(C.GoBytes(locData, length), &location); err != nil {
112
// SetLocation sets the location
113
func (metadata *SearchMetadata) SetLocation(l *Location) error {
114
location := locationMarshal{marshalFloat(l.Latitude),
115
marshalFloat(l.Longitude),
116
marshalFloat(l.Altitude),
121
marshalFloat(l.HorizontalAccuracy),
122
marshalFloat(l.VerticalAccuracy),
126
data, err := json.Marshal(location)
130
var errorString *C.char
131
C.search_metadata_set_location((*C._SearchMetadata)(metadata.m), (*C.char)(unsafe.Pointer(&data[0])), C.int(len(data)), &errorString)
132
return checkError(errorString)
135
func (metadata *SearchMetadata) SetAggregatedKeywords(keywords []string) error {
136
var errorString *C.char
137
C.search_metadata_set_aggregated_keywords((*C._SearchMetadata)(metadata.m), unsafe.Pointer(&keywords[0]), C.int(len(keywords)), &errorString)
138
return checkError(errorString)
141
func (metadata *SearchMetadata) AggregatedKeywords() []string {
143
keywordData := C.search_metadata_get_aggregated_keywords((*C._SearchMetadata)(metadata.m), &length)
144
var keywords []string
145
if err := json.Unmarshal(C.GoBytes(keywordData, length), &keywords); err != nil {
151
func (metadata *SearchMetadata) IsAggregated() bool {
152
if C.search_metadata_is_aggregated((*C._SearchMetadata)(metadata.m)) == 0 {
158
// ActionMetadata holds additional metadata about the preview request
159
// or result activation.
160
type ActionMetadata struct {
164
func finalizeActionMetadata(metadata *ActionMetadata) {
165
if metadata.m != nil {
166
C.destroy_action_metadata((*C._ActionMetadata)(metadata.m))
171
// NewActionMetadata creates a new ActionMetadata with the given locale and
173
func NewActionMetadata(locale, form_factor string) *ActionMetadata {
174
return makeActionMetadata(C.new_action_metadata(unsafe.Pointer(&locale),
175
unsafe.Pointer(&form_factor)))
178
func makeActionMetadata(m *C._ActionMetadata) *ActionMetadata {
179
metadata := new(ActionMetadata)
180
runtime.SetFinalizer(metadata, finalizeActionMetadata)
181
metadata.m = (*C._QueryMetadata)(m)
185
// ScopeData decodes the stored scope data into the given variable.
187
// Scope data is either set by the shell when calling a preview
188
// action, or set by the scope through an ActivationResponse object.
189
func (metadata *ActionMetadata) ScopeData(v interface{}) error {
191
scopeData := C.action_metadata_get_scope_data((*C._ActionMetadata)(metadata.m), &dataLength)
192
defer C.free(scopeData)
193
return json.Unmarshal(C.GoBytes(scopeData, dataLength), v)
196
// SetScopeData attaches arbitrary data to this ActionMetadata.
197
func (metadata *ActionMetadata) SetScopeData(v interface{}) error {
198
data, err := json.Marshal(v)
202
var errorString *C.char
203
C.action_metadata_set_scope_data((*C._ActionMetadata)(metadata.m), (*C.char)(unsafe.Pointer(&data[0])), C.int(len(data)), &errorString)
204
return checkError(errorString)
207
// SetHint sets a hint.
208
func (metadata *ActionMetadata) SetHint(key string, value interface{}) error {
209
data, err := json.Marshal(value)
213
var errorString *C.char
214
C.action_metadata_set_hint((*C._ActionMetadata)(metadata.m), unsafe.Pointer(&key), (*C.char)(unsafe.Pointer(&data[0])), C.int(len(data)), &errorString)
215
return checkError(errorString)
218
// Hint returns a hint.
219
// Returns error if the hint does not exist or if we got an error unmarshaling
220
func (metadata *ActionMetadata) Hint(key string, value interface{}) error {
222
var errorString *C.char
223
scopeData := C.action_metadata_get_hint((*C._ActionMetadata)(metadata.m), unsafe.Pointer(&key), &dataLength, &errorString)
224
if dataLength > 0 && errorString == nil {
225
defer C.free(scopeData)
226
return json.Unmarshal(C.GoBytes(scopeData, dataLength), value)
228
return checkError(errorString)
232
// Hints gets all hints.
233
func (metadata *ActionMetadata) Hints(value interface{}) error {
235
data := C.action_metadata_get_hints((*C._ActionMetadata)(metadata.m), &length)
240
return json.Unmarshal(C.GoBytes(data, length), value)
243
// we use this type to reimplement the marshaller interface in order to make values
244
// like 1.0 not being converted as 1 (integer).
245
type marshalFloat float64
247
func (n marshalFloat) MarshalJSON() ([]byte, error) {
248
return []byte(fmt.Sprintf("%f", n)), nil
251
// the following structure is only used to control how the float64 types are
252
// marshaled. It is not exported.
253
type locationMarshal struct {
254
Latitude marshalFloat `json:"latitude"`
255
Longitude marshalFloat `json:"longitude"`
256
Altitude marshalFloat `json:"altitude"`
257
AreaCode string `json:"area_code"`
258
City string `json:"city"`
259
CountryCode string `json:"country_code"`
260
CountryName string `json:"country_name"`
261
HorizontalAccuracy marshalFloat `json:"horizontal_accuracy"`
262
VerticalAccuracy marshalFloat `json:"vertical_accuracy"`
263
RegionCode string `json:"region_code"`
264
RegionName string `json:"region_name"`
265
ZipPostalCode string `json:"zip_postal_code"`
268
type ProxyScopeMetadata struct {
269
Identity string `json:"identity"`
270
EndPoint string `json:"endpoint"`
273
// ScopeMetadata holds scope attributes such as name, description, icon etc.
275
// The information stored by ScopeMetadata comes from the .ini file for the given scope (for local scopes)
276
// or is fetched from the remote server (for scopes running on Smart Scopes Server).
277
// Use ListRegistryScopes from ScopeBase to get the metadata for all scopes.
278
type ScopeMetadata struct {
280
Art string `json:"art"`
281
Author string `json:"author"`
282
Description string `json:"description"`
283
DisplayName string `json:"display_name"`
284
Icon string `json:"icon"`
285
Invisible bool `json:"invisible"`
286
IsAggregator bool `json:"is_aggregator"`
287
LocationDataNeeded bool `json:"location_data_needed"`
288
ScopeDir string `json:"scope_dir"`
289
ScopeId string `json:"scope_id"`
290
Version int `json:"version"`
291
Proxy ProxyScopeMetadata `json:"proxy"`
292
AppearanceAttributes map[string]interface{} `json:"appearance_attributes"`
293
SettingsDefinitions []interface{} `json:"settings_definitions"`
294
Keywords []string `json:"keywords"`
297
func finalizeScopeMetadata(metadata *ScopeMetadata) {
298
C.destroy_scope_metadata_ptr(metadata.m)
301
func makeScopeMetadata(m *C._ScopeMetadata, json_data string) *ScopeMetadata {
302
metadata := new(ScopeMetadata)
303
if err := json.Unmarshal([]byte(json_data), &metadata); err != nil {
307
runtime.SetFinalizer(metadata, finalizeScopeMetadata)