2022-02-22 14:17:50 +08:00
|
|
|
use clipboard::ClipbaordFile;
|
|
|
|
use hbb_common::message_proto::*;
|
|
|
|
|
|
|
|
pub fn clip_2_msg(clip: ClipbaordFile) -> Message {
|
|
|
|
match clip {
|
|
|
|
ClipbaordFile::ServerFormatList {
|
2022-02-24 11:22:19 +08:00
|
|
|
conn_id,
|
2022-02-22 14:17:50 +08:00
|
|
|
format_list,
|
|
|
|
} => {
|
|
|
|
let mut formats: Vec<CliprdrFormat> = Vec::new();
|
|
|
|
for v in format_list.iter() {
|
|
|
|
formats.push(CliprdrFormat {
|
2022-02-24 11:22:19 +08:00
|
|
|
conn_id: 0,
|
2022-02-22 14:17:50 +08:00
|
|
|
id: v.0,
|
|
|
|
format: v.1.clone(),
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
Message {
|
2022-07-14 17:20:01 +08:00
|
|
|
union: Some(message::Union::Cliprdr(Cliprdr {
|
|
|
|
union: Some(cliprdr::Union::FormatList(CliprdrServerFormatList {
|
2022-02-24 11:22:19 +08:00
|
|
|
conn_id,
|
2022-02-22 14:17:50 +08:00
|
|
|
formats,
|
|
|
|
..Default::default()
|
|
|
|
})),
|
|
|
|
..Default::default()
|
|
|
|
})),
|
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
}
|
2022-02-24 11:22:19 +08:00
|
|
|
ClipbaordFile::ServerFormatListResponse { conn_id, msg_flags } => Message {
|
2022-07-14 17:20:01 +08:00
|
|
|
union: Some(message::Union::Cliprdr(Cliprdr {
|
|
|
|
union: Some(cliprdr::Union::FormatListResponse(
|
2022-02-22 14:17:50 +08:00
|
|
|
CliprdrServerFormatListResponse {
|
2022-02-24 11:22:19 +08:00
|
|
|
conn_id,
|
2022-02-22 14:17:50 +08:00
|
|
|
msg_flags,
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
..Default::default()
|
|
|
|
})),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
ClipbaordFile::ServerFormatDataRequest {
|
2022-02-24 11:22:19 +08:00
|
|
|
conn_id,
|
2022-02-22 14:17:50 +08:00
|
|
|
requested_format_id,
|
|
|
|
} => Message {
|
2022-07-14 17:20:01 +08:00
|
|
|
union: Some(message::Union::Cliprdr(Cliprdr {
|
|
|
|
union: Some(cliprdr::Union::FormatDataRequest(
|
2022-02-22 14:17:50 +08:00
|
|
|
CliprdrServerFormatDataRequest {
|
2022-02-24 11:22:19 +08:00
|
|
|
conn_id,
|
2022-02-22 14:17:50 +08:00
|
|
|
requested_format_id,
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
..Default::default()
|
|
|
|
})),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
ClipbaordFile::ServerFormatDataResponse {
|
2022-02-24 11:22:19 +08:00
|
|
|
conn_id,
|
2022-02-22 14:17:50 +08:00
|
|
|
msg_flags,
|
|
|
|
format_data,
|
|
|
|
} => Message {
|
2022-07-14 17:20:01 +08:00
|
|
|
union: Some(message::Union::Cliprdr(Cliprdr {
|
|
|
|
union: Some(cliprdr::Union::FormatDataResponse(
|
2022-02-22 14:17:50 +08:00
|
|
|
CliprdrServerFormatDataResponse {
|
2022-02-24 11:22:19 +08:00
|
|
|
conn_id,
|
2022-02-22 14:17:50 +08:00
|
|
|
msg_flags,
|
2022-07-16 00:45:23 +08:00
|
|
|
format_data: format_data.into(),
|
2022-02-22 14:17:50 +08:00
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
..Default::default()
|
|
|
|
})),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
ClipbaordFile::FileContentsRequest {
|
2022-02-24 11:22:19 +08:00
|
|
|
conn_id,
|
2022-02-22 14:17:50 +08:00
|
|
|
stream_id,
|
|
|
|
list_index,
|
|
|
|
dw_flags,
|
|
|
|
n_position_low,
|
|
|
|
n_position_high,
|
|
|
|
cb_requested,
|
|
|
|
have_clip_data_id,
|
|
|
|
clip_data_id,
|
|
|
|
} => Message {
|
2022-07-14 17:20:01 +08:00
|
|
|
union: Some(message::Union::Cliprdr(Cliprdr {
|
|
|
|
union: Some(cliprdr::Union::FileContentsRequest(
|
2022-02-22 14:17:50 +08:00
|
|
|
CliprdrFileContentsRequest {
|
2022-02-24 11:22:19 +08:00
|
|
|
conn_id,
|
2022-02-22 14:17:50 +08:00
|
|
|
stream_id,
|
|
|
|
list_index,
|
|
|
|
dw_flags,
|
|
|
|
n_position_low,
|
|
|
|
n_position_high,
|
|
|
|
cb_requested,
|
|
|
|
have_clip_data_id,
|
|
|
|
clip_data_id,
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
..Default::default()
|
|
|
|
})),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
ClipbaordFile::FileContentsResponse {
|
2022-02-24 11:22:19 +08:00
|
|
|
conn_id,
|
2022-02-22 14:17:50 +08:00
|
|
|
msg_flags,
|
|
|
|
stream_id,
|
|
|
|
requested_data,
|
|
|
|
} => Message {
|
2022-07-14 17:20:01 +08:00
|
|
|
union: Some(message::Union::Cliprdr(Cliprdr {
|
|
|
|
union: Some(cliprdr::Union::FileContentsResponse(
|
2022-02-22 14:17:50 +08:00
|
|
|
CliprdrFileContentsResponse {
|
2022-02-24 11:22:19 +08:00
|
|
|
conn_id,
|
2022-02-22 14:17:50 +08:00
|
|
|
msg_flags,
|
|
|
|
stream_id,
|
2022-07-16 00:45:23 +08:00
|
|
|
requested_data: requested_data.into(),
|
2022-02-22 14:17:50 +08:00
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
..Default::default()
|
|
|
|
})),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn msg_2_clip(msg: Cliprdr) -> Option<ClipbaordFile> {
|
|
|
|
match msg.union {
|
2022-07-14 17:20:01 +08:00
|
|
|
Some(cliprdr::Union::FormatList(data)) => {
|
2022-02-22 14:17:50 +08:00
|
|
|
let mut format_list: Vec<(i32, String)> = Vec::new();
|
|
|
|
for v in data.formats.iter() {
|
|
|
|
format_list.push((v.id, v.format.clone()));
|
|
|
|
}
|
|
|
|
Some(ClipbaordFile::ServerFormatList {
|
2022-02-24 11:22:19 +08:00
|
|
|
conn_id: data.conn_id,
|
2022-02-22 14:17:50 +08:00
|
|
|
format_list,
|
|
|
|
})
|
|
|
|
}
|
2022-07-14 17:20:01 +08:00
|
|
|
Some(cliprdr::Union::FormatListResponse(data)) => {
|
2022-02-22 14:17:50 +08:00
|
|
|
Some(ClipbaordFile::ServerFormatListResponse {
|
2022-02-24 11:22:19 +08:00
|
|
|
conn_id: data.conn_id,
|
2022-02-22 14:17:50 +08:00
|
|
|
msg_flags: data.msg_flags,
|
|
|
|
})
|
|
|
|
}
|
2022-07-14 17:20:01 +08:00
|
|
|
Some(cliprdr::Union::FormatDataRequest(data)) => {
|
2022-02-22 14:17:50 +08:00
|
|
|
Some(ClipbaordFile::ServerFormatDataRequest {
|
2022-02-24 11:22:19 +08:00
|
|
|
conn_id: data.conn_id,
|
2022-02-22 14:17:50 +08:00
|
|
|
requested_format_id: data.requested_format_id,
|
|
|
|
})
|
|
|
|
}
|
2022-07-14 17:20:01 +08:00
|
|
|
Some(cliprdr::Union::FormatDataResponse(data)) => {
|
2022-02-22 14:17:50 +08:00
|
|
|
Some(ClipbaordFile::ServerFormatDataResponse {
|
2022-02-24 11:22:19 +08:00
|
|
|
conn_id: data.conn_id,
|
2022-02-22 14:17:50 +08:00
|
|
|
msg_flags: data.msg_flags,
|
2022-07-16 00:45:23 +08:00
|
|
|
format_data: data.format_data.as_ref().to_vec(),
|
2022-02-22 14:17:50 +08:00
|
|
|
})
|
|
|
|
}
|
2022-07-14 17:20:01 +08:00
|
|
|
Some(cliprdr::Union::FileContentsRequest(data)) => {
|
2022-02-22 14:17:50 +08:00
|
|
|
Some(ClipbaordFile::FileContentsRequest {
|
2022-02-24 11:22:19 +08:00
|
|
|
conn_id: data.conn_id,
|
2022-02-22 14:17:50 +08:00
|
|
|
stream_id: data.stream_id,
|
|
|
|
list_index: data.list_index,
|
|
|
|
dw_flags: data.dw_flags,
|
|
|
|
n_position_low: data.n_position_low,
|
|
|
|
n_position_high: data.n_position_high,
|
|
|
|
cb_requested: data.cb_requested,
|
|
|
|
have_clip_data_id: data.have_clip_data_id,
|
|
|
|
clip_data_id: data.clip_data_id,
|
|
|
|
})
|
|
|
|
}
|
2022-07-14 17:20:01 +08:00
|
|
|
Some(cliprdr::Union::FileContentsResponse(data)) => {
|
2022-02-22 14:17:50 +08:00
|
|
|
Some(ClipbaordFile::FileContentsResponse {
|
2022-02-24 11:22:19 +08:00
|
|
|
conn_id: data.conn_id,
|
2022-02-22 14:17:50 +08:00
|
|
|
msg_flags: data.msg_flags,
|
|
|
|
stream_id: data.stream_id,
|
2022-07-16 00:45:23 +08:00
|
|
|
requested_data: data.requested_data.as_ref().to_vec(),
|
2022-02-22 14:17:50 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|