coremethods.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #ifndef MENU_H
  2. #define MENU_H
  3. #include <QtCore>
  4. #include <QAction>
  5. #include <QString>
  6. #include <QWidget>
  7. #include <QMap>
  8. #include <QSet>
  9. #include "hybridfw_global.h"
  10. class QMainWindow;
  11. class QWebFrame;
  12. class HybridPluginManager;
  13. class MenuItem : public QObject
  14. {
  15. Q_OBJECT
  16. public:
  17. MenuItem(const QString& label, const int id, const int parentId, const QString &handlerFunction, QAction *qAction) :
  18. m_label(label),
  19. m_id(id),
  20. m_parentId(parentId),
  21. m_handlerFunction(handlerFunction),
  22. m_qAction(qAction)
  23. {}
  24. QString m_label;
  25. int m_id;
  26. int m_parentId;
  27. QString m_handlerFunction;
  28. QAction *m_qAction;
  29. };
  30. class DLL_EXPORT CoreMethods : public QObject
  31. {
  32. Q_OBJECT
  33. public:
  34. CoreMethods(QMainWindow *parentWindow,
  35. QWebFrame *webFrame,
  36. HybridPluginManager* pluginManager,
  37. QString identifier);
  38. signals:
  39. /**
  40. * Signal when item is selected,
  41. *
  42. * @param id Id of the selected item.
  43. */
  44. void itemSelected(int id);
  45. /**
  46. * Signal when menu is shown.
  47. */
  48. void menuOnShow();
  49. public slots:
  50. /**
  51. * Call the appendMenuItem method to add a menu item to the top level of the options menu list.
  52. *
  53. * Call the append method to add a child menu item to the parent menu item in the options menu list.
  54. * This results in the creation of a submenu list in the menu tree. Use this method to create a cascading submenu when needed.
  55. *
  56. * Menu items are shown on the options menu list in the order in which they are appended.
  57. *
  58. * @param label A text string that defines the label for the menu item.
  59. * @param id A unique integer that identifies the menu item.
  60. * @param parentId A unique integer that identifies the parent menu item, 0 if no parent exists.
  61. * @param onSelect Name of the event handler for the event of when the menu item is selected.
  62. */
  63. void appendMenuItem(const QString &label, const int id, const int parentId, const QString &onSelect);
  64. /**
  65. * Call the setDimmed method to show or hide an existing menu item.
  66. * By default, a menu item is shown when it is appended to the options menu.
  67. *
  68. * @param id The id of the menu item to be hidden or shown
  69. * @param flag True to hide the menu item, and false to show the menu item.
  70. */
  71. void setDimmed(const int id, bool flag);
  72. /**
  73. * Call the remove method to remove a menu item and its children (if any).
  74. *
  75. * @param id The id of the menu item to be removed
  76. */
  77. void remove(const int id);
  78. /**
  79. * Call the clear method to delete all the menu items in the options menu pane.
  80. * This operation will also clear all submenus if such exist.
  81. *
  82. */
  83. void clear();
  84. /**
  85. * Call the showSoftkeys method to display the softkey pane at all times.
  86. *
  87. */
  88. void showSoftkeys();
  89. /**
  90. * Call the hideSoftkeys method to hide the softkey pane.
  91. *
  92. */
  93. void hideSoftkeys();
  94. /**
  95. * Call the setLeftSoftkeyLabel method to customize the label and the operation associated with the left softkey.
  96. *
  97. * By default, the left softkey of a device is assigned to the "Options" function, which invokes a list of menu items.
  98. * The default label depends on the current used system language (Options for English).
  99. *
  100. * @param label A text string specifies the label to be shown on the left softkey.
  101. * @param callbackfunc A reference to the callback function, which will be called by the system when the left softkey is pressed.
  102. */
  103. void setLeftSoftkeyLabel(const QString &label, const QString &callbackfunc);
  104. /**
  105. * Call the setRightSoftkeyLabel method to customize the label and the operation associated with the right softkey.
  106. *
  107. * By default, the right softkey of a device is assigned to the "Exit" function, which terminates a running widget.
  108. * The default label depends on the current used system language (Exit for English).
  109. *
  110. * @param label A text string specifies the label to be shown on the right softkey.
  111. * @param callbackfunc A reference to the callback function, which will be called by the system when the right softkey is pressed.
  112. */
  113. void setRightSoftkeyLabel(const QString &label, const QString &callbackfunc);
  114. void menuHandler();
  115. void menuItemHandler();
  116. void customSoftkeyHandler();
  117. void debugLog(const QString &line);
  118. /**
  119. * The setPreferenceForKey method allows a key to be stored along with its associated preference.
  120. * The arguments are like name and value pairs. The preference value for the key is stored persistently,
  121. * so if the widget or device is restarted, the value is retained. However, the values stored by a widget
  122. * are removed when a widget is uninstalled from the device. This includes the case when a widget is
  123. * reinstalled; where the old widget is uninstalled, the new widget is installed.
  124. *
  125. * An existing preference can be overwritten with a new value by simply calling the method with the same key and new value.
  126. *
  127. * A stored preference for a key can be removed by calling the method with the preference argument set to null
  128. *
  129. * @param value String defining the value for the key.
  130. * @param key String defining the preference key.
  131. */
  132. void setPreferenceForKey(const QString &value, const QString &key);
  133. /**
  134. * The preferenceForKey method allows a previously stored preference to be restored.
  135. *
  136. * @param key A text string specifying the name that represents the preference to be restored.
  137. */
  138. QString preferenceForKey(const QString &key);
  139. /**
  140. * The setDisplayPortrait method changes the orientation of a widget's screen to the portrait mode.
  141. */
  142. void setDisplayPortrait();
  143. /**
  144. * The setDisplayLandscape method changes the orientation of a widget's screen to the landscape mode.
  145. */
  146. void setDisplayLandscape();
  147. /**
  148. * The navigation mode in a widget can be toggled between a cursor and a tabbed navigation mode.
  149. * By default, the browsing mode of a widget is set to use a cursor (pointer).
  150. * The setNavigationEnabled method is used for changing the widget's navigation mode.
  151. *
  152. * The argument navigationType is of Boolean type and can be set to true or false to toggle the navigation mode between the cursor mode and the tab mode respectively.
  153. */
  154. void setNavigationEnabled(bool mode);
  155. /**
  156. * The navigation mode in a widget can be set to cursor, tabbed, or none.
  157. * By default, the browsing mode of a widget is set to use a cursor (pointer).
  158. * The setNavigationType method is used for changing the widget's navigation mode.
  159. *
  160. * The argument type is a String and can be set to:
  161. *
  162. * cursor for cursor mode.
  163. * tabbed for tab mode.
  164. * none for no navigation mode. In this mode, WRT passes all events to the application.
  165. * This includes all key events for non-touch devices and all events for
  166. * touch devices. The application must handle all events.
  167. */
  168. void setNavigationType(const QString &navigationType);
  169. void prepareForTransition(const QString &transitionMode);
  170. void performTransition();
  171. /**
  172. * The openApplication method enables a widget to launch an S60 mobile application in the stand-alone mode.
  173. *
  174. * @param Uid A hexadecimal number that specifies the UID of the S60 application to be activated.
  175. * @param param A text string defining a possible argument string that is accepted by the S60 application
  176. * to be activated. The arguments vary between applications. For example, when defined for the Web Browser
  177. * for S60 application (UID: 0x10008D39), the parameter "4"+"<Space>"+"<url>" tells the browser to open with
  178. * content from a specific URL. The parameter "5" launches the browser with the Start page open. You can also use
  179. * an empty string with any application, which results in launching the specified application with default behavior.
  180. *
  181. */
  182. void openApplication(const int Uid, const QString &param);
  183. /**
  184. * The openURL method opens a specified link in the Web Browser for S60 in the stand-alone mode.
  185. * The widget remains open but is sent to the background.
  186. *
  187. * @param url A compact string specifying a link to a resource to be opened. The URL string format is
  188. * compliant with the RFC-1738 specification and must be encoded if it contains non-ASCII characters.
  189. *
  190. */
  191. void openURL(const QString &url);
  192. bool rotationSupported();
  193. QObject *getPlugin(const QString &pluginName);
  194. QString widgetIdentifier();
  195. private:
  196. bool eventFilter(QObject *object, QEvent *event);
  197. MenuItem *menuItem(QAction *act);
  198. void removeSoftkey(bool rightSoftkey);
  199. QMainWindow *m_parentWindow;
  200. QWebFrame *m_webFrame;
  201. QMap<int, MenuItem*> m_menuItems; // <id, MenuItem*>
  202. MenuItem *m_leftSoftkey;
  203. MenuItem *m_rightSoftkey;
  204. HybridPluginManager *m_pluginManager;
  205. QSet<QString> m_menuItemHandlerFunctions;
  206. QString m_identifier;
  207. };
  208. #endif // MENU_H