~ubuntu-branches/ubuntu/utopic/clementine/utopic

« back to all changes in this revision

Viewing changes to src/scripting/scriptinfo.cpp

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of Clementine.
2
 
   Copyright 2010, David Sansome <me@davidsansome.com>
3
 
 
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.
8
 
 
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.
13
 
 
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/>.
16
 
*/
17
 
 
18
 
#include "languageengine.h"
19
 
#include "scriptinfo.h"
20
 
 
21
 
#include <QDir>
22
 
#include <QFile>
23
 
#include <QFileInfo>
24
 
#include <QSettings>
25
 
#include <QtDebug>
26
 
 
27
 
const char* ScriptInfo::kIniFileName = "script.ini";
28
 
const char* ScriptInfo::kIniSettingsGroup = "Script";
29
 
 
30
 
ScriptInfo::ScriptInfo()
31
 
  : d(new Private)
32
 
{
33
 
}
34
 
 
35
 
void ScriptInfo::InitFromDirectory(const ScriptManager* manager, const QString& path) {
36
 
  const QString ini_file = path + "/" + kIniFileName;
37
 
  const QString id = QFileInfo(path).fileName();
38
 
 
39
 
  // Does the file exist?
40
 
  if (!QFile::exists(ini_file)) {
41
 
    qWarning() << "Script definition file not found:" << ini_file;
42
 
    return;
43
 
  }
44
 
 
45
 
  InitFromFile(manager, id, path, ini_file);
46
 
}
47
 
 
48
 
void ScriptInfo::InitFromFile(const ScriptManager* manager,
49
 
                              const QString& id,
50
 
                              const QString& path,
51
 
                              const QString& ini_file) {
52
 
  // Open it
53
 
  QSettings s(ini_file, QSettings::IniFormat);
54
 
  if (!s.childGroups().contains(kIniSettingsGroup)) {
55
 
    qWarning() << "Missing" << kIniSettingsGroup << "section in" << ini_file;
56
 
    return;
57
 
  }
58
 
  s.beginGroup(kIniSettingsGroup);
59
 
 
60
 
  // Find out what language it's in
61
 
  QString language_name = s.value("language").toString();
62
 
  LanguageEngine* engine = manager->EngineForLanguage(language_name);
63
 
  if (!engine) {
64
 
    qWarning() << "Unknown language" << language_name << "in" << ini_file;
65
 
    return;
66
 
  }
67
 
  d->language_ = engine->language();
68
 
 
69
 
  // Load the rest of the metadata
70
 
  d->path_ = path;
71
 
  d->id_ = id;
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();
78
 
}
79
 
 
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();
88
 
}
89
 
 
90
 
bool ScriptInfo::operator !=(const ScriptInfo& other) const {
91
 
  return !(*this == other);
92
 
}
93
 
 
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();
103
 
}