diff --git a/src/libprs500/gui2/images.qrc b/src/libprs500/gui2/images.qrc index 9f7187e088..77e7146766 100644 --- a/src/libprs500/gui2/images.qrc +++ b/src/libprs500/gui2/images.qrc @@ -48,5 +48,6 @@ images/sync.svg images/trash.svg images/view.svg + images/viewer.svg diff --git a/src/libprs500/gui2/images/viewer.svg b/src/libprs500/gui2/images/viewer.svg new file mode 100644 index 0000000000..b9ba4bd264 --- /dev/null +++ b/src/libprs500/gui2/images/viewer.svg @@ -0,0 +1,3834 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libprs500/gui2/lrf_renderer/main.py b/src/libprs500/gui2/lrf_renderer/main.py index 158d06ed3a..c8f00b0c9c 100644 --- a/src/libprs500/gui2/lrf_renderer/main.py +++ b/src/libprs500/gui2/lrf_renderer/main.py @@ -188,7 +188,12 @@ def file_renderer(stream, opts, parent=None, logger=None): level = logging.DEBUG if opts.verbose else logging.INFO logger = logging.getLogger('lrfviewer') setup_cli_handlers(logger, level) - + if islinux: + try: + from subprocess import call + call('xdg-mime default libprs500-lrfviewer.desktop application/lrf', shell=True) + except: + pass return Main(stream, logger, opts, parent=parent) diff --git a/src/libprs500/gui2/lrf_renderer/main.ui b/src/libprs500/gui2/lrf_renderer/main.ui index 99fde22556..047d20bae4 100644 --- a/src/libprs500/gui2/lrf_renderer/main.ui +++ b/src/libprs500/gui2/lrf_renderer/main.ui @@ -19,7 +19,7 @@ LRF Viewer - :/library + :/images/viewer.svg diff --git a/src/libprs500/linux.py b/src/libprs500/linux.py index 8f0a72a3ec..d11e34dace 100644 --- a/src/libprs500/linux.py +++ b/src/libprs500/linux.py @@ -12,9 +12,11 @@ ## You should have received a copy of the GNU General Public License along ## with this program; if not, write to the Free Software Foundation, Inc., ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.Warning +import shutil ''' Post installation script for linux ''' import sys, os from subprocess import check_call +from libprs500 import __version__ def options(option_parser): parser = option_parser() @@ -171,7 +173,7 @@ complete -o nospace -F _prs500 prs500 traceback.print_exc() def setup_udev_rules(): - print 'Trying to setup udev rules...', + print 'Trying to setup udev rules...' sys.stdout.flush() groups = open('/etc/group', 'rb').read() group = 'plugdev' if 'plugdev' in groups else 'usb' @@ -182,11 +184,9 @@ def setup_udev_rules(): udev.close() try: check_call('udevstart', shell=True) - print 'success' except: try: check_call('/etc/init.d/udev reload', shell=True) - print 'success' except: print >>sys.stderr, "Couldn't reload udev, you may have to reboot" @@ -197,6 +197,85 @@ def post_install(): setup_udev_rules() setup_completion() + setup_desktop_integration() + + + +VIEWER = '''\ +[Desktop Entry] +Version=%s +Type=Application +Name=LRF Viewer +Comment=Viewer for LRF files (SONY ebook format files) +TryExec=lrfviewer +Exec=lrfviewer %%F +Icon=libprs500-viewer +MimeType=application/lrf; +Categories=Graphics;Viewer; +'''%(__version__,) + +GUI = '''\ +[Desktop Entry] +Version=%s +Type=Application +Name=Libprs500 +Comment=E-book library management +TryExec=libprs500 +Exec=libprs500 +Icon=libprs500-gui +Categories=Office; +'''%(__version__,) + +MIME = '''\ + + + + SONY E-book compiled format + + + + SONY E-book source format + + + +''' + +def setup_desktop_integration(): + from PyQt4.QtGui import QApplication, QPixmap + from PyQt4.QtCore import Qt + from libprs500.gui2 import images_rc + from tempfile import mkdtemp + + print 'Setting up desktop integration...' + + app = QApplication([]) + svg = QPixmap(':/images/mimetypes/lrf.svg').scaled(128, 128, Qt.KeepAspectRatio, Qt.SmoothTransformation) + gui = QPixmap(':library').scaled(128, 128, Qt.KeepAspectRatio, Qt.SmoothTransformation) + viewer = QPixmap(':/images/viewer.svg').scaled(128, 128, Qt.KeepAspectRatio, Qt.SmoothTransformation) + tdir = mkdtemp() + try: + os.chdir(tdir) + svg.save(os.path.join(tdir, 'libprs500-lrf.png'), 'PNG') + gui.save(os.path.join(tdir, 'libprs500-gui.png'), 'PNG') + viewer.save(os.path.join(tdir, 'libprs500-viewer.png'), 'PNG') + check_call('xdg-icon-resource install --context mimetypes --size 128 libprs500-lrf.png application-lrf', shell=True) + check_call('xdg-icon-resource install --context mimetypes --size 128 libprs500-lrf.png text-lrs', shell=True) + check_call('xdg-icon-resource install --size 128 libprs500-gui.png libprs500-gui', shell=True) + check_call('xdg-icon-resource install --size 128 libprs500-gui.png libprs500-gui', shell=True) + f = open('libprs500-lrfviewer.desktop', 'wb') + f.write(VIEWER) + f.close() + f = open('libprs500-gui.desktop', 'wb') + f.write(GUI) + f.close() + check_call('xdg-desktop-menu install ./libprs500-gui.desktop ./libprs500-lrfviewer.desktop', shell=True) + f = open('libprs500-mimetypes', 'wb') + f.write(MIME) + f.close() + check_call('xdg-mime install libprs500-mimetypes', shell=True) + finally: + shutil.rmtree(tdir) + if __name__ == '__main__': post_install()