mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 09:35:28 +00:00
implement set_default search provider method
This commit is contained in:
parent
5347ffbbfd
commit
58d4439fcf
2 changed files with 43 additions and 4 deletions
|
|
@ -18,28 +18,36 @@ impl Search {
|
|||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn build(connection: &Rc<RwLock<Connection>>, profile_id: &Rc<i64>) -> Self {
|
||||
pub fn build(connection: &Rc<RwLock<Connection>>, profile_id: &Rc<i64>) -> Result<Self, Error> {
|
||||
// Init children components
|
||||
let database = Database::init(connection, profile_id);
|
||||
let memory = Memory::init();
|
||||
|
||||
// Build initial index
|
||||
index(&database, &memory);
|
||||
index(&database, &memory)?;
|
||||
|
||||
// Return new `Self`
|
||||
Self { database, memory }
|
||||
Ok(Self { database, memory })
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/// Add new search provider record
|
||||
/// * requires valid [Uri](https://docs.gtk.org/glib/struct.Uri.html)
|
||||
pub fn add(&self, query: Uri, is_default: bool) -> Result<(), Error> {
|
||||
pub fn add(&self, query: &Uri, is_default: bool) -> Result<(), Error> {
|
||||
match self.database.add(query.to_string(), is_default) {
|
||||
Ok(_) => Ok(index(&self.database, &self.memory)?),
|
||||
Err(e) => Err(Error::Database(e)),
|
||||
}
|
||||
}
|
||||
/// Add new search provider record
|
||||
/// * requires valid [Uri](https://docs.gtk.org/glib/struct.Uri.html)
|
||||
pub fn set_default(&self, profile_search_id: i64) -> Result<(), Error> {
|
||||
match self.database.set_default(profile_search_id) {
|
||||
Ok(_) => Ok(index(&self.database, &self.memory)?),
|
||||
Err(e) => Err(Error::Database(e)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get records from the memory index
|
||||
pub fn records(&self) -> Vec<database::Row> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue