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: Applications identified sometimes with with appId, but mostly with desktopFile.
71 // TODO: convert entire shell to use appId only.
72 if (desktopFile.indexOf(".desktop") >= 0) {
73 appId = desktopFileToAppId(desktopFile);
78 var application = ApplicationManager.findApplication(appId);
79 if (application !== null) {
83 var execFlags = sideStageEnabled ? ApplicationManager.NoFlag : ApplicationManager.ForceMainStage;
86 return ApplicationManager.startApplication(appId, execFlags, [argument]);
88 return ApplicationManager.startApplication(appId, execFlags);
92 function stopApplication(application) {
95 // HACK: Applications identified sometimes with with appId, but mostly with desktopFile.
96 // TODO: convert entire shell to use appId only.
97 if (typeof application == "string") {
100 appId = desktopFileToAppId(application.desktopFile);
103 ApplicationManager.stopApplication(appId);
106 function focusApplication(application) {
107 if (application == null || application == undefined) {
111 ApplicationManager.focusApplication(application.appId);
114 function unfocusCurrentApplication() {
115 ApplicationManager.unfocusCurrentApplication();
118 function moveRunningApplicationStackPosition(from, to, stage) {
119 if (from == to || from < 0 || to < 0) return;
121 if (stage == ApplicationInfo.SideStage) {
122 sideStageModel.move(from, to);
124 mainStageModel.move(from, to);
128 function getApplicationFromDesktopFile(desktopFile, stage) {
131 // HACK: Applications identified sometimes with with appId, but mostly with desktopFile.
132 // TODO: convert entire shell to use appId only.
133 if (desktopFile.indexOf(".desktop") >= 0) {
134 appId = desktopFileToAppId(desktopFile);
139 for (var i = 0, len = ApplicationManager.count; i < len; i++ ) {
140 var app = ApplicationManager.get(i);
142 // if stage not specified, return whichever app running on either stage
143 if (app.appId == appId && (stage == undefined || app.stage == stage)) {
149 function desktopFileToAppId(desktopFile) {
150 var right = desktopFile.lastIndexOf(".desktop");
151 var left = desktopFile.lastIndexOf("/");
152 if (left == -1 || right == -1 || left == right) {
153 console.log("ApplicationManagerWrapper: unable to extract appId from '" + desktopFile + "'");
156 return desktopFile.substring(left+1, right);
160 target: ApplicationManager
162 // FIXME: hardcoded mapping from ApplicationManager.FavoriteApplications
163 // enum to desktop files
165 if (favoriteApplication == ApplicationManager.CameraApplication) {
166 desktopFile = "/usr/share/applications/camera-app.desktop"
167 } else if (favoriteApplication == ApplicationManager.GalleryApplication) {
168 desktopFile = "/usr/share/applications/gallery-app.desktop"
169 } else if (favoriteApplication == ApplicationManager.ShareApplication) {
170 desktopFile = "/usr/share/applications/share-app.desktop"
171 } else if (favoriteApplication == ApplicationManager.BrowserApplication) {
172 desktopFile = "/usr/share/applications/webbrowser-app.desktop"
173 } else if (favoriteApplication == ApplicationManager.PhoneApplication) {
174 desktopFile = "/usr/share/applications/phone-app.desktop"
175 } else if (favoriteApplication == ApplicationManager.DialerApplication) {
176 desktopFile = "/usr/share/applications/dialer-app.desktop"
177 } else if (favoriteApplication == ApplicationManager.MessagingApplication) {
178 desktopFile = "/usr/share/applications/messaging-app.desktop"
179 } else if (favoriteApplication == ApplicationManager.AddressbookApplication) {
180 desktopFile = "/usr/share/applications/address-book-app.desktop"
183 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