Commit 48fb6cc6 authored by Dirk Wilden's avatar Dirk Wilden

moved recentFiles/currentDir to QSettings

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8390 383ad7c9-94d9-4d36-a494-682f7c89f535
parent ba2765d4
......@@ -889,11 +889,13 @@ void Core::multiViewMode( int _mode ) {
void
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 )
if ( recentFiles[i].filename == _action->text() ){
if ( recentFiles[i] == _action->text() ){
OpenFlipper::Options::loadingRecentFile(true);
loadObject(recentFiles[i].type, recentFiles[i].filename);
loadObject(typeId(recentTypes[i]), recentFiles[i]);
OpenFlipper::Options::loadingRecentFile(false);
return;
}
......
......@@ -135,7 +135,7 @@ void Core::readApplicationOptions(INIFile& _ini) {
//============================================================================
QString startup_dir;
if( _ini.get_entry(startup_dir, "Options", "StartupDir") )
OpenFlipper::Options::currentDir(startup_dir);
OpenFlipperSettings().setValue("Core/CurrentDir", startup_dir );
//============================================================================
// Load the default script directory
......@@ -383,9 +383,9 @@ void Core::readRecentFiles(QString _filename){
OpenFlipper::Options::loadingSettings(true);
// Load maxRecent Setting
int mrecent = 6;
int mrecent = 10;
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) {
QString file;
......@@ -416,18 +416,20 @@ void Core::readRecentFiles(QString _filename){
void Core::writeApplicationOptions(INIFile& _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
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) {
// Save filename
QString key = "recent" + QString::number(j);
QString filename = recentFiles[j].filename;
QString filename = recentFiles[j];
_ini.add_entry( "Options" , key , filename );
// Save DataType
key = "type" + QString::number(j);
QString type = typeName( recentFiles[j].type );
QString type = recentTypes[j];
_ini.add_entry( "Options" , key , type );
}
......@@ -513,7 +515,7 @@ void Core::writeApplicationOptions(INIFile& _ini) {
if ( !_ini.section_exists("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);
QString scriptDir = OpenFlipper::Options::currentScriptDirStr().toUtf8();
......
......@@ -217,7 +217,7 @@ void Core::slotLoadPlugin(){
filter = "Plugins (*.so)";
// 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())
return;
......
......@@ -707,7 +707,7 @@ void Core::loadSettings(){
QFileDialog fileDialog( coreWidget_,
tr("Load Settings"),
OpenFlipper::Options::currentDirStr(),
OpenFlipperSettings().value("Core/CurrentDir").toString(),
tr("INI files (*.ini)") );
fileDialog.setOption (QFileDialog::DontUseNativeDialog, true);
......@@ -763,7 +763,7 @@ void Core::loadSettings(){
QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2);
OpenFlipper::Options::currentDir(newpath);
OpenFlipperSettings().setValue("Core/CurrentDir", newpath);
if ( complete_name.endsWith("ini") ) {
openIniFile( complete_name,
......@@ -785,7 +785,7 @@ void Core::loadSettings(QString _filename){
return;
QString newpath = _filename.section(OpenFlipper::Options::dirSeparator(),0,-2);
OpenFlipper::Options::currentDir(newpath);
OpenFlipperSettings().setValue("Core/CurrentDir", newpath);
if ( _filename.endsWith("ini") ) {
// Loaded function for recent files. Load everything.
......
......@@ -218,8 +218,7 @@ void Core::setupOptions() {
OpenFlipper::Options::currentTextureDir(OpenFlipper::Options::textureDirStr());
// Default to home directory
OpenFlipper::Options::currentDir( QDir::home() );
OpenFlipperSettings().setValue("Core/CurrentDir", QDir::homePath() );
// ==============================================================
// Load Application options from all files available
......
......@@ -64,7 +64,7 @@ void Core::saveSettings(){
QFileDialog fileDialog( coreWidget_,
tr("Save Settings"),
OpenFlipper::Options::currentDirStr(),
OpenFlipperSettings().value("Core/CurrentDir").toString(),
tr("INI files (*.ini);;OBJ files (*.obj )") );
fileDialog.setOption (QFileDialog::DontUseNativeDialog, true);
......@@ -149,7 +149,7 @@ void Core::saveSettings(){
// Get the chosen directory and remember it.
QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2);
OpenFlipper::Options::currentDir(newpath);
OpenFlipperSettings().setValue("Core/CurrentDir", newpath);
// ========================================================================================
// update status information
......
......@@ -93,6 +93,9 @@
*
* <b>File Handling</b>
* * 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
*
* <b>Log Settings</b>
......@@ -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
DLLEXPORT
QString currentScriptDirStr();
......
......@@ -53,41 +53,39 @@
#include "RecentFiles.hh"
#include <OpenFlipper/common/GlobalOptions.hh>
#include <OpenFlipper/common/Types.hh>
namespace OpenFlipper {
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 addRecentFile(QString _file, DataType _type) {
void maxRecent(int _max) { maxRecent_ = _max; }
void recentFiles(QVector<RecentFile> _list ) { recentFiles_ = _list;}
QStringList recentFiles = OpenFlipperSettings().value("Core/File/RecentFiles").toStringList();
QStringList recentTypes = OpenFlipperSettings().value("Core/File/RecentTypes").toStringList();
QString type = typeName(_type);
void addRecentFile(QString _file, DataType _type) {
// Check if file already in recent list
for ( int i = 0 ; i < recentFiles_.size() ; ++i)
if ( _file == recentFiles_[i].filename && _type == recentFiles_[i].type )
recentFiles_.remove(i);
for ( int i = 0 ; i < recentFiles.size() ; ++i)
if ( _file == recentFiles[i] && type == recentTypes[i] ){
recentFiles.removeAt(i);
recentTypes.removeAt(i);
}
// Erase if too many files in list
if ( recentFiles_.size() >= maxRecent_ ) {
recentFiles_.pop_back();
if ( recentFiles.size() >= OpenFlipperSettings().value("Core/File/MaxRecent").toInt() ) {
recentFiles.pop_back();
recentTypes.pop_back();
}
RecentFile recent;
recent.filename = _file;
recent.type = _type;
recentFiles_.push_front(recent);
recentFiles.push_front(_file);
recentTypes.push_front(type);
OpenFlipperSettings().setValue("Core/File/RecentFiles", recentFiles);
OpenFlipperSettings().setValue("Core/File/RecentTypes", recentTypes);
}
}
......
......@@ -66,12 +66,6 @@
namespace OpenFlipper {
namespace Options {
/// struct storing infos about recent files
struct RecentFile{
QString filename;
DataType type;
};
//===========================================================================
/** @name Recent Files
......@@ -82,22 +76,6 @@ struct RecentFile{
DLLEXPORT
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,
setupMenuBar();
updateRecent();
statusBar_->showMessage(tr("Ready"), 5000);
registerCoreKeys();
......@@ -854,15 +852,17 @@ CoreWidget::updateRecent()
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 ) {
QFileInfo fi(recentFiles[i].filename);
QFileInfo fi(recentFiles[i]);
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
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
//overwrite dialog shouldn't be handled by the qfiledialog
setConfirmOverwrite(false);
setDirectory(OpenFlipper::Options::currentDirStr());
setDirectory( OpenFlipperSettings().value("Core/CurrentDir").toString() );
}
/// Desctructor
......@@ -233,7 +233,7 @@ void LoadWidget::loadFile(){
QFileInfo fi(files[i]);
QString filename = fi.absoluteFilePath();
OpenFlipper::Options::currentDir(fi.absolutePath());
OpenFlipperSettings().setValue("Core/CurrentDir", filename);
QFile file(filename);
if (fi.isDir() || !file.exists()) continue; //do nothing if its a not a valid file
......@@ -311,8 +311,7 @@ void LoadWidget::saveFile(){
if ( pluginForExtension_.find( fi.suffix() ) != pluginForExtension_.end() )
emit save(id_,filename, pluginForExtension_[fi.suffix()] );
OpenFlipper::Options::currentDir(fi.absolutePath());
OpenFlipperSettings().setValue("Core/CurrentDir", fi.absolutePath() );
}
/// 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