~canonical-dx-team/unity/unity.fix-ql-losing-focus

701.2.1 by Gord Allott
initial places view
1
/*
2
 * Copyright (C) 2010 Canonical Ltd
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License version 3 as
6
 * published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 *
16
 * Authored by: Gordon Allott <gord.allott@canonical.com>
17
 */
18
19
#include "config.h"
20
21
#include "Nux/Nux.h"
22
#include "NuxGraphics/GLThread.h"
23
#include "UBusMessages.h"
24
697.4.48 by Neil Jagdish Patel
add launching of tiles
25
#include <gtk/gtk.h>
26
#include <gio/gdesktopappinfo.h>
27
697.4.5 by Neil Jagdish Patel
fix up test so it simply presents the places view
28
#include "ubus-server.h"
29
#include "UBusMessages.h"
30
697.4.13 by Neil Jagdish Patel
Some clean up of current work, make sure we're not using factory implementations directly
31
#include "PlaceFactory.h"
894.1.17 by Neil Jagdish Patel
Add the dash edges :)
32
#include "PlacesStyle.h"
697.4.13 by Neil Jagdish Patel
Some clean up of current work, make sure we're not using factory implementations directly
33
701.2.1 by Gord Allott
initial places view
34
#include "PlacesView.h"
35
697.4.12 by Neil Jagdish Patel
use ubus to request place entry activation
36
static void place_entry_activate_request (GVariant *payload, PlacesView *self);
37
701.2.4 by Gord Allott
fix for the weird offset + jay nux fixes
38
NUX_IMPLEMENT_OBJECT_TYPE (PlacesView);
39
822.1.14 by Neil Jagdish Patel
global search stuff
40
PlacesView::PlacesView (PlaceFactory *factory)
697.4.31 by Neil Jagdish Patel
more internal bits
41
: nux::View (NUX_TRACKER_LOCATION),
822.1.14 by Neil Jagdish Patel
global search stuff
42
  _factory (factory),
894.1.26 by Neil Jagdish Patel
Add support for dash Size Modes
43
  _entry (NULL),
44
  _size_mode (SIZE_MODE_FULLSCREEN)
701.2.1 by Gord Allott
initial places view
45
{
822.1.14 by Neil Jagdish Patel
global search stuff
46
  _home_entry = new PlaceEntryHome (_factory);
47
894.1.17 by Neil Jagdish Patel
Add the dash edges :)
48
  _layout = new nux::HLayout (NUX_TRACKER_LOCATION);
49
50
  nux::VLayout *vlayout = new nux::VLayout (NUX_TRACKER_LOCATION);
51
  _layout->AddLayout (vlayout, 1, nux::eCenter, nux::eFull);
52
894.1.26 by Neil Jagdish Patel
Add support for dash Size Modes
53
  _h_spacer= new nux::SpaceLayout (1, 1, 1, nux::AREA_MAX_HEIGHT);
54
  _layout->AddLayout (_h_spacer, 0, nux::eCenter, nux::eFull);
894.3.1 by Gord Allott
erm, bunch of stuff. support for keynav, woo
55
697.4.21 by Jay Taoko
* Fixed rendering, blending
56
  _search_bar = new PlacesSearchBar ();
894.1.17 by Neil Jagdish Patel
Add the dash edges :)
57
  vlayout->AddView (_search_bar, 0, nux::eCenter, nux::eFull);
697.2.2 by Neil Jagdish Patel
Beginnings of some places stuff
58
  AddChild (_search_bar);
894.1.17 by Neil Jagdish Patel
Add the dash edges :)
59
822.1.14 by Neil Jagdish Patel
global search stuff
60
  _search_bar->search_changed.connect (sigc::mem_fun (this, &PlacesView::OnSearchChanged));
822.1.1 by Neil Jagdish Patel
Fix blending (zomg), use layered layout
61
62
  _layered_layout = new nux::LayeredLayout (NUX_TRACKER_LOCATION);
894.1.17 by Neil Jagdish Patel
Add the dash edges :)
63
  vlayout->AddLayout (_layered_layout, 1, nux::eCenter, nux::eFull);
64
894.1.26 by Neil Jagdish Patel
Add support for dash Size Modes
65
  _v_spacer = new nux::SpaceLayout (1, nux::AREA_MAX_WIDTH, 1, 1);
66
  vlayout->AddLayout (_v_spacer, 0, nux::eCenter, nux::eFull);
894.3.1 by Gord Allott
erm, bunch of stuff. support for keynav, woo
67
697.2.7 by Neil Jagdish Patel
[merge] unity
68
  _home_view = new PlacesHomeView ();
822.1.1 by Neil Jagdish Patel
Fix blending (zomg), use layered layout
69
  _layered_layout->AddLayer (_home_view);
697.2.7 by Neil Jagdish Patel
[merge] unity
70
  AddChild (_home_view);
697.3.1 by Jay Taoko
* Fix text entry in places: need Nux trunk
71
697.4.39 by Neil Jagdish Patel
Some basic integration
72
  _results_controller = new PlacesResultsController ();
73
  _results_view = new PlacesResultsView ();
74
  _results_controller->SetView (_results_view);
822.1.1 by Neil Jagdish Patel
Fix blending (zomg), use layered layout
75
  _layered_layout->AddLayer (_results_view);
894.1.20 by Neil Jagdish Patel
updated assets and some other bits and bobs
76
  _results_view->GetLayout ()->OnGeometryChanged.connect (sigc::mem_fun (this, &PlacesView::OnResultsViewGeometryChanged));
697.4.39 by Neil Jagdish Patel
Some basic integration
77
822.1.4 by Neil Jagdish Patel
Lots of fixes in views
78
  _layered_layout->SetActiveLayer (_home_view);
79
884.2.3 by Jay Taoko
* Support for scrolling and keyboard navigation
80
  SetLayout (_layout);
697.4.12 by Neil Jagdish Patel
use ubus to request place entry activation
81
894.1.20 by Neil Jagdish Patel
updated assets and some other bits and bobs
82
  {
894.3.2 by Gord Allott
merged latest from neil
83
    nux::ROPConfig rop;
894.1.20 by Neil Jagdish Patel
updated assets and some other bits and bobs
84
    rop.Blend = true;
85
    rop.SrcBlend = GL_ONE;
86
    rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
87
    _bg_layer = new nux::ColorLayer (nux::Color (0.0f, 0.0f, 0.0f, 0.90f), true, rop);
88
  }
894.1.18 by Neil Jagdish Patel
Draw the background properly
89
697.4.12 by Neil Jagdish Patel
use ubus to request place entry activation
90
  // Register for all the events
91
  UBusServer *ubus = ubus_server_get_default ();
92
  ubus_server_register_interest (ubus, UBUS_PLACE_ENTRY_ACTIVATE_REQUEST,
93
                                 (UBusCallback)place_entry_activate_request,
94
                                 this);
697.4.33 by Neil Jagdish Patel
correct show active states for the places, had to disable search bar due to a crash
95
  ubus_server_register_interest (ubus, UBUS_PLACE_VIEW_CLOSE_REQUEST,
96
                                 (UBusCallback)&PlacesView::CloseRequest,
97
                                 this);
894.1.9 by Neil Jagdish Patel
Lots more clean up and first bits of making PlacesResultsController use the new stuff
98
  ubus_server_register_interest (ubus, UBUS_PLACE_TILE_ACTIVATE_REQUEST,
99
                                 (UBusCallback)&PlacesView::OnResultClicked,
100
                                 this);
829.2.1 by Neil Jagdish Patel
started to copy things into final implementation
101
102
  _icon_loader = IconLoader::GetDefault ();
822.1.14 by Neil Jagdish Patel
global search stuff
103
104
  SetActiveEntry (_home_entry, 0, "");
894.3.1 by Gord Allott
erm, bunch of stuff. support for keynav, woo
105
106
  //_layout->SetFocused (true);
701.2.1 by Gord Allott
initial places view
107
}
108
109
PlacesView::~PlacesView ()
110
{
822.1.14 by Neil Jagdish Patel
global search stuff
111
  delete _home_entry;
701.2.1 by Gord Allott
initial places view
112
}
113
697.4.12 by Neil Jagdish Patel
use ubus to request place entry activation
114
long
115
PlacesView::ProcessEvent(nux::IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
701.2.1 by Gord Allott
initial places view
116
{
867.2.5 by Neil Jagdish Patel
close dash when you click on home button
117
  // FIXME: This breaks with multi-monitor
118
  nux::Geometry homebutton (0.0f, 0.0f, 66.0f, 24.0f);
701.2.1 by Gord Allott
initial places view
119
  long ret = TraverseInfo;
867.2.4 by Neil Jagdish Patel
make escape close the dash
120
884.2.8 by Jay Taoko
* Code Cleanup
121
  if ((ievent.e_event == nux::NUX_KEYDOWN) &&
122
   (ievent.GetKeySym () == NUX_VK_ESCAPE))
867.2.4 by Neil Jagdish Patel
make escape close the dash
123
  {
124
    SetActiveEntry (NULL, 0, "");
867.2.5 by Neil Jagdish Patel
close dash when you click on home button
125
    return TraverseInfo;
126
  }
127
894.1.26 by Neil Jagdish Patel
Add support for dash Size Modes
128
  if (ievent.e_event == nux::NUX_MOUSE_PRESSED)
867.2.5 by Neil Jagdish Patel
close dash when you click on home button
129
  {
894.1.26 by Neil Jagdish Patel
Add support for dash Size Modes
130
    PlacesStyle      *style = PlacesStyle::GetDefault ();
131
    nux::BaseTexture *corner = style->GetDashCorner ();
132
    nux::Geometry     geo = GetGeometry ();
133
    nux::Geometry     fullscreen (geo.x + geo.width - corner->GetWidth () + 66,
134
                                  geo.y + geo.height - corner->GetHeight () + 24,
135
                                  corner->GetWidth (),
136
                                  corner->GetHeight ());
137
    if (fullscreen.IsPointInside (ievent.e_x, ievent.e_y))
884.2.8 by Jay Taoko
* Code Cleanup
138
    {
894.1.26 by Neil Jagdish Patel
Add support for dash Size Modes
139
      fullscreen_request.emit ();
894.1.27 by Neil Jagdish Patel
Don't load any icons that we don't need to
140
894.1.26 by Neil Jagdish Patel
Add support for dash Size Modes
141
      return TraverseInfo |= nux::eMouseEventSolved;
884.2.8 by Jay Taoko
* Code Cleanup
142
    }
867.2.4 by Neil Jagdish Patel
make escape close the dash
143
  }
871.4.3 by Neil Jagdish Patel
Some speed improvements and a simple tool for doing time calculations when your trying to do performance improvements
144
697.4.4 by Neil Jagdish Patel
Move to basewindow outside, but painting seems to be broken :(
145
  ret = _layout->ProcessEvent (ievent, ret, ProcessEventInfo);
701.2.1 by Gord Allott
initial places view
146
  return ret;
147
}
148
697.4.12 by Neil Jagdish Patel
use ubus to request place entry activation
149
void
894.1.17 by Neil Jagdish Patel
Add the dash edges :)
150
PlacesView::Draw (nux::GraphicsEngine& GfxContext, bool force_draw)
701.2.1 by Gord Allott
initial places view
151
{
894.1.17 by Neil Jagdish Patel
Add the dash edges :)
152
  PlacesStyle  *style = PlacesStyle::GetDefault ();
153
  nux::Geometry geo = GetGeometry ();
154
155
  GfxContext.PushClippingRectangle (geo);
156
894.1.18 by Neil Jagdish Patel
Draw the background properly
157
  nux::GetPainter ().PaintBackground (GfxContext, geo);
894.1.17 by Neil Jagdish Patel
Add the dash edges :)
158
159
  GfxContext.GetRenderStates ().SetBlend (true);
160
  GfxContext.GetRenderStates ().SetPremultipliedBlend (nux::SRC_OVER);
894.3.2 by Gord Allott
merged latest from neil
161
894.1.26 by Neil Jagdish Patel
Add support for dash Size Modes
162
  if (_size_mode == SIZE_MODE_HOVER)
894.1.17 by Neil Jagdish Patel
Add the dash edges :)
163
  {
164
    nux::BaseTexture *corner = style->GetDashCorner ();
165
    nux::BaseTexture *bottom = style->GetDashBottomTile ();
166
    nux::BaseTexture *right = style->GetDashRightTile ();
894.1.25 by Neil Jagdish Patel
Add the fullscreen toggle
167
    nux::BaseTexture *icon = style->GetDashFullscreenIcon ();
894.1.17 by Neil Jagdish Patel
Add the dash edges :)
168
    nux::TexCoordXForm texxform;
