# HG changeset patch # User Chris Cannam # Date 1304956649 -3600 # Node ID eaab4c65c7bcc10f19b0027211280c42b8a3576a # Parent 944167b96d0143f8e36c924fbcef319cdb416d3f Add a bit more substance to the templates menu, and improve some naming diff -r 944167b96d01 -r eaab4c65c7bc main/MainWindow.cpp --- a/main/MainWindow.cpp Mon May 09 16:56:50 2011 +0100 +++ b/main/MainWindow.cpp Mon May 09 16:57:29 2011 +0100 @@ -113,6 +113,7 @@ #include #include #include +#include #include #include @@ -431,11 +432,17 @@ menu->addSeparator(); - m_templatesMenu = menu->addMenu(tr("Set Session Open Template")); + QString templatesMenuLabel = tr("Session Template for Audio Files"); + +#ifdef Q_OS_MAC + // Normally this menu will go next to Preferences on the File + // menu. But on OS/X Preferences doesn't appear on the File menu, + // so we put it next to the other Session stuff instead. + m_templatesMenu = menu->addMenu(templatesMenuLabel); m_templatesMenu->setTearOffEnabled(true); setupTemplatesMenu(); - menu->addSeparator(); +#endif icon = il.load("filesave"); icon.addPixmap(il.loadPixmap("filesave-22")); @@ -504,6 +511,13 @@ menu->addSeparator(); +#ifndef Q_OS_MAC + // See note for Q_OS_MAC alternative above + m_templatesMenu = menu->addMenu(templatesMenuLabel); + m_templatesMenu->setTearOffEnabled(true); + setupTemplatesMenu(); +#endif + action = new QAction(tr("&Preferences..."), this); action->setStatusTip(tr("Adjust the application preferences")); connect(action, SIGNAL(triggered()), this, SLOT(preferences())); @@ -1637,7 +1651,7 @@ QSettings settings; settings.beginGroup("MainWindow"); QString deflt = settings.value("sessiontemplate", "").toString(); - setDefaultSessionTemplate(deflt); + setDefaultSessionTemplate(deflt == "" ? "default" : ""); settings.endGroup(); QActionGroup *templatesGroup = new QActionGroup(this); @@ -1652,24 +1666,37 @@ m_templatesMenu->addSeparator(); - QStringList templates = ResourceFinder().getResourceFiles("templates", "xml"); + QStringList templates = ResourceFinder().getResourceFiles("templates", "svt"); + + bool havePersonal = false; + + // (ordered by name) + std::set byName; foreach (QString t, templates) { - QString tname = QFileInfo(t).baseName(); - if (tname.toLower() == "default") continue; - action = new QAction(tname, this); - action->setObjectName(t); + if (!t.startsWith(":")) havePersonal = true; + byName.insert(QFileInfo(t).baseName()); + } + + foreach (QString t, byName) { + if (t.toLower() == "default") continue; + action = new QAction(t, this); connect(action, SIGNAL(triggered()), this, SLOT(changeTemplate())); action->setCheckable(true); - action->setChecked(deflt == tname); + action->setChecked(deflt == t); templatesGroup->addAction(action); m_templatesMenu->addAction(action); } if (!templates.empty()) m_templatesMenu->addSeparator(); - action = new QAction(tr("Save Session as New Template..."), this); + action = new QAction(tr("Save Template from Current Session..."), this); connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAsTemplate())); m_templatesMenu->addAction(action); + + action = new QAction(tr("Manage Saved Templates"), this); + connect(action, SIGNAL(triggered()), this, SLOT(manageSavedTemplates())); + action->setEnabled(havePersonal); + m_templatesMenu->addAction(action); } void @@ -2803,7 +2830,46 @@ void MainWindow::changeTemplate() { - //!!! + QObject *s = sender(); + QAction *action = qobject_cast(s); + + if (!action) { + std::cerr << "WARNING: MainWindow::changeTemplate: sender is not an action" + << std::endl; + return; + } + + QString n = action->objectName(); + if (n == "") n = action->text(); + + if (n == "") { + std::cerr << "WARNING: MainWindow::changeTemplate: sender has no name" + << std::endl; + return; + } + + setDefaultSessionTemplate(n); +} + +void +MainWindow::saveSessionAsTemplate() +{ + QString name = QInputDialog::getText + (this, tr("Enter template name"), + tr("Please enter a name for the saved template:")); + if (name == "") return; + + //!!! sanitise! + + +} + +void +MainWindow::manageSavedTemplates() +{ + //!!! really we should watch this directory and recreate the menu when it changes + ResourceFinder rf; + QDesktopServices::openUrl("file:" + rf.getResourceSaveDir("templates")); } void diff -r 944167b96d01 -r eaab4c65c7bc main/MainWindow.h --- a/main/MainWindow.h Mon May 09 16:56:50 2011 +0100 +++ b/main/MainWindow.h Mon May 09 16:57:29 2011 +0100 @@ -171,6 +171,9 @@ virtual void midiEventsAvailable(); virtual void playStatusChanged(bool); + virtual void saveSessionAsTemplate(); + virtual void manageSavedTemplates(); + virtual void website(); virtual void help(); virtual void about(); diff -r 944167b96d01 -r eaab4c65c7bc sonic-visualiser.qrc --- a/sonic-visualiser.qrc Mon May 09 16:56:50 2011 +0100 +++ b/sonic-visualiser.qrc Mon May 09 16:57:29 2011 +0100 @@ -104,8 +104,9 @@ samples/stick.wav samples/strike.wav samples/tap.wav - templates/default.xml - templates/testtemplate.xml + templates/default.svt + templates/tk.svt + templates/testtemplate.svt i18n/sonic-visualiser_ru.qm i18n/sonic-visualiser_en_GB.qm i18n/sonic-visualiser_en_US.qm