Skip to content

Commit

Permalink
Import QtCurve into the calibre source tree so I can fix the various …
Browse files Browse the repository at this point in the history
…platform specific bugs myself
  • Loading branch information
kovidgoyal committed Jun 3, 2012
1 parent 5cc583c commit 28d6e85
Show file tree
Hide file tree
Showing 53 changed files with 24,794 additions and 30 deletions.
6 changes: 6 additions & 0 deletions COPYRIGHT
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ License: BSD
The full text of the BSD license is distributed as in
/usr/share/common-licenses/BSD on Debian systems.

Files: src/qtcurve/*
Copyright: Craig Drummond, 2007 - 2010 [email protected]
License: GPL-2
The full text of the GPL is distributed as in
/usr/share/common-licenses/GPL-2 on Debian systems.

Files: src/calibre/ebooks/chardet/*
Copyright: Copyright (C) 1998-2001 Netscape Communications Corporation
License: LGPL-2.1+
Expand Down
99 changes: 99 additions & 0 deletions setup/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import textwrap, os, shlex, subprocess, glob, shutil
from distutils import sysconfig
from multiprocessing import cpu_count

from PyQt4.pyqtconfig import QtGuiModuleMakefile

Expand Down Expand Up @@ -268,6 +269,7 @@ def run(self, opts):
self.obj_dir = os.path.join(os.path.dirname(SRC), 'build', 'objects')
if not os.path.exists(self.obj_dir):
os.makedirs(self.obj_dir)
self.build_style(self.j(self.SRC, 'calibre', 'plugins'))
for ext in extensions:
if opts.only != 'all' and opts.only != ext.name:
continue
Expand Down Expand Up @@ -362,6 +364,103 @@ def check_call(self, *args, **kwargs):
print "Error while executing: %s\n" % (cmdline)
raise

def build_style(self, dest):
self.info('\n####### Building calibre style', '#'*7)
sdir = self.j(self.SRC, 'qtcurve')
def path(x):
return '"%s"'%self.j(sdir, x).replace(os.sep, '/')
headers = [
"common/colorutils.h",
"common/common.h",
"common/config_file.h",
"style/blurhelper.h",
"style/dialogpixmaps.h",
"style/fixx11h.h",
"style/pixmaps.h",
"style/qtcurve.h",
"style/shortcuthandler.h",
"style/utils.h",
"style/windowmanager.h",
]
sources = [
"common/colorutils.c",
"common/common.c",
"common/config_file.c",
"style/blurhelper.cpp",
"style/qtcurve.cpp",
"style/shortcuthandler.cpp",
"style/utils.cpp",
"style/windowmanager.cpp",
]
if not iswindows and not isosx:
headers.append( "style/shadowhelper.h")
sources.append('style/shadowhelper.cpp')

pro = textwrap.dedent('''
TEMPLATE = lib
CONFIG += qt plugin release
CONFIG -= embed_manifest_dll
VERSION = 1.0.0
DESTDIR = .
TARGET = calibre
QT *= svg
INCLUDEPATH *= . {inc}
win32-msvc*:DEFINES *= _CRT_SECURE_NO_WARNINGS
# Force C++ language
*g++*:QMAKE_CFLAGS *= -x c++
*msvc*:QMAKE_CFLAGS *= -TP
*msvc*:QMAKE_CXXFLAGS += /MP
''').format(inc=path('common'))
if isosx:
pro += '\nCONFIG += x86 x86_64\n'
else:
pro += '\nunix:QT *= dbus\n'

for x in headers:
pro += 'HEADERS += %s\n'%path(x)
for x in sources:
pro += 'SOURCES += %s\n'%path(x)
config = textwrap.dedent('''
#pragma once
/* #define VERSION "1.5.3" */
#define KDE3PREFIX "/usr"
#define KDE4PREFIX "/usr"
#define QTC_QT_ONLY
/* #undef QTC_OLD_NVIDIA_ARROW_FIX */
#undef QTC_STYLE_SUPPORT
/* #undef QTC_KWIN_MAX_BUTTON_HACK */
''')
odir = self.j(self.d(self.SRC), 'build', 'qtcurve')
if not os.path.exists(odir):
os.makedirs(odir)
ocwd = os.getcwdu()
os.chdir(odir)
try:
if not os.path.exists('qtcurve.pro') or (open('qtcurve.pro',
'rb').read() != pro):
with open('qtcurve.pro', 'wb') as f:
f.write(pro)
if not os.path.exists('config.h') or (open('config.h',
'rb').read() != config):
with open('config.h', 'wb') as f:
f.write(config)
qmc = [QMAKE, '-o', 'Makefile']
if iswindows:
qmc += ['-spec', 'win32-msvc2008']
self.check_call(qmc + ['qtcurve.pro'])
self.check_call([make]+([] if iswindows else ['-j%d'%(cpu_count()
or 1)]))
src = (glob.glob('*.so') + glob.glob('release/*.dll') +
glob.glob('*.dylib'))
ext = 'pyd' if iswindows else 'so'
shutil.copy2(src[0], self.j(dest, 'calibre_style.'+ext))
finally:
os.chdir(ocwd)

def build_qt_objects(self, ext):
obj_pat = 'release\\*.obj' if iswindows else '*.o'
objects = glob.glob(obj_pat)
Expand Down
4 changes: 0 additions & 4 deletions setup/installer/osx/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,6 @@ def add_qt_frameworks(self):
self.add_qt_framework(f)
for d in glob.glob(join(SW, 'qt', 'plugins', '*')):
shutil.copytree(d, join(self.contents_dir, 'MacOS', basename(d)))
sty = join(self.contents_dir, 'MacOS', 'styles')
os.mkdir(sty)
shutil.copyfile(glob.glob(join(SW, 'build', 'QtCurve*', 'build', 'style',
'qtcurve.so'))[-1], join(sty, 'qtcurve.dylib'))
for l in glob.glob(join(self.contents_dir, 'MacOS', '*/*.dylib')):
self.fix_dependencies_in_lib(l)
x = os.path.relpath(l, join(self.contents_dir, 'MacOS'))
Expand Down
10 changes: 2 additions & 8 deletions setup/installer/windows/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,6 @@ def ignore_lib(root, items):
if os.path.exists(tg):
shutil.rmtree(tg)
shutil.copytree(imfd, tg)
self.info('\nAdding QtCurve...')
qtcurve = self.j(QTCURVE, 'qtcurve.dll')
tg = self.j(tdir, 'styles')
if os.path.exists(tg):
shutil.rmtree(tg)
os.mkdir(tg)
shutil.copy2(qtcurve, tg)

for dirpath, dirnames, filenames in os.walk(tdir):
for x in filenames:
Expand Down Expand Up @@ -494,7 +487,8 @@ def archive_lib_dir(self):
# Add the .pyds from python and calibre to the zip file
for x in (self.plugins_dir, self.dll_dir):
for pyd in os.listdir(x):
if pyd.endswith('.pyd') and pyd != 'sqlite_custom.pyd':
if pyd.endswith('.pyd') and pyd not in {
'sqlite_custom.pyd', 'calibre_style.pyd'}:
# sqlite_custom has to be a file for
# sqlite_load_extension to work
self.add_to_zipfile(zf, pyd, x)
Expand Down
8 changes: 0 additions & 8 deletions setup/installer/windows/notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,6 @@ Now, run configure and make::

Add the path to the bin folder inside the Qt dir to your system PATH.

Now build QtCurve
cd qmake
edit the qmake.pro file setting the TARGET to Release

qmake && nmake

The plugin will be in c:\plugins\styles

SIP
-----

Expand Down
23 changes: 13 additions & 10 deletions src/calibre/gui2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,16 @@ def __init__(self, args):
self._file_open_lock = RLock()
self.setup_styles()

def load_calibre_style(self):
# On OS X QtCurve resets the palette, so we preserve it explicitly
orig_pal = QPalette(self.palette())
from calibre.constants import plugins
pi = plugins['progress_indicator'][0]
path = os.path.join(sys.extensions_location, 'calibre_style.'+(
'pyd' if iswindows else 'so'))
pi.load_style(path, 'Calibre')
self.setPalette(orig_pal)

def setup_styles(self):
self.original_font = QFont(QApplication.font())
fi = gprefs['font']
Expand All @@ -744,23 +754,16 @@ def setup_styles(self):
QApplication.setFont(font)

if gprefs['widget_style'] != 'system':
# On OS X QtCurve resets the palette, so we preserve it explicitly
orig_pal = QPalette(self.palette())
QApplication.setStyle('QtCurve')
self.setPalette(orig_pal)
self.load_calibre_style()
else:
st = self.style()
if st is not None:
st = unicode(st.objectName()).lower()
if (islinux or isbsd) and st in ('windows', 'motif', 'cde'):
from PyQt4.Qt import QStyleFactory
styles = set(map(unicode, QStyleFactory.keys()))
if 'QtCurve' in styles and os.environ.get('KDE_FULL_SESSION',
False):
self.setStyle('QtCurve')
elif 'Plastique' in styles and os.environ.get('KDE_FULL_SESSION',
False):
self.setStyle('Plastique')
if os.environ.get('KDE_FULL_SESSION', False):
self.load_calibre_style()
elif 'Cleanlooks' in styles:
self.setStyle('Cleanlooks')

Expand Down
1 change: 1 addition & 0 deletions src/qtcurve/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Craig Drummond <[email protected]>
Loading

0 comments on commit 28d6e85

Please sign in to comment.