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

Don't overwrite events unnecessarily when parsing #482

Merged
merged 7 commits into from
Mar 26, 2020
Merged
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
3 changes: 2 additions & 1 deletion data/io.elementary.calendar.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
</p>
</description>
<releases>
<release version="5.0.4" date="2020-01-03" urgency="medium">
<release version="5.0.4" date="2020-03-23" urgency="medium">
<description>
<p>Correctly save event reminders</p>
<p>Fix unwanted rescheduling when editing event title</p>
</description>
</release>
<release version="5.0.3" date="2019-11-27" urgency="medium">
Expand Down
28 changes: 21 additions & 7 deletions src/EventEdition/EventDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,27 @@ public class EventDialog : Gtk.Dialog {
if (!event_parsed) {
var ev = parser.parse_source (ev_str);
info_panel.title = ev.title;
info_panel.from_date = ev.from;
info_panel.to_date = ev.to;
info_panel.from_time = ev.from;
info_panel.to_time = ev.to;
info_panel.all_day = ev.all_day;
guests_panel.guests = ev.participants;
location_panel.location = ev.location;

if (ev.date_parsed) {
info_panel.from_date = ev.from;
info_panel.to_date = ev.to;
}

if (ev.time_parsed) {
info_panel.from_time = ev.from;
info_panel.to_time = ev.to;
}

if (ev.all_day != null) {
info_panel.all_day = ev.all_day;
}

guests_panel.guests += ev.participants;

if (ev.location.length > 0) {
location_panel.location = ev.location;
}

event_parsed = true;
}
else
Expand Down
12 changes: 8 additions & 4 deletions src/EventParser/ParsedEvent.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
Expand All @@ -28,15 +28,19 @@ public class ParsedEvent : GLib.Object {
public string participants;
public DateTime from;
public DateTime to;
public bool all_day;
public bool? all_day;
public bool date_parsed;
public bool time_parsed;

public ParsedEvent (string _title = "", DateTime? _from = null, DateTime? _to = null, string _location = "", bool _all_day = false, string _participants = "") {
public ParsedEvent (string _title = "", DateTime? _from = null, DateTime? _to = null, string _location = "", bool? _all_day = null, string _participants = "", bool _date_parsed = false, bool _time_parsed = false) {
this.title = _title;
this.location = _location;
this.participants = _participants;
this.from = _from;
this.to = _to;
this.all_day = _all_day;
this.date_parsed = _date_parsed;
this.time_parsed = _time_parsed;
}

public void set_length_to_minutes (int minutes) {
Expand Down
48 changes: 43 additions & 5 deletions src/EventParser/Parsers/ParserDe.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
Expand Down Expand Up @@ -155,21 +155,25 @@ public class ParserDe : GLib.Object, EventParser {
// --- Date ---

analyze_pattern ("vorgestern", (data) => {
event.date_parsed = true;
event.from = event.from.add_days (-2);
event.set_one_entire_day ();
});

analyze_pattern ("gestern", (data) => {
event.date_parsed = true;
event.from = event.from.add_days (-1);
event.set_one_entire_day ();
});

analyze_pattern ("(ab )?morgen", (data) => {
event.date_parsed = true;
event.from = event.from.add_days (1);
event.set_one_entire_day ();
});

analyze_pattern ("(ab )?übermorgen", (data) => {
event.date_parsed = true;
event.from = event.from.add_days (2);
event.set_one_entire_day ();
});
Expand All @@ -180,45 +184,53 @@ public class ParserDe : GLib.Object, EventParser {

analyze_pattern ("vor (?<p1>\\d+) tagen", (data) => {
int days = int.parse ( data.p.index (0));

event.date_parsed = true;
event.from = event.from.add_days (-days);
event.set_one_entire_day ();
});

analyze_pattern ("in (?<p1>\\d+) tagen", (data) => {
int days = int.parse (data.p.index (0));

event.date_parsed = true;
event.from = event.from.add_days (days);
event.set_one_entire_day ();
});

analyze_pattern (@"diesen (?<p1>$weekdays_regex)", (data) => {
int weekday = get_number_of_weekday (data.p.index (0));
int add_days = (weekday - this.simulated_dt.get_day_of_week () + 7 ) % 7;
event.from = event.from.add_days (add_days);

event.date_parsed = true;
event.from = event.from.add_days (add_days);
event.set_one_entire_day ();
});

analyze_pattern (@"nächsten (?<p1>$weekdays_regex)", (data) => {
int weekday = get_number_of_weekday (data.p.index (0));
int add_days = (weekday - this.simulated_dt.get_day_of_week () + 7 ) % 7;
event.from = event.from.add_days (add_days);

event.date_parsed = true;
event.from = event.from.add_days (add_days);
event.set_one_entire_day ();
});

analyze_pattern (@"übernächsten (?<p1>$weekdays_regex)", (data) => {
int weekday = get_number_of_weekday (data.p.index (0));
int add_days = (weekday - this.simulated_dt.get_day_of_week () + 7 ) % 7;

event.date_parsed = true;
event.from = event.from.add_weeks (1);
event.from = event.from.add_days (add_days);

event.set_one_entire_day ();
});

analyze_pattern ("am (?<p1>\\d+).(?<p2>\\d+)(.(?<p3>\\d+))?", (data) => {
int day = int.parse (data.p.index (0));
int month = int.parse (data.p.index (1));

event.date_parsed = true;
event.from_set_day (day);
event.set_one_entire_day ();

Expand All @@ -239,6 +251,7 @@ public class ParserDe : GLib.Object, EventParser {
int day_1 = int.parse (data.p.index (0));
int day_2 = int.parse (data.p.index (1));

event.date_parsed = true;
event.from_set_day (day_1);
event.to_set_day (day_2);
event.set_all_day ();
Expand All @@ -258,6 +271,7 @@ public class ParserDe : GLib.Object, EventParser {
int day = int.parse (data.p.index (0));
int month = get_number_of_month (data.p.index (1));

event.date_parsed = true;
event.from_set_day (day);
event.from_set_month (month);
event.set_one_entire_day ();
Expand All @@ -266,6 +280,7 @@ public class ParserDe : GLib.Object, EventParser {
});

analyze_pattern ("heiligabend", (data) => {
event.date_parsed = true;
event.from_set_month (12);
event.from_set_day (24);
event.set_one_entire_day ();
Expand All @@ -276,43 +291,51 @@ public class ParserDe : GLib.Object, EventParser {
// --- Time ---

analyze_pattern ("früh", (data) => {
event.time_parsed = true;
event.from_set_hour (9);
event.set_length_to_hours (1);
event.all_day = false;
});

analyze_pattern ("vormittags", (data) => {
event.time_parsed = true;
event.from_set_hour (11);
event.set_length_to_hours (1);
event.all_day = false;
});

analyze_pattern ("mittag(s?)", (data) => {
event.time_parsed = true;
event.from_set_hour (12);
event.set_length_to_hours (1);
event.all_day = false;
});

analyze_pattern ("nachmittags", (data) => {
event.time_parsed = true;
event.from_set_hour (15);
event.set_length_to_hours (1);
event.all_day = false;
});

analyze_pattern ("abends", (data) => {
event.time_parsed = true;
event.from_set_hour (18);
event.set_length_to_hours (1);
event.all_day = false;
});

analyze_pattern ("spät", (data) => {
event.time_parsed = true;
event.from_set_hour (19);
event.set_length_to_hours (3);
event.all_day = false;
});

analyze_pattern ("(um|ab) (?<p1>\\d+)(:(?<p2>\\d+))?( (uhr|h))?", (data) => {
int hour = int.parse (data.p.index (0));

event.time_parsed = true;
event.from_set_hour (hour);

if (data.p.index (1) != null) {
Expand All @@ -328,6 +351,7 @@ public class ParserDe : GLib.Object, EventParser {
int hour_1 = int.parse (data.p.index (0));
int hour_2 = int.parse (data.p.index (1));

event.time_parsed = true;
event.from_set_hour (hour_1);
event.to_set_hour (hour_2);

Expand All @@ -345,6 +369,8 @@ public class ParserDe : GLib.Object, EventParser {

analyze_pattern ("(?<p1>\\d+)(:(?<p2>\\d+))? (uhr|h)", (data) => {
int hour = int.parse (data.p.index (0));

event.time_parsed = true;
event.from_set_hour (hour);

if (data.p.index (1) != null) {
Expand All @@ -358,21 +384,33 @@ public class ParserDe : GLib.Object, EventParser {

analyze_pattern ("für (?<p1>\\d+)(\\s?min| Minuten)", (data) => {
int minutes = int.parse (data.p.index (0));

event.date_parsed = true;
event.time_parsed = true;
event.all_day = false;
event.set_length_to_minutes (minutes);
});

analyze_pattern ("für (?<p1>\\d+)(\\s?h| Stunden)", (data) => {
int hours = int.parse (data.p.index (0));

event.date_parsed = true;
event.time_parsed = true;
event.all_day = false;
event.set_length_to_hours (hours);
});

analyze_pattern ("für (?<p1>\\d+)(\\s?d| Tage)", (data) => {
int days = int.parse (data.p.index (0));

event.date_parsed = true;
event.set_length_to_days (days);
});

analyze_pattern ("für (?<p1>\\d+) Wochen", (data) => {
int weeks = int.parse (data.p.index (0));

event.date_parsed = true;
event.set_length_to_weeks (weeks);
});

Expand Down
Loading