Skip to content

Commit

Permalink
Flag task
Browse files Browse the repository at this point in the history
  • Loading branch information
sanpii committed Jan 5, 2018
1 parent 1298adc commit 5f3a232
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 7 deletions.
Binary file added resources/flag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 13 additions & 2 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use agenda::Msg::Edit as AgendaEdit;
use done::Msg::Complete as DoneComplete;
use done::Msg::Edit as DoneEdit;
use edit::Msg::{Cancel, Done};
use flag::Msg::Complete as FlagComplete;
use flag::Msg::Edit as FlagEdit;
use inbox::Msg::Complete as InboxComplete;
use inbox::Msg::Edit as InboxEdit;
use search::Msg::Complete as SearchComplete;
Expand All @@ -22,6 +24,7 @@ enum Page {
Projects,
Contexts,
Agenda,
Flag,
Done,
Search,
}
Expand All @@ -35,8 +38,9 @@ impl ::std::convert::From<u32> for Page
1 => Page::Projects,
2 => Page::Contexts,
3 => Page::Agenda,
4 => Page::Done,
5 => Page::Search,
4 => Page::Flag,
5 => Page::Done,
6 => Page::Search,
_ => panic!("Invalid page {}", n),
}
}
Expand Down Expand Up @@ -173,6 +177,7 @@ impl Widget
Page::Projects => "projects",
Page::Contexts => "contexts",
Page::Agenda => "agenda",
Page::Flag => "flag",
Page::Done => "done",
Page::Search => "search",
};
Expand Down Expand Up @@ -323,6 +328,7 @@ impl Widget
self.contexts.emit(::widgets::tags::Msg::Update(list.clone(), defered, done));
self.agenda.emit(::agenda::Msg::Update(list.clone(), defered, done));
self.done.emit(::done::Msg::Update(list.clone(), defered, done));
self.flag.emit(::flag::Msg::Update(list.clone(), defered, done));
self.search.emit(::search::Msg::Update(list.clone(), defered, done));

