2017-11-11 08:56:14 +00:00
|
|
|
#!/usr/bin/python2
|
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
import os
|
|
|
|
|
2017-11-11 08:56:14 +00:00
|
|
|
import gi
|
|
|
|
gi.require_version("Gtk", "3.0")
|
2019-02-11 13:54:20 +00:00
|
|
|
from gi.repository import Gtk
|
2017-11-11 08:56:14 +00:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
from plugins.easybuttons import ApplicationLauncher
|
2017-11-11 08:56:14 +00:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
home = os.path.expanduser("~")
|
2017-11-11 08:56:14 +00:00
|
|
|
recentApps = []
|
|
|
|
mintMenuWin = None
|
|
|
|
recentAppBox = None
|
|
|
|
numentries = 10
|
|
|
|
iconSize = 16
|
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def recentAppsAdd(recentAppsButton):
|
2017-11-11 08:56:14 +00:00
|
|
|
if recentAppsButton:
|
2019-02-11 13:54:20 +00:00
|
|
|
recentApps.insert(0, recentAppsButton)
|
2017-11-11 08:56:14 +00:00
|
|
|
counter = 0
|
|
|
|
for recentApp in recentApps:
|
2019-02-11 13:54:20 +00:00
|
|
|
if counter != 0 and (recentApp.desktopFile == recentAppsButton.desktopFile or counter >= numentries):
|
2017-11-11 08:56:14 +00:00
|
|
|
del recentApps[counter]
|
|
|
|
counter = counter + 1
|
|
|
|
|
|
|
|
def recentAppsSave():
|
|
|
|
try:
|
2019-02-11 13:54:20 +00:00
|
|
|
path = os.path.join(home, ".linuxmint/mintMenu/recentApplications.list")
|
|
|
|
with open(path, "w") as recentAppListFile:
|
|
|
|
for recentApp in recentApps:
|
|
|
|
if not hasattr(recentApp, "type") or recentApp.type == "location":
|
|
|
|
recentAppListFile.write("location:" + recentApp.desktopFile + "\n")
|
|
|
|
else:
|
|
|
|
recentAppListFile.write(recentApp.type + "\n")
|
2017-11-11 08:56:14 +00:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
|
|
|
msgDlg = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK,
|
|
|
|
_("Couldn't save recent apps. Check if you have write access to ~/.linuxmint/mintMenu")+"\n(" + e.__str__() + ")")
|
|
|
|
msgDlg.run()
|
|
|
|
msgDlg.destroy()
|
2017-11-11 08:56:14 +00:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def recentAppBuildLauncher(location):
|
2017-11-11 08:56:14 +00:00
|
|
|
try:
|
|
|
|
# For Folders and Network Shares
|
2019-02-11 13:54:20 +00:00
|
|
|
location = "".join(location.split("%20"))
|
|
|
|
|
|
|
|
# ButtonIcon = None
|
2017-11-11 08:56:14 +00:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
# if location.startswith("file"):
|
|
|
|
# ButtonIcon = "mate-fs-directory"
|
2017-11-11 08:56:14 +00:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
# if location.startswith("smb") or location.startswith("ssh") or location.startswith("network"):
|
|
|
|
# ButtonIcon = "mate-fs-network"
|
2017-11-11 08:56:14 +00:00
|
|
|
|
|
|
|
#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"
|
2019-02-11 13:54:20 +00:00
|
|
|
elif location.startswith("x-nautilus-desktop:///"):
|
2017-11-11 08:56:14 +00:00
|
|
|
location = "/usr/share/applications/nautilus-computer.desktop"
|
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
if location.startswith("file://"):
|
2017-11-11 08:56:14 +00:00
|
|
|
location = location[7:]
|
2019-09-26 09:42:01 +01:00
|
|
|
if os.path.exists(location):
|
|
|
|
appButton = ApplicationLauncher(location, iconSize)
|
|
|
|
if appButton.appExec:
|
|
|
|
appButton.show()
|
|
|
|
appButton.connect("clicked", applicationButtonClicked)
|
|
|
|
appButton.type = "location"
|
|
|
|
return appButton
|
|
|
|
print("RecentApp: %s not found." % location)
|
2019-02-11 13:54:20 +00:00
|
|
|
except Exception as e:
|
|
|
|
print("File in recentapp not found: '%s': %s" % (location, e))
|
2017-11-11 08:56:14 +00:00
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
def buildRecentApps():
|
|
|
|
del recentApps[:]
|
|
|
|
try:
|
2019-02-11 13:54:20 +00:00
|
|
|
path = os.path.join(home, ".linuxmint/mintMenu/recentApplications.list")
|
|
|
|
if not os.path.exists(path):
|
|
|
|
recentApplicationsList = []
|
|
|
|
else:
|
|
|
|
recentApplicationsList = open(path).readlines()
|
2017-11-11 08:56:14 +00:00
|
|
|
|
|
|
|
for app in recentApplicationsList :
|
|
|
|
app = app.strip()
|
|
|
|
|
|
|
|
if app[0:9] == "location:":
|
2019-02-11 13:54:20 +00:00
|
|
|
appButton = recentAppBuildLauncher(app[9:])
|
2017-11-11 08:56:14 +00:00
|
|
|
else:
|
2019-02-11 13:54:20 +00:00
|
|
|
if (app.endswith(".desktop")):
|
|
|
|
appButton = recentAppBuildLauncher(app)
|
2017-11-11 08:56:14 +00:00
|
|
|
else:
|
|
|
|
appButton = None
|
|
|
|
|
|
|
|
if appButton:
|
2019-02-11 13:54:20 +00:00
|
|
|
recentApps.append(appButton)
|
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
2017-11-11 08:56:14 +00:00
|
|
|
return recentApps
|
|
|
|
|
|
|
|
def doRecentApps():
|
2018-06-08 12:19:59 +01:00
|
|
|
if recentAppBox is not None:
|
|
|
|
# recentAppBox is initiated by the recent plugin
|
|
|
|
# only build UI widgets if it's enabled
|
|
|
|
for i in recentAppBox.get_children():
|
|
|
|
i.destroy()
|
2017-11-11 08:56:14 +00:00
|
|
|
|
2018-06-08 12:19:59 +01:00
|
|
|
# recent apps
|
|
|
|
buildRecentApps()
|
|
|
|
for AButton in recentApps:
|
2019-02-11 13:54:20 +00:00
|
|
|
AButton.set_size_request(200, -1)
|
|
|
|
AButton.set_relief(Gtk.ReliefStyle.NONE)
|
|
|
|
recentAppBox.pack_start(AButton, False, True, 0)
|
2017-11-11 08:56:14 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def applicationButtonClicked(widget):
|
2017-11-11 08:56:14 +00:00
|
|
|
mintMenuWin.hide()
|
|
|
|
recentAppsAdd(widget)
|
|
|
|
recentAppsSave()
|
|
|
|
doRecentApps()
|