Exemplo n.º 1
0
 def copy_metadata(self):
     rows = self.gui.library_view.selectionModel().selectedRows()
     if not rows or len(rows) == 0:
         return error_dialog(self.gui,
                             _('Cannot copy metadata'),
                             _('No books selected'),
                             show=True)
     if len(rows) > 1:
         return error_dialog(
             self.gui,
             _('Cannot copy metadata'),
             _('Multiple books selected, can only copy from one book at a time.'
               ),
             show=True)
     db = self.gui.current_db
     book_id = db.id(rows[0].row())
     mi = db.new_api.get_metadata(book_id)
     md = QMimeData()
     md.setText(str(mi))
     md.setData('application/calibre-book-metadata',
                bytearray(metadata_to_opf(mi, default_lang='und')))
     img = db.new_api.cover(book_id, as_image=True)
     if img:
         md.setImageData(img)
     c = QApplication.clipboard()
     c.setMimeData(md)
Exemplo n.º 2
0
 def mime_data_for_copy(self):
     md = QMimeData()
     text = self.lineEdit().selectedText()
     md.setText(text or self.dateTime().toString())
     md.setData(
         self.MIME_TYPE,
         self.dateTime().toString(Qt.DateFormat.ISODate).encode('ascii'))
     return md
Exemplo n.º 3
0
def drag_data(self):
    m = self.model()
    db = m.db
    selected = self.get_selected_ids()
    ids = ' '.join(map(str, selected))
    md = QMimeData()
    md.setData('application/calibre+from_library', ids.encode('utf-8'))
    fmt = prefs['output_format']

    def url_for_id(i):
        try:
            ans = db.format_path(i, fmt, index_is_id=True)
        except:
            ans = None
        if ans is None:
            fmts = db.formats(i, index_is_id=True)
            if fmts:
                fmts = fmts.split(',')
            else:
                fmts = []
            for f in fmts:
                try:
                    ans = db.format_path(i, f, index_is_id=True)
                except:
                    ans = None
        if ans is None:
            ans = db.abspath(i, index_is_id=True)
        return QUrl.fromLocalFile(ans)

    md.setUrls([url_for_id(i) for i in selected])
    drag = QDrag(self)
    col = self.selectionModel().currentIndex().column()
    try:
        md.column_name = self.column_map[col]
    except AttributeError:
        md.column_name = 'title'
    drag.setMimeData(md)
    cover = self.drag_icon(m.cover(self.currentIndex().row()),
                           len(selected) > 1)
    drag.setHotSpot(QPoint(-15, -15))
    drag.setPixmap(cover)
    return drag
Exemplo n.º 4
0
 def mimeData(self, indexes):
     data = ','.join(unicode_type(i.row()) for i in indexes)
     md = QMimeData()
     md.setData('application/calibre_charcode_indices',
                data.encode('utf-8'))
     return md