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

calendar@schorschii improvements #941

Merged
merged 2 commits into from
Oct 29, 2023
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
11 changes: 11 additions & 0 deletions calendar@schorschii/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Calendar Desklet
A simple local calendar desklet that can display the number of today's appointments from an ical/ics file.

## Usage With Thunderbird
You can e.g. configure the Thunderbird calendar to save your appointments in an ics file.

1. Create an empty file on your computer, e.g. `/home/<username>/calendar.ics`.
2. Create a new calendar in Thunderbird using this file.
- In the "New Calendar" dialog, choose "Network".
- As address, enter the URL path to the file on your computer, e.g. `file:///home/<username>/calendar.ics`.
3. Choose the file in the desklet settings. The desklet will now display the number of today's appointments in the ics file.
110 changes: 54 additions & 56 deletions calendar@schorschii/files/calendar@schorschii/desklet.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Clutter = imports.gi.Clutter;
const GdkPixbuf = imports.gi.GdkPixbuf;
const Cogl = imports.gi.Cogl;
const Gettext = imports.gettext;
const Gio = imports.gi.Gio;

const UUID = "calendar@schorschii";
const DESKLET_ROOT = imports.ui.deskletManager.deskletMeta[UUID].path;
Expand All @@ -33,7 +34,7 @@ function main(metadata, desklet_id) {
}

