void PluginItem::setState(const State &destState) { if(hasError() || !m_enabled) return; switch(destState) { case Loaded: loadPlugin(); break; case Initialized: initializePlugin(); break; case Running: runPlugin(); break; case Stopped: stopPlugin(); break; case Unloaded: unloadPlugin(); break; default: break; } }
RESULT YandexNarodRVFSDriver::sync() { RESULT res = eERROR_GENERAL; SettingStorage* settings = WebMounter::getSettingStorage(); QString pluginStoragePath = settings->getAppStoragePath() + QString(QDir::separator()) + m_pluginName; QFileInfo fInfo(pluginStoragePath); unsigned int uNotDownloaded = 0; PluginSettings plSettings; settings->getData(plSettings, m_pluginName); m_driverMutex.lock(); if(m_state != eSyncStopping) { updateState(0, RemoteDriver::eSync); } m_driverMutex.unlock(); QList<VFSElement> elements; VFSElement elem = VFSElement(VFSElement::DIRECTORY , fInfo.absoluteFilePath() , "ROOT" , "" , "" , "" , ROOT_ID , ROOT_ID , "" , m_pluginName); elements.append(elem); res = getElements(elements); if(!res) { QDir qDir; QFile qFile; uNotDownloaded = elements.count(); VFSCache* vfsCache = WebMounter::getCache(); VFSCache::iterator iter = vfsCache->begin(); for(iter; iter != vfsCache->end(); ++iter) { if(iter->getPluginName() == m_pluginName) { bool found = false; int count = elements.count(); // Try to find element in new data for(int i=0; i<count; i++) { if(iter->getId() == elements[i].getId()) { found = true; if(iter != elements[i]) { if(iter->getType() == VFSElement::DIRECTORY) { qDir.rename(iter->getPath(), elements[i].getPath()); } break; } elements.removeAt(i); break; } } // Element has been deleted if(!found) { VFSCache::iterator iter1 = iter--; vfsCache->erase(iter1); } } } { LOCK(m_driverMutex); if(m_state != eSyncStopping) { updateState(30, RemoteDriver::eSync); } } // Add newly created elements for(int i=0; i<elements.count(); i++) { vfsCache->insert(elements[i]); } { LOCK(m_driverMutex); if(m_state != eSyncStopping) { updateState(40, RemoteDriver::eSync); } } QString rootPath = WebMounter::getSettingStorage()->getAppStoragePath() + QString(QDir::separator()) + m_pluginName; QFileInfo fInfo(rootPath); syncCacheWithFileSystem(fInfo.absoluteFilePath()); { LOCK(m_driverMutex); if(m_state != eSyncStopping) { updateState(50, RemoteDriver::eSync); } } if(plSettings.m_fullSync) { res = downloadFiles(); } } if(res != eNO_ERROR) { stopPlugin(); notifyUser(Ui::Notification::eCRITICAL, tr("Error"), tr("Sync failed !\n")); //updateState(100, RemoteDriver::eNotConnected); } else { m_driverMutex.lock(); if(m_state != eSyncStopping) { updateState(100, eConnected); } m_driverMutex.unlock(); } return res; }
ctkPluginBrowser::ctkPluginBrowser(ctkPluginFramework* framework) : framework(framework) { pluginEventTypeToString[ctkPluginEvent::INSTALLED] = "Installed"; pluginEventTypeToString[ctkPluginEvent::LAZY_ACTIVATION] = "Lazy Activation"; pluginEventTypeToString[ctkPluginEvent::RESOLVED] = "Resolved"; pluginEventTypeToString[ctkPluginEvent::STARTED] = "Started"; pluginEventTypeToString[ctkPluginEvent::STARTING] = "Starting"; pluginEventTypeToString[ctkPluginEvent::STOPPED] = "Stopped"; pluginEventTypeToString[ctkPluginEvent::STOPPING] = "Stopping"; pluginEventTypeToString[ctkPluginEvent::UNINSTALLED] = "Uninstalled"; pluginEventTypeToString[ctkPluginEvent::UNRESOLVED] = "Unresolved"; pluginEventTypeToString[ctkPluginEvent::UPDATED] = "Updated"; framework->getPluginContext()->connectFrameworkListener(this, SLOT(frameworkEvent(ctkPluginFrameworkEvent))); framework->getPluginContext()->connectPluginListener(this, SLOT(pluginEvent(ctkPluginEvent))); framework->getPluginContext()->connectServiceListener(this, "serviceEvent"); QStringList pluginDirs; #ifdef CMAKE_INTDIR pluginDirs << CTK_PLUGIN_DIR CMAKE_INTDIR "/"; #else pluginDirs << CTK_PLUGIN_DIR; #endif QStringListIterator dirIt(pluginDirs); while (dirIt.hasNext()) { QApplication::addLibraryPath(dirIt.next()); } QStringList libFilter; libFilter << "*.dll" << "*.so" << "*.dylib"; QDirIterator dirIter(pluginDirs.at(0), libFilter, QDir::Files); while(dirIter.hasNext()) { try { framework->getPluginContext()->installPlugin(QUrl::fromLocalFile(dirIter.next()).toString()); //plugin->start(ctkPlugin::START_ACTIVATION_POLICY); } catch (const ctkPluginException& e) { qCritical() << e.what(); } } framework->start(); ui.setupUi(this); tabifyDockWidget(ui.qtResourcesDockWidget, ui.pluginResourcesDockWidget); editors = new ctkPluginBrowserEditors(ui.centralwidget); QAbstractItemModel* pluginTableModel = new ctkPluginTableModel(framework->getPluginContext(), this); ui.pluginsTableView->setModel(pluginTableModel); QAbstractItemModel* qtresourcesTreeModel = new ctkQtResourcesTreeModel(this); ui.qtResourcesTreeView->setModel(qtresourcesTreeModel); connect(ui.pluginsTableView, SIGNAL(clicked(QModelIndex)), this, SLOT(pluginSelected(QModelIndex))); connect(ui.pluginsTableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(pluginDoubleClicked(QModelIndex))); connect(ui.pluginResourcesTreeView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(dbResourceDoubleClicked(QModelIndex))); connect(ui.qtResourcesTreeView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(qtResourceDoubleClicked(QModelIndex))); startPluginNowAction = new QAction(QIcon(":/pluginbrowser/images/run-now.png"), "Start Plugin (ignore activation policy)", this); startPluginAction = new QAction(QIcon(":/pluginbrowser/images/run.png"), "Start Plugin", this); stopPluginAction = new QAction(QIcon(":/pluginbrowser/images/stop.png"), "Stop Plugin", this); connect(startPluginNowAction, SIGNAL(triggered()), this, SLOT(startPluginNow())); connect(startPluginAction, SIGNAL(triggered()), this, SLOT(startPlugin())); connect(stopPluginAction, SIGNAL(triggered()), this, SLOT(stopPlugin())); startPluginNowAction->setEnabled(false); startPluginAction->setEnabled(false); stopPluginAction->setEnabled(false); ui.pluginToolBar->addAction(startPluginNowAction); ui.pluginToolBar->addAction(startPluginAction); ui.pluginToolBar->addAction(stopPluginAction); QSettings settings; if(settings.contains(SETTINGS_WND_GEOM)) { this->restoreGeometry(settings.value(SETTINGS_WND_GEOM).toByteArray()); } if (settings.contains(SETTINGS_WND_STATE)) { this->restoreState(settings.value(SETTINGS_WND_STATE).toByteArray()); } }