flameshot/params/
gui.rs

1#[cfg(feature = "serde")]
2use serde::{Deserialize, Serialize};
3
4use crate::CmdParameters;
5
6#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Hash, Ord)]
7#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8/// Allows to build parameters for flameshot gui capture
9pub struct GuiArgs {
10    path: Option<String>,
11    clipboard: bool,
12    delay: Option<usize>,
13    region: Option<(usize, usize, usize, usize)>,
14    last_region: bool,
15    raw: bool,
16    print_geometry: bool,
17    upload: bool,
18    pin: bool,
19    accept_on_select: bool,
20    pub args: Vec<String>,
21}
22
23impl GuiArgs {
24    pub fn builder() -> GuiArgsBuilder {
25        GuiArgsBuilder::default()
26    }
27}
28
29impl CmdParameters for GuiArgs {
30    fn generate_args(&self) -> Vec<String> {
31        let mut args = vec![String::from("gui")];
32        if let Some(path) = self.path.to_owned() {
33            args.push(format!("--path={path}"));
34        };
35
36        if self.clipboard {
37            args.push(String::from("--clipboard"));
38        };
39
40        if let Some(delay) = self.delay {
41            args.push(format!("--delay={delay}"));
42        };
43
44        if let Some(region) = self.region {
45            args.push(format!(
46                "--region={},{},{},{}",
47                region.0, region.1, region.2, region.3,
48            ));
49        };
50
51        if self.last_region {
52            args.push(String::from("--last-region"));
53        }
54
55        if self.raw {
56            args.push(String::from("--raw"));
57        };
58
59        if self.print_geometry {
60            args.push(String::from("--print-geometry"));
61        }
62
63        if self.upload {
64            args.push(String::from("--upload"));
65        };
66
67        if self.pin {
68            args.push(String::from("--pin"));
69        }
70
71        if self.accept_on_select {
72            args.push(String::from("--accept-on-select"))
73        }
74
75        args
76    }
77}
78#[derive(Default)]
79pub struct GuiArgsBuilder {
80    path: Option<String>,
81    clipboard: bool,
82    delay: Option<usize>,
83    region: Option<(usize, usize, usize, usize)>,
84    last_region: bool,
85    raw: bool,
86    print_geometry: bool,
87    upload: bool,
88    pin: bool,
89    accept_on_select: bool,
90    pub args: Vec<String>,
91}
92
93impl GuiArgsBuilder {
94    pub fn path(mut self, path: &str) -> Self {
95        self.path = Some(path.to_string());
96        self
97    }
98
99    pub fn clipboard(mut self) -> Self {
100        self.clipboard = true;
101        self
102    }
103
104    pub fn delay(mut self, delay: usize) -> Self {
105        self.delay = Some(delay);
106        self
107    }
108
109    pub fn region(mut self, region: (usize, usize, usize, usize)) -> Self {
110        self.region = Some(region);
111        self
112    }
113
114    pub fn last_region(mut self) -> Self {
115        self.last_region = true;
116        self
117    }
118
119    pub fn raw(mut self) -> Self {
120        self.raw = true;
121        self
122    }
123
124    pub fn print_geometry(mut self) -> Self {
125        self.print_geometry = true;
126        self
127    }
128
129    pub fn upload(mut self) -> Self {
130        self.upload = true;
131        self
132    }
133
134    pub fn pin(mut self) -> Self {
135        self.pin = true;
136        self
137    }
138
139    pub fn accept_on_select(mut self) -> Self {
140        self.accept_on_select = true;
141        self
142    }
143
144    pub fn build(self) -> GuiArgs {
145        let mut cmd = GuiArgs {
146            path: self.path,
147            clipboard: self.clipboard,
148            delay: self.delay,
149            region: self.region,
150            last_region: self.last_region,
151            raw: self.raw,
152            print_geometry: self.print_geometry,
153            upload: self.upload,
154            pin: self.pin,
155            accept_on_select: self.accept_on_select,
156            args: self.args,
157        };
158        cmd.args = cmd.generate_args();
159
160        cmd
161    }
162}