https://bugs.kde.org/show_bug.cgi?id=332380

Shunsuke Shimizu <gr...@grafi.jp> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gr...@grafi.jp

--- Comment #9 from Shunsuke Shimizu <gr...@grafi.jp> ---
Created attachment 95830
  --> https://bugs.kde.org/attachment.cgi?id=95830&action=edit
The patch implementing basic dbus support for kbibtex 0.7 (based on 6d9d476)

Dear auxsvr, Thomas,

It seems the "correct" way to implement dbus functionality is, as dbus object,
publishing each opened bibtex document (tied to KBibTeXPart) and files on
document lists.
I tried that and succeed to implement basic functionalities: listing of opened
files, opening another file, and insertion of elements. Though currently entry
editing operation is limited, it is also a start point to make KBibTeX fully
controlable from other applications.

Following python scripts demonstrates the functionalities. It create
"/tmp/foo.bib" with two entries. 

import dbus
import re
import sys

bus = dbus.SessionBus()

names = bus.list_names()
kbibtex_names = filter(lambda name: re.match(r"\Aorg.gna.kbibtex-\d+\Z", name),
names)
if not kbibtex_names:
    print("kbibtex is not running")
    sys.exit(1)
kbibtex_name = kbibtex_names[0]
print(kbibtex_name)

file_manager = bus.get_object(kbibtex_name, '/FileManager')
file_manager_interface = dbus.Interface(file_manager, dbus_interface =
'org.gna.KBibTeX.FileManager')

opened_id = int(file_manager.open('file:///tmp/foo.bib'))
file_manager.setCurrentFileId(opened_id)
print("opend id: "+str(opened_id))
current_file_id = int(file_manager_interface.currentFileId())
print("current file id: "+str(current_file_id))
if not current_file_id:
    print("no file is opened")
    sys.exit(2)

current_file = bus.get_object(kbibtex_name,
'/FileManager/'+str(current_file_id))
current_file_interface = dbus.Interface(current_file, dbus_interface =
'org.gna.KBibTeX.FileManager.FileInfo')
current_url = str(current_file_interface.url())
print("current url: "+current_url)
current_document_id = int(current_file_interface.documentId())
print("current document id: "+str(current_document_id))
if not current_document_id:
    print("no document is opend")
    sys.exit(3)

current_document = bus.get_object(kbibtex_name,
'/KBibTeX/Documents/'+str(current_document_id))
current_document_interface = dbus.Interface(current_document, dbus_interface =
'org.gna.KBibTeX.Document')
indexes = current_document_interface.insertEntries("""\
@book{Knuth86,
  author    = {Donald E. Knuth},
  title     = {The TeXbook},
  publisher = {Addison-Wesley},
  year      = {1986},
  isbn      = {0-201-13447-0}
}
@book{Lamport86,
  author    = {Leslie Lamport},
  title     = {LaTeX: User's Guide and Reference Manual},
  publisher = {Addison-Wesley},
  year      = {1986},
  isbn      = {0-201-15790-X}
}""", 'application/x-bibtex')
for i in indexes:
    print("entry index: "+str(i))
current_document_interface.documentSave()

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to