2009-07-27 11:45:34 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2013-03-05 02:56:18 +00:00
|
|
|
from gi.repository import Gtk, Gio
|
2009-07-27 11:45:34 +01:00
|
|
|
import os
|
|
|
|
import string
|
|
|
|
import gettext
|
|
|
|
import commands
|
|
|
|
import time
|
|
|
|
|
|
|
|
from easybuttons import *
|
|
|
|
from execute import Execute
|
|
|
|
from user import home
|
2010-10-25 12:23:16 +01:00
|
|
|
from urllib import unquote
|
2009-07-27 11:45:34 +01:00
|
|
|
|
|
|
|
# i18n
|
2009-11-03 11:29:52 +00:00
|
|
|
gettext.install("mintmenu", "/usr/share/linuxmint/locale")
|
2009-07-27 11:45:34 +01:00
|
|
|
|
|
|
|
class pluginclass( object ):
|
|
|
|
|
2011-03-29 18:50:33 +01:00
|
|
|
def __init__( self, mintMenuWin, toggleButton, de ):
|
2010-09-12 12:56:38 +01:00
|
|
|
|
|
|
|
self.mintMenuWin = mintMenuWin
|
|
|
|
self.toggleButton = toggleButton
|
2011-03-29 18:50:33 +01:00
|
|
|
self.de = de
|
2010-09-12 12:56:38 +01:00
|
|
|
|
2013-03-04 16:50:14 +00:00
|
|
|
# Read UI file
|
|
|
|
builder = Gtk.Builder()
|
2013-03-05 02:56:18 +00:00
|
|
|
builder.add_from_file(os.path.join( os.path.dirname( __file__ ), "places.glade" ))
|
2013-03-04 16:50:14 +00:00
|
|
|
|
|
|
|
self.placesBtnHolder = builder.get_object( "places_button_holder" )
|
|
|
|
self.editableBtnHolder = builder.get_object( "editable_button_holder" )
|
|
|
|
self.scrolledWindow=builder.get_object("scrolledwindow2")
|
2010-09-12 12:56:38 +01:00
|
|
|
# These properties are NECESSARY to maintain consistency
|
|
|
|
|
|
|
|
# Set 'window' property for the plugin (Must be the root widget)
|
2013-03-04 16:50:14 +00:00
|
|
|
self.window = builder.get_object( "mainWindow" )
|
2010-09-12 12:56:38 +01:00
|
|
|
|
|
|
|
# Set 'heading' property for plugin
|
|
|
|
self.heading = _("Places")
|
|
|
|
|
|
|
|
# This should be the first item added to the window in glade
|
2013-03-04 16:50:14 +00:00
|
|
|
self.content_holder = builder.get_object( "Places" )
|
2010-09-12 12:56:38 +01:00
|
|
|
|
|
|
|
# Items to get custom colors
|
2013-03-04 16:50:14 +00:00
|
|
|
self.itemstocolor = [ builder.get_object( "viewport2" ) ]
|
|
|
|
|
|
|
|
# Settings
|
|
|
|
self.settings = Gio.Settings.new("com.linuxmint.mintmenu")
|
|
|
|
|
|
|
|
self.settings.connect( "changed::places-icon-size", self.RegenPlugin )
|
|
|
|
self.settings.connect( "changed::places-show-computer", self.RegenPlugin )
|
|
|
|
self.settings.connect( "changed::places-show-desktop", self.RegenPlugin )
|
|
|
|
self.settings.connect( "changed::places-show-home_folder", self.RegenPlugin )
|
|
|
|
self.settings.connect( "changed::places-show-network", self.RegenPlugin )
|
|
|
|
self.settings.connect( "changed::places-show-trash", self.RegenPlugin )
|
|
|
|
self.settings.connect( "changed::places-custom-names", self.RegenPlugin )
|
|
|
|
self.settings.connect( "changed::places-custom-paths", self.RegenPlugin )
|
|
|
|
self.settings.connect( "changed::places-allow-scrollbar", self.RegenPlugin )
|
|
|
|
self.settings.connect( "changed::places-show-gtk-bookmarks", self.RegenPlugin )
|
|
|
|
self.settings.connect( "changed::places-height", self.changePluginSize )
|
|
|
|
self.settings.connect( "changed::places-width", self.changePluginSize )
|
|
|
|
|
|
|
|
self.loadSettings()
|
2010-09-12 12:56:38 +01:00
|
|
|
|
2011-03-29 18:50:33 +01:00
|
|
|
self.content_holder.set_size_request( self.width, self.height )
|
2010-09-12 12:56:38 +01:00
|
|
|
|
|
|
|
def wake (self) :
|
|
|
|
if ( self.showtrash == True ):
|
|
|
|
self.refreshTrash()
|
|
|
|
|
|
|
|
def destroy( self ):
|
2013-03-04 16:50:14 +00:00
|
|
|
self.settings.disconnect_all()
|
2010-09-12 12:56:38 +01:00
|
|
|
|
|
|
|
def changePluginSize( self, client, connection_id, entry, args ):
|
2013-03-04 16:50:14 +00:00
|
|
|
self.allowScrollbar = self.settings.get_boolean( "places-allow-scrollbar" )
|
|
|
|
self.width = self.settings.get_int( "places-width" )
|
|
|
|
if (self.allowScrollbar == False):
|
|
|
|
self.height = -1
|
|
|
|
self.scrolledWindow.set_policy( Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER )
|
|
|
|
else:
|
|
|
|
self.scrolledWindow.set_policy( Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC )
|
|
|
|
self.height = self.settings.get_int( "places-height" )
|
2010-09-12 12:56:38 +01:00
|
|
|
self.content_holder.set_size_request( self.width, self.height )
|
|
|
|
|
|
|
|
def RegenPlugin( self, *args, **kargs ):
|
2013-03-04 16:50:14 +00:00
|
|
|
self.loadSettings()
|
2010-09-12 12:56:38 +01:00
|
|
|
self.ClearAll()
|
|
|
|
self.do_standard_places()
|
|
|
|
self.do_custom_places()
|
2010-09-23 09:54:23 +01:00
|
|
|
self.do_gtk_bookmarks()
|
2010-09-12 12:56:38 +01:00
|
|
|
|
2013-03-04 16:50:14 +00:00
|
|
|
def loadSettings( self ):
|
|
|
|
self.width = self.settings.get_int( "places-width" )
|
|
|
|
self.allowScrollbar = self.settings.get_boolean( "places-allow-scrollbar" )
|
|
|
|
self.showGTKBookmarks = self.settings.get_boolean( "places-show-gtk-bookmarks" )
|
|
|
|
self.scrolledWindow.set_policy( Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC )
|
|
|
|
self.height = self.settings.get_int( "places-height" )
|
2010-09-12 12:56:38 +01:00
|
|
|
self.content_holder.set_size_request( self.width, self.height )
|
|
|
|
if (self.allowScrollbar == False):
|
|
|
|
self.height = -1
|
2013-03-04 16:50:14 +00:00
|
|
|
self.scrolledWindow.set_policy( Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER )
|
|
|
|
self.content_holder.set_size_request( self.width, self.height )
|
|
|
|
self.iconsize = self.settings.get_int( "places-icon-size" )
|
2010-09-12 12:56:38 +01:00
|
|
|
|
|
|
|
# Check default items
|
|
|
|
|
2013-03-05 02:56:18 +00:00
|
|
|
self.showcomputer = self.settings.get_boolean( "places-show-computer" )
|
2013-03-04 16:50:14 +00:00
|
|
|
self.showhomefolder = self.settings.get_boolean( "places-show-home-folder" )
|
|
|
|
self.shownetwork = self.settings.get_boolean( "places-show-network" )
|
|
|
|
self.showdesktop = self.settings.get_boolean( "places-show-desktop" )
|
|
|
|
self.showtrash = self.settings.get_boolean( "places-show-trash" )
|
2010-09-12 12:56:38 +01:00
|
|
|
|
|
|
|
# Get paths for custom items
|
2013-03-04 16:50:14 +00:00
|
|
|
self.custompaths = self.settings.get_strv( "places-custom-paths" )
|
2010-09-12 12:56:38 +01:00
|
|
|
|
|
|
|
# Get names for custom items
|
2013-03-04 16:50:14 +00:00
|
|
|
self.customnames = self.settings.get_strv( "places-custom-names" )
|
2010-09-12 12:56:38 +01:00
|
|
|
|
|
|
|
# Hide vertical dotted separator
|
2013-03-04 16:50:14 +00:00
|
|
|
self.hideseparator = self.settings.get_boolean( "places-hide-separator" )
|
2010-09-12 12:56:38 +01:00
|
|
|
# Plugin icon
|
2013-03-05 02:56:18 +00:00
|
|
|
self.icon = self.settings.get_string( "places-icon" )
|
2010-09-12 12:56:38 +01:00
|
|
|
# Allow plugin to be minimized to the left plugin pane
|
2013-03-05 02:56:18 +00:00
|
|
|
self.sticky = self.settings.get_boolean( "places-sticky")
|
|
|
|
self.minimized = self.settings.get_boolean( "places-minimized")
|
2010-10-26 14:44:31 +01:00
|
|
|
|
2010-09-12 12:56:38 +01:00
|
|
|
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 )
|
2011-11-18 10:42:20 +00:00
|
|
|
if self.de == "mate":
|
2011-11-28 12:44:49 +00:00
|
|
|
Button1.connect( "clicked", self.ButtonClicked, "caja computer:" )
|
2011-03-29 18:34:59 +01:00
|
|
|
else:
|
|
|
|
Button1.connect( "clicked", self.ButtonClicked, "xdg-open /" )
|
2010-09-12 12:56:38 +01:00
|
|
|
Button1.show()
|
2013-03-05 02:56:18 +00:00
|
|
|
self.placesBtnHolder.pack_start( Button1, False, False, 0)
|
2010-09-12 12:56:38 +01:00
|
|
|
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 )
|
2011-11-28 12:44:49 +00:00
|
|
|
if self.de == "mate":
|
|
|
|
Button2.connect( "clicked", self.ButtonClicked, "caja %s " % home )
|
|
|
|
else:
|
|
|
|
Button2.connect( "clicked", self.ButtonClicked, "xdg-open %s " % home )
|
2010-09-12 12:56:38 +01:00
|
|
|
Button2.show()
|
2013-03-05 02:56:18 +00:00
|
|
|
self.placesBtnHolder.pack_start( Button2, False, False, 0)
|
2010-09-12 12:56:38 +01:00
|
|
|
self.mintMenuWin.setTooltip( Button2, _("Open your personal folder") )
|
|
|
|
|
2013-03-04 16:50:14 +00:00
|
|
|
if ( self.shownetwork == True and self.de == "mate"):
|
|
|
|
mate_settings = Gio.Settings.new("org.mate.interface")
|
|
|
|
icon_theme = mate_settings.get_string( "icon-theme" )
|
2010-10-26 14:44:31 +01:00
|
|
|
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)
|
2011-11-28 12:44:49 +00:00
|
|
|
if self.de == "mate":
|
|
|
|
Button3.connect( "clicked", self.ButtonClicked, "caja network:" )
|
|
|
|
else:
|
|
|
|
Button3.connect( "clicked", self.ButtonClicked, "xdg-open network:" )
|
2010-09-12 12:56:38 +01:00
|
|
|
Button3.show()
|
2013-03-05 02:56:18 +00:00
|
|
|
self.placesBtnHolder.pack_start( Button3, False, False, 0)
|
2010-09-12 12:56:38 +01:00
|
|
|
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
|
2012-05-22 16:43:20 +01:00
|
|
|
Button4 = easyButton( "desktop", self.iconsize, [_("Desktop")], -1, -1 )
|
2011-11-28 12:44:49 +00:00
|
|
|
if self.de == "mate":
|
|
|
|
Button4.connect( "clicked", self.ButtonClicked, "caja \"" + desktopDir + "\"")
|
|
|
|
else:
|
|
|
|
Button4.connect( "clicked", self.ButtonClicked, "xdg-open \"" + desktopDir + "\"")
|
2010-09-12 12:56:38 +01:00
|
|
|
Button4.show()
|
2013-03-05 02:56:18 +00:00
|
|
|
self.placesBtnHolder.pack_start( Button4, False, False, 0)
|
2010-09-12 12:56:38 +01:00
|
|
|
self.mintMenuWin.setTooltip( Button4, _("Browse items placed on the desktop") )
|
|
|
|
|
|
|
|
if ( self.showtrash == True ):
|
|
|
|
self.trashButton = easyButton( "user-trash", self.iconsize, [_("Trash")], -1, -1 )
|
2011-03-29 18:38:10 +01:00
|
|
|
if self.de == "xfce":
|
|
|
|
self.trashButton.connect( "clicked", self.ButtonClicked, "thunar trash:" )
|
2011-11-28 12:44:49 +00:00
|
|
|
elif self.de == "mate":
|
|
|
|
self.trashButton.connect( "clicked", self.ButtonClicked, "caja trash:" )
|
2011-03-29 18:38:10 +01:00
|
|
|
else:
|
|
|
|
self.trashButton.connect( "clicked", self.ButtonClicked, "xdg-open trash:" )
|
2010-09-12 12:56:38 +01:00
|
|
|
self.trashButton.show()
|
|
|
|
self.trashButton.connect( "button-release-event", self.trashPopup )
|
|
|
|
self.refreshTrash()
|
2013-03-05 02:56:18 +00:00
|
|
|
self.placesBtnHolder.pack_start( self.trashButton, False, False, 0)
|
2010-09-12 12:56:38 +01:00
|
|
|
self.mintMenuWin.setTooltip( self.trashButton, _("Browse deleted files") )
|
|
|
|
|
|
|
|
def do_custom_places( self ):
|
|
|
|
for index in range( len(self.custompaths) ):
|
|
|
|
path = self.custompaths[index]
|
|
|
|
path = path.replace("~", home)
|
2011-11-28 12:44:49 +00:00
|
|
|
if self.de == "mate":
|
|
|
|
command = ( "caja \"" + path + "\"")
|
|
|
|
else:
|
|
|
|
command = ( "xdg-open \"" + path + "\"")
|
2010-09-12 12:56:38 +01:00
|
|
|
currentbutton = easyButton( "folder", self.iconsize, [self.customnames[index]], -1, -1 )
|
|
|
|
currentbutton.connect( "clicked", self.ButtonClicked, command )
|
|
|
|
currentbutton.show()
|
2013-03-05 02:56:18 +00:00
|
|
|
self.placesBtnHolder.pack_start( currentbutton, False, False, 0)
|
2010-09-12 12:56:38 +01:00
|
|
|
|
2010-09-23 09:54:23 +01:00
|
|
|
def do_gtk_bookmarks( self ):
|
|
|
|
if self.showGTKBookmarks:
|
2010-10-25 12:23:16 +01:00
|
|
|
bookmarks = {}
|
2010-09-23 09:54:23 +01:00
|
|
|
with open(os.path.expanduser('~/.gtk-bookmarks'), 'r') as f:
|
|
|
|
for line in f:
|
2010-10-25 12:23:16 +01:00
|
|
|
#line = line.replace('file://', '')
|
2010-09-23 09:54:23 +01:00
|
|
|
line = line.rstrip()
|
|
|
|
parts = line.split(' ')
|
|
|
|
|
|
|
|
if len(parts) == 2:
|
|
|
|
bookmarks[parts[1]] = parts[0]
|
|
|
|
elif len(parts) == 1:
|
|
|
|
junk = os.path.split(parts[0])
|
|
|
|
bookmarks[junk[len(junk) - 1]] = parts[0]
|
|
|
|
|
2010-10-25 12:23:16 +01:00
|
|
|
for name, path in bookmarks.iteritems():
|
|
|
|
name = unquote(name)
|
2010-09-23 09:54:23 +01:00
|
|
|
currentbutton = easyButton( "folder", self.iconsize, [name], -1, -1 )
|
2010-10-25 12:23:16 +01:00
|
|
|
currentbutton.connect( "clicked", self.launch_gtk_bookmark, path )
|
2010-09-23 09:54:23 +01:00
|
|
|
currentbutton.show()
|
|
|
|
self.placesBtnHolder.pack_start( currentbutton, False, False )
|
2010-10-25 12:23:16 +01:00
|
|
|
|
|
|
|
def launch_gtk_bookmark (self, widget, path):
|
|
|
|
self.mintMenuWin.hide()
|
2011-11-28 12:44:49 +00:00
|
|
|
if self.de == "mate":
|
|
|
|
os.system("caja %s &" % path)
|
|
|
|
else:
|
|
|
|
os.system("xdg-open %s &" % path)
|
2010-09-23 09:54:23 +01:00
|
|
|
|
2010-09-12 12:56:38 +01:00
|
|
|
def trashPopup( self, widget, event ):
|
|
|
|
if event.button == 3:
|
2013-03-04 16:50:14 +00:00
|
|
|
trashMenu = Gtk.Menu()
|
|
|
|
emptyTrashMenuItem = Gtk.MenuItem(_("Empty trash"))
|
2010-09-12 12:56:38 +01:00
|
|
|
trashMenu.append(emptyTrashMenuItem)
|
|
|
|
trashMenu.show_all()
|
|
|
|
emptyTrashMenuItem.connect ( "activate", self.emptyTrash, widget )
|
|
|
|
trashMenu.popup( None, None, None, event.button, event.time )
|
|
|
|
self.mintMenuWin.grab()
|
|
|
|
|
|
|
|
|
|
|
|
def emptyTrash( self, menu, widget):
|
|
|
|
os.system("rm -rf " + home + "/.local/share/Trash/info/*")
|
|
|
|
os.system("rm -rf " + home + "/.local/share/Trash/files/*")
|
|
|
|
self.trashButton.setIcon("user-trash")
|
|
|
|
|
|
|
|
def ButtonClicked( self, widget, Exec ):
|
|
|
|
self.mintMenuWin.hide()
|
|
|
|
if Exec:
|
|
|
|
Execute( Exec )
|
|
|
|
|
|
|
|
def do_plugin( self ):
|
|
|
|
self.do_standard_places()
|
|
|
|
self.do_custom_places()
|
2010-09-23 09:54:23 +01:00
|
|
|
self.do_gtk_bookmarks()
|
2010-09-12 12:56:38 +01:00
|
|
|
|
|
|
|
def refreshTrash (self):
|
|
|
|
iconName = "user-trash"
|
|
|
|
if (os.path.exists(home + "/.local/share/Trash/info")):
|
|
|
|
infoFiles = commands.getoutput("ls " + home + "/.local/share/Trash/info/ | wc -l")
|
|
|
|
if (int(infoFiles) > 0):
|
|
|
|
iconName = "user-trash-full"
|
|
|
|
self.trashButton.setIcon(iconName)
|