LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
dimensionslauncher.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2010-2013 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef DIMENSIONSLAUNCHER_H_
23 #define DIMENSIONSLAUNCHER_H_
24 
25 #include <QUuid>
26 #include <QRectF>
27 #include <QVector>
28 #include <QList>
29 #include <QSet>
30 #include <QEvent>
31 
32 #include "groupanchoritem.h"
33 #include "dimensionstypes.h"
34 #include "icon.h"
35 #include "page.h"
36 #include "vcamera.h"
37 #include "appmonitor.h"
38 #include "pagetab.h"
39 
40 class DimensionsUI;
41 class Page;
42 class PageTabBar;
43 class AlphabetPage;
44 class ReorderablePage;
46 
47 class QGraphicsSceneMouseEvent;
48 class QGesture;
49 class QGestureEvent;
50 class QTouchEvent;
51 class QPanGesture;
52 class QSwipeGesture;
53 class QPinchGesture;
54 class QTapAndHoldGesture;
55 class QTapGesture;
56 class QAnimationGroup;
57 class QEvent;
58 class QDeclarativeComponent;
59 
60 class PixmapButton;
61 class PixButton2State;
63 class OverlayLayer;
64 
65 namespace DimensionsSystemInterface
66 {
67 class ExternalApp;
68 class WebOSApp;
69 class PageSaver;
70 class PageRestore;
71 }
72 
73 namespace LauncherAreas
74 {
75  enum Enum
76  {
83  LauncherEther //nowhere in particular
84  };
85 }
86 
88 {
89  Q_OBJECT
90 public:
93 };
94 
96 {
97  Q_OBJECT
98 public:
101 };
102 
104 {
105  Q_OBJECT
106 public:
108  {
114  };
116  : m_qp_srcPage(p_srcPage) , m_qp_icon(p_icon) , m_direction(d) , m_targetPageIndex(-1) { m_valid = true; }
118  : m_qp_srcPage(p_srcPage) , m_qp_icon(p_icon) , m_direction(d) , m_targetPageIndex(targetPageIndex) { m_valid = true; }
120  QPointer<Page> m_qp_srcPage;
121  QPointer<IconBase> m_qp_icon;
124 
125  static QString dbgDirectionToString(Direction d)
126  {
127  switch (d)
128  {
130  return QString("Left");
132  return QString("Right");
134  return QString("QuickLaunch");
136  return QString("TabBar");
138  default:
139  return QString("INVALID");
140  }
141  return QString("INVALID?");
142  }
143 };
144 
146 {
147  Q_OBJECT
148  Q_INTERFACES(QGraphicsItem)
149  Q_PROPERTY(quint32 numPages READ numPages)
150 
151 public:
152 
153  friend class Page;
154  friend class DimensionsSystemInterface::PageSaver;
155  friend class DimensionsSystemInterface::PageRestore;
156  friend class VirtualCamera;
157 
158  //TODO: should make this return a const obj, and assure all functions that are useful to the outside are const as well
159  // or, DimensionsUI could be a proper singleton...but that precludes some eeeevil, advanced ideas I have for it....
160  static LauncherObject * primaryInstance();
161 
162  LauncherObject(const QRectF& geometry,DimensionsUI * p_mainWindow);
163  virtual ~LauncherObject();
164 
165  //returns the app uid, or QUuid() (nonvalid) if no such icon exists
166  QUuid appUidFromIconUid(const QUuid& iconUid) const;
167  QRectF areaTabBar() const;
168  QRectF areaQuickLaunchBar() const;
169  QRectF areaPageLeftSide(Page * pPage=0) const;
170  QRectF areaPageRightSide(Page * pPage=0) const;
171  //uid should be an icon uid, but if an app uid is provided, the app's main icon uid will be used automatically
172  bool canShowRemoveDeleteDecoratorOnIcon(const QUuid& uid);
173  qint32 centerPageIndex() const; //-1 if nothing is currently center or the ui is not currently static (i.e. it's animating pages)
174  bool checkAllowedIconTransferInterPage(Page * p_srcPage,Page * p_destPage,IconBase * p_icon);
175  LauncherAreas::Enum classifyPageLocation(const QPointF& launcherCoordinate) const;
176  qint32 closestToCenter(qint32& r_dist) const; //-1 if no pages, r_dist unspecified
177  qint32 closestToCenterDistance() const; // 0 if no pages
178  qint32 closestToCenterPageIndex() const; //-1 if no pages
179  //called when the ui finally gets information about the max-visible-area size
180  //this can only be done once, while the m_geom rect is w,h == 0. After that,
181  //I can resize() but not do this init anymore
182  void fullSizeInit(quint32 width,quint32 height);
183  quint32 horizontalLengthOfPageTrain() const;
184  //returns the icon uid of the primary (default) launch point, or QUuid() (nonvalid) if no such app exists
185  QUuid iconUidFromAppUid(const QUuid& appUid) const;
186  //uid can be either an app uid or an icon uid (that belongs to an app). The function will do the right thing regardless, automatically.
187  bool isAppRemovable(const QUuid& uid);
188  quint32 numPages() const;
189  virtual bool offer(Thing * p_offer,Thing * p_offeringThing);
190  qint32 pageHorizontalOffsetToCenter(quint32 pageIndex) const;
191  Page * currentPage() const;
192  Page * pageLeft(Page * p_fromPage) const;
193  Page * pageRight(Page * p_fromPage) const;
194  virtual void resize(int w, int h);
196  void sendIconToQuickLaunchBar(IconBase * p_icon);
197  PageTab * tabForPage(Page * p_page) const;
198  virtual bool take(Thing * p_takerThing);
199  virtual void taken(Thing * p_takenThing,Thing * p_takerThing);
200  virtual bool taking(Thing * p_victimThing, Thing * p_takerThing);
201  Page * testForIntersectOnPageTab(const QPointF& scenePosition,PageTab ** r_p_tabForPage=0);
202  bool testForIntersectPageArea(const QPointF& scenePosition);
203  qint32 testForIntersectPageAreaAndPageActive(const QPointF& scenePosition); //-1 if no page active (in center) or param not in page area; center/active index otherwise
204 
205 
206 
207 
208 
209  virtual bool event(QEvent * e);
210 
211  //TODO: TEMP: EXPERIMENTAL:
212  VirtualCamera * virtualCamera() { return &m_dbg_vcam; }
213 
214  static QSize LauncherSizeFromScreenSize(quint32 width,quint32 height);
215 
216 
217  //TODO: HACK: makes the temp. way of communicating icon txfer context, opaque
218  static bool wasIconDroppedOnTab(IconBase * p_icon);
219  static bool wasIconMovedOntoPage(IconBase * p_icon);
220  static void clearIconTxContext(IconBase * p_icon);
221  static void setIconTxContextDroppedOnTab(IconBase * p_icon);
222  static void setIconTxContextMovedOntoPage(IconBase * p_icon);
223 
224 public Q_SLOTS:
225 
226  void slotAppScanCompleted(bool initialScan=false);
227 
228  //prior to the appmonitor deleting all the app structures
230  //post appmonitor deleting all the app structures
232 
233  void slotAppAuxiliaryIconRemove(const QUuid& appUid,
234  const QString& launchpointId,
236 
237  //for adding the full app to the launcher; this particular slot is used when the app scan has already completed and all those apps have already been added;
238  // the other time that it would trigger is when the installer started installing a new app sometime after that
240 
241  void slotAppAuxiliaryIconAdd(const QUuid& appUid,
242  const QUuid& newLaunchPointIconUid,
244 
245  //this will destory the current page state (i.e. delete all pages that are currently
246  // set up and replace them with what was saved)
248 
249  //immediately saves the entire launcher state w.r.t. pages
250  void slotSavePages();
251  void slotIconActivatedTap(IconBase* pIcon);
252 
253  //TODO: TEMP: shortcutting for now to get to the page quicker.
254  // replace this with uid of page and a lookup...
255  void slotTabActivatedTap(Page * tabRelatedPage);
256  void slotTabActivatedTapAndHold(Page * tabRelatedPage);
257 
258  //This will create and attempt an animation to the given page index
259  // It will not interrupt currently running animations; it will just silently not do anything
260  void slotGotoPageIndex(quint32 pageIndex);
261  //the no animation version.
262  // It will not interrupt currently running animations; it will just silently not do anything
263  void slotGotoPageIndexNoAnim(quint32 pageIndex);
264  //this are simplified variants to just move 1 page left or right
265  // (same restrictions and behaviors apply as the others. They do animate)
266  // if already at left or right -most pages, they do nothing
267  void slotGotoLeftPage();
268  void slotGotoRightPage();
269 
270  //called when the system (overlay window manager in the current sys version) is showing the launcher
271  // DO NOT rely on this being called before or after it is actually visually showing. If that is what's needed
272  // implement a new function for it
274  //called when the system is hiding the launcher from view
275  // again, DO NOT rely on a particular time that this is called; before or after the visual hide
277 
278  //called when system is showing/hiding something ON TOP of the launcher (usually Just Type/Quick search)
279  // same conditions as slotSystemShowingLauncher....
282 
283  //TODO: it's all or nothing; either all the pages are in reorder or none of 'em
287 
290 
291  void slotLauncherFullyOpen();
293 
295 // These are always to be connected with QueuedConnection as the connection type param to connect()
296 // This will NOT be enforced by language features, so it must be respected by convention
297 public Q_SLOTS:
298 
299  // cmdRequest should be cast as IconActionRequest::Enum (see iconbase.h). if p_iconSource = 0, then sender() will be used to get the icon source
300  virtual void slotIconActionRequest(int cmdRequest,IconBase * p_iconSource=0);
301 
303 
304 
305 
306 Q_SIGNALS:
307 
308  void signalGeometryChange();
309  void signalNumPagesChanged();
310  void signalUiStateChanged();
311 
312  void signalReady();
313  void signalNotReady();
314 
317 
318  //parameter: the launchpoint id (from ApplicationManager land; the external world) of the icon to send
319  void signalDropIconOnQuicklaunch(const QString&);
320 
322  void signalPageCentered(QUuid pageUid);
323 
326 
327  //these are for the page panning control mechanism
328  void signalPagePanLeft();
329  void signalPagePanRight();
330  void signalPageMovementEnd();
331 
332  /* These two are necessary to protect/synchronize touch propagation and interactions when the various layers of the launcher are visible....
333  The problem is that some of the layers of the launcher, such as the app info dialog, can be effectors on the lower layers, such as the pages. An instance of this is
334  when the app info dialog removes an app: touches/gestures to the app dialog can effect the page below (due to touch propagation in Qt) but the "remove" also effects the
335  page and page layouts since it reorders the icons. This can lead to potential problems. Thus, the launcher object will be given the power to block page interactions when necessary
336  */
339 
340 protected:
341 
342  void blockPageInteraction();
343  void restorePageInteraction();
344 
345  void appDeleteDecoratorActivated(DimensionsSystemInterface::ExternalApp * p_eapp,const QUuid& iconUid);
346  void showAppInfoDialog(const QString& dialogTitle,
347  const QString& innerText,
348  const QString& appIdContext,
349  const QUuid& iconUid,
350  bool showRemoveButton,
351  const QPointF& dialogPos = QPointF());
352  void hideAppInfoDialog(bool ignoreInvisible=false,bool noAnimation=false);
353  bool appInfoDialogIsVisible() const;
354 
355  virtual bool touchEvent(QTouchEvent * event) { return true; }
356  virtual bool touchStartEvent(QTouchEvent *event) { return true; }
357  virtual bool touchUpdateEvent(QTouchEvent *event) { return true; }
358  virtual bool touchEndEvent(QTouchEvent *event) { return true; }
359 
360  virtual bool sceneEvent(QEvent * event);
361  virtual bool gestureEvent(QGestureEvent *gestureEvent) { return true; }
362  virtual bool panGesture(QPanGesture *panEvent) { return true; }
363  virtual bool swipeGesture(QSwipeGesture *swipeEvent) { return true; }
364  virtual bool flickGesture(FlickGesture *flickEvent,QGestureEvent * baseGestureEvent);
365  virtual bool pinchGesture(QPinchGesture *pinchEvent) { return true; }
366  virtual bool tapAndHoldGesture(QTapAndHoldGesture *tapHoldEvent) { return true; }
367  virtual bool tapGesture(QTapGesture *tapEvent) { return true; }
368  virtual bool customGesture(QGesture *customGesture) { return true; }
369 
370 protected Q_SLOTS:
371 
373  void slotStopAnimationEnsemble(bool * r_result=0);
374  void slotStartAnimationEnsemble(bool canInterrupt=true);
376  void slotAddAnimationTo(QAnimationGroup * p_addToGroup,QAbstractAnimation * p_anim,DimensionsTypes::AnimationType::Enum animType = DimensionsTypes::AnimationType::None);
377 
379 
380  //Since gestures can't seem to be redirected during the final, GestureComplete stage, I have to do it this way
381  //WARNING: This gesture object and event does NOT belong to me in here! don't do anything but read from it
382  //TODO: perhaps make this safer by only sending relevant details as params, like hot spot and velocity
383  void slotRedirectedFlick(FlickGesture *flickEvent,QGestureEvent * baseGestureEvent);
384 
385  void slotAppInfoDialogRemoveButtonPressed(const QString& appIdContext,const QString& iconUidAsString);
387 
389 
390  void slotDbgPageSaverDebugProcessDone(int exitCode);
391 
393 public:
394 
395  virtual void redirectedTouchTrackedPointMoved(Thing * p_sourceThing,int id,const QPointF& scenePosition,const QPointF& lastScenePosition,const QPointF& initialPosition,const RedirectContext& redirContext);
396  virtual void redirectedTouchTrackedPointReleased(Thing * p_sourceThing,int id,const QPointF& scenePosition,const QPointF& lastScenePosition,const QPointF& initialPosition,const RedirectContext& redirContext);
397 
398  virtual void redirectedTTPMovedLimbo(Thing * p_sourceThing,int id,const QPointF& scenePosition,const QPointF& lastScenePosition,const QPointF& initialPosition,const RedirectContext& redirContext);
399  virtual void redirectedTTPReleasedLimbo(Thing * p_sourceThing,int id,const QPointF& scenePosition,const QPointF& lastScenePosition,const QPointF& initialPosition,const RedirectContext& redirContext);
400 
401 protected:
402 
403  virtual void touchTrackedPointMoved(int id,const QPointF& scenePosition,const QPointF& lastScenePosition,const QPointF& initialPosition);
404  virtual void touchTrackedPointReleased(int id,const QPointF& scenePosition,const QPointF& lastScenePosition,const QPointF& initialPosition);
405 
406  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option=0,QWidget *widget=0);
407  virtual void paintOffscreen(QPainter *painter);
408  void paintBackground(QPainter * painter);
409 
410  bool isAnimationEnsembleRunning() const;
411  //this one will return whether or not an immediate call to stopAnimationEnsemble will succeed
412  bool canStopAnimationEnsemble() const;
413  bool stopAnimationEnsemble();
414 
415  QList<QPointer<Page> > pages() const;
416  quint32 initPages();
417 
418  //and these are the helpers
422 
424  // in effect (see OperationalSettings). It does not do anything about apps that already exist nor does it modify any app uid maps
425  // here in the launcherobject.
427  //these two are the helpers to pageIndexForApp
428  bool pageIndexForAppByLoadedMappings(const DimensionsSystemInterface::ExternalApp& eapp,quint32& r_index); //see OperationalSettings (look at info for the 'preferAppKeywordsForAppPlacement' key)
429  bool pageIndexForAppByPredefinedDesignators(const DimensionsSystemInterface::ExternalApp& eapp,quint32& r_index); //see OperationalSettings...
430 
431 //GEMSTONE-RD
432 // quint32 addDefaultPages();
433 //GEMSTONE-RD
434 
436 
437  //if ignoreRestoredPageIndex = true, then all restored pages are appended instead of inserted
438  // into the list at index positions that were saved with the page
439  quint32 addRestoredPages(bool ignoreRestoredPageIndex=false);
440  //special case utility fn to create a favorites page with all available icons
441  // returns null if the page can't be created
443  //...and the version that creates a blank favorites
445 
446  //another special case utility fn to create an initial layout of launcher3 pages.
447  // This one will create pages with icons as defined and implemented in
448  // pageIndexForApp , pageIndexForAppByLoadedMappings , and/or pageIndexForAppByPredefinedDesignators
449  // Essentially, it will create N pages, as defined in OperationalSettings::appKeywordsToPageDesignatorMapFilepath
450  // and then go through all the currently registered apps, placing each on the page that the decision logic of the aforementioned functions
451  // decides.
452  // The parameter leftoverIconsToIndex will place all the apps that didn't map to anything explicitly into that index.
453  // if the index passed in is invalid, it will default to 0 (again, 1 page must always exist, so that will be index 0)
454  QList<Page *> dynamicMultiPageConfiguration();
455 
456  // ..and this variant will read in the configuration from a file.
457  QList<Page *> staticMultiPageConfiguration();
458 
459  //never use these on their own...they're meant to be used from within e.g. staticMultiPageConfiguration
460  QList<Page *> helperCreatePagesFromConfiguration(QList<QPair<QString,QList<QString> > >& staticLauncherConfig);
462  const QString& pageDesignator,const QList<QString>& webosAppLaunchPointIdList);
463 
464  //goes through the launcher's icon registry, and any icon that hasn't been placed on a page is assigned according
465  // to the policies in place (see pageIndexForApp )
466  qint32 assignLeftoversToPages();
467 
468  //PREREQUISITE: pages must all be loaded
469  //RESULT: the page designated in the layout settings as "startOnPageDesignated" will be in the center and active
470  // returns false if the page specified in the settings couldn't be set as the center (probably) because it wasn't found)
471  // true if it was set, including if no startup page was specified in settings
472  // NOTE: no animation takes place. This is an insta-set by repositioning the horizontal anchor. So don't do it if the launcher ui is visible
473  bool setStartupPage();
474 
475  //shortcuts to the special pages - it doesn't create any pages. Returns null is no such special page was created
476 
478  ReorderablePage * pageByDesignator(const QString& designator);
479 
480  void eraseAllLauncherFiles() const;
481 
482  ReorderablePage * pageByUid(const QString& uidString);
483  //
484 
485  bool isLaunchpointAssignedToSomePage(const QUuid& uid) const;
486  void launchPointAssigned(const QUuid& uid);
487 
488  // will reinitialize the tab bar
489  bool createTabsForAllPages();
490 
491  void activateCenterPage();
492  void deactivateCenterPage();
493 
494  //these two active___() are used in conjunction with slotPageModeChanged()
497 
498  void initObjects();
500 
501  //see the "slot" versions of these for info (the same name, just slot prepended)
502  bool gotoPageIndex(quint32 pageIndex, qint32 xSpeed = 0, bool canInterrupt = false);
503  bool gotoPageIndexNoAnim(quint32 pageIndex);
504  bool gotoLeftPage(qint32 xSpeed = 0);
505  bool gotoRightPage(qint32 xSpeed = 0);
506 
507  void _animationFinishedProcessGroup(QAnimationGroup * pAnim);
508  void _animationFinishedProcessAnim(QAbstractAnimation * pAnim);
509  void _pageFinishedAddAnim(Page * p_page);
510  void _pageFinishedHPanAnim();
511  void _pageAddDirect(Page * p_page,quint32 idx);
512 
513 
514  //work in conjunction with take/taken system to temporarily own and manage icons during reorders and other transitions that have the icon
515  // in-flight
516  void acceptIncomingIcon(IconBase * p_icon);
517  void releaseIcon(IconBase * p_icon);
518  IconBase * getIconInLimbo(const QUuid& iconUid);
519  bool iconLimboContains(const QUuid& iconUid);
520  bool iconLimboContains(IconBase * p_icon);
521 
523 
524  void setAppLaunchFeedback(IconBase* pIcon);
525  void cancelLaunchFeedback();
526 
527  // ------------------- APP HANDLING ----------------------------------//
528 
529  //on a successful return (true), r_iconList contains all the icons that were mapped into the app<->icon translation maps
530  bool processNewWebOSApp(DimensionsSystemInterface::WebOSApp * p_app,bool mainIconOnly,IconList& r_iconList);
532 
533  //removes an icon with the given uid from any page currently in the launcher object
534  // does not call any other cleanup function in the launcher object (e.g. removeIconUidFromMaps) on its own
535  void removeIconFromPages(IconBase * p_icon);
536 
537  //will not remove any of its copies. it *will* take care of the reverse map too, if it's a "main"/primary icon
538  // if the appid is given as a hint, then the reverse map can be more quickly processed
539  void removeIconUidFromMaps(const QUuid& iconUid,const QUuid& optAppUid = QUuid());
540 
541  //adds this icon to the given page. Make sure that the icon doesn't already belong to any other page. If it does, then make a clone first
542  // and pass that in. This is will NOT be enforced in code and is by convention
543  // this function doesn't do any automatic adjustments to the structures on this object, e.g. the app->icon uid maps, etc
544  void addIconToPage(IconBase * p_icon,Page * p_page);
545 
546  // ------------------- DEBUG: /////////////////////////////////////////
547 
549  void dbgPageVectorContents();
550 
551 protected:
552 
553  QPointer<DimensionsUI> m_qp_mainWindow;
554  static QPointer<LauncherObject> s_qp_primaryInstance;
556 
558  QPointer<PixmapObject> m_qp_background;
561 
563  QRectF m_currentPageGeom; //pre-computed from m_currentPageSize
564  QPointF m_currentPagePos; //pre-computed, relative to where the pagetab and quicklaunch bar are located
566  QRectF m_currentPageRightBorderArea; // these two also pre-computed; they're for the icon page->page movement detection
567  // (they are basically a guideline of where the page left/right "hot" area for movement detect.
568  // WOULD be if a page of m_currentPageGeom geometry was in the center (active)
569  // For the actual left/right rect of a page in the system, ask the page itself (e.g. Page::areaLeftBorder()) )
570 
571  QList<QPointer<Page> > m_pages;
572  //this is wrong...qset shouldnt have a qp item
573  QSet<QPointer<Page> > m_pageLimbo; //anything temporarily floating
574  QMap<QUuid,QPointer<IconBase> > m_iconLimbo; // icons that are temporarily the property of the launcher
575 
579 
580  QPointer<PageTabBar> m_qp_pageTabBar;
581  QPointer<QAnimationGroup> m_qp_ensembleAnimation;
582 
583  QPointer<PixButton2State> m_qp_doneButton;
584  QPointer<ColorRoundRectButton> m_qp_testButton;
585 
586  QPointer<OverlayLayer> m_qp_overlay;
587 
588  QDeclarativeComponent* m_qmlAppInfoDialog;
589 
591 
595 
597 
599 
600  // ------------------- APP HANDLING ----------------------------------//
601 
602  typedef QMap<QUuid,QUuid> UidTranslationMap;
603  typedef UidTranslationMap::iterator UidTranslationMapIter;
604  typedef UidTranslationMap::const_iterator UidTranslationMapConstIter;
606  UidTranslationMap m_appMapByAppUid; //reverse map - only for the main icon. So, app uid -> main icon uid //TODO: bad naming; rename so it's more clear
607 
609  // assignments when the leftovers get assigned
610  // the set stores launchpoint uids. Right now, these are icon uids of the primary app icon.
611  // but this can easily just be swapped for whatever uid->lpoint mapping desired
612  // After all icons are assigned, this set is empty and should represent a very minimal memory impact/cost
613 
615 
618 
619 protected Q_SLOTS:
620 
621  void dbg_slotTriggerCamera(ThingPaintable * excludeMe);
622  void dbg_slotPrint();
623 
624 };
625 
626 #endif /* DIMENSIONSLAUNCHER_H_ */