~macslow/unity/backported-remote-add-to-5.0

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
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
 * Copyright (C) 2011 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Gordon Allott <gord.allott@canonical.com>
 */

#ifndef UNITY_HUD_H
#define UNITY_HUD_H

#include <deque>
#include <string>
#include <memory>
#include <NuxCore/Property.h>
#include <glib.h>

namespace unity
{
namespace hud
{


class Query
{
public:
  typedef std::shared_ptr<Query> Ptr;
  
  Query(std::string const& formatted_text_, std::string const& icon_name_,
        std::string const& item_icon_, std::string const& completion_text_,
        std::string const& shortcut_, GVariant* key_)
  : formatted_text(formatted_text_)
  , icon_name(icon_name_)
  , item_icon(item_icon_)
  , completion_text(completion_text_)
  , shortcut(shortcut_)
  , key(key_)
  {
    g_variant_ref(key);
  }
  
  ~Query()
  {
    g_variant_unref(key);
  }
  
  Query(const Query &rhs);
  Query& operator=(Query);

  std::string formatted_text;   // Pango formatted text
  std::string icon_name;        // icon name using standard lookups
  std::string item_icon;        // Future API
  std::string completion_text;  // Non formatted text f or completion
  std::string shortcut;         // Shortcut key
  GVariant *key;
};


class HudImpl;
class Hud
{
public:
  typedef std::shared_ptr<Hud> Ptr;
  typedef std::deque<Query::Ptr> Queries;

  /*
   * Constructor for the hud
   * \param dbus_name string that specifies the name of the hud service
   * \param dbus_path string that specifies the path of the hud service
   */
  Hud(std::string const& dbus_name,
      std::string const& dbus_path);

  ~Hud();

  Hud(const Hud &rhs);
  Hud& operator=(Hud);

  nux::Property<std::string> target;
  nux::Property<bool> connected;

  /*
   * Queries the service for new suggestions, will fire off the 
   * suggestion_search_finished signal when the suggestions are returned
   */
  void RequestQuery(std::string const& search_string);
  
  /*
   * Executes a Query
   */
  void ExecuteQuery(Query::Ptr query, unsigned int timestamp);

  /*
   * Executes a query that returns from a search,
   * Implicitly calls CloseQuery();
   */
  void ExecuteQueryBySearch(std::string execute_string, unsigned int timestamp);

  /*
   * Closes the query connection, call when the hud closes
   */
  void CloseQuery();

  /*
   * Returns a deque of Query types when the service provides them
   */
  sigc::signal<void, Queries> queries_updated;

private:
  HudImpl *pimpl_;
};

}
}

#endif /* UNITY_HUD_H */