0001-Update-to-new-GTK-version-and-new-version-of-depende.patch 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. From f1543fa847bb40a8b26457a98925f7707c19d9f9 Mon Sep 17 00:00:00 2001
  2. From: Maxime Devos <maximedevos@telenet.be>
  3. Date: Sun, 22 May 2022 10:12:11 +0000
  4. Subject: [PATCH] Update to new GTK version (and new version of dependencies)
  5. I don't use Cargo myself, so you may need to double-check Cargo.toml.
  6. ---
  7. Cargo.toml | 16 +++++++--------
  8. src/colors.rs | 4 ++--
  9. src/dialog.rs | 20 +++++++++----------
  10. src/draw.rs | 54 +++++++++++++++++++++++++--------------------------
  11. src/gui.rs | 23 +++++++++++-----------
  12. src/main.rs | 30 +++++++++++++---------------
  13. 6 files changed, 72 insertions(+), 75 deletions(-)
  14. diff --git a/Cargo.toml b/Cargo.toml
  15. index 3c8fd77..5f60017 100644
  16. --- a/Cargo.toml
  17. +++ b/Cargo.toml
  18. @@ -7,13 +7,13 @@ edition = "2018"
  19. # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
  20. [dependencies]
  21. -gdk = "~0.12"
  22. -gdk-pixbuf = "~0.8"
  23. -gio = "~0.8"
  24. -glib = "~0.9"
  25. -glib-sys = "~0.9"
  26. -pango = "~0.8"
  27. -pango-sys = "~0.9"
  28. +gdk = "~0.14"
  29. +gdk-pixbuf = "~0.14"
  30. +gio = "~0.14"
  31. +glib = "~0.14"
  32. +glib-sys = "~0.14"
  33. +pango = "~0.14"
  34. +pango-sys = "~0.14"
  35. open = "~2.0"
  36. regex = "~1.5"
  37. linkify = "~0.7"
  38. @@ -31,5 +31,5 @@ serde_derive="~1.0"
  39. textwrap="~0.14"
  40. [dependencies.gtk]
  41. -version = "0.8.0"
  42. +version = "0.14.3"
  43. features = ["v3_18"]
  44. \ No newline at end of file
  45. diff --git a/src/colors.rs b/src/colors.rs
  46. index 1535214..684e727 100644
  47. --- a/src/colors.rs
  48. +++ b/src/colors.rs
  49. @@ -34,14 +34,14 @@ pub mod colors {
  50. span_opened += 1;
  51. s.push_str(&format!(
  52. "<span foreground={:?}>",
  53. - ansi_color_to_hex(*color)
  54. + ansi_color_to_hex((*color).into())
  55. ))
  56. } else {
  57. let color = colors.last().unwrap();
  58. span_opened += 1;
  59. s.push_str(&format!(
  60. "<span background={:?}>",
  61. - ansi_color_to_hex(*color)
  62. + ansi_color_to_hex((*color).into())
  63. ))
  64. }
  65. }
  66. diff --git a/src/dialog.rs b/src/dialog.rs
  67. index 485a5ec..3188c42 100644
  68. --- a/src/dialog.rs
  69. +++ b/src/dialog.rs
  70. @@ -8,16 +8,16 @@ use crate::gui::Gui;
  71. use crate::protocols::Gemini;
  72. pub fn info(gui: &Arc<Gui>, message: &str) {
  73. - let dialog = gtk::Dialog::new_with_buttons(
  74. + let dialog = gtk::Dialog::with_buttons(
  75. Some("Info"),
  76. Some(gui.window()),
  77. gtk::DialogFlags::MODAL,
  78. &[("Close", ResponseType::Close)],
  79. );
  80. dialog.set_default_response(ResponseType::Close);
  81. - dialog.connect_response(|dialog, _| dialog.destroy());
  82. + dialog.connect_response(|dialog, _| unsafe { dialog.destroy() });
  83. - let content_area = dialog.get_content_area();
  84. + let content_area = dialog.content_area();
  85. let message = gtk::Label::new(Some(message));
  86. content_area.add(&message);
  87. @@ -25,16 +25,16 @@ pub fn info(gui: &Arc<Gui>, message: &str) {
  88. }
  89. pub fn error(gui: &Arc<Gui>, message: &str) {
  90. - let dialog = gtk::Dialog::new_with_buttons(
  91. + let dialog = gtk::Dialog::with_buttons(
  92. Some("Error"),
  93. Some(gui.window()),
  94. gtk::DialogFlags::MODAL,
  95. &[("Close", ResponseType::Close)],
  96. );
  97. dialog.set_default_response(ResponseType::Close);
  98. - dialog.connect_response(|dialog, _| dialog.destroy());
  99. + dialog.connect_response(|dialog, _| unsafe { dialog.destroy() });
  100. - let content_area = dialog.get_content_area();
  101. + let content_area = dialog.content_area();
  102. let message = gtk::Label::new(Some(message));
  103. content_area.add(&message);
  104. @@ -42,7 +42,7 @@ pub fn error(gui: &Arc<Gui>, message: &str) {
  105. }
  106. pub fn input(gui: &Arc<Gui>, url: Url, message: &str) {
  107. - let dialog = gtk::Dialog::new_with_buttons(
  108. + let dialog = gtk::Dialog::with_buttons(
  109. Some(message),
  110. Some(gui.window()),
  111. gtk::DialogFlags::MODAL,
  112. @@ -52,19 +52,19 @@ pub fn input(gui: &Arc<Gui>, url: Url, message: &str) {
  113. ],
  114. );
  115. - let content_area = dialog.get_content_area();
  116. + let content_area = dialog.content_area();
  117. let entry = gtk::Entry::new();
  118. content_area.add(&entry);
  119. dialog.show_all();
  120. if dialog.run() == gtk::ResponseType::Accept {
  121. - let response = entry.get_text().expect("get_text failed").to_string();
  122. + let response = entry.text().to_string();
  123. let cleaned: &str = &url[..Position::AfterPath];
  124. let full_url = format!("{}?{}", cleaned.to_string(), response);
  125. crate::visit_url(&gui, Gemini { source: full_url });
  126. }
  127. - dialog.destroy();
  128. + unsafe { dialog.destroy() };
  129. }
  130. diff --git a/src/draw.rs b/src/draw.rs
  131. index b435910..fd62406 100644
  132. --- a/src/draw.rs
  133. +++ b/src/draw.rs
  134. @@ -22,7 +22,7 @@ pub fn gemini_content(
  135. content: Vec<Result<crate::gemini::parser::TextElement, crate::gemini::parser::ParseError>>,
  136. ) -> TextBuffer {
  137. let content_view = gui.content_view();
  138. - let buffer = content_view.get_buffer().unwrap();
  139. + let buffer = content_view.buffer().unwrap();
  140. let mut mono_toggle = false;
  141. let font_family = crate::settings::get_gemini_text_font_family();
  142. @@ -33,7 +33,7 @@ pub fn gemini_content(
  143. mono_toggle = !mono_toggle;
  144. }
  145. Ok(crate::gemini::parser::TextElement::H1(header)) => {
  146. - let mut end_iter = buffer.get_end_iter();
  147. + let mut end_iter = buffer.end_iter();
  148. if mono_toggle {
  149. buffer.insert_markup(&mut end_iter, &mono_span(escape_text(&header)));
  150. } else {
  151. @@ -52,7 +52,7 @@ pub fn gemini_content(
  152. }
  153. }
  154. Ok(crate::gemini::parser::TextElement::H2(header)) => {
  155. - let mut end_iter = buffer.get_end_iter();
  156. + let mut end_iter = buffer.end_iter();
  157. if mono_toggle {
  158. buffer.insert_markup(&mut end_iter, &mono_span(escape_text(&header)));
  159. } else {
  160. @@ -71,7 +71,7 @@ pub fn gemini_content(
  161. }
  162. }
  163. Ok(crate::gemini::parser::TextElement::H3(header)) => {
  164. - let mut end_iter = buffer.get_end_iter();
  165. + let mut end_iter = buffer.end_iter();
  166. if mono_toggle {
  167. buffer.insert_markup(&mut end_iter, &mono_span(escape_text(&header)));
  168. } else {
  169. @@ -90,7 +90,7 @@ pub fn gemini_content(
  170. }
  171. }
  172. Ok(crate::gemini::parser::TextElement::ListItem(item)) => {
  173. - let mut end_iter = buffer.get_end_iter();
  174. + let mut end_iter = buffer.end_iter();
  175. if mono_toggle {
  176. buffer.insert_markup(&mut end_iter, &mono_span(item));
  177. } else {
  178. @@ -109,7 +109,7 @@ pub fn gemini_content(
  179. }
  180. }
  181. Ok(crate::gemini::parser::TextElement::Quote(text)) => {
  182. - let mut end_iter = buffer.get_end_iter();
  183. + let mut end_iter = buffer.end_iter();
  184. if mono_toggle {
  185. buffer.insert_markup(&mut end_iter, &mono_span(text));
  186. } else {
  187. @@ -128,7 +128,7 @@ pub fn gemini_content(
  188. }
  189. }
  190. Ok(crate::gemini::parser::TextElement::Text(text)) => {
  191. - let mut end_iter = buffer.get_end_iter();
  192. + let mut end_iter = buffer.end_iter();
  193. if mono_toggle {
  194. buffer.insert_markup(&mut end_iter, &mono_span(colors::colorize(&text)));
  195. } else {
  196. @@ -146,7 +146,7 @@ pub fn gemini_content(
  197. }
  198. Ok(crate::gemini::parser::TextElement::LinkItem(link_item)) => {
  199. if mono_toggle {
  200. - let mut end_iter = buffer.get_end_iter();
  201. + let mut end_iter = buffer.end_iter();
  202. buffer.insert_markup(&mut end_iter, &mono_span(escape_text(&link_item)));
  203. } else {
  204. gemini_link(&gui, link_item);
  205. @@ -160,10 +160,10 @@ pub fn gemini_content(
  206. pub fn gemini_text_content(gui: &Arc<Gui>, content: std::str::Lines) -> TextBuffer {
  207. let content_view = gui.content_view();
  208. - let buffer = content_view.get_buffer().unwrap();
  209. + let buffer = content_view.buffer().unwrap();
  210. for line in content {
  211. - let mut end_iter = buffer.get_end_iter();
  212. + let mut end_iter = buffer.end_iter();
  213. buffer.insert_markup(
  214. &mut end_iter,
  215. &format!(
  216. @@ -181,12 +181,12 @@ pub fn gopher_content(
  217. content: Vec<Result<crate::gopher::parser::TextElement, crate::gopher::parser::ParseError>>,
  218. ) -> TextBuffer {
  219. let content_view = gui.content_view();
  220. - let buffer = content_view.get_buffer().unwrap();
  221. + let buffer = content_view.buffer().unwrap();
  222. for el in content {
  223. match el {
  224. Ok(crate::gopher::parser::TextElement::Text(text)) => {
  225. - let mut end_iter = buffer.get_end_iter();
  226. + let mut end_iter = buffer.end_iter();
  227. let text = colors::colorize(&text);
  228. buffer.insert_markup(
  229. @@ -223,12 +223,12 @@ pub fn finger_content(
  230. content: Vec<Result<crate::finger::parser::TextElement, crate::finger::parser::ParseError>>,
  231. ) -> TextBuffer {
  232. let content_view = gui.content_view();
  233. - let buffer = content_view.get_buffer().unwrap();
  234. + let buffer = content_view.buffer().unwrap();
  235. for el in content {
  236. match el {
  237. Ok(crate::finger::parser::TextElement::Text(text)) => {
  238. - let mut end_iter = buffer.get_end_iter();
  239. + let mut end_iter = buffer.end_iter();
  240. buffer.insert_markup(
  241. &mut end_iter,
  242. @@ -392,7 +392,7 @@ pub fn gopher_link(gui: &Arc<Gui>, link_item: String) {
  243. pub fn insert_button(gui: &Arc<Gui>, url: Url, label: String) {
  244. let content_view = gui.content_view();
  245. - let buffer = content_view.get_buffer().unwrap();
  246. + let buffer = content_view.buffer().unwrap();
  247. let button_label = if label.is_empty() {
  248. url.to_string()
  249. @@ -400,7 +400,7 @@ pub fn insert_button(gui: &Arc<Gui>, url: Url, label: String) {
  250. label
  251. };
  252. - let button = gtk::Button::new_with_label(&button_label);
  253. + let button = gtk::Button::with_label(&button_label);
  254. button.set_tooltip_text(Some(&url.to_string()));
  255. button.connect_clicked(clone!(@weak gui => move |_| {
  256. @@ -412,16 +412,16 @@ pub fn insert_button(gui: &Arc<Gui>, url: Url, label: String) {
  257. }
  258. }));
  259. - let mut start_iter = buffer.get_end_iter();
  260. + let mut start_iter = buffer.end_iter();
  261. let anchor = buffer.create_child_anchor(&mut start_iter).unwrap();
  262. content_view.add_child_at_anchor(&button, &anchor);
  263. - let mut end_iter = buffer.get_end_iter();
  264. + let mut end_iter = buffer.end_iter();
  265. buffer.insert(&mut end_iter, "\n");
  266. }
  267. pub fn insert_gopher_file_button(gui: &Arc<Gui>, url: Url, label: String) {
  268. let content_view = gui.content_view();
  269. - let buffer = content_view.get_buffer().unwrap();
  270. + let buffer = content_view.buffer().unwrap();
  271. let button_label = if label.is_empty() {
  272. url.to_string()
  273. @@ -429,7 +429,7 @@ pub fn insert_gopher_file_button(gui: &Arc<Gui>, url: Url, label: String) {
  274. label
  275. };
  276. - let button = gtk::Button::new_with_label(&button_label);
  277. + let button = gtk::Button::with_label(&button_label);
  278. button.set_tooltip_text(Some(&url.to_string()));
  279. button.connect_clicked(move |_| {
  280. @@ -440,28 +440,28 @@ pub fn insert_gopher_file_button(gui: &Arc<Gui>, url: Url, label: String) {
  281. crate::client::download(content);
  282. });
  283. - let mut start_iter = buffer.get_end_iter();
  284. + let mut start_iter = buffer.end_iter();
  285. let anchor = buffer.create_child_anchor(&mut start_iter).unwrap();
  286. content_view.add_child_at_anchor(&button, &anchor);
  287. - let mut end_iter = buffer.get_end_iter();
  288. + let mut end_iter = buffer.end_iter();
  289. buffer.insert(&mut end_iter, "\n");
  290. }
  291. pub fn insert_external_button(gui: &Arc<Gui>, url: Url, label: &str) {
  292. let content_view = gui.content_view();
  293. - let buffer = content_view.get_buffer().unwrap();
  294. + let buffer = content_view.buffer().unwrap();
  295. - let button = gtk::Button::new_with_label(&label);
  296. + let button = gtk::Button::with_label(&label);
  297. button.set_tooltip_text(Some(&url.to_string()));
  298. button.connect_clicked(move |_| {
  299. open::that(url.to_string()).unwrap();
  300. });
  301. - let mut start_iter = buffer.get_end_iter();
  302. + let mut start_iter = buffer.end_iter();
  303. let anchor = buffer.create_child_anchor(&mut start_iter).unwrap();
  304. content_view.add_child_at_anchor(&button, &anchor);
  305. - let mut end_iter = buffer.get_end_iter();
  306. + let mut end_iter = buffer.end_iter();
  307. buffer.insert(&mut end_iter, "\n");
  308. }
  309. @@ -483,7 +483,7 @@ fn mono_span(text: String) -> String {
  310. }
  311. fn width(gui: &Arc<Gui>) -> usize {
  312. - let (win_width, _) = gtk::ApplicationWindow::get_size(gui.window());
  313. + let (win_width, _) = gtk::ApplicationWindow::size(gui.window());
  314. let calculated_width = (win_width / 10).try_into().unwrap();
  315. std::cmp::min(calculated_width, crate::settings::max_width().unwrap_or(std::usize::MAX))
  316. }
  317. diff --git a/src/gui.rs b/src/gui.rs
  318. index 5b896c9..da7074b 100644
  319. --- a/src/gui.rs
  320. +++ b/src/gui.rs
  321. @@ -1,7 +1,6 @@
  322. use gtk::prelude::*;
  323. use gtk::{ApplicationWindow, Button, Entry, TextView};
  324. -use gdk::WindowExt;
  325. pub struct Gui {
  326. window: ApplicationWindow,
  327. @@ -24,28 +23,28 @@ impl Gui {
  328. pub fn new() -> Gui {
  329. // Initialize the UI from the Glade XML.
  330. let glade_src = include_str!("castor.glade");
  331. - let builder = gtk::Builder::new_from_string(glade_src);
  332. + let builder = gtk::Builder::from_string(glade_src);
  333. // Get handles for the various controls we need to use.
  334. - let window: ApplicationWindow = builder.get_object("window").expect("Couldn't get window");
  335. - let url_bar: Entry = builder.get_object("url_bar").expect("Couldn't get url_bar");
  336. + let window: ApplicationWindow = builder.object("window").expect("Couldn't get window");
  337. + let url_bar: Entry = builder.object("url_bar").expect("Couldn't get url_bar");
  338. let content_view: TextView = builder
  339. - .get_object("content_view")
  340. + .object("content_view")
  341. .expect("Couldn't get content_view");
  342. let back_button: Button = builder
  343. - .get_object("back_button")
  344. + .object("back_button")
  345. .expect("Couldn't get back_button");
  346. let forward_button: Button = builder
  347. - .get_object("forward_button")
  348. + .object("forward_button")
  349. .expect("Couldn't get forward_button");
  350. let refresh_button: Button = builder
  351. - .get_object("refresh_button")
  352. + .object("refresh_button")
  353. .expect("Couldn't get refresh_button");
  354. let add_bookmark_button: Button = builder
  355. - .get_object("add_bookmark_button")
  356. + .object("add_bookmark_button")
  357. .expect("Couldn't get add_bookmark_button");
  358. let show_bookmarks_button: Button = builder
  359. - .get_object("show_bookmarks_button")
  360. + .object("show_bookmarks_button")
  361. .expect("Couldn't get show_bookmarks_button");
  362. Gui {
  363. @@ -68,8 +67,8 @@ impl Gui {
  364. Inhibit(false)
  365. });
  366. self.content_view.connect_motion_notify_event(|win, _| {
  367. - let w = gtk::TextViewExt::get_window(win, gtk::TextWindowType::Text).unwrap();
  368. - w.set_cursor(gdk::Cursor::new_from_name(&w.get_display(), "default").as_ref());
  369. + let w = gtk::traits::TextViewExt::window(win, gtk::TextWindowType::Text).unwrap();
  370. + w.set_cursor(gdk::Cursor::from_name(&w.display(), "default").as_ref());
  371. Inhibit(false)
  372. });
  373. self.window.show_all();
  374. diff --git a/src/main.rs b/src/main.rs
  375. index 6557411..bb35339 100644
  376. --- a/src/main.rs
  377. +++ b/src/main.rs
  378. @@ -46,7 +46,7 @@ fn main() {
  379. .expect("Failed to load CSS");
  380. gtk::StyleContext::add_provider_for_screen(
  381. - &gdk::Screen::get_default().expect("Error initializing gtk css provider."),
  382. + &gdk::Screen::default().expect("Error initializing gtk css provider."),
  383. &provider,
  384. gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
  385. );
  386. @@ -101,7 +101,7 @@ fn main() {
  387. let gui_clone = gui.clone();
  388. let url_bar = gui.url_bar();
  389. url_bar.connect_activate(move |b| {
  390. - let url = b.get_text().expect("get_text failed").to_string();
  391. + let url = b.text().to_string();
  392. route_url(&gui_clone, url)
  393. });
  394. }
  395. @@ -111,7 +111,7 @@ fn main() {
  396. let gui_clone = gui.clone();
  397. let content_view = gui.content_view();
  398. content_view.connect_button_press_event(move |_, event| {
  399. - if event.get_button() == 8 {
  400. + if event.button() == 8 {
  401. go_back(&gui_clone);
  402. }
  403. Inhibit(false)
  404. @@ -190,26 +190,24 @@ fn visit(gui: &Arc<Gui>, url: &Url) {
  405. fn refresh(gui: &Arc<Gui>) {
  406. let url_bar = gui.url_bar();
  407. - let url = url_bar.get_text().expect("get_text failed").to_string();
  408. + let url = url_bar.text().to_string();
  409. route_url(&gui, url)
  410. }
  411. fn update_url_field(gui: &Arc<Gui>, url: &str) {
  412. let url_bar = gui.url_bar();
  413. - url_bar.get_buffer().set_text(url);
  414. + url_bar.buffer().set_text(url);
  415. }
  416. fn add_bookmark(gui: &Arc<Gui>) {
  417. let url_bar = gui.url_bar();
  418. - let current_url = url_bar.get_text();
  419. -
  420. - if let Some(url) = current_url {
  421. - if bookmarks::is_valid(&url) {
  422. - bookmarks::add(&url);
  423. - dialog::info(&gui, "Bookmark added.");
  424. - } else {
  425. - dialog::error(&gui, "Invalid bookmark URL.");
  426. - }
  427. + let current_url = url_bar.text();
  428. +
  429. + if bookmarks::is_valid(&current_url) {
  430. + bookmarks::add(&current_url);
  431. + dialog::info(&gui, "Bookmark added.");
  432. + } else {
  433. + dialog::error(&gui, "Invalid bookmark URL.");
  434. }
  435. }
  436. @@ -354,8 +352,8 @@ pub fn visit_url<T: AbsoluteUrl + Protocol>(gui: &Arc<Gui>, url: T) {
  437. }
  438. fn clear_buffer(view: &gtk::TextView) {
  439. - if let Some(buffer) = view.get_buffer() {
  440. - let (mut start, mut end) = buffer.get_bounds();
  441. + if let Some(buffer) = view.buffer() {
  442. + let (mut start, mut end) = buffer.bounds();
  443. buffer.delete(&mut start, &mut end);
  444. }
  445. }
  446. base-commit: ec77c753e86074f9b540b0f41cfbec527b17ef0a
  447. --
  448. 2.30.2