@@ -1369,18 +1369,42 @@ public class Objects.Item : Objects.BaseObject {
13691369 }
13701370 });
13711371 } else if (project. source_type == SourceType . CALDAV ) {
1372- loading = true ;
1373- var caldav_client = Services . CalDAV . Core . get_default (). get_client (project. source);
1374- caldav_client. delete_item. begin (this , (obj, res) = > {
1375- HttpResponse response = caldav_client. delete_item. end (res);
1376- loading = false ;
1372+ delete_caldav. begin ();
1373+ }
1374+ }
13771375
1378- if (response. status) {
1379- Services . Store . instance (). delete_item (this );
1380- } else {
1381- Services . EventBus . get_default (). send_error_toast (response. error_code, response. error);
1382- }
1383- });
1376+ private async void delete_caldav () {
1377+ loading = true ;
1378+ var caldav_client = Services . CalDAV . Core . get_default (). get_client (project. source);
1379+
1380+ try {
1381+ yield delete_subitems_caldav (this , caldav_client);
1382+
1383+ var response = yield caldav_client. delete_item (this );
1384+
1385+ if (! response. status) {
1386+ throw new IOError .FAILED (response. error);
1387+ }
1388+
1389+ Services . Store . instance (). delete_item (this );
1390+ } catch (Error e) {
1391+ Services . EventBus . get_default (). send_error_toast (0 , e. message);
1392+ }
1393+
1394+ loading = false ;
1395+ }
1396+
1397+ private async void delete_subitems_caldav (Objects .Item item , Services .CalDAV .CalDAVClient caldav_client ) throws Error {
1398+ foreach (Objects . Item subitem in Services . Store . instance (). get_subitems (item)) {
1399+ yield delete_subitems_caldav (subitem, caldav_client);
1400+
1401+ var response = yield caldav_client. delete_item (subitem);
1402+
1403+ if (! response. status) {
1404+ throw new IOError .FAILED (response. error);
1405+ }
1406+
1407+ Services . Store . instance (). delete_item (subitem);
13841408 }
13851409 }
13861410
@@ -1495,12 +1519,12 @@ public class Objects.Item : Objects.BaseObject {
14951519 }
14961520
14971521 public void move (Objects .Project project , string _section_id ) {
1498- loading = true ;
1499- show_item = false ;
1500-
15011522 if (project. source_type == SourceType . LOCAL ) {
15021523 _move (project. id, _section_id);
15031524 } else if (project. source_type == SourceType . TODOIST ) {
1525+ loading = true ;
1526+ sensitive = false ;
1527+
15041528 string move_id = project. id;
15051529 string move_type = " project_id" ;
15061530 if (_section_id != " " ) {
@@ -1511,7 +1535,6 @@ public class Objects.Item : Objects.BaseObject {
15111535 Services . Todoist . get_default (). move_item. begin (this , move_type, move_id, (obj, res) = > {
15121536 var response = Services . Todoist . get_default (). move_item. end (res);
15131537 loading = false ;
1514- show_item = true ;
15151538
15161539 if (response. status) {
15171540 _move (project. id, _section_id);
@@ -1520,6 +1543,9 @@ public class Objects.Item : Objects.BaseObject {
15201543 }
15211544 });
15221545 } else if (project. source_type == SourceType . CALDAV ) {
1546+ loading = true ;
1547+ sensitive = false ;
1548+
15231549 move_caldav_recursive. begin (project, _section_id);
15241550 }
15251551 }
@@ -1738,4 +1764,29 @@ public class Objects.Item : Objects.BaseObject {
17381764
17391765 return response;
17401766 }
1767+
1768+ public void to_string () {
1769+ print (" _________________________________\n " );
1770+ print (" ID: %s\n " , id);
1771+ print (" Content: %s\n " , content);
1772+ print (" Description: %s\n " , description);
1773+ print (" Project ID: %s\n " , project_id);
1774+ print (" Section ID: %s\n " , section_id);
1775+ print (" Parent ID: %s\n " , parent_id);
1776+ print (" Priority: %d (%s )\n " , priority, priority_text);
1777+ print (" Checked: %s\n " , checked ? " true" : " false" );
1778+ print (" Pinned: %s\n " , pinned ? " true" : " false" );
1779+ print (" Has Due: %s\n " , has_due ? " true" : " false" );
1780+ if (has_due) {
1781+ print (" Due Date: %s\n " , due. date);
1782+ }
1783+ print (" Child Order: %d\n " , child_order);
1784+ print (" Added At: %s\n " , added_at);
1785+ print (" Completed At: %s\n " , completed_at);
1786+ print (" Labels: %d\n " , labels. size);
1787+ foreach (var label in labels) {
1788+ print (" - %s\n " , label. name);
1789+ }
1790+ print (" ---------------------------------\n " );
1791+ }
17411792}
0 commit comments