Skip to content
Permalink
Browse files

add a start of unregisterPlugin function

  • Loading branch information...
lasconic committed Jul 17, 2014
1 parent a227994 commit 963fd379e5410ea796b3150e38df3b5f4da440b5
Showing with 101 additions and 1 deletion.
  1. +97 −0 mscore/mscorePlugins.cpp
  2. +4 −1 mscore/musescore.h
@@ -124,6 +124,39 @@ void MuseScore::registerPlugin(PluginDescription* plugin)
delete obj;
}

void MuseScore::unregisterPlugin(PluginDescription* plugin)
{
QString pluginPath = plugin->path;
QFileInfo np(pluginPath);
if (np.suffix() != "qml")
return;
QString baseName = np.baseName();

bool found = false;
foreach(QString s, plugins) {
QFileInfo fi(s);
if (fi.baseName() == baseName) {
found = true;
break;
}
}
if (!found) {
if (MScore::debugMode)
qDebug(" Plugin <%s> not registered", qPrintable(pluginPath));
return;
}
plugins.removeAll(pluginPath);


removeMenuEntry(plugin);
QAction* a = plugin->shortcut.action();
pluginActions.removeAll(a);

disconnect(a, SIGNAL(triggered()), pluginMapper, SLOT(map()));
pluginMapper->removeMappings(a);

}

//---------------------------------------------------------
// createMenuEntry
// syntax: "entry.entry.entry"
@@ -218,6 +251,70 @@ void MuseScore::createMenuEntry(PluginDescription* plugin)
}
}


void MuseScore::removeMenuEntry(PluginDescription* plugin)
{
if (!pluginMapper)
return;

QString menu = plugin->menuPath;
QStringList ml;
QString s;
bool escape = false;
foreach (QChar c, menu) {
if (escape) {
escape = false;
s += c;
}
else {
if (c == '\\')
escape = true;
else {
if (c == '.') {
ml += s;
s = "";
}
else {
s += c;
}
}
}
}
if (!s.isEmpty())
ml += s;

int n = ml.size();
QWidget* curMenu = menuBar();

for(int i = 0; i < n-1; ++i) {
QString m = ml[i];
QList<QObject*> ol = curMenu->children();
foreach(QObject* o, ol) {
QMenu* menu = qobject_cast<QMenu*>(o);
if (!menu)
continue;
if (menu->objectName() == m || menu->title() == m) {
curMenu = menu;
break;
}
}
}
QString m = ml[n-1];
QStringList sl = m.split(":");
QAction* a = plugin->shortcut.action();
QMenu* cm = static_cast<QMenu*>(curMenu);
cm->removeAction(a);
for(int i = n-2; i >= 0; --i) {

QMenu* menu = qobject_cast<QMenu*>(cm->parent());
if (cm->isEmpty())
if(cm->isEmpty()) {
delete cm;
}
cm = menu;
}
}

//---------------------------------------------------------
// pluginIdxFromPath
//---------------------------------------------------------
@@ -293,6 +293,7 @@ class MuseScore : public QMainWindow, public MuseScoreCore {
QString pluginPath;

void createMenuEntry(PluginDescription*);
void removeMenuEntry(PluginDescription*);

QTimer* autoSaveTimer;
QList<QAction*> qmlPluginActions;
@@ -371,7 +372,6 @@ class MuseScore : public QMainWindow, public MuseScoreCore {
bool saveFile();
bool saveFile(Score* score);
void fingeringMenu();
void registerPlugin(PluginDescription*);

int pluginIdxFromPath(QString pluginPath);
void startDebugger();
@@ -650,6 +650,9 @@ class MuseScore : public QMainWindow, public MuseScoreCore {
ScoreView* currentScoreView() const { return cv; }
void showMessage(const QString& s, int timeout);
void helpBrowser(const QString = QString()) const;

void registerPlugin(PluginDescription*);
void unregisterPlugin(PluginDescription*);
};

extern MuseScore* mscore;

0 comments on commit 963fd37

Please sign in to comment.
You can’t perform that action at this time.