Commit 04544d3d authored by Felix Häcker's avatar Felix Häcker
Browse files

Open FlatpakRefs with known repositories directly in Souk

parent 1e17b01c
Pipeline #243191 passed with stages
in 15 minutes and 52 seconds
......@@ -18,6 +18,7 @@ use crate::db::SoukDatabase;
use crate::sideload;
use crate::ui::about_dialog;
use crate::ui::pages::{ExplorePage, InstalledPage, LoadingPage, PackageDetailsPage, SearchPage};
use crate::ui::utils;
use crate::ui::{SoukApplicationWindow, View};
#[derive(Debug, Clone)]
......@@ -142,7 +143,7 @@ impl ApplicationImpl for SoukApplicationPrivate {
// Wrap SoukApplicationPrivate into a usable gtk-rs object
glib_wrapper! {
pub struct SoukApplication(ObjectSubclass<SoukApplicationPrivate>)
@extends gio::Application, gtk::Application;
@extends gio::ActionGroup, gio::ActionMap, gio::Application, gtk::Application;
}
// SoukApplication implementation itself
......@@ -273,6 +274,26 @@ impl SoukApplication {
);
app.set_accels_for_action("app.rebuild-database", &["<primary>r"]);
// app.details-pkg-ref
action!(
app,
"details-pkg-ref",
Some(&glib::VariantType::new("s").unwrap()),
clone!(@strong sender, @weak self_.flatpak_backend as flatpak_backend => move |_, v| {
let flatpak_ref = v.unwrap().get_str().unwrap().to_string();
debug!("Show details for {}", &flatpak_ref);
// TODO: This conflicts with database rebuild process and only works
// when no data rebuild process is running while startup...
match flatpak_backend.get_package_by_ref(flatpak_ref.clone()) {
Some(package) => send!(sender, Action::ViewSet(View::PackageDetails(package))),
None => utils::show_error_dialog(&format!("No details for {} available", flatpak_ref)),
}
//send!(sender, Action::DatabasePopulate);
})
);
// win.go-back
action!(
window,
......
......@@ -229,6 +229,21 @@ impl SoukFlatpakBackend {
None
}
pub fn get_package_by_ref(&self, flatpak_ref: String) -> Option<SoukPackage> {
let f_ref = flatpak::Ref::parse(&flatpak_ref).unwrap();
// TODO: We're currently only searching for the flatpak ref inside the database,
// and ignore the remote information completely. But it is possible to have a package
// with the same ref from two different remotes.
//
// To fix this we should extend the database schema to also include the remote URL.
// Why the URL? Because the remote name itself is not unique, and it's user changeable.
match queries::get_packages_by_ref(f_ref).unwrap().pop() {
Some(package) => Some(package),
None => None,
}
}
fn is_sandboxed() -> bool {
std::path::Path::new("/.flatpak-info").exists()
}
......
use crate::db;
use crate::db::*;
use crate::diesel::prelude::*;
use diesel::dsl::sql;
use flatpak::prelude::*;
use crate::backend::SoukPackage;
use crate::db;
use crate::db::*;
use crate::diesel::prelude::*;
#[allow(dead_code)]
pub enum DisplayLevel {
......@@ -47,6 +48,28 @@ pub fn get_package(
Ok(packages.pop().map(|p| p.into()))
}
pub fn get_packages_by_ref(
flatpak_ref: flatpak::Ref,
) -> Result<Vec<SoukPackage>, diesel::result::Error> {
use crate::db::schema::appstream_packages::dsl::*;
let con = connect_db!();
dbg!(flatpak_ref.format_ref().unwrap().to_string());
let mut packages = appstream_packages
.filter(name.eq(flatpak_ref.get_name().unwrap().to_string()))
.filter(branch.eq(flatpak_ref.get_branch().unwrap().to_string()))
.filter(arch.eq(flatpak_ref.get_arch().unwrap().to_string()))
.load::<DbPackage>(&con)?;
let mut result: Vec<SoukPackage> = Vec::new();
for p in packages {
result.insert(0, p.into());
}
Ok(result)
}
pub fn get_db_package(
pkg_app_id: String,
pkg_branch: String,
......
......@@ -83,6 +83,10 @@ pub async fn sideload_file(sideload_file: gio::File) {
SideloadFlags::BundleAlreadyInstalled(ref_name)
| SideloadFlags::RefAlreadyAddedRemote(ref_name) => {
debug!("No need to sideload, stop sideloading.");
app.activate();
app.activate_action("details-pkg-ref", Some(&ref_name.to_variant()));
return;
}
_ => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment