2015-06-26 01:36:36 +01:00
|
|
|
#!/usr/bin/python2
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2019-05-20 14:31:05 +01:00
|
|
|
import locale
|
2019-02-11 13:54:20 +00:00
|
|
|
import gettext
|
2009-07-27 11:45:34 +01:00
|
|
|
import os
|
|
|
|
import string
|
2019-02-11 13:54:20 +00:00
|
|
|
from glob import glob
|
2010-10-25 12:23:16 +01:00
|
|
|
from urllib import unquote
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
import gi
|
|
|
|
gi.require_version("Gtk", "3.0")
|
|
|
|
from gi.repository import Gtk, Gio, GLib
|
|
|
|
|
|
|
|
from plugins.easybuttons import easyButton
|
|
|
|
from plugins.easygsettings import EasyGSettings
|
|
|
|
from plugins.execute import Execute
|
|
|
|
|
|
|
|
|
2009-07-27 11:45:34 +01:00
|
|
|
# i18n
|
2009-11-03 11:29:52 +00:00
|
|
|
gettext.install("mintmenu", "/usr/share/linuxmint/locale")
|
2019-05-20 14:31:05 +01:00
|
|
|
locale.bindtextdomain("mintmenu", "/usr/share/linuxmint/locale")
|
|
|
|
locale.textdomain("mintmenu")
|
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
home = os.path.expanduser("~")
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
class pluginclass(object):
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2019-02-11 13:54:20 +00: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
|
|
|
|
2016-05-21 17:11:36 +01:00
|
|
|
# Read UI file
|
2013-03-04 16:50:14 +00:00
|
|
|
builder = Gtk.Builder()
|
2019-05-20 14:31:05 +01:00
|
|
|
builder.set_translation_domain("mintmenu")
|
|
|
|
builder.add_from_file("/usr/share/linuxmint/mintmenu/places.ui")
|
2016-05-21 17:11:36 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
self.placesBtnHolder = builder.get_object("places_button_holder")
|
|
|
|
self.editableBtnHolder = builder.get_object("editable_button_holder")
|
2013-03-04 16:50:14 +00:00
|
|
|
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)
|
2019-02-11 13:54:20 +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
|
2019-02-11 13:54:20 +00:00
|
|
|
self.content_holder = builder.get_object("Places")
|
2010-09-12 12:56:38 +01:00
|
|
|
|
|
|
|
# Items to get custom colors
|
2019-02-11 13:54:20 +00:00
|
|
|
self.itemstocolor = [builder.get_object("viewport2")]
|
2013-03-04 16:50:14 +00:00
|
|
|
|
2016-05-21 17:11:36 +01:00
|
|
|
# Settings
|
2013-03-09 02:29:49 +00:00
|
|
|
self.settings = EasyGSettings("com.linuxmint.mintmenu.plugins.places")
|
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
self.settings.notifyAdd("icon-size", self.RegenPlugin)
|
|
|
|
self.settings.notifyAdd("show-computer", self.RegenPlugin)
|
|
|
|
self.settings.notifyAdd("show-desktop", self.RegenPlugin)
|
|
|
|
self.settings.notifyAdd("show-home_folder", self.RegenPlugin)
|
|
|
|
self.settings.notifyAdd("show-network", self.RegenPlugin)
|
|
|
|
self.settings.notifyAdd("show-trash", self.RegenPlugin)
|
|
|
|
self.settings.notifyAdd("custom-names", self.RegenPlugin)
|
|
|
|
self.settings.notifyAdd("allow-scrollbar", self.RegenPlugin)
|
|
|
|
self.settings.notifyAdd("show-gtk-bookmarks", self.RegenPlugin)
|
|
|
|
self.settings.notifyAdd("height", self.changePluginSize)
|
|
|
|
self.settings.notifyAdd("width", self.changePluginSize)
|
2013-03-04 16:50:14 +00:00
|
|
|
|
|
|
|
self.loadSettings()
|
2010-09-12 12:56:38 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
self.content_holder.set_size_request(self.width, self.height)
|
2010-09-12 12:56:38 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def wake(self):
|
|
|
|
if self.showtrash:
|
2010-09-12 12:56:38 +01:00
|
|
|
self.refreshTrash()
|
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def destroy(self):
|
2013-03-09 02:29:49 +00:00
|
|
|
self.settings.notifyRemoveAll()
|
2010-09-12 12:56:38 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def changePluginSize(self, settings, key, args = None):
|
|
|
|
self.allowScrollbar = self.settings.get("bool", "allow-scrollbar")
|
|
|
|
self.width = self.settings.get("int", "width")
|
|
|
|
if not self.allowScrollbar:
|
2013-03-04 16:50:14 +00:00
|
|
|
self.height = -1
|
2019-02-11 13:54:20 +00:00
|
|
|
self.scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
|
2013-03-04 16:50:14 +00:00
|
|
|
else:
|
2019-02-11 13:54:20 +00:00
|
|
|
self.scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
|
|
|
|
self.height = self.settings.get("int", "height")
|
|
|
|
self.content_holder.set_size_request(self.width, self.height)
|
2010-09-12 12:56:38 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
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
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def loadSettings(self):
|
|
|
|
self.width = self.settings.get("int", "width")
|
|
|
|
self.allowScrollbar = self.settings.get("bool", "allow-scrollbar")
|
|
|
|
self.showGTKBookmarks = self.settings.get("bool", "show-gtk-bookmarks")
|
|
|
|
self.scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
|
|
|
|
self.height = self.settings.get("int", "height")
|
|
|
|
self.content_holder.set_size_request(self.width, self.height)
|
|
|
|
if not self.allowScrollbar:
|
2010-09-12 12:56:38 +01:00
|
|
|
self.height = -1
|
2019-02-11 13:54:20 +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", "icon-size")
|
2010-09-12 12:56:38 +01:00
|
|
|
|
|
|
|
# Check default items
|
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
self.showcomputer = self.settings.get("bool", "show-computer")
|
|
|
|
self.showhomefolder = self.settings.get("bool", "show-home-folder")
|
|
|
|
self.shownetwork = self.settings.get("bool", "show-network")
|
|
|
|
self.showdesktop = self.settings.get("bool", "show-desktop")
|
|
|
|
self.showtrash = self.settings.get("bool", "show-trash")
|
2010-09-12 12:56:38 +01:00
|
|
|
|
|
|
|
# Get paths for custom items
|
2019-02-11 13:54:20 +00:00
|
|
|
self.custompaths = self.settings.get("list-string", "custom-paths")
|
2010-09-12 12:56:38 +01:00
|
|
|
|
|
|
|
# Get names for custom items
|
2019-02-11 13:54:20 +00:00
|
|
|
self.customnames = self.settings.get("list-string", "custom-names")
|
2010-09-12 12:56:38 +01:00
|
|
|
|
|
|
|
# Hide vertical dotted separator
|
2019-02-11 13:54:20 +00:00
|
|
|
self.hideseparator = self.settings.get("bool", "hide-separator")
|
2010-09-12 12:56:38 +01:00
|
|
|
# Plugin icon
|
2019-02-11 13:54:20 +00:00
|
|
|
self.icon = self.settings.get("string", "icon")
|
2010-09-12 12:56:38 +01:00
|
|
|
# Allow plugin to be minimized to the left plugin pane
|
2019-02-11 13:54:20 +00:00
|
|
|
self.sticky = self.settings.get("bool", "sticky")
|
|
|
|
self.minimized = self.settings.get("bool", "minimized")
|
2016-05-21 17:11:36 +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
|
2019-02-11 13:54:20 +00:00
|
|
|
def do_standard_places(self):
|
2010-09-12 12:56:38 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
if self.showcomputer:
|
|
|
|
Button1 = easyButton("computer", self.iconsize, [_("Computer")], -1, -1)
|
|
|
|
Button1.connect("clicked", self.ButtonClicked, "xdg-open computer:")
|
2010-09-12 12:56:38 +01:00
|
|
|
Button1.show()
|
2019-02-11 13:54:20 +00:00
|
|
|
self.placesBtnHolder.pack_start(Button1, False, False, 0)
|
|
|
|
self.mintMenuWin.setTooltip(Button1, _("Browse all local and remote disks and folders accessible from this computer"))
|
2010-09-12 12:56:38 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
if self.showhomefolder:
|
|
|
|
Button2 = easyButton("user-home", self.iconsize, [_("Home Folder")], -1, -1)
|
|
|
|
Button2.connect("clicked", self.ButtonClicked, "xdg-open %s " % home)
|
2010-09-12 12:56:38 +01:00
|
|
|
Button2.show()
|
2019-02-11 13:54:20 +00:00
|
|
|
self.placesBtnHolder.pack_start(Button2, False, False, 0)
|
|
|
|
self.mintMenuWin.setTooltip(Button2, _("Open your personal folder"))
|
2010-09-12 12:56:38 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
if self.shownetwork and self.de == "mate":
|
2013-03-04 16:50:14 +00:00
|
|
|
mate_settings = Gio.Settings.new("org.mate.interface")
|
2019-02-11 13:54:20 +00:00
|
|
|
icon_theme = mate_settings.get_string("icon-theme")
|
2010-10-26 14:44:31 +01:00
|
|
|
if "Mint-X" in icon_theme:
|
2019-02-11 13:54:20 +00:00
|
|
|
Button3 = easyButton("notification-network-ethernet-connected", self.iconsize, [_("Network")], -1, -1)
|
2010-10-26 14:44:31 +01:00
|
|
|
else:
|
2019-02-11 13:54:20 +00:00
|
|
|
Button3 = easyButton("network-workgroup", self.iconsize, [_("Network")], -1, -1)
|
|
|
|
Button3.connect("clicked", self.ButtonClicked, "xdg-open network:")
|
2010-09-12 12:56:38 +01:00
|
|
|
Button3.show()
|
2019-02-11 13:54:20 +00:00
|
|
|
self.placesBtnHolder.pack_start(Button3, False, False, 0)
|
|
|
|
self.mintMenuWin.setTooltip(Button3, _("Browse bookmarked and local network locations"))
|
2010-09-12 12:56:38 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
if self.showdesktop:
|
2010-09-12 12:56:38 +01:00
|
|
|
# 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']
|
2015-07-30 17:28:26 +01:00
|
|
|
if os.path.exists(os.path.expandvars(tmpdesktopDir)):
|
2010-09-12 12:56:38 +01:00
|
|
|
desktopDir = tmpdesktopDir
|
2019-02-11 13:54:20 +00:00
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
|
|
|
Button4 = easyButton("desktop", self.iconsize, [_("Desktop")], -1, -1)
|
|
|
|
Button4.connect("clicked", self.ButtonClicked, 'xdg-open "%s"' % desktopDir)
|
2010-09-12 12:56:38 +01:00
|
|
|
Button4.show()
|
2019-02-11 13:54:20 +00:00
|
|
|
self.placesBtnHolder.pack_start(Button4, False, False, 0)
|
|
|
|
self.mintMenuWin.setTooltip(Button4, _("Browse items placed on the desktop"))
|
2010-09-12 12:56:38 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
if self.showtrash:
|
|
|
|
self.trashButton = easyButton("user-trash", self.iconsize, [_("Trash")], -1, -1)
|
|
|
|
self.trashButton.connect("clicked", self.ButtonClicked, "xdg-open trash:")
|
2010-09-12 12:56:38 +01:00
|
|
|
self.trashButton.show()
|
2019-02-11 13:54:20 +00:00
|
|
|
self.trashButton.connect("button-release-event", self.trashPopup)
|
|
|
|
self.trash_path = os.path.join(home, ".local/share/Trash/info")
|
2010-09-12 12:56:38 +01:00
|
|
|
self.refreshTrash()
|
2019-02-11 13:54:20 +00:00
|
|
|
self.placesBtnHolder.pack_start(self.trashButton, False, False, 0)
|
|
|
|
self.mintMenuWin.setTooltip(self.trashButton, _("Browse deleted files"))
|
2010-09-12 12:56:38 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def do_custom_places(self):
|
|
|
|
for index in range(len(self.custompaths)):
|
2010-09-12 12:56:38 +01:00
|
|
|
path = self.custompaths[index]
|
|
|
|
path = path.replace("~", home)
|
2019-02-11 13:54:20 +00:00
|
|
|
command = 'xdg-open "%s"' % path
|
|
|
|
currentbutton = easyButton("folder", self.iconsize, [self.customnames[index]], -1, -1)
|
|
|
|
currentbutton.connect("clicked", self.ButtonClicked, command)
|
2010-09-12 12:56:38 +01:00
|
|
|
currentbutton.show()
|
2019-02-11 13:54:20 +00:00
|
|
|
self.placesBtnHolder.pack_start(currentbutton, False, False, 0)
|
2010-09-12 12:56:38 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def do_gtk_bookmarks(self):
|
2010-09-23 09:54:23 +01:00
|
|
|
if self.showGTKBookmarks:
|
2017-05-06 14:07:02 +01:00
|
|
|
bookmarksFile = os.path.join(GLib.get_user_config_dir(), "gtk-3.0", "bookmarks")
|
|
|
|
if not os.path.exists(bookmarksFile):
|
|
|
|
bookmarksFile = os.path.join(GLib.get_home_dir(), ".gtk-bookmarks")
|
|
|
|
if not os.path.exists(bookmarksFile):
|
2013-05-20 22:58:02 +01:00
|
|
|
return
|
2013-05-03 19:00:22 +01:00
|
|
|
bookmarks = []
|
2017-05-06 14:07:02 +01:00
|
|
|
with open(bookmarksFile, "r") as f:
|
2010-09-23 09:54:23 +01:00
|
|
|
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()
|
2013-05-03 19:00:22 +01:00
|
|
|
if not line:
|
|
|
|
continue
|
|
|
|
parts = line.split(' ', 1)
|
2010-09-23 09:54:23 +01:00
|
|
|
|
|
|
|
if len(parts) == 2:
|
2013-05-03 19:00:22 +01:00
|
|
|
path, name = parts
|
2010-09-23 09:54:23 +01:00
|
|
|
elif len(parts) == 1:
|
2013-05-03 19:00:22 +01:00
|
|
|
path = parts[0]
|
|
|
|
name = os.path.basename(os.path.normpath(path))
|
|
|
|
bookmarks.append((name, path))
|
|
|
|
|
|
|
|
for name, path in bookmarks:
|
2010-10-25 12:23:16 +01:00
|
|
|
name = unquote(name)
|
2019-02-11 13:54:20 +00:00
|
|
|
currentbutton = easyButton("folder", self.iconsize, [name], -1, -1)
|
|
|
|
currentbutton.connect("clicked", self.launch_gtk_bookmark, path)
|
2010-09-23 09:54:23 +01:00
|
|
|
currentbutton.show()
|
2019-02-11 13:54:20 +00:00
|
|
|
self.placesBtnHolder.pack_start(currentbutton, False, False, 0)
|
2016-05-21 17:11:36 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def launch_gtk_bookmark(self, widget, path):
|
2010-10-25 12:23:16 +01:00
|
|
|
self.mintMenuWin.hide()
|
2019-01-21 15:20:00 +00:00
|
|
|
os.system("xdg-open \"%s\" &" % path)
|
2010-09-23 09:54:23 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def trashPopup(self, widget, event):
|
2010-09-12 12:56:38 +01:00
|
|
|
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()
|
2019-02-11 13:54:20 +00:00
|
|
|
emptyTrashMenuItem.connect("activate", self.emptyTrash, widget)
|
2014-04-02 09:42:43 +01:00
|
|
|
self.mintMenuWin.stopHiding()
|
2017-04-28 16:04:01 +01:00
|
|
|
trashMenu.attach_to_widget(widget, None)
|
2016-09-06 15:58:34 +01:00
|
|
|
trashMenu.popup(None, None, None, None, 3, 0)
|
2010-09-12 12:56:38 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def emptyTrash(self, menu, widget):
|
2010-09-12 12:56:38 +01:00
|
|
|
os.system("rm -rf " + home + "/.local/share/Trash/info/*")
|
|
|
|
os.system("rm -rf " + home + "/.local/share/Trash/files/*")
|
|
|
|
self.trashButton.setIcon("user-trash")
|
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def ButtonClicked(self, widget, Exec):
|
2010-09-12 12:56:38 +01:00
|
|
|
self.mintMenuWin.hide()
|
|
|
|
if Exec:
|
2019-02-11 13:54:20 +00:00
|
|
|
Execute(Exec)
|
2010-09-12 12:56:38 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def do_plugin(self):
|
2010-09-12 12:56:38 +01:00
|
|
|
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
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def refreshTrash(self):
|
|
|
|
if os.path.exists(self.trash_path) and glob(os.path.join(self.trash_path, "*")):
|
|
|
|
iconName = "user-trash-full"
|
|
|
|
else:
|
|
|
|
iconName = "user-trash"
|
2010-09-12 12:56:38 +01:00
|
|
|
self.trashButton.setIcon(iconName)
|