~khurshid-alam/libunity/glib-2.59.3

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
/*
 * Copyright (C) 2013 Canonical, Ltd.
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * version 3.0 as published by the Free Software Foundation.
 *
 * This library 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 version 3.0 for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * Authored by Michal Hruby <michal.hruby@canonical.com>
 *             Pawel Stolowski <pawel.stolowski@canonical.com>
 *
 */

using Unity.Protocol;

namespace Unity {

public abstract class AggregatorScope : DeprecatedScopeBase
{
  public enum SortFlags
  {
    ASCENDING,
    DESCENDING,

    CASE_INSENSITIVE = 1 << 10
  }

  public enum MergeMode
  {
    CATEGORY_ID,
    OWNER_SCOPE
  }

  public MergeMode merge_mode { get; set; }

  public bool proxy_filter_hints { get; set; }

  public bool automatic_flushing { get; set; default = true; }

  /**
   * Maps scope ids to associated category index, needed if merge mode is OWNER_SCOPE.
   * A dummy implementation may be provided for merge mode = DISPLAY_NAME.
   */
  public abstract int category_index_for_scope_id (string scope_id);

  public AggregatorScope (string dbus_path_, string id_, MergeMode merge_mode = AggregatorScope.MergeMode.OWNER_SCOPE, bool proxy_filter_hints = false)
  {
    Object (dbus_path: dbus_path_, id: id_, is_master: true,
            merge_mode: merge_mode, proxy_filter_hints: proxy_filter_hints);
  }

  /**
   * Sort data in a given category by values of 'field'.
   *
   * Aggregating results from multiple scopes often needs a clear way to sort
   * the results, to do that you can define category-specific sorting rules.
   * As an example, a category displaying recent items might be sorted using
   * a "timestamp" field (which would be defined as either a required or 
   * optional metadata field {@link Unity.Scope.metadata_schema}).
   * For categories that don't have any obvious order it is recommended to sort
   * them according to the "title" field.
   *
   * @param category_index Index of the sorted category
   * @param field Name of the field the order will be based on
   * @param flags The way sorting is performed
   */
  public void add_sorter (uint category_index, string field, SortFlags flags)
  {
    var pimpl = get_impl () as Internal.AggregatorScopeImpl;
    pimpl.add_sorter (category_index, field, flags);
  }

  /**
   * Constraint data to be unique according to value of 'field'.
   *
   * This method allows de-duplication of results from multiple scopes
   * by only allowing unique values for the given field.
   * As an example, a scope that is aggregating results from different local
   * music databases could simply constraint the results on values of the "uri"
   * field, which would ensure that songs with the same uri are displayed only
   * once.
   * 
   * @param category_index Index of the constrained category,
   *                       or -1 to constraint all categories
   * @param field Name of the constrained field
   */
  public void add_constraint (int category_index, string field)
  {
    var pimpl = get_impl () as Internal.AggregatorScopeImpl;
    pimpl.add_constraint (category_index, field);
  }

  public abstract async void search (Unity.AggregatedScopeSearch scope_search);

  public virtual async ActivationResponse? activate (Unity.AggregatorActivation activation)
  {
    return null;
  }

  internal async HashTable<string, Variant> search_scope (
      Unity.AggregatedScopeSearch search,
      string scope_id,
      string search_query,
      SearchType search_type,
      HashTable<string, Variant>? hints,
      GLib.Cancellable? cancellable) throws Error
  {
    var pimpl = get_impl () as Internal.AggregatorScopeImpl;
    try
    {
      var res = yield pimpl.search_scope (search, scope_id, search_query,
                                          search_type, hints, cancellable);
      return res;
    }
    catch (ScopeError.DISABLED_CONTENT scope_error)
    {
      // not really an error
      return new HashTable<string, Variant> (str_hash, str_equal);
    }
  }

  internal async void push_results (string channel_id, string search_string,
                                    string scope_id,
                                    Dee.SerializableModel results_model,
                                    string[] category_ids,
                                    GLib.Cancellable? cancellable)
  {
    var pimpl = get_impl () as Internal.AggregatorScopeImpl;
    try
    {
      yield pimpl.push_results_to_scope (channel_id, search_string,
                                         scope_id, results_model,
                                         category_ids, cancellable);
    }
    catch (Error err)
    {
      warning ("%s", err.message);
    }
  }

  internal void push_filter_settings (string channel_id, FilterSet filters)
  {
    var pimpl = get_impl () as Internal.AggregatorScopeImpl;
    pimpl.push_filter_settings (channel_id, filters);
  }

  internal override Object create_impl ()
  {
    return new Internal.AggregatorScopeImpl (this);
  }
}

} /* namespace */