2 * Copyright (C) 2013 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
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.
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/>.
18import Unity.Application 0.1
21 id: applicationManager
23 property alias mainStageApplications: mainStageModel
24 property alias sideStageApplications: sideStageModel
25 property variant mainStageFocusedApplication: null
26 property variant sideStageFocusedApplication: null
27 property bool sideStageEnabled: true
28 signal focusRequested(string desktopFile)
29 property bool keyboardVisible: ApplicationManager.keyboardVisible
30 property int keyboardHeight: ApplicationManager.keyboardHeight
32 property bool fake: ApplicationManager.fake ? ApplicationManager.fake : false
34 ApplicationsModelStageFiltered {
36 stage: ApplicationInfo.MainStage
39 ApplicationsModelStageFiltered {
41 stage: ApplicationInfo.SideStage
45 target: ApplicationManager
46 onFocusedApplicationIdChanged: {
47 var app = ApplicationManager.findApplication(ApplicationManager.focusedApplicationId)
48 if (!app) { //nothing at all focused, so clear all
49 mainStageFocusedApplication = null;
50 sideStageFocusedApplication = null;
52 if (app.stage == ApplicationInfo.MainStage) {
53 mainStageFocusedApplication = app;
54 // possible the side stage app being unfocused fired this signal, so check for it
55 if (sideStageFocusedApplication && !sideStageFocusedApplication.focused)
56 sideStageFocusedApplication = null;
58 sideStageFocusedApplication = app;
59 // possible the main stage app being unfocused fired this signal, so check for it
60 if (mainStageFocusedApplication && !mainStageFocusedApplication.focused)
61 mainStageFocusedApplication = null;
67 function activateApplication(desktopFile, argument) {
70 // HACK: might be called with appId, but mostly with desktopFile
71 if (desktopFile.indexOf(".desktop") >= 0) {
72 appId = desktopFileToAppId(desktopFile);
77 var application = ApplicationManager.findApplication(appId);
78 if (application !== null) {
82 var execFlags = sideStageEnabled ? ApplicationManager.NoFlag : ApplicationManager.ForceMainStage;
85 return ApplicationManager.startApplication(appId, execFlags, [argument]);
87 return ApplicationManager.startApplication(appId, execFlags);
91 function stopApplication(application) {
94 // HACK: might be called with appId, or else with Application object
95 if (typeof application == "string") {
98 appId = desktopFileToAppId(application.desktopFile);
101 ApplicationManager.stopApplication(appId);
104 function focusApplication(application) {
105 if (application == null || application == undefined) {
109 ApplicationManager.focusApplication(application.appId);
112 function unfocusCurrentApplication() {
113 ApplicationManager.unfocusCurrentApplication();
116 function moveRunningApplicationStackPosition(from, to, stage) {
117 if (from == to || from < 0 || to < 0) return;
119 if (stage == ApplicationInfo.SideStage) {
120 sideStageModel.move(from, to);
122 mainStageModel.move(from, to);
126 function getApplicationFromDesktopFile(desktopFile, stage) {
129 // HACK: might be called with appId, but mostly with desktopFile
130 if (desktopFile.indexOf(".desktop") >= 0) {
131 appId = desktopFileToAppId(desktopFile);
136 for (var i = 0, len = ApplicationManager.count; i < len; i++ ) {
137 var app = ApplicationManager.get(i);
139 // if stage not specified, return whichever app running on either stage
140 if (app.appId == appId && (stage == undefined || app.stage == stage)) {
146 function desktopFileToAppId(desktopFile) {
147 var right = desktopFile.lastIndexOf(".desktop");
148 var left = desktopFile.lastIndexOf("/");
149 if (left == -1 || right == -1 || left == right) {
150 console.log("ApplicationManagerWrapper: unable to extract appId from '" + desktopFile + "'");
153 return desktopFile.substring(left+1, right);
156 function appIdToDesktopFile(desktopFile) {
157 return "/usr/share/applications/" + desktopFile + ".desktop"
161 target: ApplicationManager
163 // FIXME: hardcoded mapping from ApplicationManager.FavoriteApplications
164 // enum to desktop files
166 if (favoriteApplication == ApplicationManager.CameraApplication) {
167 desktopFile = "/usr/share/applications/camera-app.desktop"
168 } else if (favoriteApplication == ApplicationManager.GalleryApplication) {
169 desktopFile = "/usr/share/applications/gallery-app.desktop"
170 } else if (favoriteApplication == ApplicationManager.ShareApplication) {
171 desktopFile = "/usr/share/applications/share-app.desktop"
172 } else if (favoriteApplication == ApplicationManager.BrowserApplication) {
173 desktopFile = "/usr/share/applications/webbrowser-app.desktop"
174 } else if (favoriteApplication == ApplicationManager.PhoneApplication) {
175 desktopFile = "/usr/share/applications/phone-app.desktop"
176 } else if (favoriteApplication == ApplicationManager.DialerApplication) {
177 desktopFile = "/usr/share/applications/dialer-app.desktop"
178 } else if (favoriteApplication == ApplicationManager.MessagingApplication) {
179 desktopFile = "/usr/share/applications/messaging-app.desktop"
180 } else if (favoriteApplication == ApplicationManager.AddressbookApplication) {
181 desktopFile = "/usr/share/applications/address-book-app.desktop"
184 applicationManager.focusRequested(desktopFile);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list