Skip to content

Commit

Permalink
Use GtkFileChooserNative so that the application is able to graphical…
Browse files Browse the repository at this point in the history
…ly pick files through Flatpak without requiring further file system permissions.
  • Loading branch information
marin-m committed Nov 2, 2020
1 parent 9c3b1ff commit 33d1968
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 31 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repository = "https://github.com/marin-m/SongRec"
readme = "README.md"
keywords = ["shazam", "audio", "audio-fingerprinting"]
categories = ["multimedia::audio", "command-line-utilities"]
version = "0.1.1"
version = "0.1.2"
authors = ["marin-m"]
edition = "2018"

Expand All @@ -23,12 +23,12 @@ rodio = "0.12.0" # For reading WAV/MP3/FLAG/OGG files, resampling and playing au
clap = "2.33.2" # For argument parsing
cpal = "0.12.1" # For recording audio
gag = "0.1.10" # Crate to silence stderr when CPAL produces uncontrolled AlsaLib output
gtk = "0.9.1" # For the GUI
gio = "0.9.0"
gtk = { version = "0.9.2", features = ["v3_20"] } # For the GUI
gio = "0.9.1"
hound = "3.4.0" # For writing WAV files
serde_json = "1.0.57" # For decoding and encoding JSON
uuid = { version = "0.8.1", features = ["v4"] }
glib = "0.10.1"
glib = "0.10.3"
percent-encoding = "2.1.0" # For percent-encoding contents in URLs
serde = { version = "1.0.115", features = ["derive"] }
csv = "1.1.3"
Expand Down
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,27 @@ Shazam also downsamples the sound at 16 KHz before processing, and cuts the soun

Hence, the Shazam fingerprinting algorithm, as implemented by the client, is fairly simple, as much of the processing is done server-side. The general functionment of Shazam has been documented in public [research papers](https://www.ee.columbia.edu/~dpwe/papers/Wang03-shazam.pdf) and patents.

## Compilation
## Installation

SongRec may be available in the software center of your distribution if it supports Flatpak or Snap.

Here are commands to install and run it through the command line:

Using Snap:

Using Flatpak:

```
```

Using APT:

```
```

## Compilation from sources

(**WARNING**: Remind to compile the code in "--release" mode for correct performance.)

Expand Down
4 changes: 1 addition & 3 deletions packaging/flatpak/com.github.marinm.songrec.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"--socket=fallback-x11",
"--socket=wayland",
"--device=dri",
"--filesystem=host:ro",
"--filesystem=/tmp:ro",
"--filesystem=xdg-data",
"--filesystem=home:ro",
"--socket=pulseaudio"
],
"build-options": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ https://hughsie.github.io/oars/index.html
-->
<content_rating type="oars-1.0" />
<releases>
<release version="0.1.2" date="2020-11-02">
<description>
<p>- Use GtkFileChooserNative so that the application is able to graphically pick files through Flatpak without requiring further file system permissions.</p>
</description>
</release>
<release version="0.1.1" date="2020-11-01">
<description>
<p>- Add Flatpak packaging scripts and assets.</p>
Expand Down
38 changes: 15 additions & 23 deletions src/gui/main_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,16 @@ pub fn gui_main(recording: bool) -> Result<(), Box<dyn Error>> {

// Handle various controls

let processing_tx_3 = processing_tx.clone();

recognize_file_button.connect_clicked(clone!(@weak window, @weak spinner, @weak recognize_file_button => move |_| {

let file_chooser = gtk::FileChooserDialog::new(
let file_chooser = gtk::FileChooserNative::new(
Some("Select a file to recognize"),
Some(&window),
gtk::FileChooserAction::Open
gtk::FileChooserAction::Open,
Some("_Open"),
Some("_Cancel")
);

let file_filter = gtk::FileFilter::new();
Expand All @@ -203,28 +207,16 @@ pub fn gui_main(recording: bool) -> Result<(), Box<dyn Error>> {

file_chooser.set_filter(&file_filter);

file_chooser.add_buttons(&[
("Open", ResponseType::Ok),
("Cancel", ResponseType::Cancel)
]);

let processing_tx_3 = processing_tx.clone();

file_chooser.connect_response(move |file_chooser, response| {
if response == ResponseType::Ok {
recognize_file_button.hide();

spinner.show();

let input_file_path = file_chooser.get_filename().expect("Couldn't get filename");
let input_file_string = input_file_path.to_str().unwrap().to_string();

processing_tx_3.send(ProcessingMessage::ProcessAudioFile(input_file_string)).unwrap();
}
if file_chooser.run() == ResponseType::Accept {
recognize_file_button.hide();

spinner.show();

let input_file_path = file_chooser.get_filename().expect("Couldn't get filename");
let input_file_string = input_file_path.to_str().unwrap().to_string();

file_chooser.close();
});
file_chooser.show_all();
processing_tx_3.send(ProcessingMessage::ProcessAudioFile(input_file_string)).unwrap();
};

}));

Expand Down

0 comments on commit 33d1968

Please sign in to comment.