Commits

Juha Sahakangas committed 7017a49

nautilus: GNOME 3.2 compatibility update for nautilus-thg

Port nautilus-thg from pygtk to gobject introspection based
bindings, and update file monitoring to use gio/gvfs
instead of gnome-vfs.

fixes #869 aka #1333 aka #1349

Comments (0)

Files changed (1)

contrib/nautilus-thg.py

 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2, incorporated herein by reference.
 
-import gtk
-import gobject
-import nautilus
-import gnomevfs
+from gi.repository import Nautilus
+from gi.repository import GObject
+from gi.repository import GLib
+from gi.repository import Gio
+from gi.repository import Gtk
 import os
 import sys
 
 thg_main     = 'thg'
-idstr_prefix = 'HgNautilus2'
-
-if gtk.gtk_version < (2, 14, 0):
-    # at least on 2.12.12, gtk widgets can be confused by control
-    # char markups (like "&#x1;"), so use cgi.escape instead
-    from cgi import escape as markup_escape_text
-else:
-    from gobject import markup_escape_text
+idstr_prefix = 'HgNautilus3'
 
 try:
     from mercurial import demandimport
 
 nofilecmds = 'about serve synch repoconfig userconfig merge unmerge'.split()
 
-class HgExtensionDefault:
+class HgExtensionDefault(GObject.GObject):
 
     def __init__(self):
         self.scanStack = []
         self.hgtk = paths.find_in_path(thg_main)
         self.menu = menuthg.menuThg()
         self.notify = os.path.expanduser('~/.tortoisehg/notify')
-        try:
-            f = open(self.notify, 'w')
-            f.close()
-            ds_uri = gnomevfs.get_uri_from_local_path(self.notify)
-            self.gmon = gnomevfs.monitor_add(ds_uri,
-                      gnomevfs.MONITOR_FILE, self.notified)
-        except (gnomevfs.NotSupportedError, IOError), e:
-            debugf('no notification because of %s', e)
-            self.notify = ''
+
+        f = open(self.notify, 'w')
+        f.close()
+        self.gmon = Gio.file_new_for_path(self.notify).monitor(Gio.FileMonitorFlags.NONE, None)
+        self.gmon.connect('changed', self.notified)
 
     def icon(self, iname):
         return paths.get_tortoise_icon(iname)
                 # can not insert a separator till now
                 pass
             elif menu_info.isSubmenu():
-                if hasattr(nautilus, 'Menu'):
-                    item = nautilus.MenuItem(idstr, menu_info.menutext,
-                            menu_info.helptext)
-                    submenu = nautilus.Menu()
+                if hasattr(Nautilus, 'Menu'):
+                    item = Nautilus.MenuItem(name=idstr, label=menu_info.menutext,
+                            tip=menu_info.helptext)
+                    submenu = Nautilus.Menu()
                     item.set_submenu(submenu)
                     for subitem in self._buildMenu(menu_info.get_menus()):
                         submenu.append_item(subitem)
                         items.append(subitem)
             else:
                 if menu_info.state:
-                    item = nautilus.MenuItem(idstr,
+                    item = Nautilus.MenuItem.new(idstr,
                                  menu_info.menutext,
                                  menu_info.helptext,
                                  self.icon(menu_info.icon))
             return self.buildMenu(vfs_files, False)
 
     def get_columns(self):
-        return nautilus.Column(idstr_prefix + "::80hg_status",
+        return Nautilus.Column.new(idstr_prefix + "::80hg_status",
                                "hg_status",
                                "Hg Status",
                                "Version control status"),
         emblem, status = cache2state.get(cachestate, (None, '?'))
         return emblem, status
 
-    def notified(self, mon_uri=None, event_uri=None, event=None):
+    def notified(self, monitor=None, changedfile=None, otherfile=None, event=None):
+        if event == Gio.FileMonitorEvent.CHANGES_DONE_HINT: return
+
         debugf('notified from hgtk, %s', event, level='n')
         f = open(self.notify, 'a+')
         files = None
             self._invalidate_dirs()
         else:
             #group invalidation of directories
-            gobject.timeout_add(200, self._invalidate_dirs)
+            GLib.timeout_add(200, self._invalidate_dirs)
 
     def _invalidate_dirs(self):
         for path in self.inv_dirs:
 
     # property page borrowed from http://www.gnome.org/~gpoo/hg/nautilus-hg/
     def __add_row(self, row, label_item, label_value):
-        label = gtk.Label(label_item)
+        label = Gtk.Label(label_item)
         label.set_use_markup(True)
         label.set_alignment(1, 0)
-        self.table.attach(label, 0, 1, row, row + 1, gtk.FILL, gtk.FILL, 0, 0)
+        self.table.attach(label, 0, 1, row, row + 1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL, 0, 0)
         label.show()
 
-        label = gtk.Label(label_value)
+        label = Gtk.Label(label_value)
         label.set_use_markup(True)
         label.set_alignment(0, 1)
         label.show()
-        self.table.attach(label, 1, 2, row, row + 1, gtk.FILL, 0, 0, 0)
+        self.table.attach(label, 1, 2, row, row + 1, Gtk.AttachOptions.FILL, 0, 0, 0)
 
     def get_property_pages(self, vfs_files):
         if len(vfs_files) != 1:
         parents = '\n'.join([short(p.node()) for p in ctx.parents()])
         description = ctx.description()
         user = ctx.user()
-        user = markup_escape_text(user)
+        user = GLib.markup_escape_text(user)
         tags = ', '.join(ctx.tags())
         branch = ctx.branch()
 
-        self.property_label = gtk.Label('Mercurial')
+        self.property_label = Gtk.Label('Mercurial')
 
-        self.table = gtk.Table(7, 2, False)
+        self.table = Gtk.Table(7, 2, False)
         self.table.set_border_width(5)
         self.table.set_row_spacings(5)
         self.table.set_col_spacings(5)
             self.__add_row(6, '<b>Branch</b>:', branch)
 
         self.table.show()
-        return nautilus.PropertyPage("MercurialPropertyPage::status",
+        return Nautilus.PropertyPage.new("MercurialPropertyPage::status",
                                      self.property_label, self.table),
 
 class HgExtensionIcons(HgExtensionDefault):
         '''Queue file for emblem and hg status update'''
         self.scanStack.append(file)
         if len(self.scanStack) == 1:
-            gobject.idle_add(self.fileinfo_on_idle)
+            GLib.idle_add(self.fileinfo_on_idle)
 
     def fileinfo_on_idle(self):
         '''Update emblem and hg status for files when there is time'''
         return True
 
 if ui.ui().configbool("tortoisehg", "overlayicons", default = True):
-    class HgExtension(HgExtensionIcons, nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.PropertyPageProvider, nautilus.InfoProvider):
+    class HgExtension(HgExtensionIcons, Nautilus.MenuProvider, Nautilus.ColumnProvider, Nautilus.PropertyPageProvider, Nautilus.InfoProvider):
         pass
 else:
-    class HgExtension(HgExtensionDefault, nautilus.MenuProvider, nautilus.ColumnProvider, nautilus.PropertyPageProvider):
+    class HgExtension(HgExtensionDefault, Nautilus.MenuProvider, Nautilus.ColumnProvider, Nautilus.PropertyPageProvider):
         pass
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.