Guest User

Untitled

a guest
Jan 23rd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.45 KB | None | 0 0
  1. #
  2. # QDigiDoc Nautilus Extension
  3. #
  4. # Copyright (C) 2010  Erkko Kebbinau
  5. # Copyright (C) 2011 Guido Tabbernuk
  6. #
  7. # This library is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU Lesser General Public
  9. # License as published by the Free Software Foundation; either
  10. # version 2.1 of the License, or (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public
  18. # License along with this library; if not, write to the Free Software
  19. # Foundation, Inc, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20. #
  21. import os
  22. import urllib
  23. import gettext
  24. import locale
  25.  
  26. from gi.repository import Nautilus, GObject, Gio
  27.  
  28. APP = 'nautilus-qdigidoc'
  29.  
  30. class OpenDigidocExtension(GObject.GObject, Nautilus.MenuProvider):
  31.     def __init__(self):
  32.         pass
  33.        
  34.     def _open_client(self, paths):
  35.         args = ""
  36.         for path in paths:
  37.             args += "\"%s\" " % path
  38.         cmd = ("qdigidocclient " + args + "&")
  39.         os.system(cmd)
  40.        
  41.     def menu_activate_cb(self, menu, paths):
  42.         self._open_client(paths)
  43.  
  44.     def valid_file(self, file):
  45.         return file.get_file_type() == Gio.FileType.REGULAR and file.get_uri_scheme() == 'file'
  46.  
  47.     def get_file_items(self, window, files):
  48.         paths = []
  49.         for file in files:
  50.             if self.valid_file(file):
  51.                 path = urllib.unquote(file.get_uri()[7:])
  52.                 paths.append(path)
  53.  
  54.         if len(paths) < 1:
  55.             return
  56.  
  57.         locale.setlocale(locale.LC_ALL, '')
  58.         gettext.bindtextdomain(APP)
  59.         gettext.textdomain(APP)
  60.         _ = gettext.gettext
  61.  
  62.         tooltip_message = gettext.ngettext('Sign selected file with Digidoc3 Client',
  63.                                            'Sign selected files with Digidoc3 Client',
  64.                                            len(paths))
  65.  
  66.         item = Nautilus.MenuItem(
  67.             name="OpenDigidocExtension::DigidocSigner",
  68.             label=_('Sign with ID card'),
  69.             tip=tooltip_message
  70.         )
  71.         item.set_property('icon', 'qdigidoc-client')
  72.         item.connect('activate', self.menu_activate_cb, paths)
  73.  
  74.         return item,
Add Comment
Please, Sign In to add comment