Пример #1
0
class pluginclass( object ):
	
	def __init__( self, mintMenuWin, toggleButton ):
		
		self.mintMenuWin = mintMenuWin
		self.toggleButton = toggleButton
		
		# Read GLADE file
		gladefile = os.path.join( os.path.dirname( __file__ ), "places.glade" )
		wTree 	= gtk.glade.XML( gladefile, "mainWindow" )
		self.placesBtnHolder	= wTree.get_widget( "places_button_holder" )
		self.editableBtnHolder 	= wTree.get_widget( "editable_button_holder" )
		self.scrolledWindow=wTree.get_widget("scrolledwindow2")
		# These properties are NECESSARY to maintain consistency

		# Set 'window' property for the plugin (Must be the root widget)
		self.window = wTree.get_widget( "mainWindow" )

		# Set 'heading' property for plugin
		self.heading = _("Places")

		# This should be the first item added to the window in glade
		self.content_holder = wTree.get_widget( "Places" )

		# Items to get custom colors
		self.itemstocolor = [ wTree.get_widget( "viewport2" ) ]

		# Gconf stuff
		self.gconf = EasyGConf( "/apps/mintMenu/plugins/places/" )

		self.gconf.notifyAdd( "icon_size", self.RegenPlugin )
		self.gconf.notifyAdd( "show_computer", self.RegenPlugin )
		self.gconf.notifyAdd( "show_desktop", self.RegenPlugin )
		self.gconf.notifyAdd( "show_home_folder", self.RegenPlugin )
		self.gconf.notifyAdd( "show_network", self.RegenPlugin )
		self.gconf.notifyAdd( "show_trash", self.RegenPlugin )
		self.gconf.notifyAdd( "custom_names", self.RegenPlugin )
		self.gconf.notifyAdd( "custom_paths", self.RegenPlugin )
		self.gconf.notifyAdd( "allowScrollbar", self.RegenPlugin )
		self.gconf.notifyAdd( "height", self.changePluginSize )
		self.gconf.notifyAdd( "width", self.changePluginSize )		
		self.gconf.bindGconfEntryToVar( "bool", "sticky", self, "sticky" )

		self.GetGconfEntries()
		
		self.content_holder.set_size_request( self.width, self.height )

	def wake (self) :
		if ( self.showtrash == True ):
			self.refreshTrash()

	def destroy( self ):
		self.gconf.notifyRemoveAll()		

	def changePluginSize( self, client, connection_id, entry, args ):
		self.allowScrollbar = self.gconf.get( "bool", "allowScrollbar", False)
		if entry.get_key() == self.gconf.gconfDir+"width":
			self.width = entry.get_value().get_int()
		elif entry.get_key() == self.gconf.gconfDir+"height":
			if (self.allowScrollbar == False):
				self.height = -1
				self.scrolledWindow.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_NEVER )
			else:
				self.scrolledWindow.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC )
				self.height = entry.get_value().get_int()

		self.content_holder.set_size_request( self.width, self.height )
		


	def RegenPlugin( self, *args, **kargs ):
		self.GetGconfEntries()
		self.ClearAll()
		self.do_standard_places()
		self.do_custom_places()

	def GetGconfEntries( self ):

		self.width = self.gconf.get( "int", "width", 200 )
		self.allowScrollbar = self.gconf.get( "bool", "allowScrollbar", False)
		self.scrolledWindow.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC )
		self.height = self.gconf.get( "int", "height", 180 )
		self.content_holder.set_size_request( self.width, self.height )
		if (self.allowScrollbar == False):
			self.height = -1
			self.scrolledWindow.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_NEVER )
		self.content_holder.set_size_request( self.width, self.height )
		self.execapp = self.gconf.get( "string", "execute_app", "nautilus" )
		self.iconsize = self.gconf.get( "int","icon_size", 2 )
		
		# Check default items
		
		self.showcomputer = self.gconf.get( "bool", "show_computer", True )
		self.showhomefolder = self.gconf.get( "bool", "show_home_folder", True )
		self.shownetwork = self.gconf.get( "bool", "show_network", True )
		self.showdesktop = self.gconf.get( "bool", "show_desktop", True )
		self.showtrash = self.gconf.get( "bool", "show_trash", True )
		
		# Get paths for custom items
		
		self.custompaths = self.gconf.get( "list-string", "custom_paths", [ ] )
		
		# Get names for custom items
		
		self.customnames = self.gconf.get( "list-string", "custom_names", [ ] )

		# Hide vertical dotted separator
		self.hideseparator = self.gconf.get( "bool", "hide_separator", False )
		# Plugin icon
		self.icon = self.gconf.get( "string", 'icon', "gnome-fs-directory.png" )
		# Allow plugin to be minimized to the left plugin pane
		self.sticky = self.gconf.get( "bool", "sticky", False )
		self.minimized = self.gconf.get( "bool", "minimized", False )

	def ClearAll(self):
		for child in self.placesBtnHolder.get_children():
			child.destroy()
		for child in self.editableBtnHolder.get_children():
			child.destroy()

	#Add standard places
	def do_standard_places( self ):		

		if ( self.showcomputer == True ):
			Button1 = easyButton( "computer", self.iconsize, [_("Computer")], -1, -1 )
			Button1.connect( "clicked", self.ButtonClicked, "nautilus computer:" )
			Button1.show()
			self.placesBtnHolder.pack_start( Button1, False, False )
			self.mintMenuWin.setTooltip( Button1, _("Browse all local and remote disks and folders accessible from this computer") )

		if ( self.showhomefolder == True ):
			Button2 = easyButton( "user-home", self.iconsize, [_("Home Folder")], -1, -1 )
			Button2.connect( "clicked", self.ButtonClicked, "nautilus" )
			Button2.show()
			self.placesBtnHolder.pack_start( Button2, False, False )
			self.mintMenuWin.setTooltip( Button2, _("Open your personal folder") )

		if ( self.shownetwork == True ):
			Button3 = easyButton( "network-workgroup", self.iconsize, [_("Network")], -1, -1 )
			Button3.connect( "clicked", self.ButtonClicked, "nautilus network:" )
			Button3.show()
			self.placesBtnHolder.pack_start( Button3, False, False )
			self.mintMenuWin.setTooltip( Button3, _("Browse bookmarked and local network locations") )
		
		if ( self.showdesktop == True ):
			# Determine where the Desktop folder is (could be localized)
			desktopDir = home + "/Desktop"
			try:
				import sys
				sys.path.append('/usr/lib/linuxmint/common')
				from configobj import ConfigObj
				config = ConfigObj(home + "/.config/user-dirs.dirs")
				tmpdesktopDir = config['XDG_DESKTOP_DIR']
				tmpdesktopDir = commands.getoutput("echo " + tmpdesktopDir)			
				if os.path.exists(tmpdesktopDir):
					desktopDir = tmpdesktopDir
			except Exception, detail:
				print detail
			Button4 = easyButton( "gnome-fs-desktop", self.iconsize, [_("Desktop")], -1, -1 )
			Button4.connect( "clicked", self.ButtonClicked, "nautilus \"" + desktopDir + "\"")
			Button4.show()
			self.placesBtnHolder.pack_start( Button4, False, False )
			self.mintMenuWin.setTooltip( Button4, _("Browse items placed on the desktop") )

		if ( self.showtrash == True ):
			self.trashButton = easyButton( "user-trash", self.iconsize, [_("Trash")], -1, -1 )
			self.trashButton.connect( "clicked", self.ButtonClicked, "nautilus trash:" )
			self.trashButton.show()
			self.trashButton.connect( "button-release-event", self.trashPopup )				
			self.refreshTrash()		
			self.placesBtnHolder.pack_start( self.trashButton, False, False )
			self.mintMenuWin.setTooltip( self.trashButton, _("Browse deleted files") )
