~ben-kietzman/ubuntu/quantal/mountmanager/fix-for-598070

« back to all changes in this revision

Viewing changes to sources/core/diskoptionscenter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2008-08-20 10:22:14 UTC
  • Revision ID: james.westby@ubuntu.com-20080820102214-fv93myu0ncb1503r
Tags: upstream-0.2.4
ImportĀ upstreamĀ versionĀ 0.2.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//MountManager - the program for easy mounting of storage devices in Linux
 
2
//Copyright (C) 2007-2008 Tikhonov Sergey
 
3
//
 
4
//This file is part of MountManager Core
 
5
//
 
6
//This program is free software; you can redistribute it and/or
 
7
//modify it under the terms of the GNU General Public License
 
8
//as published by the Free Software Foundation; either version 2
 
9
//of the License, or (at your option) any later version.
 
10
//
 
11
//This program is distributed in the hope that it will be useful,
 
12
//but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
//GNU General Public License for more details.
 
15
//
 
16
//You should have received a copy of the GNU General Public License
 
17
//along with this program; if not, write to the Free Software
 
18
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
19
#include <QFile>
 
20
#include <QXmlInputSource>
 
21
#include <QXmlSimpleReader>
 
22
#include <QDebug>
 
23
#include "diskoptionsparser.h"
 
24
#include "diskoptionscenter.h"
 
25
#include "../gui/const.h"
 
26
 
 
27
DiskOptionsCenter::DiskOptionsCenter(const QString &fileSystem,QString lang) {
 
28
 
 
29
        optionsReader = new QXmlSimpleReader;
 
30
        optionsParser = new DiskOptionsParser(lang);
 
31
 
 
32
        optionsReader->setContentHandler(optionsParser);
 
33
        optionsReader->setErrorHandler(optionsParser);
 
34
 
 
35
        inputFile = new QFile;
 
36
        inputSource = new QXmlInputSource(inputFile);
 
37
 
 
38
        if (!fileSystem.isEmpty()) setSourcePath(QString(OPTIONS_PATH) + fileSystem + ".xml");
 
39
}
 
40
 
 
41
DiskOptionsCenter::~DiskOptionsCenter() {
 
42
        delete inputFile;
 
43
        delete inputSource;
 
44
        delete optionsParser;
 
45
        delete optionsReader;
 
46
}
 
47
 
 
48
void DiskOptionsCenter::setSourcePath(const QString& sourcePath) {
 
49
        inputFile->setFileName(sourcePath);
 
50
        optionsReader->parse(inputSource);
 
51
        inputFile->close();
 
52
        if (optionsParser->isValid())
 
53
                qDebug() << "[G] Parsing of " << sourcePath << " was successful";
 
54
        else
 
55
                qDebug() << "[W] Parsing of " << sourcePath << " was unsuccsessful";
 
56
}
 
57
 
 
58
void DiskOptionsCenter::setLanguage(const QString& language) {
 
59
        optionsParser->setLanguage(language);
 
60
}
 
61
 
 
62
QString& DiskOptionsCenter::language() {
 
63
        return optionsParser->language();
 
64
}
 
65
 
 
66
const QString& DiskOptionsCenter::language() const {
 
67
        return optionsParser->language();
 
68
}
 
69
 
 
70
const QList<Option *>& DiskOptionsCenter::fileSystemOptions(const QString& fileSystem) {
 
71
        if (fileSystem.isEmpty())
 
72
                return emptyOptions;
 
73
        if (!cache.keys().contains(fileSystem)) {
 
74
                setSourcePath(QString(OPTIONS_PATH) + fileSystem + ".xml");
 
75
                cache[fileSystem] = optionsParser->options();
 
76
        }
 
77
        return cache[fileSystem];
 
78
}