#/usr/bin/python
from gi.repository import Gtk, Gio

class Monitor:

    mon = None
    drives = []
    main = None
    show_hdd = True
    show_net = True

    def __init__(self, main):
        self.main = main

    def init(self):
        self.mon = Gio.VolumeMonitor()
        self.mon.connect('mount-added', self._add_drive)
        self.mon.connect('mount-removed', self._del_drive)
        self.refresh()

    def _add_drive(self, s, m):
        if m.can_unmount():
            root = m.get_root()
            if (root.get_uri_scheme() == "file" and self.show_hdd) \
               or (not root.is_native() and self.show_net) :
                self.drives.append(m)

    def _del_drive(self, s, d):
        self.drives.remove(d)

    def refresh(self):
        self.drives = []
        if hasattr(self.mon, "get_mounts"):
            print "segfault"
            print self.mon.get_mounts()
        #for m in self.mon.get_mounts():
        #    self._add_drive(None, m)

    def eject(self, s, m):
        m.unmount(self._eject_cb)

class Main:
    mon = None
    
    def __init__(self):
        self.mon = Monitor(self)
        self.mon.init()

m = Main()
