File: latexpackages.cpp

package info (click to toggle)
texstudio 2.11.2%2Bdebian-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 41,292 kB
  • ctags: 12,405
  • sloc: cpp: 93,072; xml: 10,217; ansic: 4,153; sh: 145; makefile: 56
file content (58 lines) | stat: -rw-r--r-- 1,283 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "latexpackages.h"
#include <QMutex>

LatexPackages *LatexPackages::m_Instance = 0;

LatexPackages::LatexPackages() :
	QObject(0), m_dataSource(None)
{
	loadStaticPackageList(":/utilities/packageList");
}

LatexPackages *LatexPackages::instance()
{
	static QMutex mutex;
	mutex.lock();
	if (!m_Instance)
		m_Instance = new LatexPackages();
	mutex.unlock();
	return m_Instance;
}

LatexPackages::DataSource LatexPackages::dataSource()
{
	return m_dataSource;
}

bool LatexPackages::loadStaticPackageList(const QString &file)
{
	if (file.isEmpty()) return false;
	packages.reserve(3000);

	QFile f(file);
	if (! f.open(QFile::ReadOnly)) return false;

	while (!f.atEnd()) {
		QString line = f.readLine().trimmed();
		if (line.startsWith('#')) continue;
		int sep = line.indexOf(':');
		if (sep < 0) {
			packages.insert(line, LatexPackageInfo(line));
		} else {
			QString name = line.left(sep);
			packages.insert(name, LatexPackageInfo(name, line.mid(sep + 1)));
		}
	}
	m_dataSource = Static;
	return true;
}

bool LatexPackages::packageExists(const QString &name)
{
	return packages.keys().contains(name);
}

QString LatexPackages::shortDescription(const QString &name)
{
	return packages[name].shortDescription;
}