Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #1190

Merged
merged 11 commits into from
Mar 18, 2024
Merged

Develop #1190

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed build-aux/io.github.alainm23.planify.Devel.flatpak
Binary file not shown.
2 changes: 1 addition & 1 deletion build-aux/io.github.alainm23.planify.Devel.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@
]
}
]
}
}
53 changes: 20 additions & 33 deletions core/Layouts/HeaderItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ public class Layouts.HeaderItem : Adw.Bin {
private Gtk.Label name_label;
private Gtk.Label placeholder_label;
private Gtk.ListBox listbox;
private Gtk.Grid content_grid;
private Adw.Bin content_grid;
private Gtk.Box action_box;
private Gtk.Revealer action_revealer;
private Gtk.Revealer content_revealer;
private Gtk.Revealer separator_revealer;
public signal void add_activated ();
Expand All @@ -92,18 +91,6 @@ public class Layouts.HeaderItem : Adw.Bin {
}
}

public bool card {
set {
if (value) {
content_grid.add_css_class ("card");
content_grid.add_css_class ("sidebar-card");
} else {
content_grid.remove_css_class ("card");
content_grid.remove_css_class ("sidebar-card");
}
}
}

public bool separator_space {
set {
if (value) {
Expand All @@ -120,17 +107,27 @@ public class Layouts.HeaderItem : Adw.Bin {
}
}

public bool box_shadow {
public bool listbox_no_margin {
set {
if (value) {
content_grid.remove_css_class ("sidebar-card");
listbox.margin_top = 0;
listbox.margin_bottom = 0;
listbox.margin_start = 0;
listbox.margin_end = 0;
}
}
}

public bool listbox_no_margin {
public bool card {
set {
if (value) {
listbox.css_classes = { "boxed-list" };
listbox.margin_top = 3;
listbox.margin_bottom = 3;
listbox.margin_start = 3;
listbox.margin_end = 3;
} else {
listbox.css_classes = { };
listbox.margin_top = 0;
listbox.margin_bottom = 0;
listbox.margin_start = 0;
Expand All @@ -154,33 +151,25 @@ public class Layouts.HeaderItem : Adw.Bin {
name_label.add_css_class (Granite.STYLE_CLASS_SMALL_LABEL);

listbox = new Gtk.ListBox () {
hexpand = true,
margin_top = 3,
margin_start = 3,
margin_end = 3,
margin_bottom = 3
hexpand = true
};

listbox.set_placeholder (get_placeholder ());
listbox.add_css_class ("bg-transparent");

content_grid = new Gtk.Grid () {
margin_end = 3
content_grid = new Adw.Bin () {
child = listbox
};

content_grid.add_css_class ("card");
content_grid.add_css_class ("sidebar-card");
content_grid.attach (listbox, 0, 0, 1, 1);

action_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) {
action_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6) {
hexpand = true,
halign = END
};

var header_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) {
hexpand = true,
margin_start = 6,
margin_end = 3
margin_end = 6
};

header_box.append (name_label);
Expand All @@ -199,9 +188,7 @@ public class Layouts.HeaderItem : Adw.Bin {

var content_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) {
hexpand = true,
margin_start = 3,
margin_top = 3,
margin_bottom = 3
margin_top = 3
};

content_box.append (header_box);
Expand Down
6 changes: 3 additions & 3 deletions core/Objects/BaseObject.vala
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ public class Objects.BaseObject : GLib.Object {
public string icon_name {
get {
if (this is Objects.Today) {
return "planner-today";
return "star-outline-thick-symbolic";
} else if (this is Objects.Scheduled) {
return "planner-scheduled";
return "month-symbolic";
} else if (this is Objects.Pinboard) {
return "planner-pin-tack";
return "pin-symbolic";
} else {
return "";
}
Expand Down
15 changes: 11 additions & 4 deletions core/Objects/Item.vala
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,12 @@ public class Objects.Item : Objects.BaseObject {
patch_from_vtodo (data, _ics);

var categories = Util.find_string_value ("CATEGORIES", data);
print ("categories: %s\n".printf (categories));
check_labels (get_labels_maps_from_caldav (categories));
}

public void patch_from_vtodo (string data, string _ics) {
ECal.Component ecal = new ECal.Component.from_string (data);
ICal.Component ical = new ICal.Component.from_string (data);

id = ical.get_uid ();
Expand Down Expand Up @@ -522,10 +524,8 @@ public class Objects.Item : Objects.BaseObject {
private Gee.ArrayList<Objects.Label> get_caldav_categories (string categories) {
Gee.ArrayList<Objects.Label> return_value = new Gee.ArrayList<Objects.Label> ();

// string _categories = categories.replace ("\\,", ";");
string[] categories_list = categories.split (",");
foreach (unowned string category in categories_list) {
// string category = str.replace (";", ",");
Objects.Label label = Services.Database.get_default ().get_label_by_name (category, true, BackendType.CALDAV);
if (label != null) {
return_value.add (label);
Expand Down Expand Up @@ -575,6 +575,15 @@ public class Objects.Item : Objects.BaseObject {
Objects.Label label = Services.Database.get_default ().get_label_by_name (category, true, BackendType.CALDAV);
if (label != null) {
return_value [label.id] = label;
} else {
label = new Objects.Label ();
label.id = Util.get_default ().generate_id (label);
label.color = Util.get_default ().get_random_color ();
label.name = category;
label.backend_type = BackendType.CALDAV;
if (Services.Database.get_default ().insert_label (label)) {
return_value [label.id] = label;
}
}
}

Expand Down Expand Up @@ -1163,8 +1172,6 @@ public class Objects.Item : Objects.BaseObject {
ical.add_property (new ICal.Property.categories (get_labels_names (labels)));
}

stdout.printf ("%s\n", ical.as_ical_string ());

return "%s%s%s".printf (
"BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Planify App (https://github.com/alainm23/planify)\n",
ical.as_ical_string (),
Expand Down
4 changes: 2 additions & 2 deletions core/Objects/Project.vala
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,14 @@ public class Objects.Project : Objects.BaseObject {
backend_type = BackendType.CALDAV;
}

public void update_from_xml (GXml.DomElement element) {
public void update_from_xml (GXml.DomElement element, bool update_sync_token = true) {
GXml.DomElement propstat = element.get_elements_by_tag_name ("d:propstat").get_element (0);
GXml.DomElement prop = propstat.get_elements_by_tag_name ("d:prop").get_element (0);
name = get_content (prop.get_elements_by_tag_name ("d:displayname").get_element (0));
color = get_content (prop.get_elements_by_tag_name ("x1:calendar-color").get_element (0));

GXml.DomHTMLCollection sync_token_collection = prop.get_elements_by_tag_name ("d:sync-token");
if (sync_token_collection.length > 0) {
if (update_sync_token && sync_token_collection.length > 0) {
sync_id = get_content (sync_token_collection.get_element (0));
}
}
Expand Down
26 changes: 11 additions & 15 deletions core/QuickAdd.vala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Layouts.QuickAdd : Adw.Bin {
content_entry = new Gtk.Entry () {
hexpand = true,
placeholder_text = _("To-do name"),
css_classes = { "flat" }
css_classes = { "flat", "font-bold" }
};

var content_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6) {
Expand All @@ -79,7 +79,8 @@ public class Layouts.QuickAdd : Adw.Bin {
description_textview.remove_css_class ("view");

item_labels = new Widgets.ItemLabels (item) {
margin_start = 12
margin_start = 6,
top_margin = 12
};

schedule_button = new Widgets.ScheduleButton ();
Expand All @@ -90,9 +91,7 @@ public class Layouts.QuickAdd : Adw.Bin {
label_button.backend_type = item.project.backend_type;

var action_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12) {
margin_start = 3,
margin_top = 6,
margin_bottom = 3
margin_top = 6
};

var action_box_right = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) {
Expand Down Expand Up @@ -122,7 +121,7 @@ public class Layouts.QuickAdd : Adw.Bin {
quick_add_content.append (action_box);

// Alert Box
var error_icon = new Widgets.DynamicIcon.from_icon_name ("dialog-warning-symbolic");
var error_icon = new Gtk.Image.from_icon_name ("dialog-warning-symbolic");
var error_label = new Gtk.Label ("Error de casa");

var error_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) {
Expand All @@ -141,7 +140,7 @@ public class Layouts.QuickAdd : Adw.Bin {
valign = Gtk.Align.CENTER,
halign = Gtk.Align.CENTER,
popover = build_context_menu_popover (),
child = new Widgets.DynamicIcon.from_icon_name ("dots-vertical"),
icon_name = "view-more-symbolic",
css_classes = { "flat" }
};

Expand All @@ -159,7 +158,7 @@ public class Layouts.QuickAdd : Adw.Bin {
var footer_content = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6) {
hexpand = true,
margin_bottom = 12,
margin_start = 6,
margin_start = 12,
margin_end = 12
};

Expand Down Expand Up @@ -197,17 +196,14 @@ public class Layouts.QuickAdd : Adw.Bin {
transition_type = Gtk.StackTransitionType.CROSSFADE
};

added_image = new Gtk.Image ();
added_image.gicon = new ThemedIcon ("planner-completed");
added_image.pixel_size = 64;

var added_label = new Gtk.Label (_("To-do added"));
added_image = new Gtk.Image.from_icon_name ("check-round-outline-symbolic") {
pixel_size = 64
};

var added_box = new Gtk.Box (VERTICAL, 0);
var added_box = new Gtk.Box (VERTICAL, 6);
added_box.halign = Gtk.Align.CENTER;
added_box.valign = Gtk.Align.CENTER;
added_box.append (added_image);
added_box.append (added_label);

main_stack.add_named (main_content, "main");
main_stack.add_named (warning_box, "warning");
Expand Down
13 changes: 9 additions & 4 deletions core/Services/CalDAV.vala
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ public class Services.CalDAV : GLib.Object {
Services.Database.get_default ().insert_project (project);
yield get_all_tasks_by_tasklist (project);
} else {
project.update_from_xml (element);
project.update_from_xml (element, false);
Services.Database.get_default ().update_project (project);
}
} else if (is_deleted_calendar (element)) {
Expand All @@ -610,10 +610,15 @@ public class Services.CalDAV : GLib.Object {
var username = Services.Settings.get_default ().settings.get_string ("caldav-username");

var url = "%s/remote.php/dav/calendars/%s/%s".printf (server_url, username, project.id);
print ("URL: %s\n".printf (url));
var message = new Soup.Message ("REPORT", url);
yield set_credential (message);
message.set_request_body_from_bytes ("application/xml", new Bytes ((SYNC_TOKEN_REQUEST.printf (project.sync_id)).data));

if (project.sync_id == "") {
return;
}

try {
GLib.Bytes stream = yield session.send_and_read_async (message, GLib.Priority.HIGH, null);

Expand All @@ -631,13 +636,14 @@ public class Services.CalDAV : GLib.Object {
}
} else {
string vtodo = yield get_vtodo_by_url (project.id, ics);

ICal.Component ical = new ICal.Component.from_string (vtodo);
Objects.Item? item = Services.Database.get_default ().get_item (ical.get_uid ());

if (item != null) {
if (item != null) {
string old_project_id = item.project_id;
string old_parent_id = item.parent_id;

item.update_from_vtodo (vtodo, ics);
item.project_id = project.id;
Services.Database.get_default ().update_item (item);
Expand Down Expand Up @@ -874,7 +880,6 @@ public class Services.CalDAV : GLib.Object {


var url = "%s/remote.php/dav/calendars/%s/%s/%s".printf (server_url, username, item.project.id, item.ics);
print ("url: %s\n".printf (url));
var message = new Soup.Message ("DELETE", url);
yield set_credential (message);

Expand Down
10 changes: 5 additions & 5 deletions core/Services/Database.vala
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,11 @@ public class Services.Database : GLib.Object {
return return_value;
}

public Gee.ArrayList<Objects.Project> get_subprojects (Objects.Project p) {
public Gee.ArrayList<Objects.Project> get_subprojects (Objects.Project _project) {
Gee.ArrayList<Objects.Project> return_value = new Gee.ArrayList<Objects.Project> ();
lock (_projects) {
foreach (var project in projects) {
if (project.parent_id == p.id) {
if (project.parent_id == _project.id) {
return_value.add (project);
}
}
Expand Down Expand Up @@ -595,15 +595,15 @@ public class Services.Database : GLib.Object {
set_parameter_str (stmt, "$id", project.id);

if (stmt.step () == Sqlite.DONE) {
foreach (Objects.Section section in project.sections) {
foreach (Objects.Section section in get_sections_by_project (project)) {
delete_section (section);
}

foreach (Objects.Item item in project.items) {
foreach (Objects.Item item in get_items_by_project (project)) {
delete_item (item);
}

foreach (Objects.Project subproject in project.subprojects) {
foreach (Objects.Project subproject in get_subprojects (project)) {
delete_project (subproject);
}

Expand Down
2 changes: 2 additions & 0 deletions core/Services/EventBus.vala
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,7 @@ public class Services.EventBus : Object {
public signal void item_added_successfully ();

// Navigate
public signal void open_item (Objects.Item item);
public signal void push_item (Objects.Item item);
public signal void close_item ();
}
Loading
Loading