Skip to content

Commit

Permalink
Initial work to fix deprecations in Gtk 4.10
Browse files Browse the repository at this point in the history
Looks like the vapi is broken and build fails on valac 0.56.4, so we need to add it manually for now
  • Loading branch information
ryonakano committed Jul 1, 2023
1 parent 7eb1bf0 commit 1c83cb8
Show file tree
Hide file tree
Showing 6 changed files with 15,096 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ Community packages maintained by volunteers are also available on some distribut

You'll need the following dependencies to build:

* libgtk-4-dev
* libgranite-7-dev
* libgstreamer1.0-dev (>= 1.20)
* libgtk-4-dev (>= 4.10)
* libpulse-dev
* libpulse-mainloop-glib0
* meson (>= 0.57.0)
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ executable(
sources,
dependencies: [
dependency('granite-7'),
dependency('gtk4'),
dependency('gstreamer-1.0', version: '>= 1.20'),
dependency('gtk4', version: '>= 4.10'),
dependency('libpulse'),
dependency('libpulse-mainloop-glib'),
dependency('pango')
Expand Down
30 changes: 18 additions & 12 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ public class MainWindow : Gtk.ApplicationWindow {

var cssprovider = new Gtk.CssProvider ();
cssprovider.load_from_resource ("/com/github/ryonakano/reco/Application.css");
// TODO: Deprecated in Gtk 4.10, buit no alternative api is provided so leave it for now
Gtk.StyleContext.add_provider_for_display (display,
cssprovider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

if (!Application.IS_ON_PANTHEON) {
var extra_cssprovider = new Gtk.CssProvider ();
extra_cssprovider.load_from_resource ("/com/github/ryonakano/reco/Extra.css");
// TODO: Deprecated in Gtk 4.10, buit no alternative api is provided so leave it for now
Gtk.StyleContext.add_provider_for_display (display,
extra_cssprovider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
Expand Down Expand Up @@ -155,33 +157,37 @@ public class MainWindow : Gtk.ApplicationWindow {
show_error_dialog (e.message);
}
} else {
var filechooser = new Gtk.FileChooserNative (
_("Save your recording"), this, Gtk.FileChooserAction.SAVE, null, null
) {
modal = true
var filechooser = new Gtk.FileDialog () {
title = _("Save your recording"),
accept_label = _("Save"),
modal = true,
initial_name = final_file_name
};
filechooser.set_current_name (final_file_name);
filechooser.save.begin (this, null, (obj, res) => {
try {
var file = filechooser.save.end (res);
if (file == null) {
return;
}

filechooser.response.connect ((response_id) => {
if (response_id == Gtk.ResponseType.ACCEPT) {
try {
if (tmp_file.move (filechooser.get_file (), FileCopyFlags.OVERWRITE)) {
if (tmp_file.move (file, FileCopyFlags.OVERWRITE)) {
welcome_view.show_success_button ();
}
} catch (Error e) {
show_error_dialog (e.message);
}
} else {
} catch (Error e) {
warning ("Failed to save recording: %s", e.message);

// May be cancelled by user, so delete the tmp recording
try {
tmp_file.delete ();
} catch (Error e) {
show_error_dialog (e.message);
}
}

filechooser.destroy ();
});
filechooser.show ();
}
});
}
Expand Down
40 changes: 16 additions & 24 deletions src/Views/WelcomeView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ public class WelcomeView : Gtk.Box {
}

// Let the user select the autosaving destination
var destination_chooser = destination_chooser_new ();
destination_chooser.show ();
show_destination_chooser ();
return false;
}

Expand All @@ -173,8 +172,7 @@ public class WelcomeView : Gtk.Box {
});

destination_chooser_button.clicked.connect (() => {
var destination_chooser = destination_chooser_new ();
destination_chooser.show ();
show_destination_chooser ();
});

record_button.clicked.connect (() => {
Expand Down Expand Up @@ -207,24 +205,25 @@ public class WelcomeView : Gtk.Box {
return destination_splitted[destination_splitted.length - 1];
}

private Gtk.FileChooserNative destination_chooser_new () {
var filechooser = new Gtk.FileChooserNative (
_("Choose a default destination"), window, Gtk.FileChooserAction.SELECT_FOLDER,
_("Select"), null
) {
private void show_destination_chooser () {
var filechooser = new Gtk.FileDialog () {
title = _("Choose a default destination"),
accept_label = _("Select"),
modal = true
};
filechooser.response.connect ((response_id) => {
if (response_id == Gtk.ResponseType.ACCEPT) {
string new_path = filechooser.get_file ().get_path ();
filechooser.select_folder.begin (window, null, (obj, res) => {
try {
var file = filechooser.select_folder.end (res);
if (file == null) {
return;
}

string new_path = file.get_path ();
set_destination (new_path);
auto_save_switch.active = true;
} catch (Error e) {
warning ("Failed to select folder: %s", e.message);

filechooser.destroy ();
return;
}

if (response_id == Gtk.ResponseType.CANCEL) {
// If the autosave switch was off previously, turn off the autosave switch
// because the user cancels setting the autosave destination
// If the autosave switch was on previously, then it means the user just cancels
Expand All @@ -233,15 +232,8 @@ public class WelcomeView : Gtk.Box {
if (autosave_dest == Application.SETTINGS_NO_AUTOSAVE) {
auto_save_switch.active = false;
}

filechooser.destroy ();
return;
}

filechooser.destroy ();
});

return filechooser;
}

public void show_success_button () {
Expand Down
6 changes: 6 additions & 0 deletions vapi/gtk4.deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
gio-2.0
cairo-gobject
gdk-pixbuf-2.0
graphene-gobject-1.0
pango
pangocairo
Loading

0 comments on commit 1c83cb8

Please sign in to comment.