Commit 067d1a40 authored by Daniel García Moreno's avatar Daniel García Moreno

Different util and global module for gtk and api

parent 52b60d19
Pipeline #1291 passed with stage
in 26 minutes and 26 seconds
pub static TIMEOUT: u64 = 10;
pub static PAGE_LIMIT: i32 = 40;
pub static CACHE_SIZE: usize = 40;
......@@ -619,20 +619,6 @@ pub fn parse_room_message(baseu: &Url, roomid: String, msg: &JsonValue) -> Messa
}
}
pub fn markup(s: &str) -> String {
let mut out = String::from(s);
out = String::from(out.trim());
out = out.replace('&', "&");
out = out.replace('<', "&lt;");
out = out.replace('>', "&gt;");
let re = Regex::new("(?P<url>https?://[^\\s&,)(\"]+(&\\w=[\\w._-]?)*(#[\\w._-]+)?)").unwrap();
out = String::from(re.replace_all(&out, "<a href=\"$url\">$url</a>"));
out
}
/// Recursive function that tries to get at least @get Messages for the room.
///
/// The @limit is the first "limit" param in the GET request.
......@@ -709,17 +695,6 @@ pub fn build_url(base: &Url, path: &str, params: Vec<(&str, String)>) -> Result<
Ok(url)
}
pub fn get_pixbuf_data(pb: &Pixbuf) -> Result<Vec<u8>, Error> {
let image = cairo::ImageSurface::create(cairo::Format::ARgb32, pb.get_width(), pb.get_height())?;
let g = cairo::Context::new(&image);
g.set_source_pixbuf(pb, 0.0, 0.0);
g.paint();
let mut buf: Vec<u8> = Vec::new();
image.write_to_png(&mut buf)?;
Ok(buf)
}
pub fn circle_image(fname: String) -> Result<String, Error> {
use std::f64::consts::PI;
......
......@@ -6,7 +6,7 @@ version = "0.1.3"
workspace = "../"
[dependencies]
fractal-api = { path = "../fractal-api" }
failure = "0.1.1"
gdk = "0.7.0"
gdk-pixbuf = "0.3.0"
gdk-pixbuf-sys = "0.5.0"
......@@ -14,15 +14,23 @@ gio = "0.3.0"
glib = "0.4.0"
notify-rust = "3.4.2"
pango = "0.3.0"
regex = "0.2.3"
secret-service = "0.4.0"
serde = "1.0.23"
serde_derive = "1.0.23"
serde_json = "1.0.6"
[dependencies.cairo-rs]
features = ["png"]
version = "0.3.0"
[dependencies.chrono]
features = ["serde"]
version = "0.4.0"
[dependencies.fractal-api]
path = "../fractal-api"
[dependencies.gtk]
features = ["v3_22"]
version = "0.3.0"
......@@ -8,7 +8,9 @@ extern crate notify_rust;
use self::notify_rust::Notification;
use util::*;
use util::get_pixbuf_data;
use util::markup;
use self::chrono::prelude::*;
use self::secret_service::SecretService;
......
......@@ -6,7 +6,7 @@ use std::io::prelude::*;
use types::RoomList;
use error::Error;
use util::cache_path;
use fractal_api::util::cache_path;
use globals;
#[derive(Serialize, Deserialize)]
......
pub static CACHE_SIZE: usize = 40;
......@@ -2,17 +2,20 @@
extern crate glib;
extern crate gio;
#[macro_use]
extern crate failure;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate fractal_api;
use fractal_api::backend;
use fractal_api::util;
use fractal_api::types;
use fractal_api::error;
use fractal_api::globals;
mod globals;
mod util;
mod widgets;
mod cache;
mod app;
......
extern crate regex;
extern crate cairo;
extern crate gdk;
extern crate gdk_pixbuf;
use self::regex::Regex;
use self::gdk_pixbuf::Pixbuf;
use failure::Error;
use self::gdk::ContextExt;
pub fn markup(s: &str) -> String {
let mut out = String::from(s);
out = String::from(out.trim());
out = out.replace('&', "&amp;");
out = out.replace('<', "&lt;");
out = out.replace('>', "&gt;");
let re = Regex::new("(?P<url>https?://[^\\s&,)(\"]+(&\\w=[\\w._-]?)*(#[\\w._-]+)?)").unwrap();
out = String::from(re.replace_all(&out, "<a href=\"$url\">$url</a>"));
out
}
pub fn get_pixbuf_data(pb: &Pixbuf) -> Result<Vec<u8>, Error> {
let image = cairo::ImageSurface::create(cairo::Format::ARgb32,
pb.get_width(),
pb.get_height())
.or(Err(format_err!("Cairo Error")))?;
let g = cairo::Context::new(&image);
g.set_source_pixbuf(pb, 0.0, 0.0);
g.paint();
let mut buf: Vec<u8> = Vec::new();
image.write_to_png(&mut buf)?;
Ok(buf)
}
......@@ -14,6 +14,7 @@ use self::chrono::prelude::*;
use backend::BKCommand;
use fractal_api as api;
use util;
use std::sync::mpsc::channel;
......@@ -107,7 +108,7 @@ impl<'a> MessageBox<'a> {
let backend = self.op.backend.clone();
let avatar;
let fname = util::cache_path(&sender).unwrap_or(strn!(""));
let fname = api::util::cache_path(&sender).unwrap_or(strn!(""));
let pathname = fname.clone();
let p = Path::new(&pathname);
......
......@@ -9,6 +9,7 @@ use types::Room;
use backend::BKCommand;
use fractal_api as api;
use util;
use std::sync::mpsc::channel;
......@@ -52,7 +53,7 @@ impl<'a> RoomBox<'a> {
Ok(fname) => {
let mut f = fname.clone();
if f.is_empty() {
f = util::draw_identicon(&id, name.clone().unwrap_or_default(), util::AvatarMode::Circle).unwrap();
f = api::util::draw_identicon(&id, name.clone().unwrap_or_default(), api::util::AvatarMode::Circle).unwrap();
}
if let Ok(pixbuf) = Pixbuf::new_from_file_at_scale(&f, 32, 32, false) {
a.set_from_pixbuf(&pixbuf);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment