~shnatsel/slingshot/update-cmake-modules

« back to all changes in this revision

Viewing changes to lib/synapse-core/match.vala

  • Committer: RabbitBot
  • Author(s): Tom Beckmann
  • Date: 2014-06-28 05:00:49 UTC
  • mfrom: (421.1.19 slingshot)
  • Revision ID: rabbitbot-20140628050049-pi540b7grh00lzcv
Copy the sources of Synapse over and implements a new searchview using libsynapse

Copying is currently necessary as synapse's library is internal. I hope we can change this soon, although I don't consider it very urgent, as synapse is almost unmaintained at the moment, so we most likely won't miss out on important updates.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010 Michal Hruby <michal.mhr@gmail.com>
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2.1 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public License
 
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
 *
 
17
 * Authored by Michal Hruby <michal.mhr@gmail.com>
 
18
 *             Alberto Aldegheri <albyrock87+dev@gmail.com>
 
19
 */
 
20
 
 
21
namespace Synapse
 
22
{
 
23
  public enum MatchType
 
24
  {
 
25
    UNKNOWN = 0,
 
26
    TEXT,
 
27
    APPLICATION,
 
28
    GENERIC_URI,
 
29
    ACTION,
 
30
    SEARCH,
 
31
    CONTACT
 
32
  }
 
33
 
 
34
  public interface Match: Object
 
35
  {
 
36
    public enum Score
 
37
    {
 
38
      INCREMENT_MINOR = 2000,
 
39
      INCREMENT_SMALL = 5000,
 
40
      INCREMENT_MEDIUM = 10000,
 
41
      INCREMENT_LARGE = 20000,
 
42
      URI_PENALTY = 15000,
 
43
 
 
44
      POOR = 50000,
 
45
      BELOW_AVERAGE = 60000,
 
46
      AVERAGE = 70000,
 
47
      ABOVE_AVERAGE = 75000,
 
48
      GOOD = 80000,
 
49
      VERY_GOOD = 85000,
 
50
      EXCELLENT = 90000,
 
51
 
 
52
      HIGHEST = 100000
 
53
    }
 
54
    
 
55
    // properties
 
56
    public abstract string title { get; construct set; }
 
57
    public abstract string description { get; set; }
 
58
    public abstract string icon_name { get; construct set; }
 
59
    public abstract bool has_thumbnail { get; construct set; }
 
60
    public abstract string thumbnail_path { get; construct set; }
 
61
    public abstract MatchType match_type { get; construct set; }
 
62
 
 
63
    public virtual void execute (Match? match)
 
64
    {
 
65
      Utils.Logger.error (this, "execute () is not implemented");
 
66
    }
 
67
    
 
68
    public virtual void execute_with_target (Match? source, Match? target = null)
 
69
    {
 
70
      if (target == null) execute (source);
 
71
      else Utils.Logger.error (this, "execute () is not implemented");
 
72
    }
 
73
    
 
74
    public virtual bool needs_target () {
 
75
      return false;
 
76
    }
 
77
    
 
78
    public virtual QueryFlags target_flags ()
 
79
    {
 
80
      return QueryFlags.ALL;
 
81
    }
 
82
    
 
83
    public signal void executed ();
 
84
  }
 
85
  
 
86
  public interface ApplicationMatch: Match
 
87
  {
 
88
    public abstract AppInfo? app_info { get; set; }
 
89
    public abstract bool needs_terminal { get; set; }
 
90
    public abstract string? filename { get; construct set; }
 
91
  }
 
92
 
 
93
  public interface UriMatch: Match
 
94
  {
 
95
    public abstract string uri { get; set; }
 
96
    public abstract QueryFlags file_type { get; set; }
 
97
    public abstract string mime_type { get; set; }
 
98
  }
 
99
  
 
100
  public interface ContactMatch: Match
 
101
  {
 
102
    public abstract void send_message (string message, bool present);
 
103
    public abstract void open_chat ();
 
104
  }
 
105
 
 
106
  public interface ExtendedInfo: Match
 
107
  {
 
108
    public abstract string? extended_info { get; set; }
 
109
  }
 
110
  
 
111
  public enum TextOrigin
 
112
  {
 
113
    UNKNOWN,
 
114
    CLIPBOARD
 
115
  }
 
116
  
 
117
  public interface TextMatch: Match
 
118
  {
 
119
    public abstract TextOrigin text_origin { get; set; }
 
120
    public abstract string get_text ();
 
121
  }
 
122
  
 
123
  public interface SearchMatch: Match, SearchProvider
 
124
  {
 
125
    public abstract Match search_source { get; set; }
 
126
  }
 
127
 
 
128
  public class DefaultMatch: Object, Match
 
129
  {
 
130
    public string title { get; construct set; }
 
131
    public string description { get; set; }
 
132
    public string icon_name { get; construct set; }
 
133
    public bool has_thumbnail { get; construct set; }
 
134
    public string thumbnail_path { get; construct set; }
 
135
    public MatchType match_type { get; construct set; }
 
136
    
 
137
    public DefaultMatch (string query_string)
 
138
    {
 
139
      Object (title: query_string, description: "", has_thumbnail: false,
 
140
              icon_name: "unknown", match_type: MatchType.UNKNOWN);
 
141
    }
 
142
  }
 
143
}
 
144