self.model.list = list;
Expand Down Expand Up @@ -452,6 +458,11 @@ impl ::relm::Widget for Widget
AgendaComplete(ref task) => Msg::Complete(task.clone()),
AgendaEdit(ref task) => Msg::Edit(task.clone()),
},
#[name="flag"]
::flag::Widget {
FlagComplete(ref task) => Msg::Complete(task.clone()),
FlagEdit(ref task) => Msg::Edit(task.clone()),
},
#[name="done"]
::done::Widget {
DoneComplete(ref task) => Msg::Complete(task.clone()),
Expand Down
27 changes: 24 additions & 3 deletions src/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use widgets::repeat::Msg::Updated as RepeatUpdated;
pub enum Msg {
Cancel,
EditKeyword(::std::collections::BTreeMap<String, String>),
Flag,
Done(::tasks::Task),
Ok,
Set(::tasks::Task),
Expand Down Expand Up @@ -37,6 +38,7 @@ impl Widget

self.subject.set_text(task.subject.as_str());
self.priority.set_value(f64::from(task.priority));
self.flag.set_active(task.flagged);
self.due.emit(::widgets::calendar::Msg::Set(task.due_date));
self.threshold.emit(::widgets::calendar::Msg::Set(task.threshold_date));
if task.create_date.is_some() {
Expand Down Expand Up @@ -101,6 +103,11 @@ impl Widget
self.model.task.tags = keywords.clone();
}

fn flag(&mut self)
{
self.model.task.flagged = self.flag.get_active();
}

fn update_date(&mut self, date_type: &DateType, date: &Option<::chrono::NaiveDate>)
{
use self::DateType::*;
Expand Down Expand Up @@ -152,6 +159,7 @@ impl ::relm::Widget for Widget
Cancel => (),
Done(_) => (),
EditKeyword(ref keywords) => self.edit_keywords(keywords),
Flag => self.flag(),
Ok => self.model.relm.stream().emit(Msg::Done(self.get_task())),
Set(task) => self.set_task(&task),
UpdateDate(ref date_type, ref date) => self.update_date(date_type, &date),
Expand All @@ -175,9 +183,22 @@ impl ::relm::Widget for Widget
},
gtk::Frame {
label: "Priority",
#[name="priority"]
gtk::SpinButton {
focus_out_event(_, _) => (Msg::UpdatePriority, ::gtk::Inhibit(false)),
gtk::Box {
orientation: ::gtk::Orientation::Horizontal,
homogeneous: true,
#[name="priority"]
gtk::SpinButton {
focus_out_event(_, _) => (Msg::UpdatePriority, ::gtk::Inhibit(false)),
},
#[name="flag"]
gtk::ToggleButton {
packing: {
fill: false,
},
image: &::gtk::Image::new_from_icon_name("emblem-favorite", ::gtk::IconSize::SmallToolbar.into()),
tooltip_text: "Flag",
toggled => Msg::Flag,
},
},
},
gtk::Frame {
Expand Down
58 changes: 58 additions & 0 deletions src/flag.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use relm_attributes::widget;
use widgets::tasks::Msg::{Complete, Edit};

#[derive(Msg)]
pub enum Msg {
Complete(::tasks::Task),
Edit(::tasks::Task),
Update(::tasks::List, bool, bool),
}

impl Widget
{
fn update_tasks(&mut self, list: &::tasks::List, defered: bool, done: bool)
{
let today = ::chrono::Local::now()
.date()
.naive_local();

let tasks = list.tasks.iter()
.filter(|x| {
x.flagged
&& (done || !x.finished)
&& (defered || x.threshold_date.is_none() || x.threshold_date.unwrap() <= today)
})
.cloned()
.collect();

self.tasks.emit(::widgets::tasks::Msg::Update(tasks));
}
}

#[widget]
impl ::relm::Widget for Widget
{
fn model(_: ()) -> ()
{
}

fn update(&mut self, event: Msg)
{
use self::Msg::*;

match event {
Complete(_) => (),
Edit(_) => (),
Update(list, defered, done) => self.update_tasks(&list, defered, done),
}
}

view!
{
#[name="tasks"]
::widgets::Tasks {
Complete(ref task) => Msg::Complete(task.clone()),
Edit(ref task) => Msg::Edit(task.clone()),
}
}
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mod agenda;
mod application;
mod done;
mod edit;
mod flag;
mod inbox;
mod logger;
mod search;
Expand Down
14 changes: 12 additions & 2 deletions src/tasks/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub struct Task {
pub id: usize,
pub note: super::Note,
pub recurrence: Option<super::Recurrence>,
pub flagged: bool,
}

impl Task
Expand All @@ -15,6 +16,7 @@ impl Task
id: 0,
note: super::Note::None,
recurrence: None,
flagged: false,
}
}

Expand Down Expand Up @@ -88,11 +90,15 @@ impl ::std::str::FromStr for Task
}
task.tags.remove(&"rec".to_owned());

let flagged = task.tags.contains_key(&"f".to_owned());
task.tags.remove(&"f".to_owned());

Ok(Self {
id: 0,
note: note,
note,
inner: task,
recurrence: recurrence,
recurrence,
flagged,
})
}
}
Expand Down Expand Up @@ -131,6 +137,10 @@ impl ::std::fmt::Display for Task
f.write_str(format!(" rec:{}", recurrence).as_str())?;
}

if self.flagged {
f.write_str(" f:1")?;
}

Ok(())
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/widgets/circle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ impl Circle

context.stroke();

if !task.finished && task.flagged {
let angle = if task.due_date.is_some() {
::std::f64::consts::PI
}
else {
0.
};

context.set_source_rgb(1., 0.5, 0.3);
context.arc(center, center, center - 5., angle, 2. * ::std::f64::consts::PI);
context.stroke();
}

if task.recurrence.is_some() {
context.set_line_width(2.);

Expand Down

0 comments on commit 5f3a232

Please sign in to comment.