Adding 'Copy Link' right click menu to links in book details.

This commit is contained in:
JimmXinu 2013-04-23 12:59:52 -05:00
parent 466fc4a522
commit 3c54bc180f
3 changed files with 51 additions and 27 deletions

View File

@ -8,7 +8,6 @@ __builtin__.__dict__['dynamic_property'] = lambda func: func(None)
from math import floor from math import floor
from functools import partial from functools import partial
print ("Hello, world!")
warnings.simplefilter('ignore', DeprecationWarning) warnings.simplefilter('ignore', DeprecationWarning)
try: try:
os.getcwdu() os.getcwdu()

View File

@ -406,6 +406,7 @@ class BookInfo(QWebView):
remove_format = pyqtSignal(int, object) remove_format = pyqtSignal(int, object)
save_format = pyqtSignal(int, object) save_format = pyqtSignal(int, object)
restore_format = pyqtSignal(int, object) restore_format = pyqtSignal(int, object)
copy_link = pyqtSignal(object)
def __init__(self, vertical, parent=None): def __init__(self, vertical, parent=None):
QWebView.__init__(self, parent) QWebView.__init__(self, parent)
@ -419,26 +420,33 @@ class BookInfo(QWebView):
palette.setBrush(QPalette.Base, Qt.transparent) palette.setBrush(QPalette.Base, Qt.transparent)
self.page().setPalette(palette) self.page().setPalette(palette)
self.css = P('templates/book_details.css', data=True).decode('utf-8') self.css = P('templates/book_details.css', data=True).decode('utf-8')
for x, icon in [('remove', 'trash.png'), ('save', 'save.png'), ('restore', 'edit-undo.png')]: for x, icon in [('remove_format', 'trash.png'), ('save_format', 'save.png'), ('restore_format', 'edit-undo.png'), ('copy_link','edit-copy.png')]:
ac = QAction(QIcon(I(icon)), '', self) ac = QAction(QIcon(I(icon)), '', self)
ac.current_fmt = None ac.current_fmt = None
ac.triggered.connect(getattr(self, '%s_format_triggerred'%x)) ac.current_url = None
setattr(self, '%s_format_action'%x, ac) ac.triggered.connect(getattr(self, '%s_triggerred'%x))
setattr(self, '%s_action'%x, ac)
def context_action_triggered(self, which): def context_action_triggered(self, which):
f = getattr(self, '%s_format_action'%which).current_fmt f = getattr(self, '%s_action'%which).current_fmt
if f: url = getattr(self, '%s_action'%which).current_url
if f and 'format' in which:
book_id, fmt = f book_id, fmt = f
getattr(self, '%s_format'%which).emit(book_id, fmt) getattr(self, which).emit(book_id, fmt)
if url and 'link' in which:
getattr(self, which).emit(url)
def remove_format_triggerred(self): def remove_format_triggerred(self):
self.context_action_triggered('remove') self.context_action_triggered('remove_format')
def save_format_triggerred(self): def save_format_triggerred(self):
self.context_action_triggered('save') self.context_action_triggered('save_format')
def restore_format_triggerred(self): def restore_format_triggerred(self):
self.context_action_triggered('restore') self.context_action_triggered('restore_format')
def copy_link_triggerred(self):
self.context_action_triggered('copy_link')
def link_activated(self, link): def link_activated(self, link):
self._link_clicked = True self._link_clicked = True
@ -474,7 +482,16 @@ class BookInfo(QWebView):
for action in list(menu.actions()): for action in list(menu.actions()):
if action is not ca: if action is not ca:
menu.removeAction(action) menu.removeAction(action)
if not r.isNull() and url.startswith('format:'): if not r.isNull():
if url.startswith('http'):
for a, t in [('copy', _('Copy Link')),
]:
ac = getattr(self, '%s_link_action'%a)
ac.current_url = url
ac.setText(t)
menu.addAction(ac)
if url.startswith('format:'):
parts = url.split(':') parts = url.split(':')
try: try:
book_id, fmt = int(parts[1]), parts[2] book_id, fmt = int(parts[1]), parts[2]
@ -594,6 +611,7 @@ class BookDetails(QWidget): # {{{
remove_specific_format = pyqtSignal(int, object) remove_specific_format = pyqtSignal(int, object)
save_specific_format = pyqtSignal(int, object) save_specific_format = pyqtSignal(int, object)
restore_specific_format = pyqtSignal(int, object) restore_specific_format = pyqtSignal(int, object)
copy_link = pyqtSignal(object)
remote_file_dropped = pyqtSignal(object, object) remote_file_dropped = pyqtSignal(object, object)
files_dropped = pyqtSignal(object, object) files_dropped = pyqtSignal(object, object)
cover_changed = pyqtSignal(object, object) cover_changed = pyqtSignal(object, object)
@ -664,6 +682,7 @@ class BookDetails(QWidget): # {{{
self.book_info.remove_format.connect(self.remove_specific_format) self.book_info.remove_format.connect(self.remove_specific_format)
self.book_info.save_format.connect(self.save_specific_format) self.book_info.save_format.connect(self.save_specific_format)
self.book_info.restore_format.connect(self.restore_specific_format) self.book_info.restore_format.connect(self.restore_specific_format)
self.book_info.copy_link.connect(self.copy_link)
self.setCursor(Qt.PointingHandCursor) self.setCursor(Qt.PointingHandCursor)
def handle_click(self, link): def handle_click(self, link):

View File

@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
import functools import functools
from PyQt4.Qt import (Qt, QStackedWidget, QMenu, QTimer, from PyQt4.Qt import (Qt, QApplication, QStackedWidget, QMenu, QTimer,
QSize, QSizePolicy, QStatusBar, QLabel, QFont) QSize, QSizePolicy, QStatusBar, QLabel, QFont)
from calibre.utils.config import prefs from calibre.utils.config import prefs
@ -274,6 +274,8 @@ class LayoutMixin(object): # {{{
self.iactions['Save To Disk'].save_library_format_by_ids) self.iactions['Save To Disk'].save_library_format_by_ids)
self.book_details.restore_specific_format.connect( self.book_details.restore_specific_format.connect(
self.iactions['Remove Books'].restore_format) self.iactions['Remove Books'].restore_format)
self.book_details.copy_link.connect(self.bd_copy_link,
type=Qt.QueuedConnection)
self.book_details.view_device_book.connect( self.book_details.view_device_book.connect(
self.iactions['View'].view_device_book) self.iactions['View'].view_device_book)
@ -295,6 +297,10 @@ class LayoutMixin(object): # {{{
if self.cover_flow: if self.cover_flow:
self.cover_flow.dataChanged() self.cover_flow.dataChanged()
def bd_copy_link(self, url):
if url:
QApplication.clipboard().setText(url)
def save_layout_state(self): def save_layout_state(self):
for x in ('library', 'memory', 'card_a', 'card_b'): for x in ('library', 'memory', 'card_a', 'card_b'):
getattr(self, x+'_view').save_state() getattr(self, x+'_view').save_state()