mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Basic support for associating file types on OS X
This commit is contained in:
parent
caac665102
commit
fe5283de4a
@ -355,6 +355,7 @@ class Py2App(object):
|
|||||||
|
|
||||||
@flush
|
@flush
|
||||||
def create_plist(self):
|
def create_plist(self):
|
||||||
|
from calibre.ebooks import BOOK_EXTENSIONS
|
||||||
env = dict(**ENV)
|
env = dict(**ENV)
|
||||||
env['CALIBRE_LAUNCHED_FROM_BUNDLE']='1';
|
env['CALIBRE_LAUNCHED_FROM_BUNDLE']='1';
|
||||||
|
|
||||||
@ -367,10 +368,11 @@ class Py2App(object):
|
|||||||
CFBundlePackageType='APPL',
|
CFBundlePackageType='APPL',
|
||||||
CFBundleSignature='????',
|
CFBundleSignature='????',
|
||||||
CFBundleExecutable='calibre',
|
CFBundleExecutable='calibre',
|
||||||
|
CFBundleTypeExtensions=list(BOOK_EXTENSIONS),
|
||||||
LSMinimumSystemVersion='10.4.2',
|
LSMinimumSystemVersion='10.4.2',
|
||||||
LSRequiresNativeExecution=True,
|
LSRequiresNativeExecution=True,
|
||||||
NSAppleScriptEnabled=False,
|
NSAppleScriptEnabled=False,
|
||||||
NSHumanReadableCopyright='Copyright 2008, Kovid Goyal',
|
NSHumanReadableCopyright='Copyright 2010, Kovid Goyal',
|
||||||
CFBundleGetInfoString=('calibre, an E-book management '
|
CFBundleGetInfoString=('calibre, an E-book management '
|
||||||
'application. Visit http://calibre-ebook.com for details.'),
|
'application. Visit http://calibre-ebook.com for details.'),
|
||||||
CFBundleIconFile='library.icns',
|
CFBundleIconFile='library.icns',
|
||||||
@ -594,6 +596,7 @@ class Py2App(object):
|
|||||||
if x == 'Info.plist':
|
if x == 'Info.plist':
|
||||||
plist = plistlib.readPlist(join(self.contents_dir, x))
|
plist = plistlib.readPlist(join(self.contents_dir, x))
|
||||||
plist['LSUIElement'] = '1'
|
plist['LSUIElement'] = '1'
|
||||||
|
plist.pop('CFBundleTypeExtensions')
|
||||||
plistlib.writePlist(plist, join(cc_dir, x))
|
plistlib.writePlist(plist, join(cc_dir, x))
|
||||||
else:
|
else:
|
||||||
os.symlink(join('../..', x),
|
os.symlink(join('../..', x),
|
||||||
|
@ -3,7 +3,8 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
""" The GUI """
|
""" The GUI """
|
||||||
import os
|
import os
|
||||||
from PyQt4.QtCore import QVariant, QFileInfo, QObject, SIGNAL, QBuffer, Qt, QSize, \
|
from PyQt4.QtCore import QVariant, QFileInfo, QObject, SIGNAL, QBuffer, Qt, QSize, \
|
||||||
QByteArray, QTranslator, QCoreApplication, QThread
|
QByteArray, QTranslator, QCoreApplication, QThread, \
|
||||||
|
QEvent
|
||||||
from PyQt4.QtGui import QFileDialog, QMessageBox, QPixmap, QFileIconProvider, \
|
from PyQt4.QtGui import QFileDialog, QMessageBox, QPixmap, QFileIconProvider, \
|
||||||
QIcon, QTableView, QApplication, QDialog, QPushButton
|
QIcon, QTableView, QApplication, QDialog, QPushButton
|
||||||
|
|
||||||
@ -524,6 +525,7 @@ class Application(QApplication):
|
|||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
qargs = [i.encode('utf-8') if isinstance(i, unicode) else i for i in args]
|
qargs = [i.encode('utf-8') if isinstance(i, unicode) else i for i in args]
|
||||||
QApplication.__init__(self, qargs)
|
QApplication.__init__(self, qargs)
|
||||||
|
self.file_event_hook = None
|
||||||
global gui_thread, qt_app
|
global gui_thread, qt_app
|
||||||
gui_thread = QThread.currentThread()
|
gui_thread = QThread.currentThread()
|
||||||
self._translator = None
|
self._translator = None
|
||||||
@ -549,6 +551,15 @@ class Application(QApplication):
|
|||||||
if set_qt_translator(self._translator):
|
if set_qt_translator(self._translator):
|
||||||
self.installTranslator(self._translator)
|
self.installTranslator(self._translator)
|
||||||
|
|
||||||
|
def event(self, e):
|
||||||
|
if callable(self.file_event_hook) and e.type() == QEvent.FileOpen:
|
||||||
|
path = unicode(e.file())
|
||||||
|
if os.access(path, os.R_OK):
|
||||||
|
self.file_event_hook(path)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return QApplication.event(self, e)
|
||||||
|
|
||||||
_store_app = None
|
_store_app = None
|
||||||
|
|
||||||
def is_ok_to_use_qt():
|
def is_ok_to_use_qt():
|
||||||
|
@ -2,6 +2,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import sys, os, time, socket, traceback
|
import sys, os, time, socket, traceback
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
from PyQt4.Qt import QCoreApplication, QIcon, QMessageBox
|
from PyQt4.Qt import QCoreApplication, QIcon, QMessageBox
|
||||||
|
|
||||||
@ -52,10 +53,12 @@ def run_gui(opts, args, actions, listener, app):
|
|||||||
wizard().exec_()
|
wizard().exec_()
|
||||||
dynamic.set('welcome_wizard_was_run', True)
|
dynamic.set('welcome_wizard_was_run', True)
|
||||||
main = Main(listener, opts, actions)
|
main = Main(listener, opts, actions)
|
||||||
|
add_filesystem_book = partial(main.add_filesystem_book, allow_device=False)
|
||||||
sys.excepthook = main.unhandled_exception
|
sys.excepthook = main.unhandled_exception
|
||||||
if len(args) > 1:
|
if len(args) > 1:
|
||||||
args[1] = os.path.abspath(args[1])
|
args[1] = os.path.abspath(args[1])
|
||||||
main.add_filesystem_book(args[1])
|
add_filesystem_book(args[1])
|
||||||
|
app.file_event_hook = add_filesystem_book
|
||||||
ret = app.exec_()
|
ret = app.exec_()
|
||||||
if getattr(main, 'run_wizard_b4_shutdown', False):
|
if getattr(main, 'run_wizard_b4_shutdown', False):
|
||||||
from calibre.gui2.wizard import wizard
|
from calibre.gui2.wizard import wizard
|
||||||
|
@ -987,10 +987,10 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
self.cover_cache.refresh([cid])
|
self.cover_cache.refresh([cid])
|
||||||
self.library_view.model().current_changed(current_idx, current_idx)
|
self.library_view.model().current_changed(current_idx, current_idx)
|
||||||
|
|
||||||
def add_filesystem_book(self, path):
|
def add_filesystem_book(self, path, allow_device=True):
|
||||||
if os.access(path, os.R_OK):
|
if os.access(path, os.R_OK):
|
||||||
books = [os.path.abspath(path)]
|
books = [os.path.abspath(path)]
|
||||||
to_device = self.stack.currentIndex() != 0
|
to_device = allow_device and self.stack.currentIndex() != 0
|
||||||
self._add_books(books, to_device)
|
self._add_books(books, to_device)
|
||||||
if to_device:
|
if to_device:
|
||||||
self.status_bar.showMessage(\
|
self.status_bar.showMessage(\
|
||||||
|
Loading…
x
Reference in New Issue
Block a user