169
170
    {
894.1.18 by Neil Jagdish Patel
Draw the background properly
171
      nux::Geometry bg = geo;
172
      bg.width -= corner->GetWidth ();
173
      bg.height -= corner->GetHeight ();
174
175
      _bg_layer->SetGeometry (bg);
176
      nux::GetPainter ().RenderSinglePaintLayer (GfxContext, bg, _bg_layer);
177
    }
178
179
    {
894.1.17 by Neil Jagdish Patel
Add the dash edges :)
180
      texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
181
      texxform.SetWrap (nux::TEXWRAP_CLAMP_TO_BORDER, nux::TEXWRAP_CLAMP_TO_BORDER);
182
183
      GfxContext.QRP_1Tex (geo.x + (geo.width - corner->GetWidth ()),
184
                           geo.y + (geo.height - corner->GetHeight ()),
185
                           corner->GetWidth (),
186
                           corner->GetHeight (),
187
                           corner->GetDeviceTexture (),
188
                           texxform,
189
                           nux::Color::White);
190
    }
191
192
    {
894.1.25 by Neil Jagdish Patel
Add the fullscreen toggle
193
      GfxContext.QRP_1Tex (geo.x + geo.width - corner->GetWidth (),
194
                           geo.y + geo.height - corner->GetHeight (),
195
                           icon->GetWidth (),
196
                           icon->GetHeight (),
197
                           icon->GetDeviceTexture (),
198
                           texxform,
199
                           nux::Color::White);
200
    }
201
202
    {
894.1.17 by Neil Jagdish Patel
Add the dash edges :)
203
      int real_width = geo.width - corner->GetWidth ();
204
      int offset = real_width % bottom->GetWidth ();
205
206
      texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
207
      texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
208
209
      GfxContext.QRP_1Tex (geo.x - offset,
210
                           geo.y + (geo.height - bottom->GetHeight ()),
211
                           real_width + offset,
212
                           bottom->GetHeight (),
213
                           bottom->GetDeviceTexture (),
214
                           texxform,
215
                           nux::Color::White);
216
    }
217
218
    {
219
      int real_height = geo.height - corner->GetHeight ();
220
      int offset = real_height % right->GetHeight ();
221
222
      texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
223
      texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
224
225
      GfxContext.QRP_1Tex (geo.x +(geo.width - right->GetWidth ()),
226
                           geo.y - offset,
227
                           right->GetWidth (),
228
                           real_height + offset,
229
                           right->GetDeviceTexture (),
230
                           texxform,
231
                           nux::Color::White);
232
    }
233
  }
894.1.26 by Neil Jagdish Patel
Add support for dash Size Modes
234
  else
235
  {
236
    _bg_layer->SetGeometry (geo);
237
    nux::GetPainter ().RenderSinglePaintLayer (GfxContext, geo, _bg_layer);
238
  }
894.3.2 by Gord Allott
merged latest from neil
239
894.1.17 by Neil Jagdish Patel
Add the dash edges :)
240
  GfxContext.GetRenderStates ().SetBlend (false);
822.1.14 by Neil Jagdish Patel
global search stuff
241
242
  GfxContext.PopClippingRectangle ();
