ctkPluginStorage.cpp

Go to the documentation of this file.
00001 /*=============================================================================
00002 
00003   Library: CTK
00004 
00005   Copyright (c) 2010 German Cancer Research Center,
00006     Division of Medical and Biological Informatics
00007 
00008   Licensed under the Apache License, Version 2.0 (the "License");
00009   you may not use this file except in compliance with the License.
00010   You may obtain a copy of the License at
00011 
00012     http://www.apache.org/licenses/LICENSE-2.0
00013 
00014   Unless required by applicable law or agreed to in writing, software
00015   distributed under the License is distributed on an "AS IS" BASIS,
00016   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017   See the License for the specific language governing permissions and
00018   limitations under the License.
00019 
00020 =============================================================================*/
00021 
00022 #include "ctkPluginStorage_p.h"
00023 
00024 #include <QPluginLoader>
00025 #include <QFileInfo>
00026 #include <QUrl>
00027 #include <QDir>
00028 
00029 // CTK includes
00030 #include "ctkPluginArchive_p.h"
00031 #include "ctkPluginFrameworkContext_p.h"
00032 #include "ctkPluginDatabaseException.h"
00033 
00034 
00035   ctkPluginStorage::ctkPluginStorage(ctkPluginFrameworkContext* framework)
00036     : framework(framework), pluginDatabase(this)
00037   {
00038 //    // See if we have a storage database
00039 //    bundlesDir = Util.getFileStorage(framework, "bs");
00040 //    if (bundlesDir == null) {
00041 //      throw RuntimeException("No plugin storage area available!");
00042 //    }
00043 
00044     pluginDatabase.open();
00045     archives << pluginDatabase.getPluginArchives();
00046   }
00047 
00048   ctkPluginArchive* ctkPluginStorage::insertPlugin(const QUrl& location, const QString& localPath)
00049   {
00050     ctkPluginArchive* pa = pluginDatabase.insertPlugin(location, localPath);
00051     archives.push_back(pa);
00052     return pa;
00053   }
00054 
00055   ctkPluginArchive* ctkPluginStorage::updatePluginArchive(ctkPluginArchive* old, const QString& localPath)
00056   {
00057     //return new BundleArchiveImpl((BundleArchiveImpl)old, is);
00058     return 0;
00059   }
00060 
00061   void ctkPluginStorage::replacePluginArchive(ctkPluginArchive* oldPA, ctkPluginArchive* newPA)
00062   {
00063 //    int pos;
00064 //    long id = oldBA.getBundleId();
00065 //    synchronized (archives) {
00066 //      pos = find(id);
00067 //      if (pos >= archives.size() || archives.get(pos) != oldBA) {
00068 //        throw new Exception("replaceBundleJar: Old bundle archive not found, pos=" + pos);
00069 //      }
00070 //      archives.set(pos, newBA);
00071 //    }
00072   }
00073 
00074   QList<ctkPluginArchive*> ctkPluginStorage::getAllPluginArchives() const
00075   {
00076     return archives;
00077   }
00078 
00079   QList<QString> ctkPluginStorage::getStartOnLaunchPlugins()
00080   {
00081     QList<QString> res;
00082     QListIterator<ctkPluginArchive*> i(archives);
00083     while(i.hasNext())
00084     {
00085       ctkPluginArchive* pa = i.next();
00086       if (pa->getAutostartSetting() != -1)
00087       {
00088         res.push_back(pa->getPluginLocation().toString());
00089       }
00090     }
00091     return res;
00092   }
00093 
00094   ctkPluginStorage::~ctkPluginStorage()
00095   {
00096     close();
00097   }
00098 
00099   void ctkPluginStorage::close()
00100   {
00101     pluginDatabase.close();
00102     qDeleteAll(archives);
00103   }
00104 
00105   bool ctkPluginStorage::removeArchive(ctkPluginArchive* pa)
00106   {
00107     QMutexLocker lock(&archivesLock);
00108 
00109     bool removed = false;
00110     try
00111     {
00112       pluginDatabase.removeArchive(pa);
00113       removed = archives.removeAll(pa);
00114       delete pa;
00115     }
00116     catch (const ctkPluginDatabaseException& exc)
00117     {
00118       qDebug() << "Removing plugin archive failed:" << exc;
00119       removed = false;
00120     }
00121 
00122     return removed;
00123   }
00124 
00125   QByteArray ctkPluginStorage::getPluginResource(long pluginId, const QString& res) const
00126   {
00127     try
00128     {
00129       return pluginDatabase.getPluginResource(pluginId, res);
00130     }
00131     catch (const ctkPluginDatabaseException& exc)
00132     {
00133       qDebug() << QString("Getting plugin resource %1 failed:").arg(res) << exc;
00134       return QByteArray();
00135     }
00136   }
00137 
00138   QStringList ctkPluginStorage::findResourcesPath(long pluginId, const QString& path) const
00139   {
00140     try
00141     {
00142       return pluginDatabase.findResourcesPath(pluginId, path);
00143     }
00144     catch (const ctkPluginDatabaseException& exc)
00145     {
00146       qDebug() << QString("Getting plugin resource paths for %1 failed:").arg(path) << exc;
00147       return QStringList();
00148     }
00149 
00150 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated on 21 May 2010 for CTK by  doxygen 1.6.1