remove use of implicit namespaces
[ladish.git] / gui / session.cpp
blob41bcc9d1523f36ce2d819cb12b5ba3fcf95e3773
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2008 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains implementation of the session class
9 **************************************************************************
11 * LADI Session Handler is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * LADI Session Handler is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
23 * or write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "common.h"
28 #include "project.hpp"
29 #include "session.hpp"
30 #include "lash_client.hpp"
32 struct session_impl
34 std::list<boost::shared_ptr<project> > projects;
35 std::list<boost::shared_ptr<lash_client> > clients;
38 session::session()
40 _impl_ptr = new session_impl;
43 session::~session()
45 delete _impl_ptr;
48 void
49 session::clear()
51 boost::shared_ptr<project> project_ptr;
53 _impl_ptr->clients.clear();
55 while (!_impl_ptr->projects.empty())
57 project_ptr = _impl_ptr->projects.front();
58 _impl_ptr->projects.pop_front();
59 project_ptr->clear();
60 _signal_project_closed.emit(project_ptr);
64 void
65 session::project_add(
66 boost::shared_ptr<project> project_ptr)
68 _impl_ptr->projects.push_back(project_ptr);
70 _signal_project_added.emit(project_ptr);
73 boost::shared_ptr<project>
74 session::find_project_by_name(
75 const std::string& name)
77 boost::shared_ptr<project> project_ptr;
78 std::string temp_name;
80 for (std::list<boost::shared_ptr<project> >::iterator iter = _impl_ptr->projects.begin(); iter != _impl_ptr->projects.end(); iter++)
82 project_ptr = *iter;
83 project_ptr->get_name(temp_name);
85 if (temp_name == name)
87 return project_ptr;
91 return boost::shared_ptr<project>();
94 void
95 session::project_close(
96 const std::string& project_name)
98 boost::shared_ptr<project> project_ptr;
99 std::string temp_name;
100 std::list<boost::shared_ptr<lash_client> > clients;
102 for (std::list<boost::shared_ptr<project> >::iterator iter = _impl_ptr->projects.begin(); iter != _impl_ptr->projects.end(); iter++)
104 project_ptr = *iter;
105 project_ptr->get_name(temp_name);
107 if (temp_name == project_name)
109 _impl_ptr->projects.erase(iter);
110 _signal_project_closed.emit(project_ptr);
112 // remove clients from session, if not removed already
113 project_ptr->get_clients(clients);
114 for (std::list<boost::shared_ptr<lash_client> >::iterator iter = clients.begin(); iter != clients.end(); iter++)
116 std::string id;
118 (*iter)->get_id(id);
120 client_remove(id);
123 return;
128 void
129 session::client_add(
130 boost::shared_ptr<lash_client> client_ptr)
132 _impl_ptr->clients.push_back(client_ptr);
135 void
136 session::client_remove(
137 const std::string& id)
139 boost::shared_ptr<lash_client> client_ptr;
140 std::string temp_id;
142 for (std::list<boost::shared_ptr<lash_client> >::iterator iter = _impl_ptr->clients.begin(); iter != _impl_ptr->clients.end(); iter++)
144 client_ptr = *iter;
145 client_ptr->get_id(temp_id);
147 if (temp_id == id)
149 _impl_ptr->clients.erase(iter);
150 return;
155 boost::shared_ptr<lash_client>
156 session::find_client_by_id(const std::string& id)
158 boost::shared_ptr<lash_client> client_ptr;
159 std::string temp_id;
161 for (std::list<boost::shared_ptr<lash_client> >::iterator iter = _impl_ptr->clients.begin(); iter != _impl_ptr->clients.end(); iter++)
163 client_ptr = *iter;
164 client_ptr->get_id(temp_id);
166 if (temp_id == id)
168 return client_ptr;
172 return boost::shared_ptr<lash_client>();