701.2.1 by Gord Allott
initial places view
243
}
244
245
697.4.12 by Neil Jagdish Patel
use ubus to request place entry activation
246
void
247
PlacesView::DrawContent (nux::GraphicsEngine &GfxContext, bool force_draw)
701.2.1 by Gord Allott
initial places view
248
{
822.1.14 by Neil Jagdish Patel
global search stuff
249
  GfxContext.PushClippingRectangle (GetGeometry() );
871.4.18 by Neil Jagdish Patel
Fix the drawing issue when results were updating, make everything in places SRC_OVER blended, and if not at least save the blending state. Stop flickering when painting
250
  GfxContext.GetRenderStates ().SetBlend (true);
251
  GfxContext.GetRenderStates ().SetPremultipliedBlend (nux::SRC_OVER);
894.3.1 by Gord Allott
erm, bunch of stuff. support for keynav, woo
252
894.1.18 by Neil Jagdish Patel
Draw the background properly
253
  nux::GetPainter ().PushLayer (GfxContext, _bg_layer->GetGeometry (), _bg_layer);
894.3.2 by Gord Allott
merged latest from neil
254
697.2.4 by Jay Taoko
* Fix rendering inside the Places.
255
  if (_layout)
256
    _layout->ProcessDraw (GfxContext, force_draw);
894.3.1 by Gord Allott
erm, bunch of stuff. support for keynav, woo
257
894.1.18 by Neil Jagdish Patel
Draw the background properly
258
  nux::GetPainter ().PopBackground ();
894.3.2 by Gord Allott
merged latest from neil
259
871.4.18 by Neil Jagdish Patel
Fix the drawing issue when results were updating, make everything in places SRC_OVER blended, and if not at least save the blending state. Stop flickering when painting
260
  GfxContext.GetRenderStates ().SetBlend (false);
822.1.14 by Neil Jagdish Patel
global search stuff
261
262
  GfxContext.PopClippingRectangle ();
701.2.1 by Gord Allott
initial places view
263
}
264
697.4.13 by Neil Jagdish Patel
Some clean up of current work, make sure we're not using factory implementations directly
265
//
266
// PlacesView Methods
267
//
268
void
697.4.52 by Neil Jagdish Patel
some fixes
269
PlacesView::SetActiveEntry (PlaceEntry *entry, guint section_id, const char *search_string, bool signal)
697.4.13 by Neil Jagdish Patel
Some clean up of current work, make sure we're not using factory implementations directly
270
{
822.1.18 by Neil Jagdish Patel
close dash when something is clicked
271
  if (signal)
272
    entry_changed.emit (entry);
273
822.1.14 by Neil Jagdish Patel
global search stuff
274
  if (entry == NULL)
275
    entry = _home_entry;
276
697.4.31 by Neil Jagdish Patel
more internal bits
277
  if (_entry)
697.4.38 by Neil Jagdish Patel
Connect up to the required bits
278
  {
697.4.31 by Neil Jagdish Patel
more internal bits
279
    _entry->SetActive (false);
822.1.4 by Neil Jagdish Patel
Lots of fixes in views
280
894.1.4 by Neil Jagdish Patel
Add support for basic place searching using the new stuff
281
    _group_added_conn.disconnect ();
282
    _result_added_conn.disconnect ();
283
    _result_removed_conn.disconnect ();
871.4.3 by Neil Jagdish Patel
Some speed improvements and a simple tool for doing time calculations when your trying to do performance improvements
284
697.4.45 by Neil Jagdish Patel
add support for clearing the results
285
    _results_controller->Clear ();
697.4.38 by Neil Jagdish Patel
Connect up to the required bits
286
  }
894.3.1 by Gord Allott
erm, bunch of stuff. support for keynav, woo
287
697.4.31 by Neil Jagdish Patel
more internal bits
288
  _entry = entry;
871.4.3 by Neil Jagdish Patel
Some speed improvements and a simple tool for doing time calculations when your trying to do performance improvements
289
822.1.14 by Neil Jagdish Patel
global search stuff
290
  _entry->SetActive (true);
871.4.3 by Neil Jagdish Patel
Some speed improvements and a simple tool for doing time calculations when your trying to do performance improvements
291
  _search_bar->SetActiveEntry (_entry, section_id, search_string, (_entry == _home_entry));
822.1.14 by Neil Jagdish Patel
global search stuff
292
894.1.4 by Neil Jagdish Patel
Add support for basic place searching using the new stuff
293
  _entry->ForeachGroup (sigc::mem_fun (this, &PlacesView::OnGroupAdded));
894.3.1 by Gord Allott
erm, bunch of stuff. support for keynav, woo
294
871.4.3 by Neil Jagdish Patel
Some speed improvements and a simple tool for doing time calculations when your trying to do performance improvements
295
  if (_entry != _home_entry)
894.1.4 by Neil Jagdish Patel
Add support for basic place searching using the new stuff
296
    _entry->ForeachResult (sigc::mem_fun (this, &PlacesView::OnResultAdded));
822.1.14 by Neil Jagdish Patel
global search stuff
297
894.1.4 by Neil Jagdish Patel
Add support for basic place searching using the new stuff
298
  _group_added_conn = _entry->group_added.connect (sigc::mem_fun (this, &PlacesView::OnGroupAdded));
299
  _result_added_conn = _entry->result_added.connect (sigc::mem_fun (this, &PlacesView::OnResultAdded));
300
  _result_removed_conn = _entry->result_removed.connect (sigc::mem_fun (this, &PlacesView::OnResultRemoved));
822.1.14 by Neil Jagdish Patel
global search stuff
301
302
  if (_entry == _home_entry && (g_strcmp0 (search_string, "") == 0))
303
    _layered_layout->SetActiveLayer (_home_view);
304
  else
822.1.12 by Neil Jagdish Patel
remove the unneeded result id stuff
305
    _layered_layout->SetActiveLayer (_results_view);
697.4.31 by Neil Jagdish Patel
more internal bits
306
}
307
308
PlaceEntry *
309
PlacesView::GetActiveEntry ()
310
{
311
  return _entry;
697.4.13 by Neil Jagdish Patel
Some clean up of current work, make sure we're not using factory implementations directly
312
}
313
697.4.40 by Neil Jagdish Patel
some more support for places
314
PlacesResultsController *
315
PlacesView::GetResultsController ()
316
{
317
  return _results_controller;
318
}
319
894.1.20 by Neil Jagdish Patel
updated assets and some other bits and bobs
320
void
321
PlacesView::OnResultsViewGeometryChanged (nux::Area *view, nux::Geometry& view_geo)
322
{
323
  if (view_geo.height >= _results_view->GetGeometry ().height)
324
  {
325
    ;
326
  }
327
  else
328
  {
329
    ;
330
  }
331
}
697.4.38 by Neil Jagdish Patel
Connect up to the required bits
332
894.1.26 by Neil Jagdish Patel
Add support for dash Size Modes
333
PlacesView::SizeMode
334
PlacesView::GetSizeMode ()
335
{
336
  return _size_mode;
337
}
338
339
void
340
PlacesView::SetSizeMode (SizeMode size_mode)
341
{
342
  PlacesStyle *style = PlacesStyle::GetDefault ();
343
344
  if (_size_mode == size_mode)
345
    return;
346
347
  _size_mode = size_mode;
348
349
  if (_size_mode == SIZE_MODE_FULLSCREEN)
350
  {
351
    _h_spacer->SetMinimumWidth (1);
352
    _h_spacer->SetMaximumWidth (1);
353
    _v_spacer->SetMinimumHeight (1);
354
    _v_spacer->SetMaximumHeight (1);
355
  }
356
  else
357
  {
358
    nux::BaseTexture *corner = style->GetDashCorner ();
359
    _h_spacer->SetMinimumWidth (corner->GetWidth ());
360
    _h_spacer->SetMaximumWidth (corner->GetWidth ());
361
    _v_spacer->SetMinimumHeight (corner->GetHeight ());
362
    _v_spacer->SetMaximumHeight (corner->GetHeight ());
363
  }
364
365
  QueueDraw ();
366
}
367
697.4.38 by Neil Jagdish Patel
Connect up to the required bits
368
//
369
// Model handlers
370
//
371
void
894.1.5 by Neil Jagdish Patel
Hook up global search to use the new stuff, we no longer leak Dee at all :)
372
PlacesView::OnGroupAdded (PlaceEntry *entry, PlaceEntryGroup& group)
894.1.4 by Neil Jagdish Patel
Add support for basic place searching using the new stuff
373
{
894.1.9 by Neil Jagdish Patel
Lots more clean up and first bits of making PlacesResultsController use the new stuff
374
  _results_controller->AddGroup (group);
894.1.4 by Neil Jagdish Patel
Add support for basic place searching using the new stuff
375
}
376
377
void
894.1.5 by Neil Jagdish Patel
Hook up global search to use the new stuff, we no longer leak Dee at all :)
378
PlacesView::OnResultAdded (PlaceEntry *entry, PlaceEntryGroup& group, PlaceEntryResult& result)
894.1.4 by Neil Jagdish Patel
Add support for basic place searching using the new stuff
379
{
697.4.53 by Neil Jagdish Patel
ignore available links
380
  //FIXME: We can't do anything with these do just ignore
894.1.4 by Neil Jagdish Patel
Add support for basic place searching using the new stuff
381
  if (g_str_has_prefix (result.GetURI (), "unity-install"))
697.4.53 by Neil Jagdish Patel
ignore available links
382
    return;
894.1.9 by Neil Jagdish Patel
Lots more clean up and first bits of making PlacesResultsController use the new stuff
383
384
  _results_controller->AddResult (group, result);
697.4.38 by Neil Jagdish Patel
Connect up to the required bits
385
}
386
387
void
894.1.5 by Neil Jagdish Patel
Hook up global search to use the new stuff, we no longer leak Dee at all :)
388
PlacesView::OnResultRemoved (PlaceEntry *entry, PlaceEntryGroup& group, PlaceEntryResult& result)
697.4.38 by Neil Jagdish Patel
Connect up to the required bits
389
{
697.4.53 by Neil Jagdish Patel
ignore available links
390
  //FIXME: We can't do anything with these do just ignore
894.1.4 by Neil Jagdish Patel
Add support for basic place searching using the new stuff
391
  if (g_str_has_prefix (result.GetURI (), "unity-install"))
697.4.53 by Neil Jagdish Patel
ignore available links
392
    return;
871.4.7 by Neil Jagdish Patel
Clean up adding/removing, fix some crashers, add UNITY_PLACES_DISABLE for disabling the file factory
393
894.1.9 by Neil Jagdish Patel
Lots more clean up and first bits of making PlacesResultsController use the new stuff
394
  _results_controller->RemoveResult (group, result);
697.4.38 by Neil Jagdish Patel
Connect up to the required bits
395
}
396
697.4.48 by Neil Jagdish Patel
add launching of tiles
397
void
894.1.9 by Neil Jagdish Patel
Lots more clean up and first bits of making PlacesResultsController use the new stuff
398
PlacesView::OnResultClicked (GVariant *data, PlacesView *self)
697.4.48 by Neil Jagdish Patel
add launching of tiles
399
{
400
  const char *uri;
401
894.1.9 by Neil Jagdish Patel
Lots more clean up and first bits of making PlacesResultsController use the new stuff
402
  uri = g_variant_get_string (data, NULL);
403
896 by Neil Jagdish Patel
[merge] Dash fixes + fix issue Mikkel noted
404
  if (!uri || g_strcmp0 (uri, "") == 0)
697.4.48 by Neil Jagdish Patel
add launching of tiles
405
  {
894.1.9 by Neil Jagdish Patel
Lots more clean up and first bits of making PlacesResultsController use the new stuff
406
    g_warning ("Unable to launch tile does not have a URI");
697.4.48 by Neil Jagdish Patel
add launching of tiles
407
    return;
408
  }
409
410
  if (g_str_has_prefix (uri, "application://"))
411
  {
412
    const char      *id = &uri[14];
413
    GDesktopAppInfo *info;
414
415
    info = g_desktop_app_info_new (id);
416
    if (G_IS_DESKTOP_APP_INFO (info))
417
    {
418
      GError *error = NULL;
419
420
      g_app_info_launch (G_APP_INFO (info), NULL, NULL, &error);
421
      if (error)
422
      {
423
        g_warning ("Unable to launch %s: %s", id,  error->message);
424
        g_error_free (error);
425
      }
426
      g_object_unref (info);
427
   }
428
  }
429
  else
430
  {
431
    GError *error = NULL;
432
    gtk_show_uri (NULL, uri, time (NULL), &error);
433
434
    if (error)
435
    {
436
      g_warning ("Unable to show %s: %s", uri, error->message);
437
      g_error_free (error);
438
    }
439
  }
697.4.52 by Neil Jagdish Patel
some fixes
440
441
  ubus_server_send_message (ubus_server_get_default (),
442
                            UBUS_PLACE_VIEW_CLOSE_REQUEST,
443
                            NULL);
697.4.48 by Neil Jagdish Patel
add launching of tiles
444
}
445
822.1.14 by Neil Jagdish Patel
global search stuff
446
void
447
PlacesView::OnSearchChanged (const char *search_string)
448
{
449
  if (_entry == _home_entry)
450
  {
451
    if (g_strcmp0 (search_string, "") == 0)
452
    {
453
      _layered_layout->SetActiveLayer (_home_view);
454
      _home_view->QueueDraw ();
455
    }
456
    else
457
    {
458
      _layered_layout->SetActiveLayer (_results_view);
459
      _results_view->QueueDraw ();
460
    }
461
462
    _results_view->QueueDraw ();
463
    _home_view->QueueDraw ();
464
    _layered_layout->QueueDraw ();
465
    QueueDraw ();
466
  }
467
}
468
697.4.13 by Neil Jagdish Patel
Some clean up of current work, make sure we're not using factory implementations directly
469
//
470
// UBus handlers
471
//
697.4.12 by Neil Jagdish Patel
use ubus to request place entry activation
472
void
473
PlacesView::PlaceEntryActivateRequest (const char *entry_id,
474
                                       guint       section_id,
475
                                       const char *search_string)
