mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Content server: When using a custom IP address to listen on via Preferences->Tweaks advertise that IP address via BonJour. Wireless device driver: Make the default save template not use folders
This commit is contained in:
commit
422f6791c8
@ -84,6 +84,8 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
PREFIX = ''
|
PREFIX = ''
|
||||||
BACKLOADING_ERROR_MESSAGE = None
|
BACKLOADING_ERROR_MESSAGE = None
|
||||||
|
|
||||||
|
SAVE_TEMPLATE = '{title} - {authors} ({id})'
|
||||||
|
|
||||||
# Some network protocol constants
|
# Some network protocol constants
|
||||||
BASE_PACKET_LEN = 4096
|
BASE_PACKET_LEN = 4096
|
||||||
PROTOCOL_VERSION = 1
|
PROTOCOL_VERSION = 1
|
||||||
|
@ -11,6 +11,7 @@ from PyQt4.Qt import QToolButton, QMenu, pyqtSignal, QIcon, QTimer
|
|||||||
|
|
||||||
from calibre.gui2.actions import InterfaceAction
|
from calibre.gui2.actions import InterfaceAction
|
||||||
from calibre.utils.smtp import config as email_config
|
from calibre.utils.smtp import config as email_config
|
||||||
|
from calibre.utils.config import tweaks
|
||||||
from calibre.constants import iswindows, isosx
|
from calibre.constants import iswindows, isosx
|
||||||
from calibre.customize.ui import is_disabled
|
from calibre.customize.ui import is_disabled
|
||||||
from calibre.devices.bambook.driver import BAMBOOK
|
from calibre.devices.bambook.driver import BAMBOOK
|
||||||
@ -84,10 +85,12 @@ class ShareConnMenu(QMenu): # {{{
|
|||||||
action=self.toggle_server_action, group=gr)
|
action=self.toggle_server_action, group=gr)
|
||||||
|
|
||||||
def server_state_changed(self, running):
|
def server_state_changed(self, running):
|
||||||
from calibre.utils.mdns import get_external_ip
|
from calibre.utils.mdns import get_external_ip, verify_ipV4_address
|
||||||
text = _('Start Content Server')
|
text = _('Start Content Server')
|
||||||
if running:
|
if running:
|
||||||
text = _('Stop Content Server') + ' [%s]'%get_external_ip()
|
listen_on = (verify_ipV4_address(tweaks['server_listen_on']) or
|
||||||
|
get_external_ip())
|
||||||
|
text = _('Stop Content Server') + ' [%s]'%listen_on
|
||||||
self.toggle_server_action.setText(text)
|
self.toggle_server_action.setText(text)
|
||||||
|
|
||||||
def hide_smartdevice_menus(self):
|
def hide_smartdevice_menus(self):
|
||||||
|
@ -5,7 +5,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os
|
import os, socket
|
||||||
import logging
|
import logging
|
||||||
from logging.handlers import RotatingFileHandler
|
from logging.handlers import RotatingFileHandler
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ from calibre.utils.date import fromtimestamp
|
|||||||
from calibre.library.server import listen_on, log_access_file, log_error_file
|
from calibre.library.server import listen_on, log_access_file, log_error_file
|
||||||
from calibre.library.server.utils import expose, AuthController
|
from calibre.library.server.utils import expose, AuthController
|
||||||
from calibre.utils.mdns import publish as publish_zeroconf, \
|
from calibre.utils.mdns import publish as publish_zeroconf, \
|
||||||
unpublish as unpublish_zeroconf, get_external_ip
|
unpublish as unpublish_zeroconf, get_external_ip, verify_ipV4_address
|
||||||
from calibre.library.server.content import ContentServer
|
from calibre.library.server.content import ContentServer
|
||||||
from calibre.library.server.mobile import MobileServer
|
from calibre.library.server.mobile import MobileServer
|
||||||
from calibre.library.server.xml import XMLServer
|
from calibre.library.server.xml import XMLServer
|
||||||
@ -78,6 +78,7 @@ class BonJour(SimplePlugin): # {{{
|
|||||||
SimplePlugin.__init__(self, engine)
|
SimplePlugin.__init__(self, engine)
|
||||||
self.port = port
|
self.port = port
|
||||||
self.prefix = prefix
|
self.prefix = prefix
|
||||||
|
self.ip_address = '0.0.0.0'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mdns_services(self):
|
def mdns_services(self):
|
||||||
@ -90,9 +91,10 @@ class BonJour(SimplePlugin): # {{{
|
|||||||
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
zeroconf_ip_address = verify_ipV4_address(self.ip_address)
|
||||||
try:
|
try:
|
||||||
for s in self.mdns_services:
|
for s in self.mdns_services:
|
||||||
publish_zeroconf(*s)
|
publish_zeroconf(*s, use_ip_address=zeroconf_ip_address)
|
||||||
except:
|
except:
|
||||||
import traceback
|
import traceback
|
||||||
cherrypy.log.error('Failed to start BonJour:')
|
cherrypy.log.error('Failed to start BonJour:')
|
||||||
@ -140,6 +142,7 @@ class LibraryServer(ContentServer, MobileServer, XMLServer, OPDSServer, Cache,
|
|||||||
if not opts.url_prefix:
|
if not opts.url_prefix:
|
||||||
opts.url_prefix = ''
|
opts.url_prefix = ''
|
||||||
|
|
||||||
|
cherrypy.engine.bonjour.ip_address = listen_on
|
||||||
cherrypy.engine.bonjour.port = opts.port
|
cherrypy.engine.bonjour.port = opts.port
|
||||||
cherrypy.engine.bonjour.prefix = opts.url_prefix
|
cherrypy.engine.bonjour.prefix = opts.url_prefix
|
||||||
|
|
||||||
|
@ -39,6 +39,19 @@ def _get_external_ip():
|
|||||||
#print 'ipaddr: %s' % ipaddr
|
#print 'ipaddr: %s' % ipaddr
|
||||||
return ipaddr
|
return ipaddr
|
||||||
|
|
||||||
|
def verify_ipV4_address(ip_address):
|
||||||
|
result = None
|
||||||
|
if ip_address != '0.0.0.0' and ip_address != '::':
|
||||||
|
# do some more sanity checks on the address
|
||||||
|
try:
|
||||||
|
socket.inet_aton(ip_address)
|
||||||
|
if len(ip_address.split('.')) == 4:
|
||||||
|
result = ip_address
|
||||||
|
except socket.error:
|
||||||
|
# Not legal ip address
|
||||||
|
pass
|
||||||
|
return result
|
||||||
|
|
||||||
_ext_ip = None
|
_ext_ip = None
|
||||||
def get_external_ip():
|
def get_external_ip():
|
||||||
global _ext_ip
|
global _ext_ip
|
||||||
@ -93,7 +106,8 @@ def publish(desc, type, port, properties=None, add_hostname=True, use_ip_address
|
|||||||
into the TXT record.
|
into the TXT record.
|
||||||
'''
|
'''
|
||||||
server = start_server()
|
server = start_server()
|
||||||
service = create_service(desc, type, port, properties, add_hostname)
|
service = create_service(desc, type, port, properties, add_hostname,
|
||||||
|
use_ip_address)
|
||||||
server.registerService(service)
|
server.registerService(service)
|
||||||
|
|
||||||
def unpublish(desc, type, port, properties=None, add_hostname=True):
|
def unpublish(desc, type, port, properties=None, add_hostname=True):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user