Commit e9d80b13 authored by Dirk Wilden's avatar Dirk Wilden
Browse files

moved recentFiles/currentDir to QSettings

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8390 383ad7c9-94d9-4d36-a494-682f7c89f535
parent e6bc0974
...@@ -889,11 +889,13 @@ void Core::multiViewMode( int _mode ) { ...@@ -889,11 +889,13 @@ void Core::multiViewMode( int _mode ) {
void void
Core::slotRecentOpen(QAction* _action) Core::slotRecentOpen(QAction* _action)
{ {
QVector< OpenFlipper::Options::RecentFile > recentFiles = OpenFlipper::Options::recentFiles(); QStringList recentFiles = OpenFlipperSettings().value("Core/File/RecentFiles").toStringList();
QStringList recentTypes = OpenFlipperSettings().value("Core/File/RecentTypes").toStringList();
for (int i = 0 ; i < recentFiles.size() ; ++i ) for (int i = 0 ; i < recentFiles.size() ; ++i )
if ( recentFiles[i].filename == _action->text() ){ if ( recentFiles[i] == _action->text() ){
OpenFlipper::Options::loadingRecentFile(true); OpenFlipper::Options::loadingRecentFile(true);
loadObject(recentFiles[i].type, recentFiles[i].filename); loadObject(typeId(recentTypes[i]), recentFiles[i]);
OpenFlipper::Options::loadingRecentFile(false); OpenFlipper::Options::loadingRecentFile(false);
return; return;
} }
......
...@@ -135,7 +135,7 @@ void Core::readApplicationOptions(INIFile& _ini) { ...@@ -135,7 +135,7 @@ void Core::readApplicationOptions(INIFile& _ini) {
//============================================================================ //============================================================================
QString startup_dir; QString startup_dir;
if( _ini.get_entry(startup_dir, "Options", "StartupDir") ) if( _ini.get_entry(startup_dir, "Options", "StartupDir") )
OpenFlipper::Options::currentDir(startup_dir); OpenFlipperSettings().setValue("Core/CurrentDir", startup_dir );
//============================================================================ //============================================================================
// Load the default script directory // Load the default script directory
...@@ -383,9 +383,9 @@ void Core::readRecentFiles(QString _filename){ ...@@ -383,9 +383,9 @@ void Core::readRecentFiles(QString _filename){
OpenFlipper::Options::loadingSettings(true); OpenFlipper::Options::loadingSettings(true);
// Load maxRecent Setting // Load maxRecent Setting
int mrecent = 6; int mrecent = 10;
if (ini.get_entry(mrecent,"Options","MaxRecent")) if (ini.get_entry(mrecent,"Options","MaxRecent"))
OpenFlipper::Options::maxRecent(mrecent); OpenFlipperSettings().setValue("Core/File/MaxRecent", mrecent);
for ( int j = mrecent-1 ; j >= 0; --j) { for ( int j = mrecent-1 ; j >= 0; --j) {
QString file; QString file;
...@@ -416,18 +416,20 @@ void Core::readRecentFiles(QString _filename){ ...@@ -416,18 +416,20 @@ void Core::readRecentFiles(QString _filename){
void Core::writeApplicationOptions(INIFile& _ini) { void Core::writeApplicationOptions(INIFile& _ini) {
// Write maximum recent file count to ini // Write maximum recent file count to ini
_ini.add_entry("Options","MaxRecent",OpenFlipper::Options::maxRecent()); _ini.add_entry("Options","MaxRecent", OpenFlipperSettings().value("Core/File/MaxRecent",10).toInt() );
// Write list of recent files to ini // Write list of recent files to ini
QVector< OpenFlipper::Options::RecentFile > recentFiles = OpenFlipper::Options::recentFiles(); QStringList recentFiles = OpenFlipperSettings().value("Core/File/RecentFiles").toStringList();
QStringList recentTypes = OpenFlipperSettings().value("Core/File/RecentTypes").toStringList();
for ( int j = 0 ; j < recentFiles.size(); ++j) { for ( int j = 0 ; j < recentFiles.size(); ++j) {
// Save filename // Save filename
QString key = "recent" + QString::number(j); QString key = "recent" + QString::number(j);
QString filename = recentFiles[j].filename; QString filename = recentFiles[j];
_ini.add_entry( "Options" , key , filename ); _ini.add_entry( "Options" , key , filename );
// Save DataType // Save DataType
key = "type" + QString::number(j); key = "type" + QString::number(j);
QString type = typeName( recentFiles[j].type ); QString type = recentTypes[j];
_ini.add_entry( "Options" , key , type ); _ini.add_entry( "Options" , key , type );
} }
...@@ -513,7 +515,7 @@ void Core::writeApplicationOptions(INIFile& _ini) { ...@@ -513,7 +515,7 @@ void Core::writeApplicationOptions(INIFile& _ini) {
if ( !_ini.section_exists("Options") ) if ( !_ini.section_exists("Options") )
_ini.add_section("Options"); _ini.add_section("Options");
QString dir = OpenFlipper::Options::currentDirStr().toUtf8(); QString dir = OpenFlipperSettings().value("Core/CurrentDir").toString().toUtf8();
_ini.add_entry("Options","StartupDir",dir); _ini.add_entry("Options","StartupDir",dir);
QString scriptDir = OpenFlipper::Options::currentScriptDirStr().toUtf8(); QString scriptDir = OpenFlipper::Options::currentScriptDirStr().toUtf8();
......
...@@ -217,7 +217,7 @@ void Core::slotLoadPlugin(){ ...@@ -217,7 +217,7 @@ void Core::slotLoadPlugin(){
filter = "Plugins (*.so)"; filter = "Plugins (*.so)";
// Ask the user to select the file to load // Ask the user to select the file to load
QString filename = ACG::getOpenFileName(coreWidget_,tr("Load Plugin"),filter,OpenFlipper::Options::currentDirStr()); QString filename = ACG::getOpenFileName(coreWidget_,tr("Load Plugin"),filter, OpenFlipperSettings().value("Core/CurrentDir").toString() );
if (filename.isEmpty()) if (filename.isEmpty())
return; return;
......
...@@ -707,7 +707,7 @@ void Core::loadSettings(){ ...@@ -707,7 +707,7 @@ void Core::loadSettings(){
QFileDialog fileDialog( coreWidget_, QFileDialog fileDialog( coreWidget_,
tr("Load Settings"), tr("Load Settings"),
OpenFlipper::Options::currentDirStr(), OpenFlipperSettings().value("Core/CurrentDir").toString(),
tr("INI files (*.ini)") ); tr("INI files (*.ini)") );
fileDialog.setOption (QFileDialog::DontUseNativeDialog, true); fileDialog.setOption (QFileDialog::DontUseNativeDialog, true);
...@@ -763,7 +763,7 @@ void Core::loadSettings(){ ...@@ -763,7 +763,7 @@ void Core::loadSettings(){
QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2); QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2);
OpenFlipper::Options::currentDir(newpath); OpenFlipperSettings().setValue("Core/CurrentDir", newpath);
if ( complete_name.endsWith("ini") ) { if ( complete_name.endsWith("ini") ) {
openIniFile( complete_name, openIniFile( complete_name,
...@@ -785,7 +785,7 @@ void Core::loadSettings(QString _filename){ ...@@ -785,7 +785,7 @@ void Core::loadSettings(QString _filename){
return; return;
QString newpath = _filename.section(OpenFlipper::Options::dirSeparator(),0,-2); QString newpath = _filename.section(OpenFlipper::Options::dirSeparator(),0,-2);
OpenFlipper::Options::currentDir(newpath); OpenFlipperSettings().setValue("Core/CurrentDir", newpath);
if ( _filename.endsWith("ini") ) { if ( _filename.endsWith("ini") ) {
// Loaded function for recent files. Load everything. // Loaded function for recent files. Load everything.
......
...@@ -218,8 +218,7 @@ void Core::setupOptions() { ...@@ -218,8 +218,7 @@ void Core::setupOptions() {
OpenFlipper::Options::currentTextureDir(OpenFlipper::Options::textureDirStr()); OpenFlipper::Options::currentTextureDir(OpenFlipper::Options::textureDirStr());
// Default to home directory // Default to home directory
OpenFlipper::Options::currentDir( QDir::home() ); OpenFlipperSettings().setValue("Core/CurrentDir", QDir::homePath() );
// ============================================================== // ==============================================================
// Load Application options from all files available // Load Application options from all files available
......
...@@ -64,7 +64,7 @@ void Core::saveSettings(){ ...@@ -64,7 +64,7 @@ void Core::saveSettings(){
QFileDialog fileDialog( coreWidget_, QFileDialog fileDialog( coreWidget_,
tr("Save Settings"), tr("Save Settings"),
OpenFlipper::Options::currentDirStr(), OpenFlipperSettings().value("Core/CurrentDir").toString(),
tr("INI files (*.ini);;OBJ files (*.obj )") ); tr("INI files (*.ini);;OBJ files (*.obj )") );
fileDialog.setOption (QFileDialog::DontUseNativeDialog, true); fileDialog.setOption (QFileDialog::DontUseNativeDialog, true);
...@@ -149,7 +149,7 @@ void Core::saveSettings(){ ...@@ -149,7 +149,7 @@ void Core::saveSettings(){
// Get the chosen directory and remember it. // Get the chosen directory and remember it.
QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2); QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2);
OpenFlipper::Options::currentDir(newpath); OpenFlipperSettings().setValue("Core/CurrentDir", newpath);
// ======================================================================================== // ========================================================================================
// update status information // update status information
......
...@@ -93,6 +93,9 @@ ...@@ -93,6 +93,9 @@
* *
* <b>File Handling</b> * <b>File Handling</b>
* * Core/CurrentDir The current Directory of the Application * * Core/CurrentDir The current Directory of the Application
* * Core/File/RecentFiles List of Recent Files
* * Core/File/RecentTypes DataTypes of Recent Files
* * Core/File/MaxRecent Maximum entries in recent File list
* * Core/File/UseLoadDefaults Use the defaults saved in the file plugins * * Core/File/UseLoadDefaults Use the defaults saved in the file plugins
* *
* <b>Log Settings</b> * <b>Log Settings</b>
...@@ -247,22 +250,6 @@ QString helpDirStr(); ...@@ -247,22 +250,6 @@ QString helpDirStr();
* @{ */ * @{ */
//=========================================================================== //===========================================================================
/// return the current directory
DLLEXPORT
QString currentDirStr();
/// return the current directory
DLLEXPORT
QDir currentDir();
/// Sets the Path to the current directory
DLLEXPORT
void currentDir(QDir _dir);
/// Sets the Path to the current directory
DLLEXPORT
bool currentDir(QString _dir);
/// return the current script-directory /// return the current script-directory
DLLEXPORT DLLEXPORT
QString currentScriptDirStr(); QString currentScriptDirStr();
......
...@@ -53,41 +53,39 @@ ...@@ -53,41 +53,39 @@
#include "RecentFiles.hh" #include "RecentFiles.hh"
#include <OpenFlipper/common/GlobalOptions.hh>
#include <OpenFlipper/common/Types.hh>
namespace OpenFlipper { namespace OpenFlipper {
namespace Options { namespace Options {
/// List of recently opened files
static QVector<RecentFile> recentFiles_;
/// Maximum number of recent files
static int maxRecent_ = 6;
int maxRecent() { return maxRecent_; }
QVector<RecentFile> recentFiles() { return recentFiles_; }
void maxRecent(int _max) { maxRecent_ = _max; }
void recentFiles(QVector<RecentFile> _list ) { recentFiles_ = _list;}
void addRecentFile(QString _file, DataType _type) { void addRecentFile(QString _file, DataType _type) {
QStringList recentFiles = OpenFlipperSettings().value("Core/File/RecentFiles").toStringList();
QStringList recentTypes = OpenFlipperSettings().value("Core/File/RecentTypes").toStringList();
QString type = typeName(_type);
// Check if file already in recent list // Check if file already in recent list
for ( int i = 0 ; i < recentFiles_.size() ; ++i) for ( int i = 0 ; i < recentFiles.size() ; ++i)
if ( _file == recentFiles_[i].filename && _type == recentFiles_[i].type ) if ( _file == recentFiles[i] && type == recentTypes[i] ){
recentFiles_.remove(i); recentFiles.removeAt(i);
recentTypes.removeAt(i);
}
// Erase if too many files in list // Erase if too many files in list
if ( recentFiles_.size() >= maxRecent_ ) { if ( recentFiles.size() >= OpenFlipperSettings().value("Core/File/MaxRecent").toInt() ) {
recentFiles_.pop_back(); recentFiles.pop_back();
recentTypes.pop_back();
} }
recentFiles.push_front(_file);
recentTypes.push_front(type);
RecentFile recent; OpenFlipperSettings().setValue("Core/File/RecentFiles", recentFiles);
recent.filename = _file; OpenFlipperSettings().setValue("Core/File/RecentTypes", recentTypes);
recent.type = _type;
recentFiles_.push_front(recent);
} }
} }
......
...@@ -66,12 +66,6 @@ ...@@ -66,12 +66,6 @@
namespace OpenFlipper { namespace OpenFlipper {
namespace Options { namespace Options {
/// struct storing infos about recent files
struct RecentFile{
QString filename;
DataType type;
};
//=========================================================================== //===========================================================================
/** @name Recent Files /** @name Recent Files
...@@ -81,22 +75,6 @@ struct RecentFile{ ...@@ -81,22 +75,6 @@ struct RecentFile{
/// Add a file to the recent files list ( removes one, if list grows to larger then maxRecent ) /// Add a file to the recent files list ( removes one, if list grows to larger then maxRecent )
DLLEXPORT DLLEXPORT
void addRecentFile(QString _file, DataType _type); void addRecentFile(QString _file, DataType _type);
/// Return the list of recent files
DLLEXPORT
QVector< RecentFile > recentFiles();
/// Set the list of recent files
DLLEXPORT
void recentFiles(QVector< RecentFile > _list );
/// Get the maximum number of recent files kept in the list
DLLEXPORT
int maxRecent();
/// Set the maximum number of recent files kept in the list
DLLEXPORT
void maxRecent(int _max);
/** @} */ /** @} */
......
...@@ -510,8 +510,6 @@ CoreWidget( QVector<ViewMode*>& _viewModes, ...@@ -510,8 +510,6 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
setupMenuBar(); setupMenuBar();
updateRecent();
statusBar_->showMessage(tr("Ready"), 5000); statusBar_->showMessage(tr("Ready"), 5000);
registerCoreKeys(); registerCoreKeys();
...@@ -854,15 +852,17 @@ CoreWidget::updateRecent() ...@@ -854,15 +852,17 @@ CoreWidget::updateRecent()
recentFilesMenu_->clear(); recentFilesMenu_->clear();
QVector< OpenFlipper::Options::RecentFile > recentFiles = OpenFlipper::Options::recentFiles(); QStringList recentFiles = OpenFlipperSettings().value("Core/File/RecentFiles").toStringList();
QStringList recentTypes = OpenFlipperSettings().value("Core/File/RecentTypes").toStringList();
for (int i = 0 ; i < recentFiles.size() ; ++i ) { for (int i = 0 ; i < recentFiles.size() ; ++i ) {
QFileInfo fi(recentFiles[i].filename); QFileInfo fi(recentFiles[i]);
if (fi.suffix() == "ini") if (fi.suffix() == "ini")
recentFilesMenu_->addAction(QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator()+"Settings-Icon.png"), recentFiles[i].filename); recentFilesMenu_->addAction(QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator()+"Settings-Icon.png"), recentFiles[i]);
else else
recentFilesMenu_->addAction(typeIcon( recentFiles[i].type ), recentFiles[i].filename); recentFilesMenu_->addAction(typeIcon( typeId(recentTypes[i]) ), recentFiles[i]);
} }
......
...@@ -84,7 +84,7 @@ LoadWidget::LoadWidget(std::vector<fileTypes>& _supportedTypes , QWidget *parent ...@@ -84,7 +84,7 @@ LoadWidget::LoadWidget(std::vector<fileTypes>& _supportedTypes , QWidget *parent
//overwrite dialog shouldn't be handled by the qfiledialog //overwrite dialog shouldn't be handled by the qfiledialog
setConfirmOverwrite(false); setConfirmOverwrite(false);
setDirectory(OpenFlipper::Options::currentDirStr()); setDirectory( OpenFlipperSettings().value("Core/CurrentDir").toString() );
} }
/// Desctructor /// Desctructor
...@@ -233,7 +233,7 @@ void LoadWidget::loadFile(){ ...@@ -233,7 +233,7 @@ void LoadWidget::loadFile(){
QFileInfo fi(files[i]); QFileInfo fi(files[i]);
QString filename = fi.absoluteFilePath(); QString filename = fi.absoluteFilePath();
OpenFlipper::Options::currentDir(fi.absolutePath()); OpenFlipperSettings().setValue("Core/CurrentDir", filename);
QFile file(filename); QFile file(filename);
if (fi.isDir() || !file.exists()) continue; //do nothing if its a not a valid file if (fi.isDir() || !file.exists()) continue; //do nothing if its a not a valid file
...@@ -311,8 +311,7 @@ void LoadWidget::saveFile(){ ...@@ -311,8 +311,7 @@ void LoadWidget::saveFile(){
if ( pluginForExtension_.find( fi.suffix() ) != pluginForExtension_.end() ) if ( pluginForExtension_.find( fi.suffix() ) != pluginForExtension_.end() )
emit save(id_,filename, pluginForExtension_[fi.suffix()] ); emit save(id_,filename, pluginForExtension_[fi.suffix()] );
OpenFlipper::Options::currentDir(fi.absolutePath()); OpenFlipperSettings().setValue("Core/CurrentDir", fi.absolutePath() );
} }
/// show Widget for loading Files /// show Widget for loading Files
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment