Skip to content

Commit

Permalink
add some metadata to plugins; extend plugin manager
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Jul 17, 2012
1 parent 692ecb3 commit 966e628
Show file tree
Hide file tree
Showing 14 changed files with 262 additions and 100 deletions.
23 changes: 23 additions & 0 deletions mscore/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,26 @@ const QTransform& MsScoreView::matrix() const
return t; // _matrix;
}

//---------------------------------------------------------
// collectPluginMetaInformation
//---------------------------------------------------------

void collectPluginMetaInformation(PluginDescription* d)
{
printf("collect meta for <%s>\n", qPrintable(d->path));

QDeclarativeComponent component(mscore->qml(), QUrl::fromLocalFile(d->path));
QObject* obj = component.create();
if (obj == 0) {
qDebug("creating component <%s> failed", qPrintable(d->path));
foreach(QDeclarativeError e, component.errors()) {
qDebug(" line %d: %s", e.line(), qPrintable(e.description()));
}
return;
}
QmlPlugin* item = qobject_cast<QmlPlugin*>(obj);
d->version = item->version();
d->description = item->description();
delete obj;
}

15 changes: 14 additions & 1 deletion mscore/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ class MsScoreView : public QDeclarativeItem, public MuseScoreView {
class QmlPlugin : public QDeclarativeItem {
Q_OBJECT
Q_PROPERTY(QString menuPath READ menuPath WRITE setMenuPath)
Q_PROPERTY(QString version READ version WRITE setVersion)
Q_PROPERTY(QString description READ description WRITE setDescription)
Q_PROPERTY(QString pluginType READ pluginType WRITE setPluginType)

Q_PROPERTY(QString dockArea READ dockArea WRITE setDockArea)
Q_PROPERTY(int division READ division)
Q_PROPERTY(int mscoreVersion READ mscoreVersion)
Expand All @@ -161,6 +164,8 @@ class QmlPlugin : public QDeclarativeItem {
QString _menuPath;
QString _pluginType;
QString _dockArea;
QString _version;
QString _description;

signals:
void run();
Expand All @@ -171,14 +176,19 @@ class QmlPlugin : public QDeclarativeItem {

void setMenuPath(const QString& s) { _menuPath = s; }
QString menuPath() const { return _menuPath; }
void setVersion(const QString& s) { _version = s; }
QString version() const { return _version; }
void setDescription(const QString& s) { _description = s; }
QString description() const { return _description; }

void setPluginType(const QString& s) { _pluginType = s; }
QString pluginType() const { return _pluginType; }
void setDockArea(const QString& s) { _dockArea = s; }
QString dockArea() const { return _dockArea; }
void runPlugin() { emit run(); }

int division() const { return MScore::division; }
int mscoreVersion() const { return version(); }
int mscoreVersion() const { return ::version(); }
int mscoreMajorVersion() const { return majorVersion(); }
int mscoreMinorVersion() const { return minorVersion(); }
int mscoreUpdateVersion() const { return updateVersion(); }
Expand All @@ -194,6 +204,9 @@ class QmlPlugin : public QDeclarativeItem {
Q_INVOKABLE bool writeScore(Score*, const QString& name, const QString& ext);
Q_INVOKABLE Score* readScore(const QString& name);
};

extern void collectPluginMetaInformation(PluginDescription*);

#endif
#endif

135 changes: 81 additions & 54 deletions mscore/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "file.h"
#include "libmscore/mscore.h"
#include "shortcut.h"
#include "plugins.h"

bool useALSA = false, useJACK = false, usePortaudio = false;

Expand Down Expand Up @@ -234,8 +235,6 @@ void Preferences::init()

profile = "default";

// TODO: pluginList

firstStartWeb = true;
};

Expand Down Expand Up @@ -652,11 +651,6 @@ PreferenceDialog::PreferenceDialog(QWidget* parent)
bgButtons->addButton(bgWallpaperButton);
connect(bgColorButton, SIGNAL(toggled(bool)), SLOT(bgClicked(bool)));


pluginTable->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("load")));
pluginTable->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Plugin Path")));
pluginTable->setHorizontalHeaderItem(2, new QTableWidgetItem(tr("Shortcut")));

connect(buttonBox, SIGNAL(clicked(QAbstractButton*)), SLOT(buttonBoxClicked(QAbstractButton*)));
connect(fgWallpaperSelect, SIGNAL(clicked()), SLOT(selectFgWallpaper()));
connect(bgWallpaperSelect, SIGNAL(clicked()), SLOT(selectBgWallpaper()));
Expand Down Expand Up @@ -709,6 +703,10 @@ PreferenceDialog::PreferenceDialog(QWidget* parent)
connect(recordButtons, SIGNAL(buttonClicked(int)), SLOT(recordButtonClicked(int)));
connect(midiRemoteControlClear, SIGNAL(clicked()), SLOT(midiRemoteControlClearClicked()));
connect(sfOpenButton, SIGNAL(clicked()), SLOT(selectSoundFont()));

connect(pluginList, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
SLOT(pluginListItemChanged(QListWidgetItem*, QListWidgetItem*)));
connect(pluginLoad, SIGNAL(toggled(bool)), SLOT(pluginLoadToggled(bool)));
updateRemote();
}

