First working for qt-sdk auto-detection and setting qt-sdk default per project with config change listener
--- a/core/com.nokia.carbide.cpp.sdk.core/META-INF/MANIFEST.MF Tue Feb 09 07:58:51 2010 -0600
+++ b/core/com.nokia.carbide.cpp.sdk.core/META-INF/MANIFEST.MF Wed Feb 10 11:48:54 2010 -0600
@@ -14,7 +14,9 @@
org.eclipse.update.core,
com.nokia.carbide.templatewizard,
org.eclipse.core.filesystem,
- com.nokia.cpp.utils.ui
+ com.nokia.cpp.utils.ui,
+ com.trolltech.qtcppproject;bundle-version="1.6.0";resolution:=optional,
+ com.trolltech.qtproject;bundle-version="1.0.1";resolution:=optional
Bundle-ActivationPolicy: lazy
Export-Package: com.nokia.carbide.cpp.internal.api.sdk,
com.nokia.carbide.cpp.internal.sdk.core.model;x-friends:="com.nokia.carbide.cpp.sdk.core.test",
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/QtSDKUtils.java Wed Feb 10 11:48:54 2010 -0600
@@ -0,0 +1,180 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+*/
+package com.nokia.carbide.cpp.internal.sdk.core.model;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+import com.nokia.carbide.cpp.sdk.core.ISymbianSDK;
+import com.nokia.cpp.internal.api.utils.core.HostOS;
+import com.trolltech.qtcppproject.QtProjectPlugin;
+import com.trolltech.qtcppproject.preferences.PreferenceConstants;
+
+@SuppressWarnings("restriction")
+public class QtSDKUtils {
+
+ private static class QtSDK {
+
+ QtSDK(String name, String incPath, String binPath){
+ this.binPath = binPath;
+ this.incPath = incPath;
+ this.name = name;
+ }
+
+ public String name;
+ public String binPath;
+ public String incPath;
+ }
+
+ /** Qt bin folder for internal SDK installs - epocroot relative */
+ private static final String QT_SDK_BIN_PATH = "epoc32/tools/qt";
+ /** Qt include folder for internal SDK installs - epocroot relative */
+ private static final String QT_SDK_INC_PATH = "epoc32/include/mw";
+
+ /** qt subfolder under QT_INC_FOLDER */
+ private static final String QT_FOLDER = "qt";
+ private static final String QT_MKSPECS = "mkspecs";
+ private static final String QT_QMAKE_WIN32 = "qmake.exe";
+ private static final String QT_QMAKE_UNIX = "qmake";
+
+ public static final String QT_DEFAULT_SDK_NAME = "<Default>";
+
+ private static List<QtSDK> qtSDKList = new ArrayList<QtSDK>();
+
+ // private data from QtProject.java
+ private static final String QTVERSION = "com.trolltech.qtcppproject.properties.qtversion";
+
+ static private boolean isQtInternallyInstalled(ISymbianSDK sdk){
+
+ String epocRoot = sdk.getEPOCROOT();
+ if (new File(epocRoot + QT_SDK_BIN_PATH).exists() &&
+ new File(epocRoot + QT_SDK_INC_PATH).exists() &&
+ new File(epocRoot + QT_SDK_INC_PATH + File.separator + QT_FOLDER).exists() &&
+ new File(epocRoot + QT_SDK_BIN_PATH + File.separator + QT_MKSPECS).exists() )
+ {
+ if (HostOS.IS_WIN32 && new File(epocRoot + QT_SDK_BIN_PATH + File.separator + QT_QMAKE_WIN32).exists()){
+ return true;
+ } else if (HostOS.IS_UNIX && new File(epocRoot + QT_SDK_BIN_PATH + File.separator + QT_QMAKE_UNIX).exists()){
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ static public String getQtSDKNameForSymbianSDK(ISymbianSDK sdk){
+
+ String epocRoot = sdk.getEPOCROOT();
+ File qtBinPath = new File (epocRoot + QT_SDK_BIN_PATH);
+ File qtIncPath = new File (epocRoot + QT_SDK_INC_PATH);
+
+ refreshQtStoredSDKs();
+
+ if (qtSDKList.size() == 0){
+ return null;
+ }
+
+ for (QtSDK qtSDK : qtSDKList){
+ File currBinPath = new File(qtSDK.binPath);
+ File currIncPath = new File(qtSDK.incPath);
+
+ if (currBinPath.equals(qtBinPath) && currIncPath.equals(qtIncPath)){
+ return qtSDK.name;
+ }
+ }
+
+ return null;
+ }
+
+ static public void addQtSDKForSymbianSDK(ISymbianSDK sdk, boolean makeDefault){
+
+ refreshQtStoredSDKs();
+ if ((getQtSDKNameForSymbianSDK(sdk) == null) && isQtInternallyInstalled(sdk)){
+ IPath binPath = new Path(sdk.getEPOCROOT() + QT_SDK_BIN_PATH);
+ IPath incPath = new Path(sdk.getEPOCROOT() + QT_SDK_INC_PATH);
+ addQtSDK(sdk.getUniqueId(), binPath, incPath, makeDefault);
+ }
+ }
+
+ static private void addQtSDK(String name, IPath binPath, IPath incPath, boolean makeDefault){
+
+ IPreferenceStore store = QtProjectPlugin.getDefault().getPreferenceStore();
+ int count = store.getInt(PreferenceConstants.QTVERSION_COUNT);
+
+ // Store settings using zero-index base
+ store.setValue(PreferenceConstants.QTVERSION_NAME + "."
+ + Integer.toString(count), name);
+ store.setValue(PreferenceConstants.QTVERSION_BINPATH + "."
+ + Integer.toString(count), binPath.toOSString());
+ store.setValue(PreferenceConstants.QTVERSION_INCLUDEPATH + "."
+ + Integer.toString(count), incPath.toOSString());
+
+ if (makeDefault || count == 0){
+ store.setValue(PreferenceConstants.QTVERSION_DEFAULT, count);
+ }
+
+ store.setValue(PreferenceConstants.QTVERSION_COUNT, count + 1); // # of table items, base is 1 (i.e. not zero)
+
+ refreshQtStoredSDKs();
+ }
+
+ static void refreshQtStoredSDKs(){
+
+ qtSDKList.clear();
+
+ IPreferenceStore store = QtProjectPlugin.getDefault().getPreferenceStore();
+ int count = store.getInt(PreferenceConstants.QTVERSION_COUNT);
+ for (int i = 0; i < count; i++) {
+ String nameKey = PreferenceConstants.QTVERSION_NAME + "."
+ + Integer.toString(i);
+ String binpathKey = PreferenceConstants.QTVERSION_BINPATH + "."
+ + Integer.toString(i);
+ String includepathKey = PreferenceConstants.QTVERSION_INCLUDEPATH
+ + "." + Integer.toString(i);
+ String name = "";
+ String binPath = "";
+ String incPath = "";
+ if (store.contains(nameKey)) {
+ name = store.getString(nameKey);
+ }
+ if (store.contains(binpathKey)) {
+ binPath = store.getString(binpathKey);
+ }
+ if (store.contains(includepathKey)) {
+ incPath = store.getString(includepathKey);
+ }
+
+ QtSDK qtSDK = new QtSDK(name, incPath, binPath);
+ qtSDKList.add(qtSDK);
+ }
+ }
+
+ public static void setDefaultQtSDKForProject(IProject project, String qtSDKName) throws CoreException{
+ project.setPersistentProperty(new QualifiedName("", QTVERSION), qtSDKName);
+ }
+
+ public static String getDefaultQtSDKForProject(IProject project) throws CoreException{
+ return project.getPersistentProperty(new QualifiedName("", QTVERSION));
+ }
+
+}
+
+
--- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/SDKManager.java Tue Feb 09 07:58:51 2010 -0600
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/SDKManager.java Wed Feb 10 11:48:54 2010 -0600
@@ -96,6 +96,7 @@
for (Iterator iter = devices.iterator(); iter.hasNext();) {
SymbianSDK sdk = new SymbianSDK((DeviceType) iter.next());
sdkList.add(sdk);
+ QtSDKUtils.addQtSDKForSymbianSDK(sdk, false);
}
return true;
--- a/project/com.nokia.carbide.cpp.project.core.tests/src/com/nokia/carbide/cpp/project/core/tests/QtPropertiesTest.java Tue Feb 09 07:58:51 2010 -0600
+++ b/project/com.nokia.carbide.cpp.project.core.tests/src/com/nokia/carbide/cpp/project/core/tests/QtPropertiesTest.java Wed Feb 10 11:48:54 2010 -0600
@@ -152,14 +152,6 @@
break;
}
}
-// if (store.contains(binpathKey)) {
-// binpath = store.getString(binpathKey);
-// System.out.println("Binpath: " + binpath);
-// }
-// if (store.contains(includepathKey)) {
-// includepath = store.getString(includepathKey);
-// System.out.println("Inc Path: " + includepath);
-// }
}
return foundIndex;
--- a/project/com.nokia.carbide.cpp.project.core/src/com/nokia/carbide/cpp/internal/api/project/core/ProjectCorePluginUtility.java Tue Feb 09 07:58:51 2010 -0600
+++ b/project/com.nokia.carbide.cpp.project.core/src/com/nokia/carbide/cpp/internal/api/project/core/ProjectCorePluginUtility.java Wed Feb 10 11:48:54 2010 -0600
@@ -20,18 +20,23 @@
import java.util.Map;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin;
import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration;
+import com.nokia.carbide.cdt.builder.project.ICarbideConfigurationChangedListener;
import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo;
import com.nokia.carbide.cdt.builder.project.ICarbideProjectModifier;
import com.nokia.carbide.cdt.builder.project.ISISBuilderInfo;
import com.nokia.carbide.cdt.internal.api.builder.SISBuilderInfo2;
+import com.nokia.carbide.cpp.internal.qt.core.QtCorePlugin;
+import com.nokia.carbide.cpp.internal.sdk.core.model.QtSDKUtils;
+import com.nokia.carbide.cpp.project.core.ProjectCorePlugin;
import com.nokia.carbide.cpp.sdk.core.ISymbianBuildContext;
-public class ProjectCorePluginUtility {
+public class ProjectCorePluginUtility implements ICarbideConfigurationChangedListener {
private static ResourceChangeListener resourceChangeListener;
private static boolean listening = false;
@@ -41,10 +46,12 @@
}
public void startup() {
+ CarbideBuilderPlugin.addBuildConfigChangedListener(this);
}
public void shutdown() {
stopProjectListener();
+ CarbideBuilderPlugin.removeBuildConfigChangedListener(this);
}
public static void startProjectListener() {
@@ -107,4 +114,27 @@
cpi.saveChanges();
}
}
+
+ public void buildConfigurationChanged(ICarbideBuildConfiguration currentConfig) {
+ checkDefaultQtSDKForProject(currentConfig);
+ }
+
+ @SuppressWarnings("restriction")
+ private void checkDefaultQtSDKForProject(ICarbideBuildConfiguration currentConfig){
+ IProject project = currentConfig.getCarbideProject().getProject();
+ if (project != null && QtCorePlugin.isQtProject(project)) {
+ try {
+ String qtSDKName = QtSDKUtils.getQtSDKNameForSymbianSDK(currentConfig.getSDK());
+ if (qtSDKName == null || QtSDKUtils.getDefaultQtSDKForProject(project).equals(QtSDKUtils.QT_DEFAULT_SDK_NAME)) {
+ return;
+ }
+
+ QtSDKUtils.setDefaultQtSDKForProject(project, qtSDKName);
+
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
}
--- a/qt/com.nokia.carbide.cpp.qt.ui/src/com/nokia/carbide/cpp/internal/qt/ui/processes/ProjectCreatedTasksQt.java Tue Feb 09 07:58:51 2010 -0600
+++ b/qt/com.nokia.carbide.cpp.qt.ui/src/com/nokia/carbide/cpp/internal/qt/ui/processes/ProjectCreatedTasksQt.java Wed Feb 10 11:48:54 2010 -0600
@@ -33,8 +33,10 @@
import com.nokia.carbide.cpp.internal.qt.core.QtCorePlugin;
import com.nokia.carbide.cpp.internal.qt.ui.QtUIPlugin;
+import com.nokia.carbide.cpp.internal.sdk.core.model.QtSDKUtils;
import com.nokia.carbide.cpp.project.ui.processes.ProjectCreatedTasks;
import com.nokia.carbide.cpp.sdk.core.ISymbianBuildContext;
+import com.nokia.carbide.cpp.sdk.core.ISymbianSDK;
import com.nokia.carbide.template.engine.ITemplate;
import com.nokia.carbide.templatewizard.process.IParameter;
import com.trolltech.qtcppproject.QtProject;
@@ -46,6 +48,7 @@
super();
}
+ @SuppressWarnings("restriction")
@Override
public void process(ITemplate template, List<IParameter> parameters, IProgressMonitor monitor) throws CoreException {
@@ -81,6 +84,19 @@
// set the qmake generated pkg files to be built
QtUIPlugin.setupSISBuilderSettings(project);
+
+ // set the default Qt SDK
+ ISymbianSDK sdk = ((ISymbianBuildContext)listOfBuildConfigs.get(0)).getSDK();
+ String qtSDKName = QtSDKUtils.getQtSDKNameForSymbianSDK(sdk);
+ if (qtSDKName == null){
+ QtSDKUtils.addQtSDKForSymbianSDK(sdk, false);
+ qtSDKName = QtSDKUtils.getQtSDKNameForSymbianSDK(sdk);
+ }
+
+ if (qtSDKName != null){
+ QtSDKUtils.setDefaultQtSDKForProject(project, qtSDKName);
+ }
+
}
}
}
--- a/qt/com.nokia.carbide.cpp.qt.ui/src/com/nokia/carbide/cpp/internal/qt/ui/wizard/QtProFileImportWizard.java Tue Feb 09 07:58:51 2010 -0600
+++ b/qt/com.nokia.carbide.cpp.qt.ui/src/com/nokia/carbide/cpp/internal/qt/ui/wizard/QtProFileImportWizard.java Wed Feb 10 11:48:54 2010 -0600
@@ -41,6 +41,7 @@
import com.nokia.carbide.cpp.internal.project.ui.ProjectUIPlugin;
import com.nokia.carbide.cpp.internal.qt.core.QtCorePlugin;
import com.nokia.carbide.cpp.internal.qt.ui.QtUIPlugin;
+import com.nokia.carbide.cpp.internal.sdk.core.model.QtSDKUtils;
import com.nokia.carbide.cpp.project.core.ProjectCorePlugin;
import com.nokia.carbide.cpp.sdk.core.*;
import com.trolltech.qtcppproject.QtProject;
@@ -120,7 +121,19 @@
// set the qmake generated pkg files to be built
QtUIPlugin.setupSISBuilderSettings(newProject);
-
+
+ // Set the default Qt SDK, if any
+ ISymbianSDK sdk = selectedConfigs.get(0).getSDK();
+ String qtSDKName = QtSDKUtils.getQtSDKNameForSymbianSDK(sdk);
+ if (qtSDKName == null){
+ QtSDKUtils.addQtSDKForSymbianSDK(sdk, false);
+ qtSDKName = QtSDKUtils.getQtSDKNameForSymbianSDK(sdk);
+ }
+
+ if (qtSDKName != null){
+ QtSDKUtils.setDefaultQtSDKForProject(newProject, qtSDKName);
+ }
+
if (monitor.isCanceled()) {
// the user canceled the import so delete the project
newProject.delete(false, true, null);