Пример #2
0
class pluginclass( object ):

    def __init__( self, mintMenuWin, toggleButton, de ):

        self.mintMenuWin = mintMenuWin
        self.toggleButton = toggleButton
        self.de = de

        # Read GLADE file
        gladefile                               = os.path.join( os.path.dirname( __file__ ), "system_management.glade" )
        wTree                                   = gtk.glade.XML( gladefile, "mainWindow" )
        self.systemBtnHolder    = wTree.get_widget( "system_button_holder" )
        self.editableBtnHolder  = wTree.get_widget( "editable_button_holder" )
        self.scrolledWindow = wTree.get_widget( "scrolledwindow2" )

        # These properties are NECESSARY to maintain consistency

        # Set 'window' property for the plugin (Must be the root widget)
        self.window = wTree.get_widget( "mainWindow" )

        # Set 'heading' property for plugin
        self.heading = _("System")

        # This should be the first item added to the window in glade
        self.content_holder = wTree.get_widget( "System" )

        # Items to get custom colors
        self.itemstocolor = [ wTree.get_widget( "viewport2" ) ]

        # Gconf stuff
        self.gconf = EasyGConf( "/apps/mintMenu/plugins/system-management/" )

        self.gconf.notifyAdd( "icon_size", self.RegenPlugin )
        self.gconf.notifyAdd( "show_control_center", self.RegenPlugin )
        self.gconf.notifyAdd( "show_lock_screen", self.RegenPlugin )
        self.gconf.notifyAdd( "show_logout", self.RegenPlugin )
        self.gconf.notifyAdd( "show_package_manager", self.RegenPlugin )
        self.gconf.notifyAdd( "show_software_manager", self.RegenPlugin )
        self.gconf.notifyAdd( "show_terminal", self.RegenPlugin )
        self.gconf.notifyAdd( "show_quit", self.RegenPlugin )
        self.gconf.notifyAdd( "allowScrollbar", self.RegenPlugin )
        self.gconf.notifyAdd( "height", self.changePluginSize )
        self.gconf.notifyAdd( "width", self.changePluginSize )
        self.gconf.bindGconfEntryToVar( "bool", "sticky", self, "sticky" )

        self.GetGconfEntries()

        self.content_holder.set_size_request( self.width, self.height )

    def destroy( self ):
        self.gconf.notifyRemoveAll()

    def wake (self) :
        pass

    def changePluginSize( self, client, connection_id, entry, args ):
        self.allowScrollbar = self.gconf.get( "bool", "allowScrollbar", False)
        if entry.get_key() == self.gconf.gconfDir+"width":
            self.width = entry.get_value().get_int()
        elif entry.get_key() == self.gconf.gconfDir+"height":
            if (self.allowScrollbar == False):
                self.height = -1
                self.scrolledWindow.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_NEVER )
            else:
                self.scrolledWindow.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC )
                self.height = entry.get_value().get_int()

        self.content_holder.set_size_request( self.width, self.height )


    def RegenPlugin( self, *args, **kargs ):
        self.GetGconfEntries()
        self.ClearAll()
        self.do_standard_items()

    def GetGconfEntries( self ):

        self.width = self.gconf.get( "int", "width", 200 )
        self.allowScrollbar = self.gconf.get( "bool", "allowScrollbar", False)
        self.scrolledWindow.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC )
        self.height = self.gconf.get( "int", "height", 180 )
        self.content_holder.set_size_request( self.width, self.height )
        if (self.allowScrollbar == False):
            self.height = -1
            self.scrolledWindow.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_NEVER )
        self.content_holder.set_size_request( self.width, self.height )
        self.iconsize = self.gconf.get( "int","icon_size", 16 )

        # Check toggles

        self.showSoftwareManager = self.gconf.get( "bool", "show_software_manager", True )
        self.showPackageManager = self.gconf.get( "bool", "show_package_manager", True )
        self.showControlCenter = self.gconf.get( "bool", "show_control_center", True )
        self.showTerminal = self.gconf.get( "bool", "show_terminal", True )
        self.showLockScreen = self.gconf.get( "bool", "show_lock_screen", True )
        self.showLogout = self.gconf.get( "bool", "show_logout", True )
        self.showQuit = self.gconf.get( "bool", "show_quit", True )

        # Hide vertical dotted separator
        self.hideseparator = self.gconf.get( "bool", "hide_separator", False )
        # Plugin icon
        self.icon = self.gconf.get( "string", 'icon', "preferences-system" )
        # Allow plugin to be minimized to the left plugin pane
        self.sticky = self.gconf.get( "bool", "sticky", False )
        self.minimized = self.gconf.get( "bool", "minimized", False )

    def ClearAll(self):
        for child in self.systemBtnHolder.get_children():
            child.destroy()
        for child in self.editableBtnHolder.get_children():
            child.destroy()

    #Add standard items
    def do_standard_items( self ):

        if ( self.showSoftwareManager == True ):
            if os.path.exists("/usr/lib/linuxmint/mintInstall/icon.svg"):
                Button1 = easyButton( "/usr/lib/linuxmint/mintInstall/icon.svg", self.iconsize, [_("Software Manager")], -1, -1 )
                Button1.connect( "clicked", self.ButtonClicked, "mintinstall" )
                Button1.show()
                self.systemBtnHolder.pack_start( Button1, False, False )
                self.mintMenuWin.setTooltip( Button1, _("Browse and install available software") )

        if ( self.showPackageManager == True ):
            Button2 = easyButton( "applications-system", self.iconsize, [_("Package Manager")], -1, -1 )
            Button2.connect( "clicked", self.ButtonClicked, "gksu /usr/sbin/synaptic" )
            Button2.show()
            self.systemBtnHolder.pack_start( Button2, False, False )
            self.mintMenuWin.setTooltip( Button2, _("Install, remove and upgrade software packages") )

        if ( self.showControlCenter == True ):
            Button3 = easyButton( "gtk-preferences", self.iconsize, [_("Control Center")], -1, -1 )
            if self.de == "xfce":
                Button3.connect( "clicked", self.ButtonClicked, "xfce4-settings-manager" )
            else:
                Button3.connect( "clicked", self.ButtonClicked, "mate-control-center" )
            Button3.show()
            self.systemBtnHolder.pack_start( Button3, False, False )
            self.mintMenuWin.setTooltip( Button3, _("Configure your system") )

        if ( self.showTerminal == True ):
            Button4 = easyButton( "terminal", self.iconsize, [_("Terminal")], -1, -1 )
            if os.path.exists("/usr/bin/mate-terminal"):
                Button4.connect( "clicked", self.ButtonClicked, "mate-terminal" )
            else:
                Button4.connect( "clicked", self.ButtonClicked, "x-terminal-emulator" )
            Button4.show()
            self.systemBtnHolder.pack_start( Button4, False, False )
            self.mintMenuWin.setTooltip( Button4, _("Use the command line") )

        if self.de == "xfce":
                Button6 = easyButton( "system-log-out", self.iconsize, [_("Logout")], -1, -1 )
                Button6.connect( "clicked", self.ButtonClicked, "xfce4-session-logout" )
                Button6.show()
                self.systemBtnHolder.pack_start( Button6, False, False )
                self.mintMenuWin.setTooltip( Button6, _("Log out or switch user") )
        else:
            if ( self.showLockScreen == True ):
                Button5 = easyButton( "system-lock-screen", self.iconsize, [_("Lock Screen")], -1, -1 )
                if os.path.exists("/usr/bin/mate-screensaver-command"):
                    Button5.connect( "clicked", self.ButtonClicked, "mate-screensaver-command -l" )
                else:
                    Button5.connect( "clicked", self.ButtonClicked, "xdg-screensaver lock" )
                Button5.show()
                self.systemBtnHolder.pack_start( Button5, False, False )
                self.mintMenuWin.setTooltip( Button5, _("Requires password to unlock") )

            if ( self.showLogout == True ):
                Button6 = easyButton( "system-log-out", self.iconsize, [_("Logout")], -1, -1 )
                Button6.connect( "clicked", self.ButtonClicked, "mate-session-save --logout-dialog" )
                Button6.show()
                self.systemBtnHolder.pack_start( Button6, False, False )
                self.mintMenuWin.setTooltip( Button6, _("Log out or switch user") )

            if ( self.showQuit == True ):
                Button7 = easyButton( "system-shutdown", self.iconsize, [_("Quit")], -1, -1 )
                Button7.connect( "clicked", self.ButtonClicked, "mate-session-save --shutdown-dialog" )
                Button7.show()
                self.systemBtnHolder.pack_start( Button7, False, False )
                self.mintMenuWin.setTooltip( Button7, _("Shutdown, restart, suspend or hibernate") )

    def ButtonClicked( self, widget, Exec ):
        self.mintMenuWin.hide()
        if Exec:
            Execute( Exec )

    def do_plugin( self ):
        self.do_standard_items()