476
{
697.4.13 by Neil Jagdish Patel
Some clean up of current work, make sure we're not using factory implementations directly
477
  std::vector<Place *> places = PlaceFactory::GetDefault ()->GetPlaces ();
478
  std::vector<Place *>::iterator it;
822.1.14 by Neil Jagdish Patel
global search stuff
479
480
  if (g_strcmp0 (entry_id, "PlaceEntryHome") == 0)
481
  {
482
    SetActiveEntry (_home_entry, section_id, search_string);
483
    return;
484
  }
894.3.1 by Gord Allott
erm, bunch of stuff. support for keynav, woo
485
697.4.13 by Neil Jagdish Patel
Some clean up of current work, make sure we're not using factory implementations directly
486
  for (it = places.begin (); it != places.end (); ++it)
487
  {
488
    Place *place = static_cast<Place *> (*it);
489
    std::vector<PlaceEntry *> entries = place->GetEntries ();
490
    std::vector<PlaceEntry *>::iterator i;
491
492
    for (i = entries.begin (); i != entries.end (); ++i)
493
    {
494
      PlaceEntry *entry = static_cast<PlaceEntry *> (*i);
495
496
      if (g_strcmp0 (entry_id, entry->GetId ()) == 0)
497
      {
498
        SetActiveEntry (entry, section_id, search_string);
499
        return;
500
      }
501
    }
502
  }
503
504
  g_warning ("%s: Unable to find entry: %s for request: %d %s",
505
             G_STRFUNC,
506
             entry_id,
507
             section_id,
508
             search_string);
697.4.12 by Neil Jagdish Patel
use ubus to request place entry activation
509
}
510
697.4.33 by Neil Jagdish Patel
correct show active states for the places, had to disable search bar due to a crash
511
void
512
PlacesView::CloseRequest (GVariant *data, PlacesView *self)
513
{
514
  self->SetActiveEntry (NULL, 0, "");
515
}
516
884.2.3 by Jay Taoko
* Support for scrolling and keyboard navigation
517
nux::TextEntry*
518
PlacesView::GetTextEntryView ()
519
{
520
  return _search_bar->_pango_entry;
521
}
522
697.4.13 by Neil Jagdish Patel
Some clean up of current work, make sure we're not using factory implementations directly
523
//
524
// Introspection
525
//
701.2.1 by Gord Allott
initial places view
526
const gchar *
527
PlacesView::GetName ()
528
{
529
  return "PlacesView";
530
}
531
532
void
533
PlacesView::AddProperties (GVariantBuilder *builder)
534
{
697.2.2 by Neil Jagdish Patel
Beginnings of some places stuff
535
  nux::Geometry geo = GetGeometry ();
536
537
  g_variant_builder_add (builder, "{sv}", "x", g_variant_new_int32 (geo.x));
538
  g_variant_builder_add (builder, "{sv}", "y", g_variant_new_int32 (geo.y));
539
  g_variant_builder_add (builder, "{sv}", "width", g_variant_new_int32 (geo.width));
894.3.1 by Gord Allott
erm, bunch of stuff. support for keynav, woo
540
  g_variant_builder_add (builder, "{sv}", "height", g_variant_new_int32 (geo.height));
697.4.12 by Neil Jagdish Patel
use ubus to request place entry activation
541
}
542
543
//
544
// C glue code
545
//
546
static void
547
place_entry_activate_request (GVariant *payload, PlacesView *self)
548
{
549
  gchar *id = NULL;
550
  guint  section = 0;
551
  gchar *search_string = NULL;
552
553
  g_return_if_fail (self);
554
555
  g_variant_get (payload, "(sus)", &id, &section, &search_string);
556
557
  self->PlaceEntryActivateRequest (id, section, search_string);
558
559
  g_free (id);
560
  g_free (search_string);
701.2.1 by Gord Allott
initial places view
561
}
884.2.3 by Jay Taoko
* Support for scrolling and keyboard navigation
562