Skip to content

Commit

Permalink
Merge pull request #573 from paper-plane-developers/misc/maintenance
Browse files Browse the repository at this point in the history
Misc/maintenance
  • Loading branch information
marhkb authored Aug 6, 2023
2 parents 4a99454 + 507ccfe commit 66a0b5a
Show file tree
Hide file tree
Showing 38 changed files with 309 additions and 273 deletions.
395 changes: 213 additions & 182 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ authors = ["Marco Melorio <marco.melorio@protonmail.com>", "Marcus Behrendt <mar
edition = "2021"

[dependencies]
adw = { version = "0.4", package = "libadwaita", features = ["v1_4"] }
adw = { version = "0.5", package = "libadwaita", features = ["v1_4"] }
anyhow = "1"
ellipse = "0.2"
futures = { version = "0.3", default-features = false }
gettext-rs = { version = "0.7", features = ["gettext-system"] }
gtk = { version = "0.6", package = "gtk4", features = ["gnome_44", "blueprint"] }
gtk = { version = "0.7", package = "gtk4", features = ["gnome_44", "blueprint"] }
image = { version = "0.24", default-features = false, features = ["jpeg", "png", "webp"] }
indexmap = "1"
indexmap = "2"
locale_config = "0.3"
log = "0.4"
once_cell = "1"
pretty_env_logger = "0.5"
qrcode-generator = { version = "4", default-features = false }
regex = "1"
rlt = { package = "gtk-rlottie", git = "https://github.com/YuraIz/gtk-rlottie-rs" }
rlt = { package = "gtk-rlottie", git = "https://github.com/YuraIz/gtk-rlottie-rs", tag = "aug6" }
tdlib = { version = "0.7", default-features = false }
temp-dir = "0.1"
thiserror = "1"
Expand Down
4 changes: 2 additions & 2 deletions build-aux/app.drey.PaperPlane.Devel.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
{
"type": "git",
"url": "https://gitlab.gnome.org/GNOME/gtk.git",
"tag": "4.11.3"
"tag": "4.12.0"
},
{
"type": "patch",
Expand Down Expand Up @@ -138,7 +138,7 @@
{
"type": "git",
"url": "https://gitlab.gnome.org/GNOME/libadwaita.git",
"tag": "1.4.alpha"
"tag": "1.4.beta"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ base_id = 'app.drey.PaperPlane'

dependency('glib-2.0', version: '>= 2.72')
dependency('gio-2.0', version: '>= 2.72')
dependency('gtk4', version: '>= 4.10')
dependency('gtk4', version: '>= 4.12')
dependency('libadwaita-1', version: '>= 1.4')
dependency('tdjson', version: '== 1.8.14')

Expand Down
3 changes: 2 additions & 1 deletion src/application.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::cell::OnceCell;

use adw::subclass::prelude::AdwApplicationImpl;
use gettextrs::gettext;
use glib::clone;
Expand All @@ -8,7 +10,6 @@ use gtk::prelude::*;
use gtk::subclass::prelude::*;
use log::debug;
use log::info;
use once_cell::sync::OnceCell;

use crate::config::APP_ID;
use crate::config::PKGDATADIR;
Expand Down
6 changes: 3 additions & 3 deletions src/components/avatar.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::cell::OnceCell;
use std::cell::RefCell;

use adw::subclass::prelude::BinImpl;
Expand All @@ -7,7 +8,6 @@ use gtk::glib;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk::CompositeTemplate;
use once_cell::unsync::OnceCell;
use tdlib::enums::UserType;

use crate::strings;
Expand Down Expand Up @@ -117,7 +117,7 @@ impl Avatar {
fn create_signal_groups(&self) {
let imp = self.imp();

let user_signal_group = glib::SignalGroup::new(User::static_type());
let user_signal_group = glib::SignalGroup::new::<User>();
user_signal_group.connect_notify_local(
Some("type"),
clone!(@weak self as obj => move |_, _| {
Expand Down Expand Up @@ -145,7 +145,7 @@ impl Avatar {
);
imp.user_signal_group.set(user_signal_group).unwrap();

let chat_signal_group = glib::SignalGroup::new(Chat::static_type());
let chat_signal_group = glib::SignalGroup::new::<Chat>();
chat_signal_group.connect_notify_local(
Some("title"),
clone!(@weak self as obj => move |_, _| {
Expand Down
22 changes: 10 additions & 12 deletions src/components/message_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,16 @@ mod imp {
// "shift" modifier are pressed at the same time.
let key_events = gtk::EventControllerKey::new();
key_events.connect_key_pressed(
clone!(@weak obj => @default-return gtk::Inhibit(false), move |_, key, _, modifier| {
gtk::Inhibit(
if !modifier.contains(gdk::ModifierType::CONTROL_MASK)
&& !modifier.contains(gdk::ModifierType::SHIFT_MASK)
&& (key == gdk::Key::Return || key == gdk::Key::KP_Enter)
{
obj.emit_by_name::<()>("activate", &[]);
true
} else {
false
},
)
clone!(@weak obj => @default-return glib::Propagation::Proceed, move |_, key, _, modifier| {
if !modifier.contains(gdk::ModifierType::CONTROL_MASK)
&& !modifier.contains(gdk::ModifierType::SHIFT_MASK)
&& (key == gdk::Key::Return || key == gdk::Key::KP_Enter)
{
obj.emit_by_name::<()>("activate", &[]);
glib::Propagation::Stop
} else {
glib::Propagation::Proceed
}
}),
);
self.text_view.add_controller(key_events);
Expand Down
2 changes: 1 addition & 1 deletion src/components/snow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ mod imp {
if super::Snow::correct_date() {
self.obj().add_tick_callback(|widget, _clock| {
widget.queue_draw();
glib::Continue(true)
glib::ControlFlow::Continue
});
} else {
self.obj().set_visible(false);
Expand Down
20 changes: 11 additions & 9 deletions src/login.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#![allow(deprecated)]

use std::cell::Cell;
use std::cell::OnceCell;
use std::cell::RefCell;

use adw::prelude::*;
Expand All @@ -11,7 +14,6 @@ use gtk::glib::clone;
use gtk::glib::SourceId;
use gtk::subclass::prelude::*;
use gtk::CompositeTemplate;
use once_cell::sync::OnceCell;
use tdlib::enums;
use tdlib::enums::AuthenticationCodeType;
use tdlib::enums::AuthorizationState;
Expand Down Expand Up @@ -185,7 +187,7 @@ mod imp {
label
.activate_action("login.show-tos-dialog", None)
.unwrap();
gtk::Inhibit(true)
glib::Propagation::Stop
});

// Disable all actions by default.
Expand Down Expand Up @@ -467,19 +469,19 @@ impl Login {

let source_id = glib::timeout_add_seconds_local(
1,
clone!(@weak self as obj => @default-return glib::Continue(false), move || {
let imp = obj.imp();
clone!(@weak self as obj => @default-return glib::ControlFlow::Break, move || {
countdown -= 1;
glib::Continue(if countdown == 0 {

if countdown == 0 {
obj.stop_code_next_type_countdown();
false
glib::ControlFlow::Break
} else {
imp.code_timeout_label.set_label(&gettext!(
obj.imp().code_timeout_label.set_label(&gettext!(
"Please still wait {} seconds",
countdown
));
true
})
glib::ControlFlow::Continue
}
}),
);
imp.code_next_type_countdown_id.replace(Some(source_id));
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod window;

use std::path::PathBuf;
use std::str::FromStr;
use std::sync::OnceLock;

use config::GETTEXT_PACKAGE;
use config::LOCALEDIR;
Expand All @@ -31,16 +32,15 @@ use gtk::glib;
use gtk::prelude::ApplicationExt;
use gtk::prelude::ApplicationExtManual;
use gtk::prelude::IsA;
use once_cell::sync::OnceCell;
use temp_dir::TempDir;

use self::application::Application;
use self::login::Login;
use self::session::Session;
use self::window::Window;

pub(crate) static APPLICATION_OPTS: OnceCell<ApplicationOptions> = OnceCell::new();
pub(crate) static TEMP_DIR: OnceCell<PathBuf> = OnceCell::new();
pub(crate) static APPLICATION_OPTS: OnceLock<ApplicationOptions> = OnceLock::new();
pub(crate) static TEMP_DIR: OnceLock<PathBuf> = OnceLock::new();

fn main() -> glib::ExitCode {
// Prepare i18n
Expand Down
7 changes: 3 additions & 4 deletions src/phone_number_input.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::borrow::Cow;
use std::cell::Cell;
use std::cell::OnceCell;
use std::cell::RefCell;
use std::rc::Rc;

Expand All @@ -13,7 +14,6 @@ use gtk::subclass::prelude::*;
use gtk::CompositeTemplate;
use locale_config::Locale;
use once_cell::sync::Lazy;
use once_cell::sync::OnceCell;

use crate::tdlib::CountryInfo;
use crate::tdlib::CountryList;
Expand Down Expand Up @@ -214,10 +214,9 @@ mod imp {
let focus_events = gtk::EventControllerFocus::new();
focus_events.connect_leave(clone!(@weak obj => move |_| {
// We need to set the cursor position at the end on the next idle.
glib::idle_add_local(clone!(
@weak obj => @default-return glib::Continue(false), move || {
glib::idle_add_local_once(clone!(
@weak obj => move || {
obj.imp().entry_row.set_position(i32::MAX);
glib::Continue(false)
}
));
}));
Expand Down
5 changes: 3 additions & 2 deletions src/session/contacts_window/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod row;

use std::cell::OnceCell;

use adw::subclass::prelude::*;
use glib::clone;
use glib::subclass::Signal;
Expand All @@ -8,7 +10,6 @@ use gtk::glib;
use gtk::prelude::*;
use gtk::CompositeTemplate;
use once_cell::sync::Lazy;
use once_cell::unsync::OnceCell;
use row::ContactRow;

use crate::strings;
Expand Down Expand Up @@ -176,7 +177,7 @@ impl ContactsWindow {

match session.fetch_contacts().await {
Ok(users) => {
let list = gio::ListStore::new(User::static_type());
let list = gio::ListStore::new::<User>();
list.splice(0, 0, &users);

self.imp().sort_model.set_model(Some(&list));
Expand Down
4 changes: 3 additions & 1 deletion src/session/content/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ impl Background {
}

pub(crate) fn set_theme(&self, theme: tdlib::types::ThemeSettings) {
let Some(background) = theme.background else { return; };
let Some(background) = theme.background else {
return;
};
let imp = self.imp();

imp.dark.set(background.is_dark);
Expand Down
18 changes: 9 additions & 9 deletions src/session/content/chat_action_bar.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::cell::Cell;
use std::cell::OnceCell;
use std::cell::RefCell;

use anyhow::anyhow;
Expand All @@ -10,7 +11,6 @@ use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk::CompositeTemplate;
use once_cell::sync::Lazy;
use once_cell::unsync::OnceCell;
use tdlib::enums::ChatAction;
use tdlib::enums::ChatMemberStatus;
use tdlib::enums::FormattedText;
Expand Down Expand Up @@ -271,7 +271,7 @@ impl ChatActionBar {
fn create_signal_groups(&self) {
let imp = self.imp();

let chat_signal_group = glib::SignalGroup::new(Chat::static_type());
let chat_signal_group = glib::SignalGroup::new::<Chat>();
chat_signal_group.connect_notify_local(
Some("notification-settings"),
clone!(@weak self as obj => move |_, _| {
Expand All @@ -286,7 +286,7 @@ impl ChatActionBar {
);
imp.chat_signal_group.set(chat_signal_group).unwrap();

let basic_group_signal_group = glib::SignalGroup::new(BasicGroup::static_type());
let basic_group_signal_group = glib::SignalGroup::new::<BasicGroup>();
basic_group_signal_group.connect_notify_local(
Some("status"),
clone!(@weak self as obj => move |_, _| {
Expand All @@ -297,7 +297,7 @@ impl ChatActionBar {
.set(basic_group_signal_group)
.unwrap();

let supergroup_signal_group = glib::SignalGroup::new(Supergroup::static_type());
let supergroup_signal_group = glib::SignalGroup::new::<Supergroup>();
supergroup_signal_group.connect_notify_local(
Some("status"),
clone!(@weak self as obj => move |_, _| {
Expand Down Expand Up @@ -480,7 +480,7 @@ impl ChatActionBar {
async fn select_file(&self) {
let dialog = gtk::FileDialog::new();
let filter = gtk::FileFilter::new();
let filters = gio::ListStore::new(gtk::FileFilter::static_type());
let filters = gio::ListStore::new::<gtk::FileFilter>();
let parent = self.root().and_downcast::<gtk::Window>().unwrap();

filter.set_name(Some(&gettext("Images")));
Expand All @@ -489,7 +489,7 @@ impl ChatActionBar {
}

filters.append(&filter);
dialog.set_filters(&filters);
dialog.set_filters(Some(&filters));

if let Ok(file) = dialog.open_future(Some(&parent)).await {
let path = file.path().unwrap().to_str().unwrap().to_string();
Expand Down Expand Up @@ -686,7 +686,7 @@ impl ChatActionBar {
async fn handle_image_clipboard(&self, chat: Chat) -> Result<(), anyhow::Error> {
if let Ok((stream, mime)) = self
.clipboard()
.read_future(PHOTO_MIME_TYPES, glib::PRIORITY_DEFAULT)
.read_future(PHOTO_MIME_TYPES, glib::Priority::DEFAULT)
.await
{
let extension = match mime.as_str() {
Expand Down Expand Up @@ -869,15 +869,15 @@ async fn save_stream_to_file(
None,
false,
gio::FileCreateFlags::REPLACE_DESTINATION,
glib::PRIORITY_DEFAULT,
glib::Priority::DEFAULT,
)
.await?;

file_stream
.splice_future(
&stream,
gio::OutputStreamSpliceFlags::CLOSE_SOURCE | gio::OutputStreamSpliceFlags::CLOSE_TARGET,
glib::PRIORITY_DEFAULT,
glib::Priority::DEFAULT,
)
.await?;

Expand Down
6 changes: 3 additions & 3 deletions src/session/content/chat_history.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::cell::Cell;
use std::cell::OnceCell;
use std::cell::RefCell;

use adw::prelude::*;
Expand All @@ -10,7 +11,6 @@ use gtk::glib;
use gtk::subclass::prelude::*;
use gtk::CompositeTemplate;
use once_cell::sync::Lazy;
use once_cell::unsync::OnceCell;
use tdlib::enums::ChatMemberStatus;
use tdlib::functions;

Expand Down Expand Up @@ -320,11 +320,11 @@ impl ChatHistory {
// Request sponsored message, if needed
let list_view_model: gio::ListModel = if matches!(chat.type_(), ChatType::Supergroup(supergroup) if supergroup.is_channel())
{
let list = gio::ListStore::new(gio::ListModel::static_type());
let list = gio::ListStore::new::<gio::ListModel>();

// We need to create a list here so that we can append the sponsored message
// to the chat history in the GtkListView using a GtkFlattenListModel
let sponsored_message_list = gio::ListStore::new(SponsoredMessage::static_type());
let sponsored_message_list = gio::ListStore::new::<SponsoredMessage>();
list.append(&sponsored_message_list);
self.request_sponsored_message(&chat.session(), chat.id(), &sponsored_message_list);

Expand Down
Loading

0 comments on commit 66a0b5a

Please sign in to comment.