diff options
| author | Max Audron <audron@cocaine.farm> | 2021-11-29 14:25:35 +0100 |
|---|---|---|
| committer | Max Audron <audron@cocaine.farm> | 2021-11-29 14:27:09 +0100 |
| commit | a05ebe460d2e12d2ff7f27cc087abeeded4ccf99 (patch) | |
| tree | a798cb82b9070cbb419ad35eed6f5e083de36d51 /src/message/signalproxy/objects/bufferview.rs | |
| parent | rework SyncProxy to use globally available channels (diff) | |
add BufferViewConfig implementation
Diffstat (limited to '')
| -rw-r--r-- | src/message/signalproxy/objects/bufferview.rs | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/src/message/signalproxy/objects/bufferview.rs b/src/message/signalproxy/objects/bufferview.rs index b522004..88ae56e 100644 --- a/src/message/signalproxy/objects/bufferview.rs +++ b/src/message/signalproxy/objects/bufferview.rs @@ -3,6 +3,7 @@ use std::{collections::HashMap, convert::TryFrom, convert::TryInto}; use libquassel_derive::{NetworkList, NetworkMap}; use crate::message::signalproxy::translation::Network; +use crate::message::{StatefulSyncableClient, StatefulSyncableServer, SyncProxy, Syncable}; use crate::primitive::{Variant, VariantList}; #[derive(Debug, Clone, PartialEq)] @@ -86,3 +87,125 @@ pub struct BufferViewConfig { #[network(rename = "showSearch")] pub show_search: bool, } + +#[allow(dead_code)] +impl BufferViewConfig { + // TODO add sync to all functions + // TODO requestAddBuffer(bufferId: BufferId, pos: Int) + // TODO requestMoveBuffer(bufferId: BufferId, pos: Int) + // TODO requestRemoveBuffer(bufferId: BufferId) + // TODO requestRemoveBufferPermanently(bufferId: BufferId) + // TODO requestSetBufferViewName(bufferViewName: QString) + // /** + // * Replaces all properties of the object with the content of the + // * "properties" parameter. This parameter is in network representation. + // */ + // DONE requestUpdate(properties: QVariantMap) + + // // S->C calls + // DONE addBuffer(bufferId: BufferId, pos: Int) + // DONE moveBuffer(bufferId: BufferId, pos: Int) + // DONE removeBuffer(bufferId: BufferId) + // DONE removeBufferPermanently(bufferId: BufferId) + // TODO setAddNewBuffersAutomatically(addNewBuffersAutomatically: Bool) + // TODO setAllowedBufferTypes(bufferTypes: Int) + // TODO setBufferViewName(bufferViewName: QString) + // TODO setDisableDecoration(disableDecoration: Bool) + // TODO setHideInactiveBuffers(hideInactiveBuffers: Bool) + // TODO setHideInactiveNetworks(hideInactiveNetworks: Bool) + // TODO setMinimumActivity(activity: Int) + // TODO setNetworkId(networkId: NetworkId) + // TODO setShowSearch(showSearch: Bool) + // TODO setSortAlphabetically(sortAlphabetically: Bool) + + fn add_buffer(&mut self, id: i32, pos: usize) { + if !self.buffers.contains(&id) { + self.buffers.insert(pos, id) + } + + #[cfg(feature = "server")] + { + // TODO replace the None with self.buffer_view_id + self.send_sync(None, "addBuffer", vec![id.into(), (pos as i32).into()]) + } + } + + fn move_buffer(&mut self, id: i32, pos: usize) { + let old_pos = self.buffers.iter().position(|&x| x == id).unwrap(); + self.buffers.remove(old_pos); + self.buffers.insert(pos, id); + } + + fn remove_buffer(&mut self, id: i32) { + if self.buffers.contains(&id) { + let old_pos = self.buffers.iter().position(|&x| x == id).unwrap(); + self.buffers.remove(old_pos); + } + + if self.removed_buffers.contains(&id) { + let old_pos = self.removed_buffers.iter().position(|&x| x == id).unwrap(); + self.removed_buffers.remove(old_pos); + } + + if !self.temporarily_removed_buffers.contains(&id) { + self.buffers.push(id) + } + } + + fn remove_buffer_permanently(&mut self, id: i32) { + if self.buffers.contains(&id) { + let old_pos = self.buffers.iter().position(|&x| x == id).unwrap(); + self.buffers.remove(old_pos); + } + + if self.temporarily_removed_buffers.contains(&id) { + let old_pos = self.removed_buffers.iter().position(|&x| x == id).unwrap(); + self.removed_buffers.remove(old_pos); + } + + if !self.removed_buffers.contains(&id) { + self.buffers.push(id) + } + } +} + +#[cfg(feature = "client")] +impl StatefulSyncableClient for BufferViewConfig { + fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) + where + Self: Sized, + { + log::debug!("entering bufferviewconfig sync_custom()"); + match msg.slot_name.as_str() { + "addBuffer" => self.add_buffer( + msg.params.remove(0).try_into().unwrap(), + i32::try_from(msg.params.remove(0)).unwrap() as usize, + ), + "moveBuffer" => self.move_buffer( + msg.params.remove(0).try_into().unwrap(), + i32::try_from(msg.params.remove(0)).unwrap() as usize, + ), + "removeBuffer" => self.remove_buffer(msg.params.remove(0).try_into().unwrap()), + "removeBufferPermanently" => { + self.remove_buffer_permanently(msg.params.remove(0).try_into().unwrap()) + } + _ => (), + } + } +} + +#[cfg(feature = "server")] +impl StatefulSyncableServer for BufferViewConfig { + fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) + where + Self: Sized, + { + match msg.slot_name.as_str() { + _ => (), + } + } +} + +impl Syncable for BufferViewConfig { + const CLASS: &'static str = "BufferViewConfig"; +} |
