Skip to content

Commit

Permalink
Now the about dialog is automatically genereted
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbende committed Dec 1, 2023
1 parent 6915ed2 commit 602acf8
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 83 deletions.
1 change: 0 additions & 1 deletion AUTHORS

This file was deleted.

84 changes: 42 additions & 42 deletions data/ui/about.ui → AUTHORS.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<object class="AdwAboutWindow" id="about_dialog">
<property name="application_name">Cozy</property>
<property name="application_icon">com.github.geigi.cozy</property>
<property name="license_type">gpl-3-0</property>
<property name="issue_url">https://github.com/geigi/cozy/issues/new</property>
<property name="website">https://github.com/geigi/cozy</property>
<property name="developer_name">geigi</property>
<property name="developers">geigi
A6GibKm
alyssais
apandada1
AsavarTzeth
Fatih20
NathanBnm
camellan
chris-kobrzak
elya5
foliva
grenade
jimmac
jnbr
jubalh
kaphula
leuc
magnickolas
meisenzahl
naglis
oleg-krv
paper42
phpwutz
rapenne-s
rdbende
thibaultamartin
umeboshi2
worldofpeace</property>
<property name="translator_credits">Ainte
# Code
- Julian Geywitz
- Benedek Dévényi
- A6GibKm
- alyssais
- apandada1
- AsavarTzeth
- Fatih20
- NathanBnm
- camellan
- chris-kobrzak
- elya5
- foliva
- grenade
- jnbr
- jubalh
- kaphula
- leuc
- magnickolas
- meisenzahl
- naglis
- oleg-krv
- paper42
- phpwutz
- rapenne-s
- thibaultamartin
- umeboshi2
- worldofpeace

# Design
- Julian Geywitz
- Tobias Bernard
- Benedek Dévényi

# Icon
- Jakub Steiner

# Translators
```
Ainte
AndreBarata
Andrey389
Asyx
Expand Down Expand Up @@ -136,6 +137,5 @@ useruseruser1233211
vanhoxx
vlabo
xfgusta
yalexaner</property>
</object>
</interface>
yalexaner
```
84 changes: 45 additions & 39 deletions cozy/ui/main_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import os
import webbrowser
from threading import Thread
from collections import defaultdict

from gi.repository import Gtk, Gio, Gdk, GLib, GObject
from gi.repository import Adw, Gtk, Gio, Gdk, GLib, GObject

import cozy.control.filesystem_monitor as fs_monitor
import cozy.ext.inject as inject
Expand Down Expand Up @@ -75,12 +76,13 @@ def __init_resources(self):
os.path.join(self.pkgdir, 'com.github.geigi.cozy.img.gresource'))
Gio.Resource._register(resource)

self.appdata_resource = Gio.resource_load(
os.path.join(self.pkgdir, 'com.github.geigi.cozy.appdata.gresource'))
Gio.Resource._register(self.appdata_resource)

self.window_builder = Gtk.Builder.new_from_resource(
"/com/github/geigi/cozy/main_window.ui")

self.about_builder = Gtk.Builder.new_from_resource(
"/com/github/geigi/cozy/about.ui")

self.window: Gtk.Window = self.window_builder.get_object("app_window")

def __init_window(self):
Expand Down Expand Up @@ -112,13 +114,6 @@ def __init_window(self):
self.no_media_file_chooser = self.window_builder.get_object("no_media_file_chooser")
self.no_media_file_chooser.connect("clicked", self._open_audiobook_dir_selector)

self.about_dialog = self.about_builder.get_object("about_dialog")
self.about_dialog.set_modal(self.window)
self.about_dialog.connect("close-request", self.hide_window)
self.about_dialog.set_version(self.version)

self._preferences = PreferencesView()

self.window.present()

def __init_actions(self):
Expand All @@ -129,6 +124,7 @@ def __init_actions(self):
about_action = Gio.SimpleAction.new("about", None)
about_action.connect("activate", self.about)
self.app.add_action(about_action)
self.app.set_accels_for_action("app.about", ["F1"])

quit_action = Gio.SimpleAction.new("quit", None)
quit_action.connect("activate", self.quit)
Expand Down Expand Up @@ -179,49 +175,62 @@ def quit(self, action, parameter):
self.on_close(None)
self.app.quit()

