1
/* This file is part of Clementine.
2
Copyright 2010, David Sansome <me@davidsansome.com>
4
Clementine is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
9
Clementine is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
18
#include "languageengine.h"
19
#include "scriptinfo.h"
27
const char* ScriptInfo::kIniFileName = "script.ini";
28
const char* ScriptInfo::kIniSettingsGroup = "Script";
30
ScriptInfo::ScriptInfo()
35
void ScriptInfo::InitFromDirectory(const ScriptManager* manager, const QString& path) {
36
const QString ini_file = path + "/" + kIniFileName;
37
const QString id = QFileInfo(path).fileName();
39
// Does the file exist?
40
if (!QFile::exists(ini_file)) {
41
qWarning() << "Script definition file not found:" << ini_file;
45
InitFromFile(manager, id, path, ini_file);
48
void ScriptInfo::InitFromFile(const ScriptManager* manager,
51
const QString& ini_file) {
53
QSettings s(ini_file, QSettings::IniFormat);
54
if (!s.childGroups().contains(kIniSettingsGroup)) {
55
qWarning() << "Missing" << kIniSettingsGroup << "section in" << ini_file;
58
s.beginGroup(kIniSettingsGroup);
60
// Find out what language it's in
61
QString language_name = s.value("language").toString();
62
LanguageEngine* engine = manager->EngineForLanguage(language_name);
64
qWarning() << "Unknown language" << language_name << "in" << ini_file;
67
d->language_ = engine->language();
69
// Load the rest of the metadata
72
d->name_ = s.value("name").toString();
73
d->description_ = s.value("description").toString();
74
d->author_ = s.value("author").toString();
75
d->url_ = s.value("url").toString();
76
d->script_file_ = QFileInfo(QDir(path), s.value("script_file").toString()).absoluteFilePath();
77
d->icon_filename_ = QFileInfo(QDir(path), s.value("icon").toString()).absoluteFilePath();
80
bool ScriptInfo::operator ==(const ScriptInfo& other) const {
81
return path() == other.path() &&
82
name() == other.name() &&
83
description() == other.description() &&
84
author() == other.author() &&
85
url() == other.url() &&
86
language() == other.language() &&
87
script_file() == other.script_file();
90
bool ScriptInfo::operator !=(const ScriptInfo& other) const {
91
return !(*this == other);
94
void ScriptInfo::TakeMetadataFrom(const ScriptInfo& other) {
95
d->path_ = other.path();
96
d->name_ = other.name();
97
d->description_ = other.description();
98
d->author_ = other.author();
99
d->url_ = other.url();
100
d->icon_filename_ = other.icon_filename();
101
d->language_ = other.language();
102
d->script_file_ = other.script_file();