comparison main/MainWindow.cpp @ 426:72a2b4210e50 templating

Add filesystem watcher to recreate template menu when templates change; start implementing save-session-as-template
author Chris Cannam
date Tue, 10 May 2011 13:58:59 +0100
parents eaab4c65c7bc
children ba07505d20e2
comparison
equal deleted inserted replaced
425:eaab4c65c7bc 426:72a2b4210e50
112 #include <QProcess> 112 #include <QProcess>
113 #include <QCheckBox> 113 #include <QCheckBox>
114 #include <QRegExp> 114 #include <QRegExp>
115 #include <QScrollArea> 115 #include <QScrollArea>
116 #include <QDesktopServices> 116 #include <QDesktopServices>
117 #include <QFileSystemWatcher>
117 118
118 #include <iostream> 119 #include <iostream>
119 #include <cstdio> 120 #include <cstdio>
120 #include <errno.h> 121 #include <errno.h>
121 122
137 m_playbackMenu(0), 138 m_playbackMenu(0),
138 m_existingLayersMenu(0), 139 m_existingLayersMenu(0),
139 m_sliceMenu(0), 140 m_sliceMenu(0),
140 m_recentFilesMenu(0), 141 m_recentFilesMenu(0),
141 m_recentTransformsMenu(0), 142 m_recentTransformsMenu(0),
143 m_templatesMenu(0),
142 m_rightButtonMenu(0), 144 m_rightButtonMenu(0),
143 m_rightButtonLayerMenu(0), 145 m_rightButtonLayerMenu(0),
144 m_rightButtonTransformsMenu(0), 146 m_rightButtonTransformsMenu(0),
145 m_rightButtonPlaybackMenu(0), 147 m_rightButtonPlaybackMenu(0),
146 m_soloAction(0), 148 m_soloAction(0),
158 m_playControlsSpacer(0), 160 m_playControlsSpacer(0),
159 m_playControlsWidth(0), 161 m_playControlsWidth(0),
160 m_preferencesDialog(0), 162 m_preferencesDialog(0),
161 m_layerTreeDialog(0), 163 m_layerTreeDialog(0),
162 m_activityLog(new ActivityLog()), 164 m_activityLog(new ActivityLog()),
163 m_keyReference(new KeyReference()) 165 m_keyReference(new KeyReference()),
166 m_templateWatcher(0)
164 { 167 {
165 Profiler profiler("MainWindow::MainWindow"); 168 Profiler profiler("MainWindow::MainWindow");
166 169
167 setWindowTitle(tr("Sonic Visualiser")); 170 setWindowTitle(tr("Sonic Visualiser"));
168 171
1695 1698
1696 action = new QAction(tr("Manage Saved Templates"), this); 1699 action = new QAction(tr("Manage Saved Templates"), this);
1697 connect(action, SIGNAL(triggered()), this, SLOT(manageSavedTemplates())); 1700 connect(action, SIGNAL(triggered()), this, SLOT(manageSavedTemplates()));
1698 action->setEnabled(havePersonal); 1701 action->setEnabled(havePersonal);
1699 m_templatesMenu->addAction(action); 1702 m_templatesMenu->addAction(action);
1703
1704 if (!m_templateWatcher) {
1705 m_templateWatcher = new QFileSystemWatcher(this);
1706 m_templateWatcher->addPath(ResourceFinder().getResourceSaveDir("templates"));
1707 connect(m_templateWatcher, SIGNAL(directoryChanged(const QString &)),
1708 this, SLOT(setupTemplatesMenu()));
1709 }
1700 } 1710 }
1701 1711
1702 void 1712 void
1703 MainWindow::setupRecentTransformsMenu() 1713 MainWindow::setupRecentTransformsMenu()
1704 { 1714 {
2857 QString name = QInputDialog::getText 2867 QString name = QInputDialog::getText
2858 (this, tr("Enter template name"), 2868 (this, tr("Enter template name"),
2859 tr("Please enter a name for the saved template:")); 2869 tr("Please enter a name for the saved template:"));
2860 if (name == "") return; 2870 if (name == "") return;
2861 2871
2862 //!!! sanitise! 2872 //!!! sanitise name!
2863 2873
2864 2874 //!!! check/confirm if target exists!
2875
2876 ResourceFinder rf;
2877 QString dir = rf.getResourceSaveDir("templates");
2878 saveSessionTemplate(QString("%1/%2.svt").arg(dir).arg(name));
2865 } 2879 }
2866 2880
2867 void 2881 void
2868 MainWindow::manageSavedTemplates() 2882 MainWindow::manageSavedTemplates()
2869 { 2883 {