Use gsettings for recent and favorite apps
during migration, - rename the old favorites file - delete the old recent file
This commit is contained in:
parent
d694deb65e
commit
6f69d0e499
@ -245,6 +245,9 @@ class pluginclass(object):
|
||||
try:
|
||||
# GSettings stuff
|
||||
self.settings = Gio.Settings("com.linuxmint.mintmenu.plugins.applications")
|
||||
|
||||
self.migrate_favorites()
|
||||
|
||||
self.GetGSettingsEntries()
|
||||
self.settings.connect("changed::icon-size", self.changeIconSize)
|
||||
self.settings.connect("changed::favicon-size", self.changeFavIconSize)
|
||||
@ -264,6 +267,7 @@ class pluginclass(object):
|
||||
self.settings.connect("changed::enable-internet-search", self.GetGSettingsEntries)
|
||||
self.settings.connect("changed::search-command", self.GetGSettingsEntries)
|
||||
self.settings.connect("changed::default-tab", self.GetGSettingsEntries)
|
||||
self.settings.connect("changed::favorite-apps-list", self.favoriteAppsChanged)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
@ -519,16 +523,6 @@ class pluginclass(object):
|
||||
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 self.favorites:
|
||||
if self.defaultTab == -1:
|
||||
@ -1245,26 +1239,44 @@ class pluginclass(object):
|
||||
|
||||
return None
|
||||
|
||||
def buildFavorites(self):
|
||||
try:
|
||||
def migrate_favorites(self):
|
||||
if self.settings.get_strv("favorite-apps-list") != []:
|
||||
return
|
||||
|
||||
default_path = os.path.join("/usr/linuxmint/mintMenu/applications.list")
|
||||
path = os.path.join(home, ".linuxmint/mintMenu/applications.list")
|
||||
|
||||
if os.path.isdir(path):
|
||||
# dir created by a bug in mint 19.2 beta
|
||||
os.system("rm -rf %s" % path)
|
||||
return
|
||||
|
||||
if not os.path.exists(path):
|
||||
os.system("mkdir -p ~/.linuxmint/mintMenu")
|
||||
os.system("cp /usr/lib/linuxmint/mintMenu/applications.list " + path)
|
||||
path = default_path
|
||||
|
||||
applicationsList = open(path).readlines()
|
||||
with open(path) as f:
|
||||
self.settings.set_strv("favorite-apps-list", f.readlines())
|
||||
|
||||
self.favorites = []
|
||||
try:
|
||||
os.replace(path, path + ".deprecated_uses_dconf_now")
|
||||
except:
|
||||
# This will fail if it was the default path, ignore it.
|
||||
pass
|
||||
|
||||
def favoriteAppsChanged(self, setting, key):
|
||||
self.buildFavorites()
|
||||
|
||||
def buildFavorites(self):
|
||||
try:
|
||||
faves = self.settings.get_strv("favorite-apps-list")
|
||||
|
||||
for child in self.favoritesBox:
|
||||
child.destroy()
|
||||
|
||||
position = 0
|
||||
self.favorites = []
|
||||
|
||||
for app in applicationsList:
|
||||
for app in faves:
|
||||
try:
|
||||
app = app.strip()
|
||||
|
||||
@ -1296,7 +1308,6 @@ class pluginclass(object):
|
||||
print("Can't add favorite: %s" % app)
|
||||
print (e)
|
||||
|
||||
self.favoritesSave()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
@ -1382,20 +1393,15 @@ class pluginclass(object):
|
||||
self.favoritesRemove(fav.position)
|
||||
|
||||
def favoritesSave(self):
|
||||
try:
|
||||
self.checkMintMenuFolder()
|
||||
with open(os.path.join(home, ".linuxmint/mintMenu/applications.list") , "w") as appListFile:
|
||||
new_faves = []
|
||||
|
||||
for favorite in self.favorites:
|
||||
if favorite.type == "location":
|
||||
appListFile.write("location:" + favorite.desktopFile + "\n")
|
||||
new_faves.append("location:" + favorite.desktopFile)
|
||||
else:
|
||||
appListFile.write(favorite.type + "\n")
|
||||
except Exception as e:
|
||||
msgDlg = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK,
|
||||
_("Couldn't save favorites. Check if you have write access to ~/.linuxmint/mintMenu") +
|
||||
"\n(" + e.__str__() + ")")
|
||||
msgDlg.run()
|
||||
msgDlg.destroy()
|
||||
new_faves.append(favorite.type)
|
||||
|
||||
self.settings.set_strv("favorite-apps-list", new_faves)
|
||||
|
||||
def isLocationInFavorites(self, location):
|
||||
for fav in self.favorites:
|
||||
|
@ -388,13 +388,6 @@ class ApplicationLauncher(easyButton):
|
||||
if os.path.exists(self.startupFilePath):
|
||||
os.remove(self.startupFilePath)
|
||||
|
||||
def addToFavourites(self):
|
||||
favouritesDir = os.path.join(os.path.expanduser("~"), ".linuxmint/mintMenu/applications")
|
||||
if not os.path.exists(favouritesDir):
|
||||
os.makedirs(favouritesDir)
|
||||
|
||||
shutil.copyfile(self.desktopFile, self.favouritesFilePath)
|
||||
|
||||
def removeFromFavourites(self):
|
||||
if os.path.exists(self.favouritesFilePath):
|
||||
os.remove(self.favouritesFilePath)
|
||||
|
@ -12,6 +12,8 @@ from gi.repository import Gtk, Gio
|
||||
import plugins.recentHelper as RecentHelper
|
||||
from plugins.execute import Execute
|
||||
|
||||
home = os.path.expanduser("~")
|
||||
|
||||
# i18n
|
||||
gettext.install("mintmenu", "/usr/share/linuxmint/locale")
|
||||
locale.bindtextdomain("mintmenu", "/usr/share/linuxmint/locale")
|
||||
@ -56,6 +58,9 @@ class pluginclass:
|
||||
self.icon = 'mate-folder.png'
|
||||
|
||||
self.settings = Gio.Settings("com.linuxmint.mintmenu.plugins.recent")
|
||||
RecentHelper.settings = self.settings
|
||||
|
||||
self.migrate_recent_apps()
|
||||
self.settings.connect('changed', self.RegenPlugin)
|
||||
|
||||
self.appSettings = Gio.Settings("com.linuxmint.mintmenu.plugins.applications")
|
||||
@ -87,6 +92,20 @@ class pluginclass:
|
||||
def RegenPlugin(self, *args, **kargs):
|
||||
self.GetGSettingsEntries()
|
||||
|
||||
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
|
||||
|
||||
def GetGSettingsEntries(self):
|
||||
self.recenth = self.settings.get_int("height")
|
||||
self.recentw = self.settings.get_int("width")
|
||||
|
@ -10,6 +10,8 @@ from plugins.easybuttons import ApplicationLauncher
|
||||
|
||||
home = os.path.expanduser("~")
|
||||
recentApps = []
|
||||
settings = None # set by recent plugin
|
||||
|
||||
mintMenuWin = None
|
||||
recentAppBox = None
|
||||
numentries = 10
|
||||
@ -25,21 +27,15 @@ def recentAppsAdd(recentAppsButton):
|
||||
counter = counter + 1
|
||||
|
||||
def recentAppsSave():
|
||||
try:
|
||||
path = os.path.join(home, ".linuxmint/mintMenu/recentApplications.list")
|
||||
with open(path, "w") as recentAppListFile:
|
||||
new_recent_apps = []
|
||||
|
||||
for recentApp in recentApps:
|
||||
if not hasattr(recentApp, "type") or recentApp.type == "location":
|
||||
recentAppListFile.write("location:" + recentApp.desktopFile + "\n")
|
||||
new_recent_apps.append("location:" + recentApp.desktopFile)
|
||||
else:
|
||||
recentAppListFile.write(recentApp.type + "\n")
|
||||
new_recent_apps.append(recentApp.type)
|
||||
|
||||
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()
|
||||
settings.set_strv("recent-apps-list", new_recent_apps)
|
||||
|
||||
def recentAppBuildLauncher(location):
|
||||
try:
|
||||
@ -82,13 +78,9 @@ def recentAppBuildLauncher(location):
|
||||
def buildRecentApps():
|
||||
del recentApps[:]
|
||||
try:
|
||||
path = os.path.join(home, ".linuxmint/mintMenu/recentApplications.list")
|
||||
if not os.path.exists(path):
|
||||
recentApplicationsList = []
|
||||
else:
|
||||
recentApplicationsList = open(path).readlines()
|
||||
recent_apps = settings.get_strv("recent-apps-list")
|
||||
|
||||
for app in recentApplicationsList :
|
||||
for app in recent_apps:
|
||||
app = app.strip()
|
||||
|
||||
if app[0:9] == "location:":
|
||||
|
@ -291,6 +291,12 @@
|
||||
<summary></summary>
|
||||
<description></description>
|
||||
</key>
|
||||
|
||||
<key type="as" name="favorite-apps-list">
|
||||
<default>[]</default>
|
||||
<summary>List of absolute desktop file paths</summary>
|
||||
</key>
|
||||
|
||||
</schema>
|
||||
|
||||
<schema id="com.linuxmint.mintmenu.plugins.system_management" path="/com/linuxmint/mintmenu/plugins/system_management/">
|
||||
@ -412,6 +418,11 @@
|
||||
<description></description>
|
||||
</key>
|
||||
|
||||
<key type="as" name="recent-apps-list">
|
||||
<default>[]</default>
|
||||
<summary>List of absolute desktop file paths</summary>
|
||||
</key>
|
||||
|
||||
</schema>
|
||||
|
||||
</schemalist>
|
||||
|
Loading…
Reference in New Issue
Block a user