Пример #3
0
class pluginclass(object):
    def __init__(self, mintMenuWin, toggleButton, de):

        self.mintMenuWin = mintMenuWin
        self.toggleButton = toggleButton
        self.de = de

        # Read GLADE file
        gladefile = os.path.join(os.path.dirname(__file__),
                                 "system_management.glade")
        wTree = gtk.glade.XML(gladefile, "mainWindow")
        self.systemBtnHolder = wTree.get_widget("system_button_holder")
        self.editableBtnHolder = wTree.get_widget("editable_button_holder")
        self.scrolledWindow = wTree.get_widget("scrolledwindow2")

        # These properties are NECESSARY to maintain consistency

        # Set 'window' property for the plugin (Must be the root widget)
        self.window = wTree.get_widget("mainWindow")

        # Set 'heading' property for plugin
        self.heading = _("System")

        # This should be the first item added to the window in glade
        self.content_holder = wTree.get_widget("System")

        # Items to get custom colors
        self.itemstocolor = [wTree.get_widget("viewport2")]

        # Gconf stuff
        self.gconf = EasyGConf("/apps/mintMenu/plugins/system-management/")

        self.gconf.notifyAdd("icon_size", self.RegenPlugin)
        self.gconf.notifyAdd("show_control_center", self.RegenPlugin)
        self.gconf.notifyAdd("show_lock_screen", self.RegenPlugin)
        self.gconf.notifyAdd("show_logout", self.RegenPlugin)
        self.gconf.notifyAdd("show_package_manager", self.RegenPlugin)
        self.gconf.notifyAdd("show_software_manager", self.RegenPlugin)
        self.gconf.notifyAdd("show_terminal", self.RegenPlugin)
        self.gconf.notifyAdd("show_quit", self.RegenPlugin)
        self.gconf.notifyAdd("allowScrollbar", self.RegenPlugin)
        self.gconf.notifyAdd("height", self.changePluginSize)
        self.gconf.notifyAdd("width", self.changePluginSize)
        self.gconf.bindGconfEntryToVar("bool", "sticky", self, "sticky")

        self.GetGconfEntries()

        self.content_holder.set_size_request(self.width, self.height)

    def destroy(self):
        self.gconf.notifyRemoveAll()

    def wake(self):
        pass

    def changePluginSize(self, client, connection_id, entry, args):
        self.allowScrollbar = self.gconf.get("bool", "allowScrollbar", False)
        if entry.get_key() == self.gconf.gconfDir + "width":
            self.width = entry.get_value().get_int()
        elif entry.get_key() == self.gconf.gconfDir + "height":
            if (self.allowScrollbar == False):
                self.height = -1
                self.scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC,
                                               gtk.POLICY_NEVER)
            else:
                self.scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC,
                                               gtk.POLICY_AUTOMATIC)
                self.height = entry.get_value().get_int()

        self.content_holder.set_size_request(self.width, self.height)

    def RegenPlugin(self, *args, **kargs):
        self.GetGconfEntries()
        self.ClearAll()
        self.do_standard_items()

    def GetGconfEntries(self):

        self.width = self.gconf.get("int", "width", 200)
        self.allowScrollbar = self.gconf.get("bool", "allowScrollbar", False)
        self.scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC,
                                       gtk.POLICY_AUTOMATIC)
        self.height = self.gconf.get("int", "height", 180)
        self.content_holder.set_size_request(self.width, self.height)
        if (self.allowScrollbar == False):
            self.height = -1
            self.scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC,
                                           gtk.POLICY_NEVER)
        self.content_holder.set_size_request(self.width, self.height)
        self.iconsize = self.gconf.get("int", "icon_size", 16)

        # Check toggles

        self.showSoftwareManager = self.gconf.get("bool",
                                                  "show_software_manager",
                                                  True)
        self.showPackageManager = self.gconf.get("bool",
                                                 "show_package_manager", True)
        self.showControlCenter = self.gconf.get("bool", "show_control_center",
                                                True)
        self.showTerminal = self.gconf.get("bool", "show_terminal", True)
        self.showLockScreen = self.gconf.get("bool", "show_lock_screen", True)
        self.showLogout = self.gconf.get("bool", "show_logout", True)
        self.showQuit = self.gconf.get("bool", "show_quit", True)

        # Hide vertical dotted separator
        self.hideseparator = self.gconf.get("bool", "hide_separator", False)
        # Plugin icon
        self.icon = self.gconf.get("string", 'icon', "preferences-system")
        # Allow plugin to be minimized to the left plugin pane
        self.sticky = self.gconf.get("bool", "sticky", False)
        self.minimized = self.gconf.get("bool", "minimized", False)

    def ClearAll(self):
        for child in self.systemBtnHolder.get_children():
            child.destroy()
        for child in self.editableBtnHolder.get_children():
            child.destroy()

    #Add standard items
    def do_standard_items(self):

        if (self.showSoftwareManager == True):
            if os.path.exists("/usr/lib/linuxmint/mintInstall/icon.svg"):
                Button1 = easyButton("applications-other", self.iconsize,
                                     [_("Software Manager")], -1, -1)
                Button1.connect("clicked", self.ButtonClicked, "mintinstall")
                Button1.show()
                self.systemBtnHolder.pack_start(Button1, False, False)
                self.mintMenuWin.setTooltip(
                    Button1, _("Browse and install available software"))

        if (self.showPackageManager == True):
            Button2 = easyButton("applications-system", self.iconsize,
                                 [_("Package Manager")], -1, -1)
            Button2.connect("clicked", self.ButtonClicked,
                            "gksu /usr/sbin/synaptic")
            Button2.show()
            self.systemBtnHolder.pack_start(Button2, False, False)
            self.mintMenuWin.setTooltip(
                Button2, _("Install, remove and upgrade software packages"))

        if (self.showControlCenter == True):
            Button3 = easyButton("gtk-preferences", self.iconsize,
                                 [_("Control Center")], -1, -1)
            if self.de == "xfce":
                Button3.connect("clicked", self.ButtonClicked,
                                "xfce4-settings-manager")
            else:
                Button3.connect("clicked", self.ButtonClicked,
                                "gnome-control-center")
            Button3.show()
            self.systemBtnHolder.pack_start(Button3, False, False)
            self.mintMenuWin.setTooltip(Button3, _("Configure your system"))

        if (self.showTerminal == True):
            Button4 = easyButton("gnome-terminal", self.iconsize,
                                 [_("Terminal")], -1, -1)
            Button4.connect("clicked", self.ButtonClicked,
                            "x-terminal-emulator")
            Button4.show()
            self.systemBtnHolder.pack_start(Button4, False, False)
            self.mintMenuWin.setTooltip(Button4, _("Use the command line"))

        if self.de == "xfce":
            Button6 = easyButton("system-log-out", self.iconsize,
                                 [_("Logout")], -1, -1)
            Button6.connect("clicked", self.ButtonClicked,
                            "xfce4-session-logout")
            Button6.show()
            self.systemBtnHolder.pack_start(Button6, False, False)
            self.mintMenuWin.setTooltip(Button6, _("Log out or switch user"))
        else:
            if (self.showLockScreen == True):
                Button5 = easyButton("system-lock-screen", self.iconsize,
                                     [_("Lock Screen")], -1, -1)
                Button5.connect("clicked", self.ButtonClicked,
                                "xdg-screensaver lock")
                Button5.show()
                self.systemBtnHolder.pack_start(Button5, False, False)
                self.mintMenuWin.setTooltip(Button5,
                                            _("Requires password to unlock"))

            if (self.showLogout == True):
                Button6 = easyButton("system-log-out", self.iconsize,
                                     [_("Logout")], -1, -1)
                Button6.connect("clicked", self.ButtonClicked,
                                "gnome-session-save --logout-dialog")
                Button6.show()
                self.systemBtnHolder.pack_start(Button6, False, False)
                self.mintMenuWin.setTooltip(Button6,
                                            _("Log out or switch user"))

            if (self.showQuit == True):
                Button7 = easyButton("system-shutdown", self.iconsize,
                                     [_("Quit")], -1, -1)
                Button7.connect("clicked", self.ButtonClicked,
                                "gnome-session-save --shutdown-dialog")
                Button7.show()
                self.systemBtnHolder.pack_start(Button7, False, False)
                self.mintMenuWin.setTooltip(
                    Button7, _("Shutdown, restart, suspend or hibernate"))

    def ButtonClicked(self, widget, Exec):
        self.mintMenuWin.hide()
        if Exec:
            Execute(Exec)

    def do_plugin(self):
        self.do_standard_items()
