2020-03-30 16:11:23 +01:00
|
|
|
#!/usr/bin/python3
|
2014-03-28 15:44:13 +00:00
|
|
|
|
2019-05-20 14:31:05 +01:00
|
|
|
import gettext
|
|
|
|
import locale
|
2019-05-20 15:19:55 +01:00
|
|
|
import os
|
|
|
|
import subprocess
|
2019-02-11 13:54:20 +00:00
|
|
|
|
2013-03-08 01:53:03 +00:00
|
|
|
import gi
|
2016-09-06 15:58:34 +01:00
|
|
|
gi.require_version("Gtk", "3.0")
|
2021-07-01 13:38:23 +01:00
|
|
|
from gi.repository import Gtk, Gio, Pango
|
2019-02-11 13:54:20 +00:00
|
|
|
|
|
|
|
import plugins.recentHelper as RecentHelper
|
|
|
|
from plugins.execute import Execute
|
2013-03-08 01:53:03 +00:00
|
|
|
|
2020-03-31 00:00:31 +01:00
|
|
|
home = os.path.expanduser("~")
|
|
|
|
|
2019-05-20 14:31:05 +01:00
|
|
|
# i18n
|
|
|
|
gettext.install("mintmenu", "/usr/share/linuxmint/locale")
|
|
|
|
locale.bindtextdomain("mintmenu", "/usr/share/linuxmint/locale")
|
|
|
|
locale.textdomain("mintmenu")
|
2009-07-27 11:45:34 +01:00
|
|
|
|
|
|
|
class pluginclass:
|
2019-02-11 13:54:20 +00:00
|
|
|
""" This is the main class for the plugin.
|
|
|
|
It MUST be named pluginclass
|
|
|
|
"""
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def __init__(self, mintMenuWin, toggleButton, de):
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2011-03-30 19:02:13 +01:00
|
|
|
self.Win = mintMenuWin
|
|
|
|
self.toggleButton = toggleButton
|
2011-03-29 18:50:33 +01:00
|
|
|
self.de = de
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2013-03-08 01:53:03 +00:00
|
|
|
self.builder = Gtk.Builder()
|
2019-05-20 14:31:05 +01:00
|
|
|
self.builder.set_translation_domain("mintmenu")
|
|
|
|
self.builder.add_from_file("/usr/share/linuxmint/mintmenu/recent.ui")
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2011-03-30 19:02:13 +01:00
|
|
|
#Set 'window' property for the plugin (Must be the root widget)
|
2019-02-11 13:54:20 +00:00
|
|
|
self.window = self.builder.get_object("window1")
|
2011-03-30 19:02:13 +01:00
|
|
|
|
|
|
|
#Set 'heading' property for plugin
|
2017-11-11 08:56:14 +00:00
|
|
|
self.heading = _("Recently used")
|
2011-03-30 19:02:13 +01:00
|
|
|
|
|
|
|
#This should be the first item added to the window in glade
|
2019-02-11 13:54:20 +00:00
|
|
|
self.content_holder = self.builder.get_object("eventbox1")
|
2011-03-30 19:02:13 +01:00
|
|
|
|
2013-05-21 16:24:01 +01:00
|
|
|
self.recentBox = self.builder.get_object("RecentBox")
|
2017-11-11 08:56:14 +00:00
|
|
|
self.recentAppBox = self.builder.get_object("RecentApps")
|
|
|
|
RecentHelper.recentAppBox = self.recentAppBox
|
2019-02-11 13:54:20 +00:00
|
|
|
|
2017-11-11 08:56:14 +00:00
|
|
|
#self.recentApps = []
|
2019-02-11 13:54:20 +00:00
|
|
|
|
|
|
|
self.recentVBox = self.builder.get_object("vbox1")
|
2013-05-21 16:24:01 +01:00
|
|
|
|
2011-03-30 19:02:13 +01:00
|
|
|
#Specify plugin width
|
|
|
|
self.width = 250
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2011-03-30 19:02:13 +01:00
|
|
|
#Plugin icon
|
2011-11-18 10:42:20 +00:00
|
|
|
self.icon = 'mate-folder.png'
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2019-05-20 15:19:55 +01:00
|
|
|
self.settings = Gio.Settings("com.linuxmint.mintmenu.plugins.recent")
|
2020-03-31 00:00:31 +01:00
|
|
|
RecentHelper.settings = self.settings
|
|
|
|
|
|
|
|
self.migrate_recent_apps()
|
2019-05-20 15:19:55 +01:00
|
|
|
self.settings.connect('changed', self.RegenPlugin)
|
2019-02-11 13:54:20 +00:00
|
|
|
|
2019-05-20 15:19:55 +01:00
|
|
|
self.appSettings = Gio.Settings("com.linuxmint.mintmenu.plugins.applications")
|
|
|
|
self.appSettings.connect("changed::icon-size", self.RegenPlugin)
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2011-03-30 19:02:13 +01:00
|
|
|
self.FileList=[]
|
2013-03-08 01:53:03 +00:00
|
|
|
self.RecManagerInstance = Gtk.RecentManager.get_default()
|
2013-05-21 18:15:39 +01:00
|
|
|
self.recentManagerId = self.RecManagerInstance.connect("changed", self.DoRecent)
|
2011-03-30 19:02:13 +01:00
|
|
|
|
|
|
|
self.RegenPlugin()
|
2019-02-11 13:54:20 +00:00
|
|
|
self.builder.get_object("RecentTabs").set_current_page(0)
|
2011-03-30 19:02:13 +01:00
|
|
|
|
|
|
|
#Connect event handlers
|
2013-03-08 01:53:03 +00:00
|
|
|
self.builder.get_object("ClrBtn").connect("clicked", self.clrmenu)
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
@staticmethod
|
|
|
|
def wake():
|
|
|
|
return
|
2011-03-30 19:02:13 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def destroy(self):
|
2013-05-21 18:15:39 +01:00
|
|
|
self.recentBox.destroy()
|
|
|
|
self.recentVBox.destroy()
|
2019-02-11 13:54:20 +00:00
|
|
|
self.builder.get_object("RecentTabs").destroy()
|
2013-05-21 18:15:39 +01:00
|
|
|
self.builder.get_object("ClrBtn").destroy()
|
|
|
|
self.content_holder.destroy()
|
|
|
|
if self.recentManagerId:
|
|
|
|
self.RecManagerInstance.disconnect(self.recentManagerId)
|
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def RegenPlugin(self, *args, **kargs):
|
2013-03-08 01:53:03 +00:00
|
|
|
self.GetGSettingsEntries()
|
2011-03-30 19:02:13 +01:00
|
|
|
|
2020-03-31 00:00:31 +01:00
|
|
|
def migrate_recent_apps(self):
|
|
|
|
if self.settings.get_strv("recent-apps-list") != []:
|
|
|
|
return
|
|
|
|
|
|
|
|
path = os.path.join(home, ".linuxmint/mintMenu/recentApplications.list")
|
|
|
|
if os.path.exists(path):
|
|
|
|
with open(path) as f:
|
|
|
|
self.settings.set_strv("recent-apps-list", f.readlines())
|
|
|
|
|
|
|
|
try:
|
|
|
|
os.unlink(path)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def GetGSettingsEntries(self):
|
2019-05-20 15:19:55 +01:00
|
|
|
self.recenth = self.settings.get_int("height")
|
|
|
|
self.recentw = self.settings.get_int("width")
|
|
|
|
self.numentries = self.settings.get_int("num-recent-docs")
|
2017-11-11 08:56:14 +00:00
|
|
|
RecentHelper.numentries = self.numentries
|
2019-05-20 15:19:55 +01:00
|
|
|
self.recentfontsize = self.settings.get_int("recent-font-size")
|
2011-03-30 19:02:13 +01:00
|
|
|
|
|
|
|
# Hide vertical dotted separator
|
2019-05-20 15:19:55 +01:00
|
|
|
self.hideseparator = self.settings.get_boolean("hide-separator")
|
2011-03-30 19:02:13 +01:00
|
|
|
# Plugin icon
|
2019-05-20 15:19:55 +01:00
|
|
|
self.icon = self.settings.get_string("icon")
|
|
|
|
RecentHelper.iconSize = self.appSettings.get_int("icon-size")
|
2011-03-30 19:02:13 +01:00
|
|
|
self.RebuildPlugin()
|
|
|
|
|
|
|
|
def RebuildPlugin(self):
|
2019-02-11 13:54:20 +00:00
|
|
|
self.content_holder.set_size_request(self.recentw, self.recenth)
|
2011-03-30 19:02:13 +01:00
|
|
|
self.DoRecent()
|
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def DoRecent(self, *args, **kargs):
|
2013-05-21 16:24:01 +01:00
|
|
|
for i in self.recentBox.get_children():
|
2011-03-30 19:02:13 +01:00
|
|
|
i.destroy()
|
2019-02-11 13:54:20 +00:00
|
|
|
|
|
|
|
self.recentVBox.set_size_request(self.recentw, self.recenth)
|
|
|
|
if len(self.recentBox.get_children()) < self.numentries:
|
|
|
|
n=len(self.recentBox.get_children())-1
|
2011-03-30 19:02:13 +01:00
|
|
|
else:
|
|
|
|
n=self.numentries-1
|
|
|
|
while n >= 0:
|
2019-02-11 13:54:20 +00:00
|
|
|
self.recentBox.remove(self.recentBox.get_children()[n])
|
2011-03-30 19:02:13 +01:00
|
|
|
n-=1
|
|
|
|
|
|
|
|
self.FileList, self.IconList = self.GetRecent()
|
|
|
|
loc = 0
|
|
|
|
for Name in self.FileList:
|
|
|
|
if Name != None:
|
2019-02-11 13:54:20 +00:00
|
|
|
self.AddRecentBtn(Name, self.IconList[loc])
|
2011-03-30 19:02:13 +01:00
|
|
|
loc = loc + 1
|
2019-02-11 13:54:20 +00:00
|
|
|
|
2017-11-11 08:56:14 +00:00
|
|
|
RecentHelper.doRecentApps()
|
2019-02-11 13:54:20 +00:00
|
|
|
|
2011-03-30 19:02:13 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
def clrmenu(self, *args, **kargs):
|
2020-03-31 00:01:29 +01:00
|
|
|
if self.builder.get_object("RecentTabs").get_current_page() == 0: # files
|
|
|
|
self.RecManagerInstance.purge_items()
|
|
|
|
else: # apps
|
|
|
|
self.settings.reset("recent-apps-list")
|
|
|
|
|
2011-03-30 19:02:13 +01:00
|
|
|
self.DoRecent()
|
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def AddRecentBtn(self, Name, RecentImage):
|
|
|
|
DispName=os.path.basename(Name)
|
2011-03-30 19:02:13 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
AButton = Gtk.Button("", "ok", True)
|
|
|
|
AButton.remove(AButton.get_children()[0])
|
|
|
|
AButton.set_size_request(200, -1)
|
|
|
|
AButton.set_relief(Gtk.ReliefStyle.NONE)
|
|
|
|
AButton.connect("clicked", self.callback, Name)
|
2017-04-28 16:18:43 +01:00
|
|
|
AButton.show()
|
2011-03-30 19:02:13 +01:00
|
|
|
|
2017-04-28 16:18:43 +01:00
|
|
|
Box1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
|
2011-03-30 19:02:13 +01:00
|
|
|
|
2017-04-28 16:18:43 +01:00
|
|
|
ButtonIcon = Gtk.Image()
|
|
|
|
ButtonIcon.set_size_request(20, -1)
|
|
|
|
ButtonIcon.set_from_pixbuf(RecentImage)
|
|
|
|
Box1.add(ButtonIcon)
|
2011-03-30 19:02:13 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
Label1 = Gtk.Label(DispName)
|
2021-07-01 13:38:23 +01:00
|
|
|
Label1.set_ellipsize(Pango.EllipsizeMode.END)
|
2019-02-11 13:54:20 +00:00
|
|
|
Box1.add(Label1)
|
2011-03-30 19:02:13 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
AButton.add(Box1)
|
2017-04-28 16:18:43 +01:00
|
|
|
AButton.show_all()
|
2011-03-30 19:02:13 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
self.recentBox.pack_start(AButton, False, True, 0)
|
2011-03-30 19:02:13 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def callback(self, widget, filename):
|
2011-03-30 19:02:13 +01:00
|
|
|
self.Win.hide()
|
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
try:
|
|
|
|
subprocess.check_call(["xdg-open", filename])
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
dialog = Gtk.MessageDialog(self.window, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
|
|
|
|
Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _("The file or location could not be opened."))
|
|
|
|
dialog.set_title("mintMenu")
|
|
|
|
dialog.run()
|
|
|
|
dialog.destroy()
|
2011-03-30 19:02:13 +01:00
|
|
|
|
|
|
|
def GetRecent(self, *args, **kargs):
|
|
|
|
FileString=[]
|
|
|
|
IconString=[]
|
2021-06-19 08:19:00 +01:00
|
|
|
RecentInfo=sorted(self.RecManagerInstance.get_items(), key=lambda item: item.get_modified(), reverse=True)
|
2011-03-30 19:02:13 +01:00
|
|
|
count=0
|
|
|
|
MaxEntries=self.numentries
|
|
|
|
if self.numentries == -1:
|
|
|
|
MaxEntries=len(RecentInfo)
|
|
|
|
for items in RecentInfo:
|
|
|
|
FileString.append(items.get_uri_display())
|
2013-03-08 01:53:03 +00:00
|
|
|
IconString.append(items.get_icon(Gtk.IconSize.MENU))
|
2011-03-30 19:02:13 +01:00
|
|
|
count+=1
|
|
|
|
if count >= MaxEntries:
|
|
|
|
break
|
2019-02-11 13:54:20 +00:00
|
|
|
return FileString, IconString
|
2011-03-30 19:02:13 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def ButtonClicked(self, widget, event, Exec):
|
2011-03-30 19:02:13 +01:00
|
|
|
self.press_x = event.x
|
|
|
|
self.press_y = event.y
|
|
|
|
self.Exec = Exec
|
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
def ButtonReleased(self, w, ev, ev2):
|
2011-03-30 19:02:13 +01:00
|
|
|
if ev.button == 1:
|
2019-02-11 13:54:20 +00:00
|
|
|
if not hasattr(self, "press_x") or \
|
|
|
|
not w.drag_check_threshold(int(self.press_x),
|
|
|
|
int(self.press_y),
|
|
|
|
int(ev.x),
|
|
|
|
int(ev.y)):
|
2011-03-30 19:02:13 +01:00
|
|
|
if self.Win.pinmenu == False:
|
2019-02-11 13:54:20 +00:00
|
|
|
self.Win.wTree.get_widget("window1").hide()
|
2011-03-30 19:02:13 +01:00
|
|
|
if "applications" in self.Win.plugins:
|
2019-02-11 13:54:20 +00:00
|
|
|
self.Win.plugins["applications"].wTree.get_widget("entry1").grab_focus()
|
|
|
|
Execute(w, self.Exec)
|
2011-03-30 19:02:13 +01:00
|
|
|
|
2019-02-11 13:54:20 +00:00
|
|
|
@staticmethod
|
|
|
|
def do_plugin():
|
|
|
|
return
|