function getImageAtScale(imageFileName, width, height, width2 = 0, height2 = 0) {
if (width2 == 0 || height2 == 0) {
if(width2 == 0 || height2 == 0) {
width2 = width;
height2 = height;
}
Expand Down Expand Up @@ -90,10 +91,10 @@ MyDesklet.prototype = {
this.default_month_top_top = 27;
this.dayofmonth = 0; this.monthofyear = 0; this.dayofweek = 0; this.year = 0;
this.dayofweek_string = ""; this.monthofyear_string = "";
this.notification_amount = 0; this.last_notification_amount = 0;
this.last_notification_amount = 0;

// load images and set initial sizes
this.refreshSize(true);
this.refreshDesklet(-1, true);

// set root eleent
this.setContent(this.calendar);
Expand Down Expand Up @@ -121,7 +122,7 @@ MyDesklet.prototype = {
this.dayofweek = this._displayTime.get_day_of_week();
this.year = this._displayTime.get_year();

switch (this.dayofweek) {
switch(this.dayofweek) {
case 1: this.dayofweek_string = _("Monday"); break;
case 2: this.dayofweek_string = _("Tuesday"); break;
case 3: this.dayofweek_string = _("Wednesday"); break;
Expand All @@ -130,7 +131,7 @@ MyDesklet.prototype = {
case 6: this.dayofweek_string = _("Saturday"); break;
case 7: this.dayofweek_string = _("Sunday"); break;
}
switch (this.monthofyear) {
switch(this.monthofyear) {
case 1: this.monthofyear_string = _("January"); break;
case 2: this.monthofyear_string = _("February"); break;
case 3: this.monthofyear_string = _("March"); break;
Expand All @@ -145,57 +146,54 @@ MyDesklet.prototype = {
case 12: this.monthofyear_string = _("December"); break;
}

this.notification_amount = 0;
if (this.read_appointments) {
let ical_content = "";
try {
// read ical file
ical_content = Cinnamon.get_file_contents_utf8_sync(this.ical_file.replace("file://", ""));
} catch(ex) {
// error reading file - maybe the file does not exist
this.notification_amount = -1;
}

var lines = ical_content.split("\n");

let ical_current_dtstart = "";
let ical_current_dtend = "";
let ical_current_text = "";
let ical_current_desc = "";
for(var i = 0;i < lines.length;i++){
if(lines[i].startsWith("BEGIN:VEVENT")) {
// calendar entry starts
if(this.read_appointments) {
// read ical file
var notification_amount = 0;
let ical_file = Gio.file_new_for_path(this.ical_file.replace("file://", ""));
ical_file.load_contents_async(null, (file, response) => {
try {
let [success, contents, tag] = file.load_contents_finish(response);
if(success) {
var lines = contents.toString().split("\n");
let ical_current_dtstart = "";
let ical_current_dtend = "";
let ical_current_text = "";
let ical_current_desc = "";
for(var i = 0;i < lines.length;i++){
if(lines[i].startsWith("DTSTART")) // read appointment start date and time
ical_current_dtstart = lines[i].split(":")[1].split("T")[0].trim();
if(lines[i].startsWith("DTEND")) // read appointment end date and time
ical_current_dtend = lines[i].split(":")[1].split("T")[0].trim();
if(lines[i].startsWith("SUMMARY")) // read appointment summary
ical_current_text = lines[i].split(":")[1];
if(lines[i].startsWith("DESCRIPTION")) // read appointment description
ical_current_desc = lines[i].split(":")[1];
if(lines[i].startsWith("END:VEVENT")) { // calendar entry ends
// check date if it matches today's date and if so, increment the counter
if(ical_current_dtstart == this.year.toString() + ("0" + this.monthofyear.toString()).slice(-2) + ("0" + this.dayofmonth.toString()).slice(-2))
notification_amount ++;
// reset temporary variables
ical_current_desc = ""; ical_current_text = ""; ical_current_dtstart = ""; ical_current_dtend = "";
}
}
this.refreshDesklet(notification_amount, false); // set text without recalc sizes
}
} catch(ex) {
global.log(ex.toString());
// error reading file - maybe the file does not exist
this.refreshDesklet(-1, false); // set text without recalc sizes
}
if(lines[i].startsWith("END:VEVENT")) {
// calendar entry ends

// check date if it matches today's date
if (ical_current_dtstart == this.year.toString() + ('0' + this.monthofyear.toString()).slice(-2) + ('0' + this.dayofmonth.toString()).slice(-2))
this.notification_amount ++;

// reset temporary variables
ical_current_desc = ""; ical_current_text = ""; ical_current_dtstart = ""; ical_current_dtend = "";
}
if(lines[i].startsWith("DTSTART")) // read appointment start date and time
ical_current_dtstart = lines[i].split(":")[1].split("T")[0].trim();
if(lines[i].startsWith("DTEND")) // read appointment end date and time
ical_current_dtend = lines[i].split(":")[1].split("T")[0].trim();
if(lines[i].startsWith("SUMMARY")) // read appointment summary
ical_current_text = lines[i].split(":")[1];
if(lines[i].startsWith("DESCRIPTION")) // read appointment description
ical_current_desc = lines[i].split(":")[1];
}
});
} else {
this.refreshDesklet(-1, false); // set text without recalc sizes
}

// set object sizes without recalc
this.refreshSize(false);

// refresh again in five seconds
this.timeout = Mainloop.timeout_add_seconds(5, Lang.bind(this, this.refresh));
},

refreshSize: function(reloadGraphics = false) {
if(this.notification_amount != this.last_notification_amount || reloadGraphics == true) {
refreshDesklet: function(notification_amount, reloadGraphics=false) {
if(notification_amount != this.last_notification_amount || reloadGraphics) {

// calc new sizes based on scale factor
let scale = this.scale_size * global.ui_scale;
Expand Down Expand Up @@ -244,12 +242,12 @@ MyDesklet.prototype = {
this.container.add_actor(this.month_big);
this.container.add_actor(this.month_sub);
this.container.add_actor(this.month_top);
if(this.notification_amount > 0 || this.notification_amount == -1)
if(this.read_appointments)
this.container.add_actor(this.notification);
this.setContent(this.calendar);

// remember last notification amount
this.last_notification_amount = this.notification_amount;
this.last_notification_amount = notification_amount;

// debug
//Main.notifyError("Complete Refresh Done", text_color_style);
Expand All @@ -260,18 +258,18 @@ MyDesklet.prototype = {
this.month_big.set_text(this.dayofmonth.toString());
this.month_sub.set_text(subtitle);
this.month_top.set_text(this.dayofweek_string);
if(this.notification_amount == -1)
if(notification_amount == -1)
this.notification.set_text("!");
else
this.notification.set_text(this.notification_amount.toString());
this.notification.set_text(notification_amount.toString());

// debug
//Main.notifyError("Text Refresh Done", " ");
},

refreshDecoration: function() {
// desklet label (header)
if(this.use_custom_label == true)
if(this.use_custom_label)
this.setHeader(this.custom_label)
else
this.setHeader(_("Calendar"));
Expand All @@ -290,11 +288,11 @@ MyDesklet.prototype = {
this.refresh();

// update size based on scale factor
this.refreshSize(true);
this.refreshDesklet(this.last_notification_amount, true);
},

on_desklet_clicked: function() {
if(this.onclick_active == true && this.onclick_command != "")
if(this.onclick_active && this.onclick_command != "")
Util.spawnCommandLine(this.onclick_command);
},

Expand Down
4 changes: 2 additions & 2 deletions calendar@schorschii/files/calendar@schorschii/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"uuid": "calendar@schorschii",
"max-instances": "10",
"description": "A calendar desklet that can display the number of today's appointments from an ical file.",
"description": "A calendar desklet that can display the number of today's appointments from an ical/ics file.",
"name": "Calendar",
"version": "1.3"
"version": "1.5"
}
8 changes: 4 additions & 4 deletions calendar@schorschii/files/calendar@schorschii/po/ca.po
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,17 @@ msgstr ""
"camp següent."

#. calendar@schorschii->settings-schema.json->ical-file->description
msgid "Path to ical file"
msgstr "Camí al fitxer ical"
msgid "Path to ical/ics file"
msgstr "Camí al fitxer ical/ics"

#. calendar@schorschii->settings-schema.json->ical-file->tooltip
msgid ""
"Select your ical file for reading the amount of appointments today.\n"
"Select your ical or ics file for reading the amount of appointments today.\n"
"\n"
"You can configure Lightning (the Thunderbird Add-On) to save your calendar "
"in an ical file."
msgstr ""
"Seleccioneu el vostre fitxer ical per llegir el nombre de cites d'avui.\n"
"Seleccioneu el vostre fitxer ical o ics per llegir la quantitat de cites d'avui.\n"
"\n"
"Podeu configurar Lightning (el connector de Thunderbird) per desar el vostre "
"calendari a un fitxer ical."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ msgid ""
msgstr ""

#. calendar@schorschii->settings-schema.json->ical-file->description
msgid "Path to ical file"
msgid "Path to ical/ics file"
msgstr ""

#. calendar@schorschii->settings-schema.json->ical-file->tooltip
msgid ""
"Select your ical file for reading the amount of appointments today.\n"
"Select your ical or ics file for reading the amount of appointments today.\n"
"\n"
"You can configure Lightning (the Thunderbird Add-On) to save your calendar in an ical file."
msgstr ""
Expand Down
8 changes: 4 additions & 4 deletions calendar@schorschii/files/calendar@schorschii/po/da.po
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,17 @@ msgstr ""
"i feltet nedenunder."

#. calendar@schorschii->settings-schema.json->ical-file->description
msgid "Path to ical file"
msgstr "Sti til iCal-fil"
msgid "Path to ical/ics file"
msgstr "Sti til iCal/ics-fil"

#. calendar@schorschii->settings-schema.json->ical-file->tooltip
msgid ""
"Select your ical file for reading the amount of appointments today.\n"
"Select your ical or ics file for reading the amount of appointments today.\n"
"\n"
"You can configure Lightning (the Thunderbird Add-On) to save your calendar "
"in an ical file."
msgstr ""
"Vælg iCal-filen, hvorfra antallet af aftaler skal indlæses.\n"
"Vælg din ical- eller ics-fil for at læse antallet af aftaler i dag.\n"
"\n"
"Du kan konfigurere Lightning (Thunderbird-tilføjelsen) til at gemme din "
"kalender som en iCal-fil."
Expand Down
8 changes: 4 additions & 4 deletions calendar@schorschii/files/calendar@schorschii/po/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,17 @@ msgstr ""
"darunter auswählen."

#. calendar@schorschii->settings-schema.json->ical-file->description
msgid "Path to ical file"
msgstr "Pfad zur ical-Datei"
msgid "Path to ical/ics file"
msgstr "Pfad zur ical/ics-Datei"

#. calendar@schorschii->settings-schema.json->ical-file->tooltip
msgid ""
"Select your ical file for reading the amount of appointments today.\n"
"Select your ical or ics file for reading the amount of appointments today.\n"
"\n"
"You can configure Lightning (the Thunderbird Add-On) to save your calendar "
"in an ical file."
msgstr ""
"Wählen Sie die ical-Datei aus, aus welcher die Anzahl der heutigen Termine "
"Wählen Sie die ical- oder ics-Datei aus, aus welcher die Anzahl der heutigen Termine "
"ausgelesen werden soll.\n"
"\n"
"Sie können Lightning (das Thunderbird Add-On) so konfigurieren, dass es die "
Expand Down
8 changes: 4 additions & 4 deletions calendar@schorschii/files/calendar@schorschii/po/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,17 @@ msgstr ""
"el campo inferior."

#. calendar@schorschii->settings-schema.json->ical-file->description
msgid "Path to ical file"
msgstr "Ruta al archivo ical"
msgid "Path to ical/ics file"
msgstr "Ruta al archivo ical/ics"

#. calendar@schorschii->settings-schema.json->ical-file->tooltip
msgid ""
"Select your ical file for reading the amount of appointments today.\n"
"Select your ical or ics file for reading the amount of appointments today.\n"
"\n"
"You can configure Lightning (the Thunderbird Add-On) to save your calendar "
"in an ical file."
msgstr ""
"Seleccione su archivo ical para leer la cantidad de compromisos de hoy.\n"
"Seleccione su archivo ical o ics para leer la cantidad de citas hoy.\n"
"\n"
"Puede configurar Lightning (el complemento de Thunderbird) para guardar su "
"calendario en un archivo ical."
Expand Down
8 changes: 4 additions & 4 deletions calendar@schorschii/files/calendar@schorschii/po/hu.po
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ msgid "Checking this box allows you to set an ical file to parse in the field be
msgstr "Ennek a négyzetnek a bejelölésével az alábbi mezőben megadhat egy importálandó ical fájlt."

#. calendar@schorschii->settings-schema.json->ical-file->description
msgid "Path to ical file"
msgstr "Elérési útvonal az ical fájlhoz"
msgid "Path to ical/ics file"
msgstr "Elérési útvonal az ical/ics fájlhoz"

#. calendar@schorschii->settings-schema.json->ical-file->tooltip
msgid ""
"Select your ical file for reading the amount of appointments today.\n"
"Select your ical or ics file for reading the amount of appointments today.\n"
"\n"
"You can configure Lightning (the Thunderbird Add-On) to save your calendar in an ical file."
msgstr ""
"Válassza ki az ical fájlt a mai találkozók mennyiségének beolvasásához.\n"
"Válassza ki az ical vagy ics fájlt a mai találkozók számának olvasásához.\n"
"\n"
"Beállíthatja a Lightning-et (a Thunderbird kiegészítőjét), hogy a naptárat egy ical fájlba mentse."

Expand Down
8 changes: 4 additions & 4 deletions calendar@schorschii/files/calendar@schorschii/po/it.po
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,17 @@ msgstr ""
"nel campo sottostante."

#. calendar@schorschii->settings-schema.json->ical-file->description
msgid "Path to ical file"
msgstr "Percorso del file ical"
msgid "Path to ical/ics file"
msgstr "Percorso del file ical/ics"

#. calendar@schorschii->settings-schema.json->ical-file->tooltip
msgid ""
"Select your ical file for reading the amount of appointments today.\n"
"Select your ical or ics file for reading the amount of appointments today.\n"
"\n"
"You can configure Lightning (the Thunderbird Add-On) to save your calendar "
"in an ical file."
msgstr ""
"Seleziona il tuo file ical per leggere la quantità di appuntamenti oggi.\n"
"Seleziona il tuo file ical o ics per leggere il numero di appuntamenti di oggi.\n"
"\n"
"Puoi configurare Lightning (il componente aggiuntivo di Thunderbird) per "
"salvare il tuo calendario in un file ical."
Expand Down
9 changes: 4 additions & 5 deletions calendar@schorschii/files/calendar@schorschii/po/pt_BR.po
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,17 @@ msgstr ""
"abaixo para ser analisado."

#. calendar@schorschii->settings-schema.json->ical-file->description
msgid "Path to ical file"
msgstr "Endereço do arquivo .ics"
msgid "Path to ical/ics file"
msgstr "Endereço do arquivo .ical/.ics"

#. calendar@schorschii->settings-schema.json->ical-file->tooltip
msgid ""
"Select your ical file for reading the amount of appointments today.\n"
"Select your ical or ics file for reading the amount of appointments today.\n"
"\n"
"You can configure Lightning (the Thunderbird Add-On) to save your calendar "
"in an ical file."
msgstr ""
"Selecione o seu arquivo .ics para saber a quantidade de compromissos no dia "
"de hoje.\n"
"Selecione seu arquivo ical ou ics para ler a quantidade de compromissos hoje.\n"
"\n"
"Você pode configurar o salvamento do seu calendário em um arquivo .ics no "
"Lightning (um complemento para o Thunderbird)."
Expand Down
Loading
Loading