~ubuntu-app-review-contributors/ubuntu-app-reviews/unity-bookmarks

« back to all changes in this revision

Viewing changes to unity_bookmarks/PreferencesUnityBookmarksDialog.py

  • Committer: App Bot
  • Author(s): Nick Lemaire
  • Date: 2012-07-09 10:57:29 UTC
  • Revision ID: appbot@holba.ch-20120709105729-svcb31zd021pgidi
Tags: 12.07
* reset count added
* minor bug fix
* bug in sort fixed
* close screen when open a url from the main window
* count added in bookmarks window
* edit dialog added
* google+ icon updated
* google+ icon updated
* toolbar update
* quicklist fix
* focus fixed
* read-xml bugfix + open image changed on set sensitive
* preferences fix
* show main window option
* autostart preference added
* social network support
* example how to deal with selected rows
* icons added for social media integration
* multiple instance fix
* ui updated
* Facebook, twitter and google plus added to the project
* quicklist updated
* quicklist refresh fix
* table and others
* add bookmark notification icon fix
* add bookmark notification added
* delete unwanted methods
* quicklist bookmarks added + update onclick
* order by count in indicator menu
* Sort introduced to the dataset, not fully implemented
* Count boodmarks visited updated
* Input check
* reference to desktop file fix -> working dynamic quicklist
* first steps to quicklist
* home clicked window focus
* indicator submenu added
* double separator fix
* first step to error messaging, auto update table on add
* IOError fixed, empty collection returned
* import fix
* new bookmark added to indicator
* small layout changes
* Table converted to an treeview, no signals implemented
* Indicator checkfile to .config
* Indicator update
* xml fix
* xml fix
* Add bookmark connected to XML
* Authors edited
* Single instance check bugfix
* Count added to XML
* Force only one indicator
* bookmarks.xml added
* XML input/output added
* XML input/output added

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
### BEGIN LICENSE
 
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.
 
7
 
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.
 
12
 
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/>.
 
15
### END LICENSE
 
16
 
 
17
# This is your preferences dialog.
 
18
#
 
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.
 
22
 
 
23
from gi.repository import Gio # pylint: disable=E0611
 
24
 
 
25
import gettext
 
26
from gettext import gettext as _
 
27
gettext.textdomain('unity-bookmarks')
 
28
import ConfigParser
 
29
import os
 
30
import shutil
 
31
 
 
32
import logging
 
33
logger = logging.getLogger('unity_bookmarks')
 
34
 
 
35
from unity_bookmarks_lib.PreferencesDialog import PreferencesDialog
 
36
 
 
37
class PreferencesUnityBookmarksDialog(PreferencesDialog):
 
38
    __gtype_name__ = "PreferencesUnityBookmarksDialog"
 
39
 
 
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()
 
44
                try:
 
45
                        cFile=open(getConfigPath() + "unity-bookmarks.conf")
 
46
                        cFile.close()
 
47
                except IOError:
 
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)
 
59
                else:
 
60
                        self.autostart.set_active(False)
 
61
                if self.config.get("general", "showhomeonstart") == "True":
 
62
                        self.main_toggle.set_active(True)
 
63
                else:
 
64
                        self.main_toggle.set_active(False)
 
65
        
 
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():
 
72
                        try:
 
73
                                shutil.copyfile("/usr/share/applications/extras-unity-bookmarks.desktop", getAutostartPath() + "extras-unity-bookmarks.desktop")
 
74
                        except:
 
75
                                pass 
 
76
                else:
 
77
                        try:
 
78
                                os.remove(getAutostartPath() + 'extras-unity-bookmarks.desktop')
 
79
                        except OSError:
 
80
                                pass
 
81
                
 
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)
 
87
        
 
88
 
 
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)
 
95
 
 
96
def getConfigPath():
 
97
        path = os.getenv("HOME") + "/.config/unity-bookmarks/" 
 
98
        if not os.path.exists(path):
 
99
                os.makedirs(path)       
 
100
        return path
 
101
        
 
102
def getAutostartPath():
 
103
        path = os.getenv("HOME") + "/.config/autostart/"
 
104
        if not os.path.exists(path):
 
105
                os.makedirs(path)       
 
106
        return path