view gui/src/ResourceManager.cpp @ 13571:a7c923ab980f

Default file gets copied to home directory when no settings file is present.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Mon, 01 Aug 2011 16:49:33 +0200
parents 7828e1bf5b0d
children fd31226d4c3a
line wrap: on
line source

/* OctaveGUI - A graphical user interface for Octave
 * Copyright (C) 2011 Jacob Dawid
 * jacob.dawid@googlemail.com
 *
 * 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 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "ResourceManager.h"
#include <QFile>

ResourceManager ResourceManager::m_singleton;

ResourceManager::ResourceManager ()
{
  m_settings = 0;
  QDesktopServices desktopServices;
  m_homePath = desktopServices.storageLocation (QDesktopServices::HomeLocation);
  setSettings(m_homePath + "/.octave-gui");
}

ResourceManager::~ResourceManager ()
{
  delete m_settings;
}

QSettings *
ResourceManager::settings ()
{
  return m_settings;
}

QString
ResourceManager::homePath ()
{
  return m_homePath;
}

void
ResourceManager::setSettings (QString file)
{
  delete m_settings;
  if (!QFile::exists (file))
    {
      QFile::copy("../default-settings/.octave-gui", file);
    }
  m_settings = new QSettings (file, QSettings::IniFormat);
}

QString
ResourceManager::findTranslatorFile (QString language)
{
  // TODO: Quick hack to be able to test language files.
  return QString("../languages/%1.qm").arg(language);
}