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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# Copyright (C) 2007, Red Hat, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
import os
import sys
import ConfigParser
import gtk
from hulahop import config
sys.path.insert(0, os.path.join(config.libxul_dir, 'python'))
from hulahop._hulahop import shutdown
from hulahop import _hulahop
_XO_DPI = 200
_app_version = ''
def set_app_version(version):
global _app_version
_app_version = version
def startup(profile_path, components_dirs=[]):
_hulahop.set_profile_path(profile_path)
if not os.path.isdir(profile_path):
try:
os.makedirs(profile_path)
except OSError, exc:
raise RuntimeError('Could not create user directory.')
_check_compreg(profile_path)
for path in components_dirs:
_hulahop.add_components_path(path)
_hulahop.startup()
from xpcom import components
cls = components.classes["@mozilla.org/preferences-service;1"]
prefService = cls.getService(components.interfaces.nsIPrefService)
branch = prefService.getBranch('')
branch.setIntPref('layout.css.dpi', _get_layout_dpi())
def _check_compreg(profile_path):
comp_path = os.path.join(profile_path, 'compatibility.ini')
existant = True
valid = True
try:
cp = ConfigParser.ConfigParser(defaults={'app_version' : ''})
if not cp.read(comp_path):
existant = False
else:
valid = cp.get('main', 'app_version') == _app_version and \
cp.get('main', 'libxul_dir') == config.libxul_dir
except ConfigParser.Error:
valid = False
if not valid and existant:
compreg = os.path.join(profile_path, 'compreg.dat')
os.unlink(comp_path)
os.unlink(compreg)
cp = ConfigParser.ConfigParser()
cp.add_section('main')
cp.set('main', 'app_version', _app_version)
cp.set('main', 'libxul_dir', config.libxul_dir)
f = open(comp_path, 'w')
cp.write(f)
f.close()
def _get_layout_dpi():
gtk_xft_dpi = gtk.settings_get_default().get_property('gtk-xft-dpi')
screen_dpi = gtk_xft_dpi / 1024
screen_width = gtk.gdk.screen_width()
if screen_dpi != _XO_DPI or screen_width != 1200:
return -1
# Layout:
# 1024x768 -> (96 * 6) / 1024 * 201 = 113 dpi
# 800x600 -> (96 * 6) / 800 * 201 = 144 dpi
#
# Fonts:
# 7 pt -> 7 / 12 * 201 = 117 dpi
# 8 pt -> 8 / 12 * 201 = 134 dpi
# 9 pt -> 9 / 12 * 201 = 150 dpi
return 134
|