summaryrefslogtreecommitdiff
path: root/boardmanager.cpp
blob: ca4dad1c3266f10405f333ae5b99090961d38c8a (plain)
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
#include <QtCore/QDir>
#include <QtCore/QDebug>
#include <QtGui/QDesktopServices>

#include "board.h"
#include "boardmanager.h"

BoardManager::BoardManager(QObject *parent) :
    QObject(parent)
{
}

Board* BoardManager::getBoard(const QUrl &url, const QString& username, const QString& password)
{
	Board *b;
	QHash<QUrl, Board*>::iterator i = _boards.find(url);
	if (i != _boards.end()) {
		b = i.value();
		if (!b->loggedIn() && !username.isEmpty()) {
			// If requested to login but wasn't before, login now.
			b->login(username, password);
		}
	} else {
		b = new Board(url, username, password, this);
		_boards.insert(url, b);
	}
	return b;
}

QString BoardManager::getCachePath() const
{
	QString path = QDesktopServices::storageLocation(QDesktopServices::CacheLocation);

	if (!QDir().mkpath(path)) {
		qWarning() << "Failed to create directory for databases:" << path;
	}

	return path;
}