Mercurial > hg > svcore
view base/RecentFiles.cpp @ 157:c03ec31005e1
* Add zoom thumbwheels to Pane. Implement horizontal thumbwheel, and
vertical depending on layer type (supported for waveform and spectrogram,
though wrong for log-scale spectrogram at the moment).
* Add bare bones of a spectrum layer.
* Add window icon
* Add shortcut for "insert time instant" on laptops without keypad enter (";")
* Delete FFT processing thread when it exits (at least, next time we're asked
for something interesting)
* Get audio file extensions from the file readers, and thus from libsndfile for
the wave file reader -- leads to rather a wide combo box in file dialog though
* Better refresh order for spectrogram (redraw centre section first)
author | Chris Cannam |
---|---|
date | Fri, 04 Aug 2006 17:01:37 +0000 |
parents | 059b0322009c |
children | 702fc936e6a6 |
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ /* Sonic Visualiser An audio file viewer and annotation editor. Centre for Digital Music, Queen Mary, University of London. This file copyright 2006 Chris Cannam. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. See the file COPYING included with this distribution for more information. */ #include "RecentFiles.h" #include "Preferences.h" #include <QFileInfo> #include <QSettings> RecentFiles * RecentFiles::m_instance = 0; RecentFiles * RecentFiles::getInstance(int maxFileCount) { if (!m_instance) { m_instance = new RecentFiles(maxFileCount); } return m_instance; } RecentFiles::RecentFiles(int maxFileCount) : m_maxFileCount(maxFileCount) { readFiles(); } RecentFiles::~RecentFiles() { // nothing } void RecentFiles::readFiles() { m_files.clear(); QSettings settings; settings.beginGroup("RecentFiles"); for (unsigned int i = 0; i < 100; ++i) { QString key = QString("recent-file-%1").arg(i); QString filename = settings.value(key, "").toString(); if (filename == "") break; if (i < m_maxFileCount) m_files.push_back(filename); else settings.setValue(key, ""); } settings.endGroup(); } void RecentFiles::writeFiles() { QSettings settings; settings.beginGroup("RecentFiles"); for (unsigned int i = 0; i < m_maxFileCount; ++i) { QString key = QString("recent-file-%1").arg(i); QString filename = ""; if (i < m_files.size()) filename = m_files[i]; settings.setValue(key, filename); } settings.endGroup(); } void RecentFiles::truncateAndWrite() { while (m_files.size() > m_maxFileCount) { m_files.pop_back(); } writeFiles(); } std::vector<QString> RecentFiles::getRecentFiles() const { std::vector<QString> files; for (unsigned int i = 0; i < m_maxFileCount; ++i) { if (i < m_files.size()) { files.push_back(m_files[i]); } } return files; } void RecentFiles::addFile(QString filename) { filename = QFileInfo(filename).absoluteFilePath(); bool have = false; for (unsigned int i = 0; i < m_files.size(); ++i) { if (m_files[i] == filename) { have = true; break; } } if (!have) { m_files.push_front(filename); } else { std::deque<QString> newfiles; newfiles.push_back(filename); for (unsigned int i = 0; i < m_files.size(); ++i) { if (m_files[i] == filename) continue; newfiles.push_back(m_files[i]); } } truncateAndWrite(); emit recentFilesChanged(); }