From d40eb89df9e0c8241cec89adc24a399312e9d1df Mon Sep 17 00:00:00 2001 From: Artur Kovacs Date: Sat, 23 May 2020 16:19:17 +0200 Subject: [PATCH] Renamed set/get_contents to set/get_text. Updated the license file structure. --- Cargo.toml | 4 ++-- LICENSE.apache2 => LICENSE-APACHE.txt | 28 ++------------------------- LICENSE-MIT.txt | 21 ++++++++++++++++++++ LICENSE.mit | 25 ------------------------ LICENSE.txt | 4 ++++ README.md | 19 +++++++----------- examples/primary_selection.rs | 2 +- src/common.rs | 7 +++---- src/lib.rs | 4 ++-- src/nop_clipboard.rs | 4 ++-- src/osx_clipboard.rs | 4 ++-- src/windows_clipboard.rs | 4 ++-- src/x11_clipboard.rs | 4 ++-- 13 files changed, 50 insertions(+), 80 deletions(-) rename LICENSE.apache2 => LICENSE-APACHE.txt (89%) create mode 100644 LICENSE-MIT.txt delete mode 100644 LICENSE.mit create mode 100644 LICENSE.txt diff --git a/Cargo.toml b/Cargo.toml index c4778da..d59c47d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT / Apache-2.0" keywords = ["clipboard"] [target.'cfg(windows)'.dependencies] -clipboard-win = "2.1" +clipboard-win = "3.0" [target.'cfg(target_os = "macos")'.dependencies] objc = "0.2" @@ -16,4 +16,4 @@ objc_id = "0.1" objc-foundation = "0.1" [target.'cfg(all(unix, not(any(target_os="macos", target_os="android", target_os="emscripten"))))'.dependencies] -x11-clipboard = "0.3" +x11-clipboard = "0.5" diff --git a/LICENSE.apache2 b/LICENSE-APACHE.txt similarity index 89% rename from LICENSE.apache2 rename to LICENSE-APACHE.txt index ad410e1..f433b1a 100644 --- a/LICENSE.apache2 +++ b/LICENSE-APACHE.txt @@ -1,4 +1,5 @@ -Apache License + + Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -174,28 +175,3 @@ Apache License of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file diff --git a/LICENSE-MIT.txt b/LICENSE-MIT.txt new file mode 100644 index 0000000..a6e1598 --- /dev/null +++ b/LICENSE-MIT.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 The arboard contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/LICENSE.mit b/LICENSE.mit deleted file mode 100644 index c8b9dd0..0000000 --- a/LICENSE.mit +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2017 Avraham Weinstock - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..e45cefd --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,4 @@ +Copyright (c) 2020 The arboard contributors + +This software is licensed under either the MIT (see LICENSE-MIT.txt) license +or the Apache 2.0 (see LICENSE-APACHE.txt) license at your option. diff --git a/README.md b/README.md index 51e38cf..f53503c 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,7 @@ -# rust-clipboard +# arboard -rust-clipboard is a cross-platform library for getting and setting the contents of the OS-level clipboard. -It has been tested on Windows, Mac OSX, GNU/Linux, and FreeBSD. -It is used in Mozilla Servo. - -[![](http://meritbadge.herokuapp.com/clipboard)](https://crates.io/crates/clipboard) -[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/github/aweinstock314/rust-clipboard)](https://ci.appveyor.com/project/aweinstock314/rust-clipboard) -[![Travis Build Status](https://travis-ci.org/aweinstock314/rust-clipboard.svg?branch=master)](https://travis-ci.org/aweinstock314/rust-clipboard) +This crate is a fork of rust-clipboard and a cross-platform library for getting and setting the contents of the OS-level clipboard. +It adds wayland support ## Prerequisites @@ -26,8 +21,8 @@ use clipboard::ClipboardContext; fn example() { let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap(); - println!("{:?}", ctx.get_contents()); - ctx.set_contents("some string".to_owned()).unwrap(); + println!("{:?}", ctx.get_text()); + ctx.set_text("some string".to_owned()).unwrap(); } ``` @@ -37,8 +32,8 @@ The `ClipboardProvider` trait has the following functions: ```rust fn new() -> Result>; -fn get_contents(&mut self) -> Result>; -fn set_contents(&mut self, String) -> Result<(), Box>; +fn get_text(&mut self) -> Result>; +fn set_text(&mut self, String) -> Result<(), Box>; ``` `ClipboardContext` is a type alias for one of {`WindowsClipboardContext`, `OSXClipboardContext`, `X11ClipboardContext`, `NopClipboardContext`}, all of which implement `ClipboardProvider`. Which concrete type is chosen for `ClipboardContext` depends on the OS (via conditional compilation). diff --git a/examples/primary_selection.rs b/examples/primary_selection.rs index b9812c0..fd3d170 100644 --- a/examples/primary_selection.rs +++ b/examples/primary_selection.rs @@ -10,7 +10,7 @@ fn main() { let the_string = "Hello, world!"; - ctx.set_contents(the_string.to_owned()).unwrap(); + ctx.set_text(the_string.to_owned()).unwrap(); } #[cfg(not(target_os = "linux"))] diff --git a/src/common.rs b/src/common.rs index 92f80d5..af9563a 100644 --- a/src/common.rs +++ b/src/common.rs @@ -15,6 +15,7 @@ limitations under the License. */ use std::error::Error; +use std::borrow::Cow; pub fn err(s: &str) -> Box { Box::::from(s) @@ -26,9 +27,7 @@ pub trait ClipboardProvider: Sized { // TODO: consider replacing Box with an associated type? fn new() -> Result>; /// Method to get the clipboard contents as a String - fn get_contents(&mut self) -> Result>; + fn get_text(&mut self) -> Result>; /// Method to set the clipboard contents as a String - fn set_contents(&mut self, String) -> Result<(), Box>; - // TODO: come up with some platform-agnostic API for richer types - // than just strings (c.f. issue #31) + fn set_text(&mut self, text: String) -> Result<(), Box>; } diff --git a/src/lib.rs b/src/lib.rs index de6169b..d411880 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,6 +61,6 @@ pub type ClipboardContext = nop_clipboard::NopClipboardContext; #[test] fn test_clipboard() { let mut ctx = ClipboardContext::new().unwrap(); - ctx.set_contents("some string".to_owned()).unwrap(); - assert!(ctx.get_contents().unwrap() == "some string"); + ctx.set_text("some string".to_owned()).unwrap(); + assert!(ctx.get_text().unwrap() == "some string"); } diff --git a/src/nop_clipboard.rs b/src/nop_clipboard.rs index 75a2913..557a81a 100644 --- a/src/nop_clipboard.rs +++ b/src/nop_clipboard.rs @@ -23,12 +23,12 @@ impl ClipboardProvider for NopClipboardContext { fn new() -> Result> { Ok(NopClipboardContext) } - fn get_contents(&mut self) -> Result> { + fn get_text(&mut self) -> Result> { println!("Attempting to get the contents of the clipboard, which hasn't yet been \ implemented on this platform."); Ok("".to_string()) } - fn set_contents(&mut self, _: String) -> Result<(), Box> { + fn set_text(&mut self, _: String) -> Result<(), Box> { println!("Attempting to set the contents of the clipboard, which hasn't yet been \ implemented on this platform."); Ok(()) diff --git a/src/osx_clipboard.rs b/src/osx_clipboard.rs index cf8c0b3..717c41d 100644 --- a/src/osx_clipboard.rs +++ b/src/osx_clipboard.rs @@ -40,7 +40,7 @@ impl ClipboardProvider for OSXClipboardContext { let pasteboard: Id = unsafe { Id::from_ptr(pasteboard) }; Ok(OSXClipboardContext { pasteboard: pasteboard }) } - fn get_contents(&mut self) -> Result> { + fn get_text(&mut self) -> Result> { let string_class: Id = { let cls: Id = unsafe { Id::from_ptr(class("NSString")) }; unsafe { transmute(cls) } @@ -61,7 +61,7 @@ impl ClipboardProvider for OSXClipboardContext { Ok(string_array[0].as_str().to_owned()) } } - fn set_contents(&mut self, data: String) -> Result<(), Box> { + fn set_text(&mut self, data: String) -> Result<(), Box> { let string_array = NSArray::from_vec(vec![NSString::from_str(&data)]); let _: usize = unsafe { msg_send![self.pasteboard, clearContents] }; let success: bool = unsafe { msg_send![self.pasteboard, writeObjects:string_array] }; diff --git a/src/windows_clipboard.rs b/src/windows_clipboard.rs index f534407..586b59f 100644 --- a/src/windows_clipboard.rs +++ b/src/windows_clipboard.rs @@ -25,10 +25,10 @@ impl ClipboardProvider for WindowsClipboardContext { fn new() -> Result> { Ok(WindowsClipboardContext) } - fn get_contents(&mut self) -> Result> { + fn get_text(&mut self) -> Result> { Ok(get_clipboard_string()?) } - fn set_contents(&mut self, data: String) -> Result<(), Box> { + fn set_text(&mut self, data: String) -> Result<(), Box> { Ok(set_clipboard_string(&data)?) } } diff --git a/src/x11_clipboard.rs b/src/x11_clipboard.rs index 79d34aa..b750f2f 100644 --- a/src/x11_clipboard.rs +++ b/src/x11_clipboard.rs @@ -54,7 +54,7 @@ where Ok(X11ClipboardContext(X11Clipboard::new()?, PhantomData)) } - fn get_contents(&mut self) -> Result> { + fn get_text(&mut self) -> Result> { Ok(String::from_utf8(self.0.load( S::atom(&self.0.getter.atoms), self.0.getter.atoms.utf8_string, @@ -63,7 +63,7 @@ where )?)?) } - fn set_contents(&mut self, data: String) -> Result<(), Box> { + fn set_text(&mut self, data: String) -> Result<(), Box> { Ok(self.0.store( S::atom(&self.0.setter.atoms), self.0.setter.atoms.utf8_string,