2008-07-03 21:50:57 +03:00
|
|
|
// -*- Mode: C++ ; indent-tabs-mode: t -*-
|
|
|
|
/* This file is part of Patchage.
|
|
|
|
* Copyright (C) 2008 Nedko Arnaudov <nedko@arnaudov.name>
|
|
|
|
*
|
|
|
|
* Patchage is free software; you can redistribute it and/or modify it under the
|
|
|
|
* terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* Patchage is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.hpp"
|
|
|
|
#include "project.hpp"
|
|
|
|
#include "session.hpp"
|
2008-07-05 21:52:35 +03:00
|
|
|
#include "lash_client.hpp"
|
2008-07-03 21:50:57 +03:00
|
|
|
|
|
|
|
struct session_impl
|
|
|
|
{
|
|
|
|
list<shared_ptr<project> > projects;
|
2008-07-05 21:52:35 +03:00
|
|
|
list<shared_ptr<lash_client> > clients;
|
2008-07-03 21:50:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
session::session()
|
|
|
|
{
|
|
|
|
_impl_ptr = new session_impl;
|
|
|
|
}
|
|
|
|
|
|
|
|
session::~session()
|
|
|
|
{
|
|
|
|
delete _impl_ptr;
|
|
|
|
}
|
|
|
|
|
2008-07-06 19:44:47 +03:00
|
|
|
void
|
|
|
|
session::clear()
|
|
|
|
{
|
|
|
|
shared_ptr<project> project_ptr;
|
|
|
|
|
|
|
|
_impl_ptr->clients.clear();
|
|
|
|
|
|
|
|
while (!_impl_ptr->projects.empty())
|
|
|
|
{
|
|
|
|
project_ptr = _impl_ptr->projects.front();
|
|
|
|
_impl_ptr->projects.pop_front();
|
|
|
|
project_ptr->clear();
|
|
|
|
_signal_project_closed.emit(project_ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-03 21:50:57 +03:00
|
|
|
void
|
|
|
|
session::project_add(
|
2008-07-04 23:36:25 +03:00
|
|
|
shared_ptr<project> project_ptr)
|
2008-07-03 21:50:57 +03:00
|
|
|
{
|
2008-07-03 23:27:11 +03:00
|
|
|
_impl_ptr->projects.push_back(project_ptr);
|
2008-07-03 21:50:57 +03:00
|
|
|
|
2008-07-03 23:27:11 +03:00
|
|
|
_signal_project_added.emit(project_ptr);
|
2008-07-03 21:50:57 +03:00
|
|
|
}
|
|
|
|
|
2008-07-04 00:20:31 +03:00
|
|
|
shared_ptr<project>
|
|
|
|
session::find_project_by_name(
|
|
|
|
const string& name)
|
|
|
|
{
|
|
|
|
shared_ptr<project> project_ptr;
|
|
|
|
string temp_name;
|
|
|
|
|
|
|
|
for (list<shared_ptr<project> >::iterator iter = _impl_ptr->projects.begin(); iter != _impl_ptr->projects.end(); iter++)
|
|
|
|
{
|
|
|
|
project_ptr = *iter;
|
|
|
|
project_ptr->get_name(temp_name);
|
|
|
|
|
|
|
|
if (temp_name == name)
|
|
|
|
{
|
|
|
|
return project_ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return shared_ptr<project>();
|
|
|
|
}
|
|
|
|
|
2008-07-03 21:50:57 +03:00
|
|
|
void
|
|
|
|
session::project_close(
|
2008-07-03 23:27:11 +03:00
|
|
|
const string& project_name)
|
2008-07-03 21:50:57 +03:00
|
|
|
{
|
2008-07-03 23:27:11 +03:00
|
|
|
shared_ptr<project> project_ptr;
|
|
|
|
string temp_name;
|
2008-07-05 21:52:35 +03:00
|
|
|
list<shared_ptr<lash_client> > clients;
|
2008-07-03 23:27:11 +03:00
|
|
|
|
|
|
|
for (list<shared_ptr<project> >::iterator iter = _impl_ptr->projects.begin(); iter != _impl_ptr->projects.end(); iter++)
|
|
|
|
{
|
|
|
|
project_ptr = *iter;
|
|
|
|
project_ptr->get_name(temp_name);
|
|
|
|
|
|
|
|
if (temp_name == project_name)
|
|
|
|
{
|
2008-07-03 23:56:10 +03:00
|
|
|
_impl_ptr->projects.erase(iter);
|
2008-07-03 23:27:11 +03:00
|
|
|
_signal_project_closed.emit(project_ptr);
|
2008-07-05 21:52:35 +03:00
|
|
|
|
|
|
|
// remove clients from session, if not removed already
|
|
|
|
project_ptr->get_clients(clients);
|
|
|
|
for (list<shared_ptr<lash_client> >::iterator iter = clients.begin(); iter != clients.end(); iter++)
|
|
|
|
{
|
|
|
|
string id;
|
|
|
|
|
|
|
|
(*iter)->get_id(id);
|
|
|
|
|
|
|
|
client_remove(id);
|
|
|
|
}
|
|
|
|
|
2008-07-03 23:56:10 +03:00
|
|
|
return;
|
2008-07-03 23:27:11 +03:00
|
|
|
}
|
|
|
|
}
|
2008-07-03 21:50:57 +03:00
|
|
|
}
|
2008-07-05 21:52:35 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
session::client_add(
|
|
|
|
shared_ptr<lash_client> client_ptr)
|
|
|
|
{
|
|
|
|
_impl_ptr->clients.push_back(client_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
session::client_remove(
|
|
|
|
const string& id)
|
|
|
|
{
|
|
|
|
shared_ptr<lash_client> client_ptr;
|
|
|
|
string temp_id;
|
|
|
|
|
|
|
|
for (list<shared_ptr<lash_client> >::iterator iter = _impl_ptr->clients.begin(); iter != _impl_ptr->clients.end(); iter++)
|
|
|
|
{
|
|
|
|
client_ptr = *iter;
|
|
|
|
client_ptr->get_id(temp_id);
|
|
|
|
|
|
|
|
if (temp_id == id)
|
|
|
|
{
|
|
|
|
_impl_ptr->clients.erase(iter);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
shared_ptr<lash_client>
|
|
|
|
session::find_client_by_id(const string& id)
|
|
|
|
{
|
|
|
|
shared_ptr<lash_client> client_ptr;
|
|
|
|
string temp_id;
|
|
|
|
|
|
|
|
for (list<shared_ptr<lash_client> >::iterator iter = _impl_ptr->clients.begin(); iter != _impl_ptr->clients.end(); iter++)
|
|
|
|
{
|
|
|
|
client_ptr = *iter;
|
|
|
|
client_ptr->get_id(temp_id);
|
|
|
|
|
|
|
|
if (temp_id == id)
|
|
|
|
{
|
|
|
|
return client_ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return shared_ptr<lash_client>();
|
|
|
|
}
|