1# -*- coding: utf-8 -*-
2#
3# gPodder - A media aggregator and podcast client
4# Copyright (c) 2005-2018 The gPodder Team
5#
6# gPodder 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 3 of the License, or
9# (at your option) any later version.
10#
11# gPodder 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 General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18#
19
20# gpodder.core - Common functionality used by all UIs
21# Thomas Perl <thp@gpodder.org>; 2011-02-06
22
23
24import gpodder
25from gpodder import config, dbsqlite, extensions, model, util
26
27
28class Core(object):
29    def __init__(self,
30                 config_class=config.Config,
31                 database_class=dbsqlite.Database,
32                 model_class=model.Model):
33        # Initialize the gPodder home directory
34        util.make_directory(gpodder.home)
35
36        # Open the database and configuration file
37        self.db = database_class(gpodder.database_file)
38        self.model = model_class(self.db)
39        self.config = config_class(gpodder.config_file)
40
41        # Load extension modules and install the extension manager
42        gpodder.user_extensions = extensions.ExtensionManager(self)
43
44        # Load installed/configured plugins
45        gpodder.load_plugins()
46
47        # Update the current device in the configuration
48        self.config.mygpo.device.type = util.detect_device_type()
49
50    def shutdown(self):
51        # Notify all extensions that we are being shut down
52        gpodder.user_extensions.shutdown()
53
54        # Close the database and store outstanding changes
55        self.db.close()
56