Пример #4
0
class pluginclass(object):
    def __init__(self, mintMenuWin, toggleButton, de):

        self.mintMenuWin = mintMenuWin
        self.toggleButton = toggleButton
        self.de = de

        # Read GLADE file
        gladefile = os.path.join(os.path.dirname(__file__), "places.glade")
        wTree = gtk.glade.XML(gladefile, "mainWindow")
        self.placesBtnHolder = wTree.get_widget("places_button_holder")
        self.editableBtnHolder = wTree.get_widget("editable_button_holder")
        self.scrolledWindow = wTree.get_widget("scrolledwindow2")
        # These properties are NECESSARY to maintain consistency

        # Set 'window' property for the plugin (Must be the root widget)
        self.window = wTree.get_widget("mainWindow")

        # Set 'heading' property for plugin
        self.heading = _("Places")

        # This should be the first item added to the window in glade
        self.content_holder = wTree.get_widget("Places")

        # Items to get custom colors
        self.itemstocolor = [wTree.get_widget("viewport2")]

        # Gconf stuff
        self.gconf = EasyGConf("/apps/mintMenu/plugins/places/")

        self.gconf.notifyAdd("icon_size", self.RegenPlugin)
        self.gconf.notifyAdd("show_computer", self.RegenPlugin)
        self.gconf.notifyAdd("show_desktop", self.RegenPlugin)
        self.gconf.notifyAdd("show_home_folder", self.RegenPlugin)
        self.gconf.notifyAdd("show_network", self.RegenPlugin)
        self.gconf.notifyAdd("show_trash", self.RegenPlugin)
        self.gconf.notifyAdd("custom_names", self.RegenPlugin)
        self.gconf.notifyAdd("custom_paths", self.RegenPlugin)
        self.gconf.notifyAdd("allowScrollbar", self.RegenPlugin)
        self.gconf.notifyAdd("show_gtk_bookmarks", self.RegenPlugin)
        self.gconf.notifyAdd("height", self.changePluginSize)
        self.gconf.notifyAdd("width", self.changePluginSize)
        self.gconf.bindGconfEntryToVar("bool", "sticky", self, "sticky")

        self.GetGconfEntries()

        self.content_holder.set_size_request(self.width, self.height)

    def wake(self):
        if (self.showtrash == True):
            self.refreshTrash()

    def destroy(self):
        self.gconf.notifyRemoveAll()

    def changePluginSize(self, client, connection_id, entry, args):
        self.allowScrollbar = self.gconf.get("bool", "allowScrollbar", False)
        if entry.get_key() == self.gconf.gconfDir + "width":
            self.width = entry.get_value().get_int()
        elif entry.get_key() == self.gconf.gconfDir + "height":
            if (self.allowScrollbar == False):
                self.height = -1
                self.scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC,
                                               gtk.POLICY_NEVER)
            else:
                self.scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC,
                                               gtk.POLICY_AUTOMATIC)
                self.height = entry.get_value().get_int()

        self.content_holder.set_size_request(self.width, self.height)

    def RegenPlugin(self, *args, **kargs):
        self.GetGconfEntries()
        self.ClearAll()
        self.do_standard_places()
        self.do_custom_places()
        self.do_gtk_bookmarks()

    def GetGconfEntries(self):

        self.width = self.gconf.get("int", "width", 200)
        self.allowScrollbar = self.gconf.get("bool", "allowScrollbar", False)
        self.showGTKBookmarks = self.gconf.get("bool", "show_gtk_bookmarks",
                                               False)
        self.scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC,
                                       gtk.POLICY_AUTOMATIC)
        self.height = self.gconf.get("int", "height", 180)
        self.content_holder.set_size_request(self.width, self.height)
        if (self.allowScrollbar == False):
            self.height = -1
            self.scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC,
                                           gtk.POLICY_NEVER)
        self.content_holder.set_size_request(self.width, self.height)
        self.execapp = self.gconf.get("string", "execute_app", "nautilus")
        self.iconsize = self.gconf.get("int", "icon_size", 16)

        # Check default items

        self.showcomputer = self.gconf.get("bool", "show_computer", True)
        self.showhomefolder = self.gconf.get("bool", "show_home_folder", True)
        self.shownetwork = self.gconf.get("bool", "show_network", True)
        self.showdesktop = self.gconf.get("bool", "show_desktop", True)
        self.showtrash = self.gconf.get("bool", "show_trash", True)

        # Get paths for custom items

        self.custompaths = self.gconf.get("list-string", "custom_paths", [])

        # Get names for custom items

        self.customnames = self.gconf.get("list-string", "custom_names", [])

        # Hide vertical dotted separator
        self.hideseparator = self.gconf.get("bool", "hide_separator", False)
        # Plugin icon
        self.icon = self.gconf.get("string", 'icon', "gnome-fs-directory.png")
        # Allow plugin to be minimized to the left plugin pane
        self.sticky = self.gconf.get("bool", "sticky", False)
        self.minimized = self.gconf.get("bool", "minimized", False)

    def ClearAll(self):
        for child in self.placesBtnHolder.get_children():
            child.destroy()
        for child in self.editableBtnHolder.get_children():
            child.destroy()

    #Add standard places
    def do_standard_places(self):

        if (self.showcomputer == True):
            Button1 = easyButton("computer", self.iconsize, [_("Computer")],
                                 -1, -1)
            if self.de == "gnome":
                Button1.connect("clicked", self.ButtonClicked,
                                "nautilus computer:")
            else:
                Button1.connect("clicked", self.ButtonClicked, "xdg-open /")
            Button1.show()
            self.placesBtnHolder.pack_start(Button1, False, False)
            self.mintMenuWin.setTooltip(
                Button1,
                _("Browse all local and remote disks and folders accessible from this computer"
                  ))

        if (self.showhomefolder == True):
            Button2 = easyButton("user-home", self.iconsize,
                                 [_("Home Folder")], -1, -1)
            Button2.connect("clicked", self.ButtonClicked,
                            "xdg-open %s " % home)
            Button2.show()
            self.placesBtnHolder.pack_start(Button2, False, False)
            self.mintMenuWin.setTooltip(Button2,
                                        _("Open your personal folder"))

        if (self.shownetwork == True and self.de == "gnome"):
            gconftheme = EasyGConf("/desktop/gnome/interface/")
            icon_theme = gconftheme.get("string", "icon_theme", "Mint-X")
            if "Mint-X" in icon_theme:
                Button3 = easyButton("notification-network-ethernet-connected",
                                     self.iconsize, [_("Network")], -1, -1)
            else:
                Button3 = easyButton("network-workgroup", self.iconsize,
                                     [_("Network")], -1, -1)
            Button3.connect("clicked", self.ButtonClicked, "nautilus network:")
            Button3.show()
            self.placesBtnHolder.pack_start(Button3, False, False)
            self.mintMenuWin.setTooltip(
                Button3, _("Browse bookmarked and local network locations"))

        if (self.showdesktop == True):
            # Determine where the Desktop folder is (could be localized)
            desktopDir = home + "/Desktop"
            try:
                import sys
                sys.path.append('/usr/lib/linuxmint/common')
                from configobj import ConfigObj
                config = ConfigObj(home + "/.config/user-dirs.dirs")
                tmpdesktopDir = config['XDG_DESKTOP_DIR']
                tmpdesktopDir = commands.getoutput("echo " + tmpdesktopDir)
                if os.path.exists(tmpdesktopDir):
                    desktopDir = tmpdesktopDir
            except Exception, detail:
                print detail
            Button4 = easyButton("gnome-fs-desktop", self.iconsize,
                                 [_("Desktop")], -1, -1)
            Button4.connect("clicked", self.ButtonClicked,
                            "xdg-open \"" + desktopDir + "\"")
            Button4.show()
            self.placesBtnHolder.pack_start(Button4, False, False)
            self.mintMenuWin.setTooltip(
                Button4, _("Browse items placed on the desktop"))

        if (self.showtrash == True):
            self.trashButton = easyButton("user-trash", self.iconsize,
                                          [_("Trash")], -1, -1)
            if self.de == "xfce":
                self.trashButton.connect("clicked", self.ButtonClicked,
                                         "thunar trash:")
            else:
                self.trashButton.connect("clicked", self.ButtonClicked,
                                         "xdg-open trash:")
            self.trashButton.show()
            self.trashButton.connect("button-release-event", self.trashPopup)
            self.refreshTrash()
            self.placesBtnHolder.pack_start(self.trashButton, False, False)
            self.mintMenuWin.setTooltip(self.trashButton,
                                        _("Browse deleted files"))
