1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::{c, to_cstring, ChannelRef};
use std::ptr;

/// Gets the current channel context.
pub fn get_current_channel() -> ChannelRef {
    ChannelRef {
        handle: unsafe { c!(hexchat_get_context) },
    }
}
/// Gets the channel that's currently focused in the HexChat window. Returns the `ChannelRef` if
/// found, or `None` if none exists.
pub fn get_focused_channel() -> Option<ChannelRef> {
    let handle = unsafe { c!(hexchat_find_context, ptr::null(), ptr::null()) };
    if handle.is_null() {
        None
    } else {
        Some(ChannelRef { handle })
    }
}
/// Gets the frontmost channel in a particular server. Returns the `ChannelRef` if found, or
/// `None` if none exists.
pub fn get_focused_channel_in_server(server_name: &str) -> Option<ChannelRef> {
    let server_name = to_cstring(server_name);
    let handle = unsafe { c!(hexchat_find_context, server_name.as_ptr(), ptr::null()) };
    if handle.is_null() {
        None
    } else {
        Some(ChannelRef { handle })
    }
}
/// Gets the first channel with the specified name in any server. Returns the `ChannelRef` if
/// found, or `None` if none exists.
pub fn get_first_channel(channel_name: &str) -> Option<ChannelRef> {
    let channel_name = to_cstring(channel_name);
    let handle = unsafe { c!(hexchat_find_context, ptr::null(), channel_name.as_ptr()) };
    if handle.is_null() {
        None
    } else {
        Some(ChannelRef { handle })
    }
}
/// Gets the first channel with the specified name in the specified server. Returns the
/// `ChannelRef` if found, or `None` if none exists.
pub fn get_channel(server_name: &str, channel_name: &str) -> Option<ChannelRef> {
    let channel_name = to_cstring(channel_name);
    let server_name = to_cstring(server_name);
    let handle = unsafe {
        c!(
            hexchat_find_context,
            server_name.as_ptr(),
            channel_name.as_ptr()
        )
    };
    if handle.is_null() {
        None
    } else {
        Some(ChannelRef { handle })
    }
}