comparison framework/MainWindowBase.cpp @ 230:976d43d3c67d templating

Split out openSessionTemplate with template name argument rather than FileSource
author Chris Cannam
date Tue, 17 May 2011 17:04:22 +0100
parents a6398a7400c1
children 65d75297a37e
comparison
equal deleted inserted replaced
227:a6398a7400c1 230:976d43d3c67d
212 this, 212 this,
213 SLOT(preferenceChanged(PropertyContainer::PropertyName))); 213 SLOT(preferenceChanged(PropertyContainer::PropertyName)));
214 214
215 Labeller::ValueType labellerType = Labeller::ValueFromTwoLevelCounter; 215 Labeller::ValueType labellerType = Labeller::ValueFromTwoLevelCounter;
216 settings.beginGroup("MainWindow"); 216 settings.beginGroup("MainWindow");
217
217 labellerType = (Labeller::ValueType) 218 labellerType = (Labeller::ValueType)
218 settings.value("labellertype", (int)labellerType).toInt(); 219 settings.value("labellertype", (int)labellerType).toInt();
219 int cycle = settings.value("labellercycle", 4).toInt(); 220 int cycle = settings.value("labellercycle", 4).toInt();
221
222 m_defaultSessionTemplate = settings.value("sessiontemplate", "").toString();
223 if (m_defaultSessionTemplate == "") m_defaultSessionTemplate = "default";
224
220 settings.endGroup(); 225 settings.endGroup();
221 226
222 m_labeller = new Labeller(labellerType); 227 m_labeller = new Labeller(labellerType);
223 m_labeller->setCounterCycleSize(cycle); 228 m_labeller->setCounterCycleSize(cycle);
224 229
1187 1192
1188 bool loadedTemplate = false; 1193 bool loadedTemplate = false;
1189 1194
1190 if (mode == ReplaceSession) { 1195 if (mode == ReplaceSession) {
1191 1196
1192 if (templateName.length() != 0) { 1197 if (templateName != "") {
1193 // Template in the user's template directory takes 1198 FileOpenStatus tplStatus = openSessionTemplate(templateName);
1194 // priority over a bundled one; we don't unbundle, but 1199 if (tplStatus != FileOpenFailed) {
1195 // open directly from the bundled file (where applicable) 1200 std::cerr << "Template load succeeded" << std::endl;
1196 ResourceFinder rf; 1201 loadedTemplate = true;
1197 QString tfile = rf.getResourcePath("templates", templateName + ".svt");
1198 if (tfile != "") {
1199 std::cerr << "SV loading template file " << tfile.toStdString() << std::endl;
1200 FileOpenStatus tplStatus = openSessionTemplate("file:" + tfile);
1201 if (tplStatus != FileOpenFailed) {
1202 std::cerr << "Template load succeeded" << std::endl;
1203 loadedTemplate = true;
1204 }
1205 } 1202 }
1206 } 1203 }
1207 1204
1208 if (!loadedTemplate) { 1205 if (!loadedTemplate) {
1209 closeSession(); 1206 closeSession();
1673 } else { 1670 } else {
1674 setWindowTitle(QApplication::applicationName()); 1671 setWindowTitle(QApplication::applicationName());
1675 } 1672 }
1676 1673
1677 return ok ? FileOpenSucceeded : FileOpenFailed; 1674 return ok ? FileOpenSucceeded : FileOpenFailed;
1675 }
1676
1677 MainWindowBase::FileOpenStatus
1678 MainWindowBase::openSessionTemplate(QString templateName)
1679 {
1680 // Template in the user's template directory takes
1681 // priority over a bundled one; we don't unbundle, but
1682 // open directly from the bundled file (where applicable)
1683 ResourceFinder rf;
1684 QString tfile = rf.getResourcePath("templates", templateName + ".svt");
1685 if (tfile != "") {
1686 std::cerr << "SV loading template file " << tfile.toStdString() << std::endl;
1687 return openSessionTemplate(FileSource("file:" + tfile));
1688 } else {
1689 return FileOpenFailed;
1690 }
1678 } 1691 }
1679 1692
1680 MainWindowBase::FileOpenStatus 1693 MainWindowBase::FileOpenStatus
1681 MainWindowBase::openSessionTemplate(FileSource source) 1694 MainWindowBase::openSessionTemplate(FileSource source)
1682 { 1695 {