Skip to content

Commit 700a363

Browse files
committed
.
1 parent 959ddd0 commit 700a363

3 files changed

Lines changed: 73 additions & 15 deletions

File tree

src/cxx_qt_bridge.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ pub mod qobject {
1414
Downgrade,
1515
}
1616

17+
#[qenum]
18+
#[namespace = "InstallStatus"]
19+
enum InstallStatus {
20+
OkToInstall,
21+
DependencyIssue,
22+
DiskSpaceInsufficient,
23+
Other,
24+
}
25+
1726
impl cxx_qt::Threading for DebInstaller {}
1827

1928
extern "RustQt" {
@@ -29,6 +38,7 @@ pub mod qobject {
2938
#[qproperty(bool, finished)]
3039
#[qproperty(QString, path)]
3140
#[qproperty(InstallAction, action)]
41+
#[qproperty(InstallStatus, status)]
3242
type DebInstaller = super::DebInstallerRust;
3343

3444
#[qinvokable]
@@ -50,9 +60,12 @@ use core::pin::Pin;
5060
use cxx_qt::Threading;
5161
use cxx_qt_lib::QString;
5262
use gettextrs::pgettext;
53-
use oma_pm::apt::{AptConfig, OmaApt, OmaAptArgs};
63+
use oma_pm::apt::{AptConfig, OmaApt, OmaAptArgs, OmaAptError};
5464

55-
use crate::{Progress, cxx_qt_bridge::qobject::InstallAction};
65+
use crate::{
66+
Progress,
67+
cxx_qt_bridge::qobject::{InstallAction, InstallStatus},
68+
};
5669

5770
pub struct DebInstallerRust {
5871
pub package: QString,
@@ -65,6 +78,7 @@ pub struct DebInstallerRust {
6578
pub progress: f32,
6679
pub is_installing: bool,
6780
pub finished: bool,
81+
pub status: InstallStatus,
6882
}
6983

7084
impl Default for DebInstallerRust {
@@ -80,6 +94,7 @@ impl Default for DebInstallerRust {
8094
is_installing: false,
8195
finished: false,
8296
action: InstallAction::Install,
97+
status: InstallStatus::OkToInstall,
8398
}
8499
}
85100
}
@@ -125,6 +140,27 @@ impl qobject::DebInstaller {
125140
};
126141

127142
this.as_mut().set_action(action);
143+
let result = apt
144+
.install(&[pkg], true)
145+
.and_then(|_| apt.resolve(false, false));
146+
147+
let mut status = InstallStatus::OkToInstall;
148+
149+
if let Err(e) = result {
150+
match e {
151+
OmaAptError::DependencyIssue { .. } => {
152+
status = InstallStatus::DependencyIssue;
153+
}
154+
OmaAptError::DiskSpaceInsufficient(_, _) => {
155+
status = InstallStatus::DiskSpaceInsufficient;
156+
}
157+
_ => {
158+
status = InstallStatus::Other;
159+
}
160+
}
161+
}
162+
163+
this.as_mut().set_status(status);
128164
}
129165
}
130166

src/main.qml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,40 @@ Kirigami.ApplicationWindow {
6464
anchors.margins: Kirigami.Units.largeSpacing
6565
spacing: Kirigami.Units.mediumSpacing
6666

67+
Kirigami.AbstractCard {
68+
Layout.fillWidth: true
69+
visible: !installer.is_installing && !installer.finished
70+
71+
contentItem: ColumnLayout {
72+
Controls.Label {
73+
text: installer.pkg_description
74+
font.bold: true
75+
wrapMode: Text.WordWrap
76+
Layout.fillWidth: true
77+
}
78+
79+
Controls.Label {
80+
text: installer.pkg_version
81+
}
82+
83+
Controls.Label {
84+
text: {
85+
switch (installer.status) {
86+
case DebInstaller.OkToInstall:
87+
return installer.i18n("OK to install");
88+
case DebInstaller.DependencyIssue:
89+
return installer.i18n("Dependencies unmet");
90+
case DebInstaller.DiskSpaceInsufficient:
91+
return installer.i18n("Insufficient disk space");
92+
case DebInstaller.Other:
93+
return installer.i18n("other");
94+
}
95+
}
96+
}
97+
}
98+
99+
}
100+
67101
ColumnLayout {
68102
visible: !installer.is_installing && !installer.finished
69103
spacing: Kirigami.Units.smallSpacing

src/main.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ use anyhow::{Context, Result};
1212
use backend::Backend;
1313
use clap::Parser;
1414
use gettextrs::{bind_textdomain_codeset, bindtextdomain, setlocale, textdomain};
15-
use oma_pm::{
16-
apt::{OmaApt, OmaAptError},
17-
matches::PackagesMatcher,
18-
pkginfo::OmaPackage,
19-
};
15+
use oma_pm::{apt::OmaApt, matches::PackagesMatcher, pkginfo::OmaPackage};
2016
use tokio::fs::create_dir_all;
2117
use tracing::{debug, error, level_filters::LevelFilter};
2218
use tracing_subscriber::{EnvFilter, Layer, fmt, layer::SubscriberExt, util::SubscriberInitExt};
@@ -60,14 +56,6 @@ pub enum Progress {
6056
Done,
6157
}
6258

63-
fn u8_oma_pm_errors(error: &OmaAptError) -> u8 {
64-
match error {
65-
OmaAptError::DependencyIssue { .. } => 6,
66-
OmaAptError::DiskSpaceInsufficient(_, _) => 17,
67-
_ => 255,
68-
}
69-
}
70-
7159
fn main() {
7260
let Args {
7361
package,

0 commit comments

Comments
 (0)