Expand Down Expand Up @@ -781,6 +779,7 @@ void PreferenceDialog::updateRemote()

void PreferenceDialog::updateValues(Preferences* p)
{
prefs = p;
rcGroup->setChecked(p->useMidiRemote);
fgWallpaper->setText(p->fgWallpaper);
bgWallpaper->setText(p->bgWallpaper);
Expand Down Expand Up @@ -1010,23 +1009,19 @@ void PreferenceDialog::updateValues(Preferences* p)
idx = 0;
exportAudioSampleRate->setCurrentIndex(idx);

//
// update plugin manager
//
p->updatePluginList();
pluginTable->setRowCount(p->pluginList.size());

for (int i = 0; i < p->pluginList.size(); ++i) {
PluginDescription* d = p->pluginList[i];
QTableWidgetItem* item = new QTableWidgetItem(d->path);
pluginTable->setItem(i, 1, item);
item = new QTableWidgetItem;
item->setCheckState(d->load ? Qt::Checked : Qt::Unchecked);
pluginTable->setItem(i, 0, item);
item = new QTableWidgetItem(d->shortcut.keysToString());
pluginTable->setItem(i, 2, item);
QListWidgetItem* item = new QListWidgetItem(QFileInfo(d->path).baseName(), pluginList);
item->setData(Qt::UserRole, i);
}
sfChanged = false;
pluginList->setCurrentRow(0);
pluginListItemChanged(pluginList->item(0), 0);

// foreach(QObject* o, children())
// o->blockSignals(false);
sfChanged = false;
}

//---------------------------------------------------------
Expand Down Expand Up @@ -1440,15 +1435,6 @@ void PreferenceDialog::apply()

mscore->setIconSize(QSize(preferences.iconWidth, preferences.iconHeight));

int n = pluginTable->rowCount();
// qDeleteAll(preferences.pluginList);
// preferences.pluginList.clear();
for (int i = 0; i < n; ++i) {
PluginDescription* d = preferences.pluginList[i];
// d->path = pluginTable->item(i, 1)->text();
d->load = pluginTable->item(i, 0)->checkState() == Qt::Checked;
// preferences.pluginList.append(d);
}
emit preferencesChanged();
preferences.write();
mscore->startAutoSave();
Expand Down Expand Up @@ -1643,32 +1629,6 @@ void PreferenceDialog::defineShortcutClicked()
shortcutsChanged = true;
}

//---------------------------------------------------------
// definePluginShortcutClicked
//---------------------------------------------------------

void PreferenceDialog::definePluginShortcutClicked()
{
QTableWidgetItem* active = pluginTable->currentItem();
if (!active)
return;
int row = active->row();
PluginDescription* pd = preferences.pluginList[row];
Shortcut* s = &pd->shortcut;
ShortcutCaptureDialog sc(s, localShortcuts, this);
int rv = sc.exec();
if (rv == 0) // abort
return;
if (rv == 2) // replace
s->clear();
s->addShortcut(sc.getKey());
QAction* action = s->action();
action->setShortcuts(s->keys());
pluginTable->item(row, 2)->setText(s->keysToString());

preferences.dirty = true;
}

