Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/extensions/cpsection/background/model.py
blob: 783781a3321e1d564059682d0e61667ca71fa0e2 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright (C) 2012 Agustin Zubiaga <aguz@sugarlabs.org>
#
# This program 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.
#
# This program 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 more 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
#

from gi.repository import GConf
from gi.repository import GdkPixbuf

from sugar3.graphics import style
from jarabe.journal.model import get_documents_path

import os

BACKGROUNDS_DIRS = [os.path.join('/usr', 'share', 'backgrounds'),
                    get_documents_path()]


def set_background(file_path):
    client = GConf.Client.get_default()
    if file_path is None:
        client.set_string('/desktop/sugar/user/background', '')
    else:
        client.set_string('/desktop/sugar/user/background', str(file_path))
    return 1


def get_background():
    client = GConf.Client.get_default()
    return client.get_string('/desktop/sugar/user/background')


def fill_background_list(store):
    paths_list = []

    for _dir in BACKGROUNDS_DIRS:
        if _dir and os.path.exists(_dir):
            for root, dirs, files in os.walk(_dir):
                for bg in files:
                    path = os.path.join(root, bg)
                    if os.path.isfile(path):
                        try:
                            pixbuf = \
                                GdkPixbuf.Pixbuf.new_from_file_at_size(path,
                                style.XLARGE_ICON_SIZE, style.XLARGE_ICON_SIZE)

                            store.append([pixbuf, path])
                            paths_list.append(path)
                        except:
                            pass
    return paths_list

BACKGROUND_CHOOSED = get_background()


def undo(store):
    set_background(BACKGROUND_CHOOSED)