2
* Copyright (C) 2009 Michael Lamothe
4
* This file is part of Me TV
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Library General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
21
#include "profile_manager.h"
22
#include "application.h"
24
ProfileManager::ProfileManager()
26
current_profile = NULL;
29
ProfileManager::~ProfileManager()
33
void ProfileManager::load()
37
profiles = data.get_all_profiles();
39
if (profiles.size() == 0)
41
current_profile = new Profile();
42
current_profile->name = _("Default");
43
profiles.push_back(*current_profile);
46
profiles = data.get_all_profiles();
49
current_profile = find_profile(get_application().get_string_configuration_value("profile"));
50
if (current_profile == NULL)
52
current_profile = &(*profiles.begin());
56
Profile* ProfileManager::find_profile(const Glib::ustring& profile_name)
58
Profile* result = NULL;
59
ProfileList::iterator iterator = profiles.begin();
60
while (iterator != profiles.end() && result == NULL)
62
Profile& profile = *iterator;
63
if (profile_name == profile.name)
72
Profile& ProfileManager::get_profile(const Glib::ustring& profile_name)
74
Profile* profile = find_profile(profile_name);
77
throw Exception(Glib::ustring::compose(_("Failed to find profile '%1'"), profile_name));
82
void ProfileManager::save()
85
g_message(_("Saving profile data"));
86
for (ProfileList::iterator profile_iterator = profiles.begin(); profile_iterator != profiles.end(); profile_iterator++)
88
data.replace_profile(*profile_iterator);
90
g_message(_("Profile data saved"));
93
Profile& ProfileManager::get_current_profile()
95
if (current_profile == NULL)
97
throw Exception(_("There is no current profile"));
99
return *current_profile;