1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Copyright (C) 2012 Nick Lemaire lemaire.nick@gmail.com
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License version 3, as published
6
# by the Free Software Foundation.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranties of
10
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
# PURPOSE. See the GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License along
14
# with this program. If not, see <http://www.gnu.org/licenses/>.
17
# This is your preferences dialog.
19
# Define your preferences in
20
# data/glib-2.0/schemas/net.launchpad.unity-bookmarks.gschema.xml
21
# See http://developer.gnome.org/gio/stable/GSettings.html for more info.
23
from gi.repository import Gio # pylint: disable=E0611
26
from gettext import gettext as _
27
gettext.textdomain('unity-bookmarks')
33
logger = logging.getLogger('unity_bookmarks')
35
from unity_bookmarks_lib.PreferencesDialog import PreferencesDialog
37
class PreferencesUnityBookmarksDialog(PreferencesDialog):
38
__gtype_name__ = "PreferencesUnityBookmarksDialog"
40
def finish_initializing(self, builder): # pylint: disable=E1002
41
"""Set up the preferences dialog"""
42
super(PreferencesUnityBookmarksDialog, self).finish_initializing(builder)
43
self.config = ConfigParser.ConfigParser()
45
cFile=open(getConfigPath() + "unity-bookmarks.conf")
48
self.write_configFile(False, True)
49
self.config.read(getConfigPath() + "unity-bookmarks.conf")
50
# Bind each preference widget to gsettings
51
#settings = Gio.Settings("net.launchpad.unity-bookmarks")
52
#widget = self.builder.get_object('example_entry')
53
self.autostart = self.builder.get_object('autostart')
54
self.autostart.connect("toggled",self.on_autostart_toggled)
55
self.main_toggle = self.builder.get_object('main_toggle')
56
self.main_toggle.connect("toggled",self.on_main_toggle_toggled)
57
if self.config.get("general", "autostart") == "True":
58
self.autostart.set_active(True)
60
self.autostart.set_active(False)
61
if self.config.get("general", "showhomeonstart") == "True":
62
self.main_toggle.set_active(True)
64
self.main_toggle.set_active(False)
66
def on_autostart_toggled(self, widget):
67
value = str(self.autostart.get_active())
68
self.config.set("general", "autostart", value)
69
confFile = open(getConfigPath() + "unity-bookmarks.conf", "w")
70
self.config.write(confFile)
71
if self.autostart.get_active():
73
shutil.copyfile("/usr/share/applications/extras-unity-bookmarks.desktop", getAutostartPath() + "extras-unity-bookmarks.desktop")
78
os.remove(getAutostartPath() + 'extras-unity-bookmarks.desktop')
82
def on_main_toggle_toggled(self, widget):
83
value = str(self.main_toggle.get_active())
84
self.config.set("general", "showhomeonstart", value)
85
confFile = open(getConfigPath() + "unity-bookmarks.conf", "w")
86
self.config.write(confFile)
89
def write_configFile(self, auto, main):
90
cFile = open(getConfigPath() + "unity-bookmarks.conf", "w")
91
self.config.add_section("general")
92
self.config.set("general","autostart",auto)
93
self.config.set("general","showhomeonstart",main)
94
self.config.write(cFile)
97
path = os.getenv("HOME") + "/.config/unity-bookmarks/"
98
if not os.path.exists(path):
102
def getAutostartPath():
103
path = os.getenv("HOME") + "/.config/autostart/"
104
if not os.path.exists(path):