Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Actions module #11878

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
359 changes: 359 additions & 0 deletions data/icons/hicolor_categories_scalable_cs-actions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 34 additions & 30 deletions files/usr/bin/xlet-about-dialog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/python3

import argparse
import sys
import os
import json
Expand All @@ -9,17 +10,14 @@ import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GdkPixbuf, GLib

usage = """
usage : xlet-about-dialog applets/desklets/extensions uuid
"""

gettext.install('cinnamon', '/usr/share/locale')

home = os.path.expanduser('~')


class AboutDialog(Gtk.AboutDialog):
def __init__(self, metadata, stype):
super(AboutDialog, self).__init__()
super().__init__()
self.metadata = metadata
self.stype = stype

Expand All @@ -33,33 +31,36 @@ class AboutDialog(Gtk.AboutDialog):
else:
self.props.version = _("Version %s") % version
elif 'last-edited' in metadata:
timestamp = datetime.datetime.fromtimestamp(self.metadata['last-edited']).isoformat(' ')
timestamp = datetime.datetime.fromtimestamp(int(self.metadata['last-edited'])).isoformat(' ')
self.props.version = _("Updated on %s") % timestamp

comments = self._(self.metadata['description'])
comments = self._(self.metadata.get('description', ''))

if 'comments' in self.metadata:
comments += '\n\n' + self._(self.metadata['comments'])
self.props.comments = comments

s_id = self.get_spices_id()
if s_id:
self.props.website = 'https://cinnamon-spices.linuxmint.com/%s/view/%s' % (self.stype, s_id)
self.props.website = f'https://cinnamon-spices.linuxmint.com/{self.stype}/view/{s_id}'
self.props.website_label = _("More info")

if 'contributors' in self.metadata:
self.props.authors = self.metadata['contributors'].split(',')

self.props.program_name = '%s (%s)' % (self._(self.metadata['name']), self.metadata['uuid'])
xlet_name = self._(self.metadata.get('name'))
self.props.program_name = f"{xlet_name} ({self.metadata['uuid']})"

self.connect('response', self.close)
self.set_title(_("About %s") % self.props.program_name)
self.show()

def close(self, *args):
Gtk.main_quit()

def set_icon(self):
# Use the generic type icon
self.set_logo_icon_name('cs-%s' % self.metadata['type'])
self.set_logo_icon_name(f"cs-{self.metadata['type']}")
# Override with metadata if set..
if 'icon' in self.metadata:
self.set_logo_icon_name(self.metadata['icon'])
Expand All @@ -68,7 +69,7 @@ class AboutDialog(Gtk.AboutDialog):
if os.path.exists(icon_path):
icon = GdkPixbuf.Pixbuf.new_from_file_at_size(icon_path, 48, 48)
self.set_logo(icon)
self.set_default_icon_name('cs-%s' % self.metadata['type'])
self.set_default_icon_name(f"cs-{self.metadata['type']}")

def _(self, msg):
gettext.bindtextdomain(self.metadata['uuid'], home + '/.local/share/locale')
Expand All @@ -81,9 +82,9 @@ class AboutDialog(Gtk.AboutDialog):

def get_spices_id(self):
try:
cache_path = os.path.join(GLib.get_user_cache_dir(), 'cinnamon', 'spices', self.stype[0:-1], 'index.json'),
cache_path = os.path.join(GLib.get_user_cache_dir(), 'cinnamon', 'spices', self.stype[0:-1], 'index.json')
if os.path.exists(cache_path):
with open(cache_path, 'r') as cache_file:
with open(cache_path, 'r', encoding='utf-8') as cache_file:
index_cache = json.load(cache_file)
if self.metadata['uuid'] in index_cache:
return index_cache[self.metadata['uuid']]['spices-id']
Expand All @@ -93,19 +94,22 @@ class AboutDialog(Gtk.AboutDialog):
print(e)
return None


if __name__ == "__main__":
if len(sys.argv) < 3:
print(usage)
quit()
parser = argparse.ArgumentParser()
parser.description = 'Arguments for xlet-about-dialog'
parser.add_argument('xlet_type', type=str, help=_('the type of the Spice'),
choices=['applets', 'desklets', 'extensions',
'actions', 'themes'])
parser.add_argument('uuid', type=str, metavar='UUID', nargs=1,
help=_('the UUID of the Spice'))
_args = parser.parse_args()

xlet_type = sys.argv[1]
uuid = sys.argv[2]
xlet_type = _args.xlet_type
uuid = _args.uuid[0]

suffix = 'share/cinnamon/%s/%s' % (xlet_type, uuid)
prefixes = [
os.path.join(home, '.local'),
'/usr'
]
suffix = f'share/nemo/actions/{uuid}' if xlet_type == 'actions' else f'share/cinnamon/{xlet_type}/{uuid}'
prefixes = [os.path.join(home, '.local'), '/usr']

path = None
for prefix in prefixes:
Expand All @@ -114,15 +118,15 @@ if __name__ == "__main__":
break

if path is None:
print('Unable to locate %s %s' % (xlet_type, uuid))
quit()
print(_('Unable to locate %s %s') % (xlet_type, uuid))
sys.exit(1)

with open(os.path.join(path, 'metadata.json')) as meta_file:
metadata = json.load(meta_file)
with open(os.path.join(path, 'metadata.json'), encoding='utf-8') as meta:
_metadata = json.load(meta)

metadata['path'] = path
metadata['type'] = xlet_type
_metadata['path'] = path
_metadata['type'] = xlet_type

AboutDialog(metadata, xlet_type)
AboutDialog(_metadata, xlet_type)

Gtk.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Desktop Entry]
Icon=cs-actions
Exec=cinnamon-settings actions
Type=Application
OnlyShowIn=X-Cinnamon;
Categories=Settings;
Name=Actions
Comment=Manage your Actions
Keywords=action;
Loading