Пример #5
0
class pluginclass( object ):
	TARGET_TYPE_TEXT = 80
	toButton = [ ( "text/uri-list", 0, TARGET_TYPE_TEXT ) ]
	TARGET_TYPE_FAV = 81
	toFav = [ ( "FAVORITES", gtk.TARGET_SAME_APP, TARGET_TYPE_FAV ), ( "text/plain", 0, 100 ), ( "text/uri-list", 0, 101 ) ]
	fromFav = [ ( "FAVORITES", gtk.TARGET_SAME_APP, TARGET_TYPE_FAV ) ]

	def __init__( self, mintMenuWin, toggleButton ):

		self.mintMenuWin = mintMenuWin
		
		self.mainMenus = [ ]

		self.toggleButton = toggleButton	
		# The Glade file for the plugin
		self.gladefile = os.path.join( os.path.dirname( __file__ ), "applications.glade" )

		# Read GLADE file
		self.wTree = gtk.glade.XML( self.gladefile, "mainWindow" )
		self.searchEntry = self.wTree.get_widget( "searchEntry" )
		self.searchButton = self.wTree.get_widget( "searchButton" )
		self.showAllAppsButton = self.wTree.get_widget( "showAllAppsButton" )
		self.showFavoritesButton = self.wTree.get_widget( "showFavoritesButton" )
		self.applicationsBox = self.wTree.get_widget( "applicationsBox" )
		self.categoriesBox = self.wTree.get_widget( "categoriesBox" )
		self.favoritesBox = self.wTree.get_widget( "favoritesBox" )
		self.applicationsScrolledWindow = self.wTree.get_widget( "applicationsScrolledWindow" )		

		#i18n
		self.wTree.get_widget("searchLabel").set_text("<span weight='bold'>" + _("Filter:") + "</span>")
		self.wTree.get_widget("searchLabel").set_use_markup(True)
		self.wTree.get_widget("label6").set_text("<span weight='bold'>" + _("Favorites") + "</span>")
		self.wTree.get_widget("label6").set_use_markup(True)
		self.wTree.get_widget("label7").set_text(_("All applications"))
		self.wTree.get_widget("label2").set_text("<span weight='bold'>" + _("All applications") + "</span>")
		self.wTree.get_widget("label2").set_use_markup(True)
		self.wTree.get_widget("label3").set_text(_("Favorites"))

		self.numApps = 0
		# These properties are NECESSARY to maintain consistency

		# Set 'window' property for the plugin (Must be the root widget)
		self.window = self.wTree.get_widget( "mainWindow" )

		# Set 'heading' property for plugin
		self.heading = _("Applications")

		# This should be the first item added to the window in glade
		self.content_holder = self.wTree.get_widget( "Applications" )

		# Items to get custom colors
		self.itemstocolor = [ self.wTree.get_widget( "viewport1" ), self.wTree.get_widget( "viewport2" ), self.wTree.get_widget( "viewport3" ), self.wTree.get_widget( "notebook2" ) ]

		# Unset all timers
		self.filterTimer = None
		self.menuChangedTimer = None
		# Hookup for text input
		self.content_holder.connect( "key-press-event", self.keyPress )

		self.favoritesBox.connect( "drag_data_received", self.ReceiveCallback )
		self.favoritesBox.drag_dest_set( gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP, self.toButton, gtk.gdk.ACTION_COPY )
		self.showFavoritesButton.connect( "drag_data_received", self.ReceiveCallback )
		self.showFavoritesButton.drag_dest_set( gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP, self.toButton, gtk.gdk.ACTION_COPY )

		self.searchButton.connect( "button_release_event", self.SearchWithButton )

		self.gconfHandlers = []
		# Gconf stuff		
		self.gconf = EasyGConf( "/apps/mintMenu/plugins/applications/" )
		self.GetGconfEntries()
		self.gconf.notifyAdd( "icon_size", self.changeIconSize )
		self.gconf.notifyAdd( "favicon_size", self.changeFavIconSize )
		self.gconf.notifyAdd( "height", self.changePluginSize )
		self.gconf.notifyAdd( "width", self.changePluginSize )
		self.gconf.notifyAdd( "categories_mouse_over", self.changeCategoriesMouseOver )
		self.gconf.notifyAdd( "swap_generic_name", self.changeSwapGenericName )
		self.gconf.notifyAdd( "show_category_icons", self.changeShowCategoryIcons )
		self.gconf.notifyAdd( "show_application_comments", self.changeShowApplicationComments )
		self.gconf.notifyAdd( "fav_cols", self.changeFavCols )
		
		self.gconf.bindGconfEntryToVar( "int", "category_hover_delay", self, "categoryhoverdelay" )
		self.gconf.bindGconfEntryToVar( "bool", "do_not_filter", self, "donotfilterapps" )
		self.gconf.bindGconfEntryToVar( "string", "search_command", self, "searchtool" )
		self.gconf.bindGconfEntryToVar( "int", "default_tab", self, "defaultTab" )

		self.currentFavCol = 0
		self.favorites = []

		self.content_holder.set_size_request( self.width, self.height )
		self.categoriesBox.set_size_request( self.width / 3, -1 )
		self.applicationsBox.set_size_request( self.width / 2, -1 )

		self.buildingButtonList = False
		self.stopBuildingButtonList = False

		self.categoryList = []
		self.applicationList = []
		self.menuFileMonitors = []
		
		self.rebuildLock = False
		self.activeFilter = (1, "")

		self.adminMenu = None

		for mainitems in [ "applications.menu", "settings.menu" ]:
			mymenu = Menu( mainitems )
			mymenu.tree.add_monitor( self.menuChanged, None )
			#for f in mymenu.directory.Files:
			#	self.menuFileMonitors.append( filemonitor.addMonitor(f, self.onMenuChanged, mymenu.directory.Filename ) )
			#for f in mymenu.directory.AppDirs:
			#	self.menuFileMonitors.append( filemonitor.addMonitor(f, self.onMenuChanged, mymenu.directory.Filename ) )

		sizeIcon = 0
		if isinstance(self.iconSize, int):
			if self.iconSize >= 4:
				sizeIcon = gtk.ICON_SIZE_DIALOG
			elif self.iconSize == 3:
				sizeIcon = gtk.ICON_SIZE_DND
			elif self.iconSize == 2:
				sizeIcon = gtk.ICON_SIZE_BUTTON
			elif self.iconSize == 1:
				sizeIcon = gtk.ICON_SIZE_MENU
			elif self.iconSize <= 0:
				return ( 0, 0 )

		#sizeIcon = gtk.icon_size_lookup( sizeIcon )
		
		self.suggestSearchAppButton = SuggestionButton(gtk.STOCK_FIND, self.iconSize, "")		
		self.suggestSearchButton = SuggestionButton(gtk.STOCK_FIND, self.iconSize, "")
		self.suggestShowButton = SuggestionButton(gtk.STOCK_INFO, self.iconSize, "")
		self.suggestInstallButton = SuggestionButton(gtk.STOCK_ADD, self.iconSize, "")

		self.suggestSearchAppButton.connect("clicked", self.search_mint)			
		self.suggestSearchButton.connect("clicked", self.search_apt)	
		self.suggestShowButton.connect("clicked", self.show_apt)	
		self.suggestInstallButton.connect("clicked", self.install_apt)	

	def search_mint(self, widget):
		os.system("/usr/bin/mint-search-portal " + self.suggestion + " &")
		self.mintMenuWin.hide()		

	def search_apt(self, widget):
		os.system("/usr/bin/mint-search-apt " + self.suggestion + " &")
		self.mintMenuWin.hide()

	def show_apt(self, widget):
		os.system("/usr/bin/mint-show-apt " + self.suggestion + " &")
		self.mintMenuWin.hide()

	def install_apt(self, widget):
		os.system("/usr/bin/mint-make-cmd " + self.suggestion + " &")
		self.mintMenuWin.hide()

	def __del__( self ):
		print u"Applications plugin deleted"

	def wake (self) :
		pass

	def destroy( self ):
		self.content_holder.destroy()
		self.searchEntry.destroy()
		self.searchButton.destroy()
		self.showAllAppsButton.destroy()
		self.showFavoritesButton.destroy()
		self.applicationsBox.destroy()
		self.categoriesBox.destroy()
		self.favoritesBox.destroy()
		
		self.gconf.notifyRemoveAll()

		for mId in self.menuFileMonitors:
			filemonitor.removeMonitor( mId )
	
	def changePluginSize( self, client, connection_id, entry, args ):
		if entry.get_key() == self.gconf.gconfDir+"width":
			self.width = entry.get_value().get_int()
			self.categoriesBox.set_size_request( self.width / 3, -1 )
			self.applicationsBox.set_size_request( self.width / 2, -1 )

		elif entry.get_key() == self.gconf.gconfDir+"height":
			self.heigth = entry.get_value().get_int()
		self.content_holder.set_size_request( self.width, self.height )

	def changeSwapGenericName( self, client, connection_id, entry, args ):
		self.swapgeneric = entry.get_value().get_bool()
		
		for child in self.favoritesBox:
			if isinstance( child, FavApplicationLauncher):
				child.setSwapGeneric( self.swapgeneric )
	
	def changeShowCategoryIcons( self, client, connection_id, entry, args ):
		self.showcategoryicons = entry.get_value().get_bool()
		
		if self.showcategoryicons:
			categoryIconSize = self.iconSize
		else:
			categoryIconSize = 0
			
		for child in self.categoriesBox:
			child.setIconSize( categoryIconSize )
			
	def changeIconSize( self, client, connection_id, entry, args ):
		self.iconSize = entry.get_value().get_int()

		if self.showcategoryicons:
			categoryIconSize = self.iconSize
		else:
			categoryIconSize = 0
			
		for child in self.categoriesBox:
			child.setIconSize( categoryIconSize )
			
		for child in self.applicationsBox:
			try:
				child.setIconSize( self.iconSize )
			except:
				pass

		self.suggestSearchAppButton.set_icon_size( self.iconSize )
		self.suggestSearchButton.set_icon_size( self.iconSize )
		self.suggestShowButton.set_icon_size( self.iconSize )
		self.suggestInstallButton.set_icon_size( self.iconSize )
		
	
	def changeFavIconSize( self, client, connection_id, entry, args ):
		self.faviconsize = entry.get_value().get_int()
		
		for child in self.favoritesBox:
			if isinstance( child, FavApplicationLauncher):
				child.setIconSize( self.faviconsize )
				
	def changeShowApplicationComments( self, client, connection_id, entry, args ):
		self.showapplicationcomments = entry.get_value().get_bool()
		for child in self.applicationsBox:
			child.setShowComment( self.showapplicationcomments )
	
	def changeCategoriesMouseOver( self, client, connection_id, entry, args ):
		self.categories_mouse_over = entry.get_value().get_bool()
		for child in self.categoriesBox:
			if self.categories_mouse_over and not child.mouseOverHandlerIds:
				startId = child.connect( "enter", self.StartFilter, child.filter )
				stopId = child.connect( "leave", self.StopFilter )
				child.mouseOverHandlerIds = ( startId, stopId )
			elif self.categories_mouse_over and child.mouseOverHandlerIds:
				child.disconnect( child.mouseOverHandlerIds[0] )
				child.disconnect( child.mouseOverHandlerIds[1] )
				child.mouseOverHandlerIds = None
				
	def changeFavCols(self, client, connection_id, entry, args):
		self.favCols = entry.get_value().get_int()
		for fav in self.favorites:
			self.favoritesBox.remove( fav )
			self.favoritesPositionOnGrid( fav )

	def RegenPlugin( self, *args, **kargs ):
		# save old config - this is necessary because the app will notified when it sets the default values and you don't want the to reload itself several times
		oldcategories_mouse_over = self.categories_mouse_over
		oldtotalrecent = self.totalrecent
		oldsticky = self.sticky
		oldminimized = self.minimized
		oldicon = self.icon
		oldhideseparator = self.hideseparator
		oldshowapplicationcomments = self.showapplicationcomments

		self.GetGconfEntries()

		# if the config hasn't changed return
		if oldcategories_mouse_over == self.categories_mouse_over and oldiconsize == self.iconSize and oldfaviconsize == self.faviconsize and oldtotalrecent == self.totalrecent and oldswapgeneric == self.swapgeneric and oldshowcategoryicons == self.showcategoryicons and oldcategoryhoverdelay == self.categoryhoverdelay and oldsticky == self.sticky and oldminimized == self.minimized and oldicon == self.icon and oldhideseparator == self.hideseparator and oldshowapplicationcomments == self.showapplicationcomments:
			return

		self.Todos()
		self.buildFavorites()
		self.RebuildPlugin()

	def GetGconfEntries( self ):

		self.categories_mouse_over = self.gconf.get( "bool", "categories_mouse_over", True )
		self.width = self.gconf.get( "int", "width", 480 )
		self.height = self.gconf.get( "int", "height", 410 )
		self.donotfilterapps = self.gconf.get( "bool", "do_not_filter", False )
		self.iconSize = self.gconf.get( "int", "icon_size", 2 )
		self.faviconsize = self.gconf.get( "int", "favicon_size", 3 )
		self.favCols = self.gconf.get( "int", "fav_cols", 2 )
		self.swapgeneric = self.gconf.get( "bool", "swap_generic_name", False )
		self.showcategoryicons = self.gconf.get( "bool", "show_category_icons", True )
		self.categoryhoverdelay = self.gconf.get( "int", "category_hover_delay", 50 )
		self.showapplicationcomments = self.gconf.get( "bool", "show_application_comments", True )
		
		self.lastActiveTab =  self.gconf.get( "int", "last_active_tab", 0 )
		self.defaultTab = self.gconf.get( "int", "default_tab", -1 )


		# Allow plugin to be minimized to the left plugin pane
		self.sticky = self.gconf.get( "bool", "sticky", False )
		self.minimized = self.gconf.get( "bool", "minimized", False )

		# Search tool
		self.searchtool = self.gconf.get( "string", "search_command", "gnome-search-tool --named \"%s\" --start" )
		if self.searchtool == "beagle-search SEARCH_STRING":
			self.searchtool = "gnome-search-tool --named \"%s\" --start"
			self.gconf.set( "string", "search_command", "gnome-search-tool --named \"%s\" --start" )

		# Plugin icon
		self.icon = self.gconf.get( "string", "icon", "applications-accessories" )

		# Hide vertical dotted separator
		self.hideseparator = self.gconf.get( "bool", "hide_separator", False )

	def SetHidden( self, state ):
		if state == True:
			self.gconf.set( "bool", "minimized", True )
		else:
			self.gconf.set( "bool", "minimized", False )

	def RebuildPlugin(self):
		self.content_holder.set_size_request( self.width, self.height )
		
	def checkMintMenuFolder( self ):
		if os.path.exists( os.path.join( os.path.expanduser( "~" ), ".linuxmint", "mintMenu", "applications" ) ):
			return True
		try:
			os.makedirs( os.path.join( os.path.expanduser( "~" ), ".linuxmint", "mintMenu", "applications" ) )
			return True
		except:
			pass

		return False

	def onShowMenu( self ):
		if len( self.favorites ):
			if self.defaultTab == -1:
				self.changeTab( self.lastActiveTab)
			else:
				self.changeTab( (self.defaultTab - 1) * -1   )
		else:
			self.changeTab( 1 )
		
		self.searchEntry.select_region( 0, -1 )

	def onHideMenu( self ):
		self.gconf.set( "int", "last_active_tab", self.lastActiveTab )

	def changeTab( self, tabNum ):
		notebook = self.wTree.get_widget( "notebook2" )
		if tabNum == 0:
			notebook.set_current_page( 0 )
		elif tabNum == 1:
			notebook.set_current_page( 1 )
			
		self.lastActiveTab = tabNum
		
		self.focusSearchEntry()

	def Todos( self ):
		
		self.searchEntry.connect( "changed", self.Filter )
		self.searchEntry.connect( "activate", self.Search )
		self.showAllAppsButton.connect( "clicked", lambda widget: self.changeTab( 1 ) )
		self.showFavoritesButton.connect( "clicked", lambda widget: self.changeTab( 0 ) )		
		self.buildButtonList()

	def focusSearchEntry( self ):
		# grab_focus() does select all text, as this is an unwanted behaviour we restore the old selection
		sel = self.searchEntry.get_selection_bounds()
		if len(sel) == 0: # no selection
			sel = ( self.searchEntry.get_position(), self.searchEntry.get_position() )
		self.searchEntry.grab_focus()
		self.searchEntry.select_region( sel[0], sel[1] )

	def buildButtonList( self ):
		if self.buildingButtonList:
			self.stopBuildingButtonList = True
			gobject.timeout_add( 100, self.buildButtonList )
			return

		self.stopBuildingButtonList = False

		gobject.idle_add( self.updateBoxes )

	def categoryBtnFocus( self, widget, event, category ):
		self.scrollItemIntoView( widget )
		self.StartFilter( widget, category )

	def StartFilter( self, widget, category ):
		# if there is a timer for a different category running stop it
		if self.filterTimer:
			gobject.source_remove( self.filterTimer )
		self.filterTimer = gobject.timeout_add( self.categoryhoverdelay, self.Filter, widget, category )

	def StopFilter( self, widget ):
		if self.filterTimer:
			gobject.source_remove( self.filterTimer )
			self.filterTimer = None

	def Filter( self, widget, category = None ):
		self.filterTimer = None

		start = time.time()
		#print "FILTER"		
		self.applicationsBox.remove(self.suggestSearchAppButton)
		self.applicationsBox.remove(self.suggestSearchButton)
		self.applicationsBox.remove(self.suggestShowButton)
		self.applicationsBox.remove(self.suggestInstallButton)

		if widget == self.searchEntry:
			if self.donotfilterapps:
				widget.set_text( "" )
			else:
				self.changeTab( 1 )
				text = widget.get_text()
				showns = False # Are any app shown?
				for i in self.applicationsBox.get_children():
					shown = i.filterText( text )
					if (shown):
						showns = True

				if (not showns and os.path.exists("/usr/lib/linuxmint/mintInstall/icon.svg")):					
					self.suggestion = text

					self.applicationsBox.add(self.suggestSearchAppButton)					
					self.suggestSearchAppButton.set_text(_("Search portal for '%s'") % text)
					self.suggestSearchAppButton.set_tooltip_text(_("Search portal for '%s'") % text)					

					self.applicationsBox.add(self.suggestSearchButton)
					self.suggestSearchButton.set_text(_("Search repositories for '%s'") % text)
					self.suggestSearchButton.set_tooltip_text(_("Search repositories for '%s'") % text)

					self.applicationsBox.add(self.suggestShowButton)					
					self.suggestShowButton.set_text(_("Show package '%s'") % text)
					self.suggestShowButton.set_tooltip_text(_("Show package '%s'") % text)

					self.applicationsBox.add(self.suggestInstallButton)
					self.suggestInstallButton.set_text(_("Install package '%s'") % text)
					self.suggestInstallButton.set_tooltip_text(_("Install package '%s'") % text)

				for i in self.categoriesBox.get_children():
					i.set_relief( gtk.RELIEF_NONE )
					
				allButton = self.categoriesBox.get_children()[0];
				allButton.set_relief( gtk.RELIEF_HALF )
				self.activeFilter = (0, text)
		else:
			#print "CATFILTER"
			self.activeFilter = (1, category)
			if category == "":
				for i in self.applicationsBox.get_children():
					i.show_all()
			else:
				for i in self.applicationsBox.get_children():
					i.filterCategory( category )
			for i in self.applicationsBox.get_children():
				i.filterCategory( category )

			for i in self.categoriesBox.get_children():
				i.set_relief( gtk.RELIEF_NONE )
			widget.set_relief( gtk.RELIEF_HALF )
			widget.grab_focus()

			self.searchEntry.set_text( "" )

		self.applicationsScrolledWindow.get_vadjustment().set_value( 0 )
		#print u"Filtertime: ", (time.time() - start), "s"	

	# Forward all text to the search box
	def keyPress( self, widget, event ):
		if event.string.strip() != "" or event.keyval == gtk.keysyms.BackSpace:
			self.searchEntry.event( event )
			return True

		if event.keyval == gtk.keysyms.Down and self.searchEntry.is_focus():
			self.applicationsBox.get_children()[0].grab_focus()
		
		return False

	def favPopup( self, widget, ev ):
		if ev.button == 3:
			if ev.y > widget.get_allocation().height / 2:
				insertBefore = False
			else:
				insertBefore = True
			
			if widget.type == "location":
				mTree = gtk.glade.XML( self.gladefile, "favoritesMenu" )
				#i18n
				launchMenuItem = gtk.MenuItem(_("Launch"))
				removeFromFavMenuItem = gtk.MenuItem(_("Remove from favorites"))
				startupMenuItem = gtk.CheckMenuItem(_("Launch when I log in"))
				separator = gtk.SeparatorMenuItem()
				insertSpaceMenuItem = gtk.MenuItem(_("Insert space"))
				insertSeparatorMenuItem = gtk.MenuItem(_("Insert separator"))
				

				launchMenuItem.connect( "activate", self.onLaunchApp, widget)
				removeFromFavMenuItem.connect( "activate", self.onFavoritesRemove, widget )
				insertSpaceMenuItem.connect( "activate", self.onFavoritesInsertSpace, widget, insertBefore )
				insertSeparatorMenuItem.connect( "activate", self.onFavoritesInsertSeparator, widget, insertBefore )

				mTree.get_widget("favoritesMenu").append(launchMenuItem)
				mTree.get_widget("favoritesMenu").append(removeFromFavMenuItem)
				mTree.get_widget("favoritesMenu").append(startupMenuItem)
				mTree.get_widget("favoritesMenu").append(separator)				
				mTree.get_widget("favoritesMenu").append(insertSpaceMenuItem)
				mTree.get_widget("favoritesMenu").append(insertSeparatorMenuItem)
				mTree.get_widget("favoritesMenu").show_all()

				mTree.get_widget( "favoritesMenu" ).popup( None, None, None, ev.button, ev.time )

				if widget.isInStartup():
					startupMenuItem.set_active( True )
					startupMenuItem.connect( "toggled", self.onRemoveFromStartup, widget )
				else:
					startupMenuItem.set_active( False )
					startupMenuItem.connect( "toggled", self.onAddToStartup, widget )
							
			else:
				mTree = gtk.glade.XML( self.gladefile, "favoritesMenuExtra" )
				#i18n
				removeMenuItem = gtk.MenuItem(_("Remove"))
				insertSpaceMenuItem = gtk.MenuItem(_("Insert space"))
				insertSeparatorMenuItem = gtk.MenuItem(_("Insert separator"))
				mTree.get_widget("favoritesMenuExtra").append(removeMenuItem)
				mTree.get_widget("favoritesMenuExtra").append(insertSpaceMenuItem)
				mTree.get_widget("favoritesMenuExtra").append(insertSeparatorMenuItem)
				mTree.get_widget("favoritesMenuExtra").show_all()

				removeMenuItem.connect( "activate", self.onFavoritesRemove, widget )
				insertSpaceMenuItem.connect( "activate", self.onFavoritesInsertSpace, widget, insertBefore )
				insertSeparatorMenuItem.connect( "activate", self.onFavoritesInsertSeparator, widget, insertBefore )
				mTree.get_widget( "favoritesMenuExtra" ).popup( None, None, None, ev.button, ev.time )

	def menuPopup( self, widget, event ):
		if event.button == 3:
			mTree = gtk.glade.XML( self.gladefile, "applicationsMenu" )

			#i18n
			launchMenuItem = gtk.MenuItem(_("Launch"))
			favoriteMenuItem = gtk.CheckMenuItem(_("Show in my favorites"))
			startupMenuItem = gtk.CheckMenuItem(_("Launch when I log in"))
			separator = gtk.SeparatorMenuItem()			
			uninstallMenuItem = gtk.MenuItem(_("Uninstall"))
			mTree.get_widget("applicationsMenu").append(launchMenuItem)
			mTree.get_widget("applicationsMenu").append(favoriteMenuItem)
			mTree.get_widget("applicationsMenu").append(startupMenuItem)
			mTree.get_widget("applicationsMenu").append(separator)
			mTree.get_widget("applicationsMenu").append(uninstallMenuItem)
			mTree.get_widget("applicationsMenu").show_all()

			launchMenuItem.connect( "activate", self.onLaunchApp, widget )
			uninstallMenuItem.connect ( "activate", self.onUninstallApp, widget )
 
			if self.isLocationInFavorites( widget.desktopFile ):
				favoriteMenuItem.set_active( True )
				favoriteMenuItem.connect( "toggled", self.onRemoveFromFavorites, widget )
			else:
				favoriteMenuItem.set_active( False )
				favoriteMenuItem.connect( "toggled", self.onAddToFavorites, widget )
			
			if widget.isInStartup():
				startupMenuItem.set_active( True )
				startupMenuItem.connect( "toggled", self.onRemoveFromStartup, widget )
			else:
				startupMenuItem.set_active( False )
				startupMenuItem.connect( "toggled", self.onAddToStartup, widget )
			
			mTree.get_widget( "applicationsMenu" ).popup( None, None, None, event.button, event.time )

	def onLaunchApp( self, menu, widget ):
		widget.execute()
		self.mintMenuWin.hide()

	def onUninstallApp( self, menu, widget ):
		widget.uninstall()
		self.mintMenuWin.hide()

	def onFavoritesInsertSpace( self, menu, widget, insertBefore ):
		if insertBefore:
			self.favoritesAdd( self.favoritesBuildSpace(), widget.position )
		else:
			self.favoritesAdd( self.favoritesBuildSpace(), widget.position + 1 )

	def onFavoritesInsertSeparator( self, menu, widget, insertBefore ):
		if insertBefore:
			self.favoritesAdd( self.favoritesBuildSeparator(), widget.position )
		else:
			self.favoritesAdd( self.favoritesBuildSeparator(), widget.position + 1 )

	def onFavoritesRemove( self, menu, widget ):
		self.favoritesRemove( widget.position )

	def onAddToStartup( self, menu, widget ):
		widget.addToStartup()
		
	def onRemoveFromStartup( self, menu, widget ):
		widget.removeFromStartup()

	def onAddToFavorites( self, menu, widget  ):
		self.favoritesAdd( self.favoritesBuildLauncher( widget.desktopFile ) )
		
	def onRemoveFromFavorites( self, menu, widget ):
		self.favoritesRemoveLocation( widget.desktopFile )

	def ReceiveCallback( self, widget, context, x, y, selection, targetType, time ):
		if targetType == self.TARGET_TYPE_TEXT:
			for uri in selection.get_uris():
				self.favoritesAdd( self.favoritesBuildLauncher( uri ) )

	def Search( self, widget ):
		text = self.searchEntry.get_text().strip()
		if text != "":
			self.searchEntry.set_text( "" )
			self.mintMenuWin.hide()
			fullstring = self.searchtool.replace( "%s", text )
			newstring = fullstring.split()
			Execute( newstring )

	def SearchWithButton( self, widget, event ):
		self.Search( widget )

	def do_plugin( self ):
		self.Todos()
		self.buildFavorites()

	# Scroll button into view
	def scrollItemIntoView( self, widget, event = None ):
		viewport = widget.parent
		while not isinstance( viewport, gtk.Viewport ):
			if not viewport.parent:
				return
			viewport = viewport.parent
		aloc = widget.get_allocation()
		viewport.get_vadjustment().clamp_page(aloc.y, aloc.y + aloc.height)

	def favoritesBuildSpace( self ):
		space = gtk.EventBox()
		space.set_size_request( -1, 20 )
		space.connect( "button_release_event", self.favPopup )
		space.type = "space"
		
		self.mintMenuWin.SetPaneColors( [ space ] )
		space.show()
		
		return space
	
	def favoritesBuildSeparator( self ):
		separator = gtk.EventBox()
		separator.add( gtk.HSeparator() )
		separator.set_size_request( -1, 20 )
		separator.connect( "button_release_event", self.favPopup )
		separator.type = "separator"

		self.mintMenuWin.SetPaneColors( [ separator ] )
		separator.show_all()
		return separator
		
	def favoritesBuildLauncher( self, location ):
		try:
			ButtonIcon = None
			# For Folders and Network Shares
			location = string.join( location.split( "%20" ) )
			
			if location.startswith( "file" ):
				ButtonIcon = "gnome-fs-directory"
			
			if location.startswith( "smb" ) or location.startswith( "ssh" ) or location.startswith( "network" ):
				ButtonIcon = "gnome-fs-network"
			
			#For Special locations
			if location == "x-nautilus-desktop:///computer":
				location = "/usr/share/applications/nautilus-computer.desktop"
			elif location == "x-nautilus-desktop:///home":
				location =  "/usr/share/applications/nautilus-home.desktop"
			elif location == "x-nautilus-desktop:///network":
				location = "/usr/share/applications/network-scheme.desktop"
			elif location.startswith( "x-nautilus-desktop:///" ):
				location = "/usr/share/applications/nautilus-computer.desktop"
			
			if location.startswith( "file://" ):
				location = location[7:]
			
			# Don't add a location twice
			for fav in self.favorites:
				if fav.type == "location" and fav.desktopFile == location:
					return None
			
			favButton = FavApplicationLauncher( location, self.faviconsize, self.swapgeneric )
			if favButton.appExec:
				favButton.show()
				favButton.connect( "popup-menu", self.favPopup )
				favButton.connect( "button_release_event", self.favPopup )
				favButton.connect( "focus-in-event", self.scrollItemIntoView )
				favButton.connect( "clicked", lambda w: self.mintMenuWin.hide() )
				
				self.mintMenuWin.setTooltip( favButton, favButton.getTooltip() )
				favButton.type = "location"
				return favButton
		except Exception, e:
			print u"File in favorites not found: '" + location + "'", e
		
		return None