def about(self, action, parameter):
def _get_contributors(self):
authors_file = self.appdata_resource.lookup_data("/com/github/geigi/cozy/authors", Gio.ResourceLookupFlags.NONE)

current_section = ""
result = defaultdict(list)
for line in authors_file.get_data().decode().splitlines():
if line.startswith("#"):
current_section = line[1:].strip().lower()
elif line.startswith("-"):
result[current_section].append(line[1:].strip())

return result

def about(self, *junk):
"""
Show about window.
"""
self.about_dialog.add_acknowledgement_section(
about = Adw.AboutWindow.new_from_appdata(
"/com/github/geigi/cozy/com.github.geigi.cozy.appdata.xml",
release_notes_version=self.version,
)

contributors = self._get_contributors()
about.set_developers(sorted(contributors["code"]))
about.set_designers(sorted(contributors["design"]))
about.set_artists(sorted(contributors["icon"]))

about.set_license_type(Gtk.License.GPL_3_0)

about.add_acknowledgement_section(
_("Patreon Supporters"),
["Fred Warren", "Gabriel", "Hu Mann", "Josiah", "Oleksii Kriukov"]
)
self.about_dialog.add_acknowledgement_section(
about.add_acknowledgement_section(
_("m4b chapter support in mutagen"),
("mweinelt",),
)
self.about_dialog.add_acknowledgement_section(
about.add_acknowledgement_section(
_("Open Source Projects"),
("Lollypop music player https://gitlab.gnome.org/World/lollypop",),
)
self.about_dialog.add_legal_section(
"python-inject",
"© 2010 Ivan Korobkov",
Gtk.License.APACHE_2_0
)

self.about_dialog.present()
# Translators: Replace "translator-credits" with your names, one name per line
about.set_translator_credits(_("translator-credits"))
about.add_legal_section("python-inject", "© 2010 Ivan Korobkov", Gtk.License.APACHE_2_0)

def show_prefs(self, action, parameter):
"""
Show preferences window.
"""
self._preferences.show()
about.set_transient_for(self.window)
about.present()

def hide_window(self, widget, data=None):
def show_prefs(self, *_):
"""
Hide a given window. This is used for the about and settings dialog
as they will never be closed only hidden.
param widget: The widget that will be hidden.
Show preferences window.
"""
widget.hide()
PreferencesView().present()

# we handeled the close event so the window must not get destroyed.
return True

def play_pause(self, action, parameter):
def play_pause(self, *_):
self._player.play_pause()

def block_ui_buttons(self, block, scan=False):
Expand Down Expand Up @@ -314,9 +323,6 @@ def _set_audiobook_path(self, path):
self.scan(None, None)
self.fs_monitor.init_offline_mode()

def __about_close_clicked(self, widget):
self.about_dialog.hide()

def on_close(self, widget, data=None):
"""
Close and dispose everything that needs to be when window is closed.
Expand Down
8 changes: 8 additions & 0 deletions data/gresource.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/com/github/geigi/cozy">
<file preprocess="xml-stripblanks">com.github.geigi.cozy.appdata.xml</file>
<file alias="authors">../AUTHORS.md</file>
</gresource>
</gresources>

9 changes: 9 additions & 0 deletions data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ subdir('img')
subdir('ui')
subdir('icons')

gnome.compile_resources(
meson.project_name() + '.appdata',
'gresource.xml',
gresource_bundle: true,
install_dir: DATA_DIR,
install: true,
)


install_data(
meson.project_name() + '.gschema.xml',
install_dir: join_paths(get_option('datadir'), 'glib-2.0', 'schemas')
Expand Down
1 change: 0 additions & 1 deletion data/ui/gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<gresources>
<gresource prefix="/com/github/geigi/cozy">
<file>style.css</file>
<file preprocess="xml-stripblanks">about.ui</file>
<file preprocess="xml-stripblanks">album_element.ui</file>
<file preprocess="xml-stripblanks">book_detail.ui</file>
<file preprocess="xml-stripblanks">book_element.ui</file>
Expand Down

0 comments on commit 602acf8

Please sign in to comment.