diff --git a/BlueBerry/Bundles/org.blueberry.osgi/src/berryPlatform.cpp b/BlueBerry/Bundles/org.blueberry.osgi/src/berryPlatform.cpp index 60345997ee..c44ae0874a 100644 --- a/BlueBerry/Bundles/org.blueberry.osgi/src/berryPlatform.cpp +++ b/BlueBerry/Bundles/org.blueberry.osgi/src/berryPlatform.cpp @@ -1,211 +1,216 @@ /*========================================================================= Program: BlueBerry Platform Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include #include "berryPlatform.h" #include "service/berryIExtensionPointService.h" #include "internal/berryInternalPlatform.h" namespace berry { int Platform::OS_FREE_BSD = BERRY_OS_FREE_BSD; int Platform::OS_AIX = BERRY_OS_AIX; int Platform::OS_HPUX = BERRY_OS_HPUX; int Platform::OS_TRU64 = BERRY_OS_TRU64; int Platform::OS_LINUX = BERRY_OS_LINUX; int Platform::OS_MAC_OS_X = BERRY_OS_MAC_OS_X; int Platform::OS_NET_BSD = BERRY_OS_NET_BSD; int Platform::OS_OPEN_BSD = BERRY_OS_OPEN_BSD; int Platform::OS_IRIX = BERRY_OS_IRIX; int Platform::OS_SOLARIS = BERRY_OS_SOLARIS; int Platform::OS_QNX = BERRY_OS_QNX; int Platform::OS_VXWORKS = BERRY_OS_VXWORKS; int Platform::OS_CYGWIN = BERRY_OS_CYGWIN; int Platform::OS_UNKNOWN_UNIX = BERRY_OS_UNKNOWN_UNIX; int Platform::OS_WINDOWS_NT = BERRY_OS_WINDOWS_NT; int Platform::OS_WINDOWS_CE = BERRY_OS_WINDOWS_CE; int Platform::OS_VMS = BERRY_OS_VMS; int Platform::ARCH_ALPHA = BERRY_ARCH_ALPHA; int Platform::ARCH_IA32 = BERRY_ARCH_IA32; int Platform::ARCH_IA64 = BERRY_ARCH_IA64; int Platform::ARCH_MIPS = BERRY_ARCH_MIPS; int Platform::ARCH_HPPA = BERRY_ARCH_HPPA; int Platform::ARCH_PPC = BERRY_ARCH_PPC; int Platform::ARCH_POWER = BERRY_ARCH_POWER; int Platform::ARCH_SPARC = BERRY_ARCH_SPARC; int Platform::ARCH_AMD64 = BERRY_ARCH_AMD64; int Platform::ARCH_ARM = BERRY_ARCH_ARM; std::string Platform::ARG_CLEAN = "BlueBerry.clean"; std::string Platform::ARG_APPLICATION = "BlueBerry.application"; std::string Platform::ARG_HOME = "BlueBerry.home"; std::string Platform::ARG_STORAGE_DIR = "BlueBerry.storageDir"; std::string Platform::ARG_PLUGIN_CACHE = "BlueBerry.plugin_cache_dir"; std::string Platform::ARG_PLUGIN_DIRS = "BlueBerry.plugin_dirs"; std::string Platform::ARG_FORCE_PLUGIN_INSTALL = "BlueBerry.forcePlugins"; std::string Platform::ARG_PROVISIONING = "BlueBerry.provisioning"; std::string Platform::ARG_CONSOLELOG = "BlueBerry.consoleLog"; std::string Platform::ARG_TESTPLUGIN = "BlueBerry.testplugin"; std::string Platform::ARG_TESTAPPLICATION = "BlueBerry.testapplication"; const Poco::Path& Platform::GetConfigurationPath() { return InternalPlatform::GetInstance()->GetConfigurationPath(); } SmartPointer Platform::GetExtensionPointService() { return InternalPlatform::GetInstance()->GetExtensionPointService(); } PlatformEvents& Platform::GetEvents() { return InternalPlatform::GetInstance()->GetEvents(); } const Poco::Path& Platform::GetInstallPath() { return InternalPlatform::GetInstance()->GetInstallPath(); } const Poco::Path& Platform::GetInstancePath() { return InternalPlatform::GetInstance()->GetInstancePath(); } int Platform::GetOS() { return BERRY_OS; } int Platform::GetOSArch() { return BERRY_ARCH; } bool Platform::IsUnix() { #ifdef BERRY_OS_FAMILY_UNIX return true; #else return false; #endif } bool Platform::IsWindows() { #ifdef BERRY_OS_FAMILY_WINDOWS return true; #else return false; #endif } bool Platform::IsBSD() { #ifdef BERRY_OS_FAMILY_BSD return true; #else return false; #endif } bool Platform::IsLinux() { #ifdef BERRY_OS_FAMILY_LINUX return true; #else return false; #endif } bool Platform::IsVMS() { #ifdef BERRY_OS_FAMILY_VMS return true; #else return false; #endif } bool Platform::GetStatePath(Poco::Path& statePath, IBundle::Pointer bundle, bool create) { return InternalPlatform::GetInstance()->GetStatePath(statePath, bundle, create); } const Poco::Path& Platform::GetUserPath() { return InternalPlatform::GetInstance()->GetUserPath(); } std::string Platform::GetProperty(const std::string& /*key*/) { return ""; } bool Platform::IsRunning() { return InternalPlatform::GetInstance()->IsRunning(); } int& Platform::GetRawApplicationArgs(char**& argv) { return InternalPlatform::GetInstance()->GetRawApplicationArgs(argv); } std::vector Platform::GetApplicationArgs() { return InternalPlatform::GetInstance()->GetApplicationArgs(); } Poco::Util::LayeredConfiguration& Platform::GetConfiguration() { return InternalPlatform::GetInstance()->GetConfiguration(); } ServiceRegistry& Platform::GetServiceRegistry() { return InternalPlatform::GetInstance()->GetServiceRegistry(); } IBundle::Pointer Platform::GetBundle(const std::string& id) { return InternalPlatform::GetInstance()->GetBundle(id); } std::vector Platform::GetBundles() { return InternalPlatform::GetInstance()->GetBundles(); } QSharedPointer Platform::GetCTKPlugin(const QString& symbolicName) { QList > plugins = InternalPlatform::GetInstance()->GetCTKPluginFrameworkContext()->getPlugins(); foreach(QSharedPointer plugin, plugins) { if (plugin->getSymbolicName() == symbolicName) return plugin; } return QSharedPointer(0); } +QSharedPointer Platform::GetCTKPlugin(long id) +{ + return InternalPlatform::GetInstance()->GetCTKPluginFrameworkContext()->getPlugin(id); +} + } diff --git a/BlueBerry/Bundles/org.blueberry.osgi/src/berryPlatform.h b/BlueBerry/Bundles/org.blueberry.osgi/src/berryPlatform.h index d3881f78fa..355411915b 100644 --- a/BlueBerry/Bundles/org.blueberry.osgi/src/berryPlatform.h +++ b/BlueBerry/Bundles/org.blueberry.osgi/src/berryPlatform.h @@ -1,346 +1,348 @@ /*========================================================================= Program: BlueBerry Platform Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef BERRY_Platform_INCLUDED #define BERRY_Platform_INCLUDED // // Platform Identification // #define BERRY_OS_FREE_BSD 0x0001 #define BERRY_OS_AIX 0x0002 #define BERRY_OS_HPUX 0x0003 #define BERRY_OS_TRU64 0x0004 #define BERRY_OS_LINUX 0x0005 #define BERRY_OS_MAC_OS_X 0x0006 #define BERRY_OS_NET_BSD 0x0007 #define BERRY_OS_OPEN_BSD 0x0008 #define BERRY_OS_IRIX 0x0009 #define BERRY_OS_SOLARIS 0x000a #define BERRY_OS_QNX 0x000b #define BERRY_OS_VXWORKS 0x000c #define BERRY_OS_CYGWIN 0x000d #define BERRY_OS_UNKNOWN_UNIX 0x00ff #define BERRY_OS_WINDOWS_NT 0x1001 #define BERRY_OS_WINDOWS_CE 0x1011 #define BERRY_OS_VMS 0x2001 #if defined(__FreeBSD__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS_FAMILY_BSD 1 #define BERRY_OS BERRY_OS_FREE_BSD #elif defined(_AIX) || defined(__TOS_AIX__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS BERRY_OS_AIX #elif defined(hpux) || defined(_hpux) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS BERRY_OS_HPUX #elif defined(__digital__) || defined(__osf__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS BERRY_OS_TRU64 #elif defined(linux) || defined(__linux) || defined(__linux__) || defined(__TOS_LINUX__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS BERRY_OS_LINUX #elif defined(__APPLE__) || defined(__TOS_MACOS__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS_FAMILY_BSD 1 #define BERRY_OS BERRY_OS_MAC_OS_X #elif defined(__NetBSD__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS_FAMILY_BSD 1 #define BERRY_OS BERRY_OS_NET_BSD #elif defined(__OpenBSD__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS_FAMILY_BSD 1 #define BERRY_OS BERRY_OS_OPEN_BSD #elif defined(sgi) || defined(__sgi) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS BERRY_OS_IRIX #elif defined(sun) || defined(__sun) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS BERRY_OS_SOLARIS #elif defined(__QNX__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS BERRY_OS_QNX #elif defined(unix) || defined(__unix) || defined(__unix__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS BERRY_OS_UNKNOWN_UNIX #elif defined(_WIN32_WCE) #define BERRY_OS_FAMILY_WINDOWS 1 #define BERRY_OS BERRY_OS_WINDOWS_CE #elif defined(_WIN32) || defined(_WIN64) #define BERRY_OS_FAMILY_WINDOWS 1 #define BERRY_OS BERRY_OS_WINDOWS_NT #elif defined(__CYGWIN__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS BERRY_OS_CYGWIN #elif defined(__VMS) #define BERRY_OS_FAMILY_VMS 1 #define BERRY_OS BERRY_OS_VMS #endif // // Hardware Architecture and Byte Order // #define BERRY_ARCH_ALPHA 0x01 #define BERRY_ARCH_IA32 0x02 #define BERRY_ARCH_IA64 0x03 #define BERRY_ARCH_MIPS 0x04 #define BERRY_ARCH_HPPA 0x05 #define BERRY_ARCH_PPC 0x06 #define BERRY_ARCH_POWER 0x07 #define BERRY_ARCH_SPARC 0x08 #define BERRY_ARCH_AMD64 0x09 #define BERRY_ARCH_ARM 0x0a #if defined(__ALPHA) || defined(__alpha) || defined(__alpha__) || defined(_M_ALPHA) #define BERRY_ARCH BERRY_ARCH_ALPHA #define BERRY_ARCH_LITTLE_ENDIAN 1 #elif defined(i386) || defined(__i386) || defined(__i386__) || defined(_M_IX86) #define BERRY_ARCH BERRY_ARCH_IA32 #define BERRY_ARCH_LITTLE_ENDIAN 1 #elif defined(_IA64) || defined(__IA64__) || defined(__ia64__) || defined(__ia64) || defined(_M_IA64) #define BERRY_ARCH BERRY_ARCH_IA64 #if defined(hpux) || defined(_hpux) #define BERRY_ARCH_BIG_ENDIAN 1 #else #define BERRY_ARCH_LITTLE_ENDIAN 1 #endif #elif defined(__x86_64__) #define BERRY_ARCH BERRY_ARCH_AMD64 #define BERRY_ARCH_LITTLE_ENDIAN 1 #elif defined(_M_X64) #define BERRY_ARCH BERRY_ARCH_AMD64 #define BERRY_ARCH_LITTLE_ENDIAN 1 #elif defined(__mips__) || defined(__mips) || defined(__MIPS__) || defined(_M_MRX000) #define BERRY_ARCH BERRY_ARCH_MIPS #define BERRY_ARCH_BIG_ENDIAN 1 #elif defined(__hppa) || defined(__hppa__) #define BERRY_ARCH BERRY_ARCH_HPPA #define BERRY_ARCH_BIG_ENDIAN 1 #elif defined(__PPC) || defined(__POWERPC__) || defined(__powerpc) || defined(__PPC__) || \ defined(__powerpc__) || defined(__ppc__) || defined(_ARCH_PPC) || defined(_M_PPC) #define BERRY_ARCH BERRY_ARCH_PPC #define BERRY_ARCH_BIG_ENDIAN 1 #elif defined(_POWER) || defined(_ARCH_PWR) || defined(_ARCH_PWR2) || defined(_ARCH_PWR3) || \ defined(_ARCH_PWR4) || defined(__THW_RS6000) #define BERRY_ARCH BERRY_ARCH_POWER #define BERRY_ARCH_BIG_ENDIAN 1 #elif defined(__sparc__) || defined(__sparc) || defined(sparc) #define BERRY_ARCH BERRY_ARCH_SPARC #define BERRY_ARCH_BIG_ENDIAN 1 #elif defined(__arm__) || defined(__arm) || defined(ARM) || defined(_ARM_) || defined(__ARM__) || defined(_M_ARM) #define BERRY_ARCH BERRY_ARCH_ARM #if defined(__ARMEB__) #define BERRY_ARCH_BIG_ENDIAN 1 #else #define BERRY_ARCH_LITTLE_ENDIAN 1 #endif #endif #include #include "event/berryPlatformEvents.h" #include "service/berryServiceRegistry.h" #include namespace berry { struct IExtensionPointService; /** * The central class of the BlueBerry Platform Runtime. This class cannot * be instantiated or subclassed by clients; all functionality is provided * by static methods. Features include: *
    *
  • the platform registry of installed plug-ins
  • *
  • the platform adapter manager
  • *
  • the platform log
  • *
*

* Most users don't have to worry about Platform's lifecycle. However, if your * code can call methods of this class when Platform is not running, it becomes * necessary to check {@link #IsRunning()} before making the call. A runtime * exception might be thrown or incorrect result might be returned if a method * from this class is called while Platform is not running. *

*/ class BERRY_OSGI Platform { public: static int OS_FREE_BSD; static int OS_AIX; static int OS_HPUX; static int OS_TRU64; static int OS_LINUX; static int OS_MAC_OS_X; static int OS_NET_BSD; static int OS_OPEN_BSD; static int OS_IRIX; static int OS_SOLARIS; static int OS_QNX; static int OS_VXWORKS; static int OS_CYGWIN; static int OS_UNKNOWN_UNIX; static int OS_WINDOWS_NT; static int OS_WINDOWS_CE; static int OS_VMS; static int ARCH_ALPHA; static int ARCH_IA32; static int ARCH_IA64; static int ARCH_MIPS; static int ARCH_HPPA; static int ARCH_PPC; static int ARCH_POWER; static int ARCH_SPARC; static int ARCH_AMD64; static int ARCH_ARM; static std::string ARG_CLEAN; static std::string ARG_APPLICATION; static std::string ARG_HOME; static std::string ARG_STORAGE_DIR; static std::string ARG_PLUGIN_CACHE; static std::string ARG_PLUGIN_DIRS; static std::string ARG_FORCE_PLUGIN_INSTALL; static std::string ARG_PROVISIONING; static std::string ARG_CONSOLELOG; static std::string ARG_TESTPLUGIN; static std::string ARG_TESTAPPLICATION; static SmartPointer GetExtensionPointService(); // static IPreferenceService GetPreferenceService(); static PlatformEvents& GetEvents(); /** * Returns the path of the configuration information * used to run this instance of the BlueBerry platform. * The configuration area typically * contains the list of plug-ins available for use, various settings * (those shared across different instances of the same configuration) * and any other such data needed by plug-ins. * An empty path is returned if the platform is running without a configuration location. * * @return the location of the platform's configuration data area */ static const Poco::Path& GetConfigurationPath(); /** * Returns the path of the base installation for the running platform * * @return the location of the platform's installation area or null if none */ static const Poco::Path& GetInstallPath(); /** * Returns the path of the platform's working directory (also known as the instance data area). * An empty path is returned if the platform is running without an instance location. * * @return the location of the platform's instance data area or null if none */ static const Poco::Path& GetInstancePath(); /** * Returns the path in the local file system of the * plug-in state area for the given bundle. * If the plug-in state area did not exist prior to this call, * it is created. *

* The plug-in state area is a file directory within the * platform's metadata area where a plug-in is free to create files. * The content and structure of this area is defined by the plug-in, * and the particular plug-in is solely responsible for any files * it puts there. It is recommended for plug-in preference settings and * other configuration parameters. *

* * @param bundle the bundle whose state location is returned * @return a local file system path * TODO Investigate the usage of a service factory */ static bool GetStatePath(Poco::Path& statePath, SmartPointer bundle, bool create = true); /** * Returns the path of the platform's user data area. The user data area is a location on the system * which is specific to the system's current user. By default it is located relative to the * location given by the System property "user.home". * An empty path is returned if the platform is running without an user location. * * @return the location of the platform's user data area or null if none */ static const Poco::Path& GetUserPath(); static int GetOS(); static int GetOSArch(); static bool IsUnix(); static bool IsWindows(); static bool IsBSD(); static bool IsLinux(); static bool IsVMS(); static std::string GetProperty(const std::string& key); static bool IsRunning(); static Poco::Util::LayeredConfiguration& GetConfiguration(); /** * Returns the unmodified, original command line arguments * */ static int& GetRawApplicationArgs(char**& argv); /** * Returns the applications command line arguments which * have not been consumed by the platform. The first * argument still is the application name */ static std::vector GetApplicationArgs(); static ServiceRegistry& GetServiceRegistry(); /** * Returns the resolved bundle with the specified symbolic name that has the * highest version. If no resolved bundles are installed that have the * specified symbolic name then null is returned. * * @param id the symbolic name of the bundle to be returned. * @return the bundle that has the specified symbolic name with the * highest version, or null if no bundle is found. */ static IBundle::Pointer GetBundle(const std::string& id); static std::vector GetBundles(); static QSharedPointer GetCTKPlugin(const QString& symbolicName); + static QSharedPointer GetCTKPlugin(long id); + private: Platform(); }; } // namespace #endif // BERRY_Platform_INCLUDED diff --git a/BlueBerry/Bundles/org.blueberry.ui.qt/src/berryQtAssistantUtil.cpp b/BlueBerry/Bundles/org.blueberry.ui.qt/src/berryQtAssistantUtil.cpp index 0250d160ec..4f523a7fde 100644 --- a/BlueBerry/Bundles/org.blueberry.ui.qt/src/berryQtAssistantUtil.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui.qt/src/berryQtAssistantUtil.cpp @@ -1,298 +1,332 @@ /*========================================================================= Program: BlueBerry Platform Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "berryQtAssistantUtil.h" #include #include #include #include #include #include #include #include #include #include #include #include #include namespace berry { QProcess* QtAssistantUtil::assistantProcess = 0; QString QtAssistantUtil::helpCollectionFile; QString QtAssistantUtil::defaultHelpUrl; -QStringList QtAssistantUtil::registeredBundles; +QSet QtAssistantUtil::registeredBundles; void QtAssistantUtil::SetHelpCollectionFile(const QString& file) { helpCollectionFile = file; } QString QtAssistantUtil::GetHelpCollectionFile() { return helpCollectionFile; } void QtAssistantUtil::OpenActivePartHelp() { //Get Plugin-ID QString pluginID; berry::IWorkbench* currentWorkbench = berry::PlatformUI::GetWorkbench(); if (currentWorkbench) { berry::IWorkbenchWindow::Pointer currentWorkbenchWindow = currentWorkbench->GetActiveWorkbenchWindow(); if (currentWorkbenchWindow) { berry::IWorkbenchPage::Pointer currentPage = currentWorkbenchWindow->GetActivePage(); if (currentPage) { berry::IWorkbenchPart::Pointer currentPart = currentPage->GetActivePart(); if (currentPart) pluginID = QString::fromStdString(currentPart->GetSite()->GetPluginId()); } } } //End get Plugin-ID QString helpUrl = defaultHelpUrl; if (!pluginID.isEmpty() && registeredBundles.contains(pluginID)) helpUrl = "qthelp://"+pluginID+"/bundle/index.html"; OpenAssistant(helpUrl); } void QtAssistantUtil::OpenAssistant(const QString& startPage) { QString startUrl = startPage; if (startUrl.isEmpty()) startUrl = defaultHelpUrl; if (assistantProcess == 0) { assistantProcess = new QProcess; } if (assistantProcess->state() == QProcess::NotRunning) { QStringList assistantArgs; if (!helpCollectionFile.isEmpty()) { assistantArgs << QLatin1String("-collectionFile") << QLatin1String(helpCollectionFile.toLatin1()); } assistantArgs << QLatin1String("-enableRemoteControl") << QLatin1String("-showUrl") << QLatin1String(startUrl.toLatin1()); assistantProcess->start(GetAssistantExecutable(), assistantArgs); } else { QByteArray ba; ba.append("setSource ").append(startUrl.toLatin1()).append('\0'); assistantProcess->write(ba); } } void QtAssistantUtil::CloseAssistant() { if (assistantProcess && (assistantProcess->state() != QProcess::NotRunning)) { assistantProcess->close(); } delete assistantProcess; } bool QtAssistantUtil::RegisterQCHFiles(const std::vector& bundles) { QStringList qchFiles = ExtractQCHFiles(bundles); // unregister old files CallQtAssistant(qchFiles, false); return CallQtAssistant(qchFiles, true); } bool QtAssistantUtil::RegisterQCHFiles(const QStringList& qchFiles) { return CallQtAssistant(qchFiles, true); } bool QtAssistantUtil::UnregisterQCHFiles(const QStringList& qchFiles) { return CallQtAssistant(qchFiles, false); } QStringList QtAssistantUtil::ExtractQCHFiles(const std::vector& bundles) { QStringList result; for (std::size_t i = 0; i < bundles.size(); ++i) { std::vector resourceFiles; bundles[i]->GetStorage().List("resources", resourceFiles); bool qchFileFound = false; for (std::size_t j = 0; j < resourceFiles.size(); ++j) { QString resource = QString::fromStdString(resourceFiles[j]); if (resource.endsWith(".qch")) { qchFileFound = true; Poco::Path qchPath = bundles[i]->GetPath(); qchPath.pushDirectory("resources"); qchPath.setFileName(resourceFiles[j]); result << QString::fromStdString(qchPath.toString()); } } if (qchFileFound) { - registeredBundles.push_back(QString::fromStdString(bundles[i]->GetSymbolicName())); + registeredBundles.insert(QString::fromStdString(bundles[i]->GetSymbolicName())); } } return result; } bool QtAssistantUtil::CallQtAssistant(const QStringList& qchFiles, bool registerFile) { if (qchFiles.empty()) return true; bool success = true; QList argsVector; foreach (QString qchFile, qchFiles) { QStringList args; if (!helpCollectionFile.isEmpty()) { args << QLatin1String("-collectionFile") << helpCollectionFile; } if (registerFile) { args << QLatin1String("-register"); } else { args << QLatin1String("-unregister"); } args << qchFile; //args << QLatin1String("-quiet"); //BERRY_INFO << "Registering " << qchFile.toStdString() << " with " << helpCollectionFile.toStdString(); argsVector.push_back(args); } QString progressLabel(registerFile ? "Registering help files..." : "Unregistering help files..."); QString progressCancel(registerFile ? "Abort Registration" : "Abort Unregistration"); QProgressDialog progress(progressLabel, progressCancel, 0, argsVector.size()); progress.setWindowModality(Qt::WindowModal); QString assistantExec = GetAssistantExecutable(); QString errorString; int exitCode = 0; for (int i = 0; i < argsVector.size(); ++i) { const QStringList& args = argsVector[i]; progress.setValue(i); QString labelText = (registerFile ? QString("Registering ") : QString("Unregistering ")) + args[3]; progress.setLabelText(labelText); if (progress.wasCanceled()) { success = false; break; } QProcess* process = new QProcess; //qDebug() << "***** " << assistantExec << args; process->start(assistantExec, args); BERRY_INFO << (registerFile ? "Registering " : "Unregistering ") << "Qt compressed help file: " << qchFiles[i].toStdString(); if (!process->waitForFinished()) { success = false; if (registerFile) { BERRY_ERROR << "Registering compressed help file" << args[3].toStdString() << " failed"; } else { BERRY_ERROR << "Unregistering compressed help file" << args[3].toStdString() << " failed"; } errorString = process->errorString(); } //qDebug() << process->readAll(); if (process->error() != QProcess::UnknownError) { errorString = process->errorString(); success = false; } // Report errors only if we are registering files. If for example the plugin containing the // original .qhc file has been updated, unregistering .qch files may fail but it should // not be treated as an error. if (process->exitCode() != 0 && registerFile) { exitCode = process->exitCode(); errorString = process->readAllStandardError(); } + + if (success && exitCode == 0) + { + // Use a hack to get the plug-in id from the qch path + QString strId = QFileInfo(qchFiles[i]).dir().dirName(); + if (strId.isEmpty()) + { + BERRY_ERROR << "Could not get last directory name from: " << qchFiles[i].toStdString(); + } + else + { + bool okay = true; + long pluginId = strId.toLong(&okay); + if (okay) + { + QSharedPointer plugin = berry::Platform::GetCTKPlugin(pluginId); + if (plugin) + { + if (registerFile) + { + registeredBundles.insert(plugin->getSymbolicName()); + } + else + { + registeredBundles.remove(plugin->getSymbolicName()); + } + } + } + else + { + BERRY_WARN << "Could convert last directory name into an integer (legacy BlueBerry plug-in?): " << qchFiles[i].toStdString(); + } + } + } } progress.setValue(argsVector.size()); if (!errorString.isEmpty() || exitCode) { QString errText; if (errorString.isEmpty()) { if (registerFile) errText += "Registering "; else errText += "Unregistering "; errText += "one or more help files failed."; errText += "\nYou may not have write permissions in " + QDir::toNativeSeparators(QDir::homePath()); } else { errText += errorString; } QMessageBox::warning(0, "Help System Error", errText); } return success; } QString QtAssistantUtil::GetAssistantExecutable() { QFileInfo assistantFile(QT_ASSISTANT_EXECUTABLE); QFileInfo localAssistant(QCoreApplication::applicationDirPath() + "/" + assistantFile.fileName() ); if (localAssistant.isExecutable()) { return localAssistant.absoluteFilePath(); } else { return assistantFile.absoluteFilePath(); } } void QtAssistantUtil::SetDefaultHelpUrl(const QString& defaultUrl) { defaultHelpUrl = defaultUrl; } } diff --git a/BlueBerry/Bundles/org.blueberry.ui.qt/src/berryQtAssistantUtil.h b/BlueBerry/Bundles/org.blueberry.ui.qt/src/berryQtAssistantUtil.h index 0764355d2b..bd1f6068bb 100644 --- a/BlueBerry/Bundles/org.blueberry.ui.qt/src/berryQtAssistantUtil.h +++ b/BlueBerry/Bundles/org.blueberry.ui.qt/src/berryQtAssistantUtil.h @@ -1,74 +1,74 @@ /*========================================================================= Program: BlueBerry Platform Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef BERRYQTASSISTANTUTIL_H_ #define BERRYQTASSISTANTUTIL_H_ #include #include #include #include #include #include #include namespace berry { class BERRY_UI_QT QtAssistantUtil { public: static void OpenAssistant(const QString& startPage = ""); static void CloseAssistant(); /** * @brief With this method you can open the help-page of the active bundle. */ static void OpenActivePartHelp(); // for legacy BlueBerry bundle support static bool RegisterQCHFiles(const std::vector& bundles); static bool RegisterQCHFiles(const QStringList& qchFiles); static bool UnregisterQCHFiles(const QStringList& qchFiles); static void SetHelpCollectionFile(const QString& file); static QString GetHelpCollectionFile(); static void SetDefaultHelpUrl(const QString& defaultUrl); private: static QProcess* assistantProcess; static QString helpCollectionFile; static QString defaultHelpUrl; - static QStringList registeredBundles; + static QSet registeredBundles; static QString GetAssistantExecutable(); static QStringList ExtractQCHFiles(const std::vector& bundles); static bool CallQtAssistant(const QStringList& qchFiles, bool registerFile = true); }; } #endif /* BERRYQTASSISTANTUTIL_H_ */