//---------------------------------------------------------
// readPluginList
//---------------------------------------------------------
Expand Down Expand Up @@ -1706,6 +1666,10 @@ bool Preferences::readPluginList()
d->load = eee.text().toInt();
else if (tag == "SC")
d->shortcut.read(eee);
else if (tag == "version")
d->version = eee.text();
else if (tag == "description")
d->description = eee.text();
else
domError(eee);
}
Expand Down Expand Up @@ -1744,6 +1708,8 @@ void Preferences::writePluginList()
xml.stag("Plugin");
xml.tag("path", d->path);
xml.tag("load", d->load);
xml.tag("version", d->version);
xml.tag("description", d->description);
if (!d->shortcut.keys().isEmpty()) {
d->shortcut.write(xml);
}
Expand Down Expand Up @@ -1786,6 +1752,7 @@ void Preferences::updatePluginList()
PluginDescription* p = new PluginDescription;
p->path = path;
p->load = false;
collectPluginMetaInformation(p);
pluginList.append(p);
}
}
Expand All @@ -1794,3 +1761,63 @@ void Preferences::updatePluginList()
}
}

//---------------------------------------------------------
// pluginListItemChanged
//---------------------------------------------------------

void PreferenceDialog::pluginListItemChanged(QListWidgetItem* item, QListWidgetItem*)
{
if (!item)
return;
int idx = item->data(Qt::UserRole).toInt();
PluginDescription* d = prefs->pluginList[idx];
QFileInfo fi(d->path);
pluginName->setText(fi.baseName());
pluginPath->setText(fi.absolutePath());
pluginLoad->setChecked(d->load);
pluginVersion->setText(d->version);
pluginShortcut->setText(d->shortcut.keysToString());
pluginDescription->setText(d->description);
}

//---------------------------------------------------------
// pluginLoadToggled
//---------------------------------------------------------

void PreferenceDialog::pluginLoadToggled(bool val)
{
QListWidgetItem* item = pluginList->currentItem();
if (!item)
return;
int idx = item->data(Qt::UserRole).toInt();
PluginDescription* d = prefs->pluginList[idx];
d->load = val;
prefs->dirty = true;
}

//---------------------------------------------------------
// definePluginShortcutClicked
//---------------------------------------------------------

void PreferenceDialog::definePluginShortcutClicked()
{
QListWidgetItem* item = pluginList->currentItem();
if (!item)
return;
int idx = item->data(Qt::UserRole).toInt();
PluginDescription* pd = preferences.pluginList[idx];
Shortcut* s = &pd->shortcut;
ShortcutCaptureDialog sc(s, localShortcuts, this);
int rv = sc.exec();
if (rv == 0) // abort
return;
if (rv == 2) // replace
s->clear();
s->addShortcut(sc.getKey());
QAction* action = s->action();
action->setShortcuts(s->keys());
pluginShortcut->setText(s->keysToString());
prefs->dirty = true;
}


2 changes: 2 additions & 0 deletions mscore/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ enum MusicxmlExportBreaks {

struct PluginDescription {
QString path;
QString version;
QString description;
bool load;
Shortcut shortcut;
QString menuPath;
Expand Down
3 changes: 3 additions & 0 deletions mscore/prefsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class PreferenceDialog : public QDialog, private Ui::PrefsDialogBase {
QMap<QString, Shortcut*> localShortcuts;
bool shortcutsChanged;
QButtonGroup* recordButtons;
Preferences* prefs;

void apply();
bool sfChanged;
Expand Down Expand Up @@ -69,6 +70,8 @@ class PreferenceDialog : public QDialog, private Ui::PrefsDialogBase {
void selectSoundFontsDirectory();
void selectImagesDirectory();
void definePluginShortcutClicked();
void pluginListItemChanged(QListWidgetItem*, QListWidgetItem*);
void pluginLoadToggled(bool);

signals:
void preferencesChanged();
Expand Down
Loading

0 comments on commit 966e628

Please sign in to comment.