2 * acpi_notifier -- for Claws Mail
4 * Copyright (C) 2005 Colin Leroy <colin@colino.net>
6 * Sylpheed is a GTK+ based, lightweight, and fast e-mail client
7 * Copyright (C) 1999-2005 Hiroyuki Yamamoto and the Claws Mail Team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include "claws-features.h"
30 #include <glib/gi18n.h>
41 #include "prefs_gtk.h"
46 #include "alertpanel.h"
48 #include "folder_item_prefs.h"
50 #define PREFS_BLOCK_NAME "AcpiNotifier"
51 #define PLUGIN_NAME _("Acpi Notifier")
53 typedef struct _PredefinedAcpis {
63 * Add your implementation here (and send me the patch!)
67 N_("Make sure that the kernel module 'acerhk' is loaded.\n"
68 "You can get it from http://www.cakey.de/acerhk/"),
69 N_("Make sure that the kernel module 'acer_acpi' is loaded.\n"
70 "You can get it from http://code.google.com/p/aceracpi/"),
71 N_("Make sure that the kernel module 'asus_laptop' is loaded."),
72 N_("Make sure that the kernel module 'asus_acpi' is loaded."),
73 N_("Make sure that the kernel module 'ibm_acpi' is loaded."),
74 N_("Make sure that you have apanelc installed.\n"
75 "You can get it from http://apanel.sourceforge.net/"),
78 PredefinedAcpis known_implementations[] = {
79 {"Other file", "", "", "", FALSE, NULL},
81 {"ACER (acerhk)", "1", "0", "/proc/driver/acerhk/led", FALSE, NULL},
83 {"ACER (acer_acpi)", "1", "0", "/proc/acpi/acer/mailled", FALSE, NULL},
85 {"ASUS (asus_laptop)", "1", "0", "/sys/class/leds/asus:mail/brightness", FALSE, NULL},
87 {"ASUS (asus_acpi)", "1", "0", "/proc/acpi/asus/mled", FALSE, NULL},
89 {"IBM (ibm_acpi)", "7 on", "7 off", "/proc/acpi/ibm/led", FALSE, NULL},
91 {"Lenovo (tp_smapi)", "on", "off", "/proc/acpi/ibm/light", FALSE, NULL},
93 {"Fujitsu (apanel)", "led on", "led off", "apanelc", TRUE, NULL},
95 {NULL, NULL, NULL, NULL, FALSE, NULL}
98 static guint folder_hook_id;
99 static guint alertpanel_hook_id;
101 struct AcpiNotifierPage
105 GtkWidget *no_mail_off_btn;
106 GtkWidget *no_mail_blink_btn;
107 GtkWidget *no_mail_on_btn;
108 GtkWidget *unread_mail_off_btn;
109 GtkWidget *unread_mail_blink_btn;
110 GtkWidget *unread_mail_on_btn;
111 GtkWidget *new_mail_off_btn;
112 GtkWidget *new_mail_blink_btn;
113 GtkWidget *new_mail_on_btn;
114 GtkWidget *default_implementations_optmenu;
115 GtkWidget *on_value_entry;
116 GtkWidget *off_value_entry;
117 GtkWidget *file_entry;
118 GtkWidget *hbox_acpi_file;
119 GtkWidget *hbox_acpi_values;
120 GtkWidget *warning_label;
121 GtkWidget *warning_box;
122 GtkWidget *blink_on_err_chkbtn;
125 typedef struct _AcpiNotifierPrefs AcpiNotifierPrefs;
127 struct _AcpiNotifierPrefs
130 gint unread_mail_action;
131 gint new_mail_action;
132 gboolean blink_on_err;
138 AcpiNotifierPrefs acpiprefs;
140 static struct AcpiNotifierPage acpi_prefs_page;
148 static PrefParam param[] = {
149 {"no_mail_action", "0", &acpiprefs.no_mail_action, P_INT,
151 {"unread_mail_action", "0", &acpiprefs.unread_mail_action, P_INT,
153 {"new_mail_action", "1", &acpiprefs.new_mail_action, P_INT,
155 {"blink_on_err", "TRUE", &acpiprefs.blink_on_err, P_BOOL,
157 {"on_param", NULL, &acpiprefs.on_param, P_STRING,
159 {"off_param", NULL, &acpiprefs.off_param, P_STRING,
161 {"file_path", NULL, &acpiprefs.file_path, P_STRING,
163 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
166 static gboolean check_impl (const gchar *filepath)
169 for (i = 0; known_implementations[i].name != NULL; i++) {
170 if (strcmp(known_implementations[i].file_path, filepath))
172 if (!known_implementations[i].is_program)
173 return is_file_exist(filepath);
175 gchar *cmd = g_strdup_printf("which %s", filepath);
176 int found = system(cmd);
181 return is_file_exist(filepath);
184 static gboolean is_program (const gchar *filepath)
187 for (i = 0; known_implementations[i].name != NULL; i++) {
188 if (strcmp(known_implementations[i].file_path, filepath))
190 return known_implementations[i].is_program;
195 static void show_error (struct AcpiNotifierPage *page, const gchar *filepath)
199 gtk_widget_hide(page->warning_box);
202 for (i = 0; known_implementations[i].name != NULL; i++) {
203 if (strcmp(known_implementations[i].file_path, filepath))
205 if (known_implementations[i].help) {
206 gchar *tmp = g_strdup_printf("%s\n%s",
207 _("Control file doesn't exist."),
208 known_implementations[i].help);
209 gtk_label_set_text(GTK_LABEL(page->warning_label), tmp);
212 gtk_label_set_text(GTK_LABEL(page->warning_label),
213 _("Control file doesn't exist."));
215 gtk_widget_show_all(page->warning_box);
220 static void type_activated(GtkMenuItem *menuitem, gpointer data)
222 GtkWidget *menu, *item;
223 struct AcpiNotifierPage *page = (struct AcpiNotifierPage *)data;
226 if (page->file_entry == NULL)
229 menu = gtk_cmoption_menu_get_menu(
230 GTK_CMOPTION_MENU(page->default_implementations_optmenu));
231 item = gtk_menu_get_active(GTK_MENU(menu));
232 selected = GPOINTER_TO_INT
233 (g_object_get_data(G_OBJECT(item), MENU_VAL_ID));
236 gtk_widget_hide(page->hbox_acpi_file);
237 gtk_widget_hide(page->hbox_acpi_values);
238 gtk_entry_set_text(GTK_ENTRY(page->file_entry),
239 known_implementations[selected].file_path);
240 gtk_entry_set_text(GTK_ENTRY(page->on_value_entry),
241 known_implementations[selected].on_param);
242 gtk_entry_set_text(GTK_ENTRY(page->off_value_entry),
243 known_implementations[selected].off_param);
244 if (!check_impl(known_implementations[selected].file_path))
245 show_error(page, known_implementations[selected].file_path);
247 show_error(page, NULL);
249 gtk_widget_show_all(page->hbox_acpi_file);
250 gtk_widget_show_all(page->hbox_acpi_values);
253 static void file_entry_changed (GtkWidget *entry, gpointer data)
255 struct AcpiNotifierPage *page = (struct AcpiNotifierPage *)data;
256 if (!page->warning_box)
259 if (!check_impl(gtk_entry_get_text(GTK_ENTRY(entry))))
260 show_error(page, gtk_entry_get_text(GTK_ENTRY(entry)));
262 show_error(page, NULL);
265 static void acpi_prefs_create_widget_func(PrefsPage * _page,
269 struct AcpiNotifierPage *page = (struct AcpiNotifierPage *) _page;
273 GtkWidget *hbox_acpi_file;
274 GtkWidget *hbox_acpi_values;
275 GtkWidget *start_label;
276 GtkWidget *no_mail_label;
277 GtkWidget *no_mail_off_btn;
278 GtkWidget *no_mail_blink_btn;
279 GtkWidget *no_mail_on_btn;
280 GtkWidget *unread_mail_label;
281 GtkWidget *unread_mail_off_btn;
282 GtkWidget *unread_mail_blink_btn;
283 GtkWidget *unread_mail_on_btn;
284 GtkWidget *new_mail_label;
285 GtkWidget *new_mail_off_btn;
286 GtkWidget *new_mail_blink_btn;
287 GtkWidget *new_mail_on_btn;
288 GtkWidget *default_implementations_optmenu;
289 GtkWidget *default_implementations_menu;
290 GtkWidget *on_value_entry;
291 GtkWidget *off_value_entry;
292 GtkWidget *file_entry;
294 GtkWidget *warning_label;
295 GtkWidget *warning_box;
297 GtkWidget *blink_on_err_chkbtn;
302 vbox = gtk_vbox_new(FALSE, 6);
303 gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER);
305 no_mail_label = gtk_label_new(_(" : no new or unread mail"));
306 unread_mail_label = gtk_label_new(_(" : unread mail"));
307 new_mail_label = gtk_label_new(_(" : new mail"));
309 no_mail_off_btn = gtk_radio_button_new_with_label(NULL, _("off"));
310 no_mail_blink_btn = gtk_radio_button_new_with_label_from_widget(
311 GTK_RADIO_BUTTON(no_mail_off_btn), _("blinking"));
312 no_mail_on_btn = gtk_radio_button_new_with_label_from_widget(
313 GTK_RADIO_BUTTON(no_mail_off_btn), _("on"));
315 unread_mail_off_btn = gtk_radio_button_new_with_label(NULL, _("off"));
316 unread_mail_blink_btn = gtk_radio_button_new_with_label_from_widget(
317 GTK_RADIO_BUTTON(unread_mail_off_btn), _("blinking"));
318 unread_mail_on_btn = gtk_radio_button_new_with_label_from_widget(
319 GTK_RADIO_BUTTON(unread_mail_off_btn), _("on"));
321 new_mail_off_btn = gtk_radio_button_new_with_label(NULL, _("off"));
322 new_mail_blink_btn = gtk_radio_button_new_with_label_from_widget(
323 GTK_RADIO_BUTTON(new_mail_off_btn), _("blinking"));
324 new_mail_on_btn = gtk_radio_button_new_with_label_from_widget(
325 GTK_RADIO_BUTTON(new_mail_off_btn), _("on"));
327 on_value_entry = gtk_entry_new();
328 off_value_entry = gtk_entry_new();
329 file_entry = gtk_entry_new();
330 gtk_widget_set_size_request(on_value_entry, 40, -1);
331 gtk_widget_set_size_request(off_value_entry, 40, -1);
333 default_implementations_optmenu = gtk_cmoption_menu_new ();
334 default_implementations_menu = gtk_menu_new();
335 gtk_cmoption_menu_set_menu (
336 GTK_CMOPTION_MENU(default_implementations_optmenu),
337 default_implementations_menu);
338 for (i = 0; known_implementations[i].name != NULL; i++) {
339 MENUITEM_ADD (default_implementations_menu,
340 menuitem, known_implementations[i].name, i);
341 g_signal_connect(G_OBJECT(menuitem), "activate",
342 G_CALLBACK(type_activated),
346 hbox = gtk_hbox_new(FALSE, 6);
347 start_label = gtk_label_new(_("LED "));
348 gtk_box_pack_start(GTK_BOX(hbox), start_label, FALSE, FALSE, 0);
349 gtk_box_pack_start(GTK_BOX(hbox), no_mail_off_btn, FALSE, FALSE, 0);
350 gtk_box_pack_start(GTK_BOX(hbox), no_mail_blink_btn, FALSE, FALSE, 0);
351 gtk_box_pack_start(GTK_BOX(hbox), no_mail_on_btn, FALSE, FALSE, 0);
352 gtk_box_pack_start(GTK_BOX(hbox), no_mail_label, FALSE, FALSE, 0);
353 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
355 hbox = gtk_hbox_new(FALSE, 6);
356 start_label = gtk_label_new(_("LED "));
357 gtk_box_pack_start(GTK_BOX(hbox),
358 start_label, FALSE, FALSE, 0);
359 gtk_box_pack_start(GTK_BOX(hbox),
360 unread_mail_off_btn, FALSE, FALSE, 0);
361 gtk_box_pack_start(GTK_BOX(hbox),
362 unread_mail_blink_btn, FALSE, FALSE, 0);
363 gtk_box_pack_start(GTK_BOX(hbox),
364 unread_mail_on_btn, FALSE, FALSE, 0);
365 gtk_box_pack_start(GTK_BOX(hbox),
366 unread_mail_label, FALSE, FALSE, 0);
367 gtk_box_pack_start(GTK_BOX(vbox),
368 hbox, FALSE, FALSE, 0);
370 hbox = gtk_hbox_new(FALSE, 6);
371 start_label = gtk_label_new(_("LED "));
372 gtk_box_pack_start(GTK_BOX(hbox),
373 start_label, FALSE, FALSE, 0);
374 gtk_box_pack_start(GTK_BOX(hbox),
375 new_mail_off_btn, FALSE, FALSE, 0);
376 gtk_box_pack_start(GTK_BOX(hbox),
377 new_mail_blink_btn, FALSE, FALSE, 0);
378 gtk_box_pack_start(GTK_BOX(hbox),
379 new_mail_on_btn, FALSE, FALSE, 0);
380 gtk_box_pack_start(GTK_BOX(hbox),
381 new_mail_label, FALSE, FALSE, 0);
382 gtk_box_pack_start(GTK_BOX(vbox),
383 hbox, FALSE, FALSE, 0);
385 hbox = gtk_hbox_new(FALSE, 6);
386 start_label = gtk_label_new(_("ACPI type: "));
387 gtk_box_pack_start(GTK_BOX(hbox),
388 start_label, FALSE, FALSE, 0);
389 gtk_box_pack_start(GTK_BOX(hbox),
390 default_implementations_optmenu, FALSE, FALSE, 0);
391 gtk_box_pack_start(GTK_BOX(vbox),
392 hbox, FALSE, FALSE, 0);
394 hbox_acpi_file = gtk_hbox_new(FALSE, 6);
395 start_label = gtk_label_new(_("ACPI file: "));
396 gtk_box_pack_start(GTK_BOX(hbox_acpi_file),
397 start_label, FALSE, FALSE, 0);
398 gtk_box_pack_start(GTK_BOX(hbox_acpi_file),
399 file_entry, FALSE, FALSE, 0);
400 gtk_box_pack_start(GTK_BOX(vbox),
401 hbox_acpi_file, FALSE, FALSE, 0);
402 g_signal_connect(G_OBJECT(file_entry), "changed",
403 G_CALLBACK(file_entry_changed), page);
405 hbox_acpi_values = gtk_hbox_new(FALSE, 6);
406 start_label = gtk_label_new(_("values - On: "));
407 gtk_box_pack_start(GTK_BOX(hbox_acpi_values),
408 start_label, FALSE, FALSE, 0);
409 gtk_box_pack_start(GTK_BOX(hbox_acpi_values),
410 on_value_entry, FALSE, FALSE, 0);
411 start_label = gtk_label_new(_(" - Off: "));
412 gtk_box_pack_start(GTK_BOX(hbox_acpi_values),
413 start_label, FALSE, FALSE, 0);
414 gtk_box_pack_start(GTK_BOX(hbox_acpi_values),
415 off_value_entry, FALSE, FALSE, 0);
416 gtk_box_pack_start(GTK_BOX(vbox),
417 hbox_acpi_values, FALSE, FALSE, 0);
419 warning_box = gtk_hbox_new(FALSE, 6);
421 image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_WARNING,
422 GTK_ICON_SIZE_SMALL_TOOLBAR);
423 gtk_box_pack_start(GTK_BOX(warning_box), image, FALSE, FALSE, 0);
424 warning_label = gtk_label_new(
425 _("Control file doesn't exist."));
426 gtk_box_pack_start(GTK_BOX(warning_box), warning_label, FALSE, FALSE, 0);
427 gtk_box_pack_start(GTK_BOX(vbox), warning_box, FALSE, FALSE, 0);
429 gtk_widget_show_all(vbox);
430 gtk_widget_hide(warning_box);
432 blink_on_err_chkbtn = gtk_check_button_new_with_label(
433 _("Blink when user interaction is required"));
434 gtk_box_pack_start(GTK_BOX(vbox), blink_on_err_chkbtn, FALSE, FALSE, 0);
435 gtk_toggle_button_set_active(
436 GTK_TOGGLE_BUTTON(blink_on_err_chkbtn),
437 acpiprefs.blink_on_err);
438 gtk_widget_show(blink_on_err_chkbtn);
440 switch (acpiprefs.no_mail_action) {
442 gtk_toggle_button_set_active(
443 GTK_TOGGLE_BUTTON(no_mail_off_btn), TRUE);
446 gtk_toggle_button_set_active(
447 GTK_TOGGLE_BUTTON(no_mail_blink_btn), TRUE);
450 gtk_toggle_button_set_active(
451 GTK_TOGGLE_BUTTON(no_mail_on_btn), TRUE);
455 switch (acpiprefs.unread_mail_action) {
457 gtk_toggle_button_set_active(
458 GTK_TOGGLE_BUTTON(unread_mail_off_btn), TRUE);
461 gtk_toggle_button_set_active(
462 GTK_TOGGLE_BUTTON(unread_mail_blink_btn), TRUE);
465 gtk_toggle_button_set_active(
466 GTK_TOGGLE_BUTTON(unread_mail_on_btn), TRUE);
470 switch (acpiprefs.new_mail_action) {
472 gtk_toggle_button_set_active(
473 GTK_TOGGLE_BUTTON(new_mail_off_btn), TRUE);
476 gtk_toggle_button_set_active(
477 GTK_TOGGLE_BUTTON(new_mail_blink_btn), TRUE);
480 gtk_toggle_button_set_active(
481 GTK_TOGGLE_BUTTON(new_mail_on_btn), TRUE);
485 if (acpiprefs.file_path != NULL) {
486 for (i = 0; known_implementations[i].name != NULL; i++) {
487 if (!strcmp(acpiprefs.file_path,
488 known_implementations[i].file_path)) {
489 gtk_cmoption_menu_set_history(
491 default_implementations_optmenu), i);
497 for (i = 0; known_implementations[i].name != NULL; i++) {
498 if (check_impl(known_implementations[i].file_path)) {
499 gtk_cmoption_menu_set_history(
501 default_implementations_optmenu), i);
506 page->page.widget = vbox;
508 page->no_mail_off_btn = no_mail_off_btn;
509 page->no_mail_blink_btn = no_mail_blink_btn;
510 page->no_mail_on_btn = no_mail_on_btn;
511 page->unread_mail_off_btn = unread_mail_off_btn;
512 page->unread_mail_blink_btn = unread_mail_blink_btn;
513 page->unread_mail_on_btn = unread_mail_on_btn;
514 page->new_mail_off_btn = new_mail_off_btn;
515 page->new_mail_blink_btn = new_mail_blink_btn;
516 page->new_mail_on_btn = new_mail_on_btn;
517 page->default_implementations_optmenu = default_implementations_optmenu;
518 page->on_value_entry = on_value_entry;
519 page->off_value_entry = off_value_entry;
520 page->file_entry = file_entry;
521 page->hbox_acpi_file = hbox_acpi_file;
522 page->hbox_acpi_values = hbox_acpi_values;
523 page->warning_box = warning_box;
524 page->warning_label = warning_label;
525 page->blink_on_err_chkbtn = blink_on_err_chkbtn;
528 gtk_widget_hide(hbox_acpi_file);
529 gtk_widget_hide(hbox_acpi_values);
530 gtk_entry_set_text(GTK_ENTRY(file_entry),
531 known_implementations[found].file_path);
532 gtk_entry_set_text(GTK_ENTRY(on_value_entry),
533 known_implementations[found].on_param);
534 gtk_entry_set_text(GTK_ENTRY(off_value_entry),
535 known_implementations[found].off_param);
537 if (!check_impl(known_implementations[found].file_path))
538 show_error(page, known_implementations[found].file_path);
540 gtk_cmoption_menu_set_history(
541 GTK_CMOPTION_MENU(default_implementations_optmenu), 0);
542 gtk_widget_show_all(hbox_acpi_file);
543 gtk_widget_show_all(hbox_acpi_values);
544 if (acpiprefs.file_path != NULL)
545 gtk_entry_set_text(GTK_ENTRY(file_entry),
546 acpiprefs.file_path);
547 if (acpiprefs.on_param != NULL)
548 gtk_entry_set_text(GTK_ENTRY(on_value_entry),
550 if (acpiprefs.off_param != NULL)
551 gtk_entry_set_text(GTK_ENTRY(off_value_entry),
552 acpiprefs.off_param);
553 if (!acpiprefs.file_path || !check_impl(acpiprefs.file_path))
554 show_error(page, acpiprefs.file_path);
558 static void acpi_prefs_destroy_widget_func(PrefsPage *_page)
562 static void acpi_prefs_save_func(PrefsPage * _page)
564 struct AcpiNotifierPage *page = (struct AcpiNotifierPage *) _page;
571 g_free(acpiprefs.file_path);
572 acpiprefs.file_path = gtk_editable_get_chars(
573 GTK_EDITABLE(page->file_entry), 0, -1);
574 g_free(acpiprefs.on_param);
575 acpiprefs.on_param = gtk_editable_get_chars(
576 GTK_EDITABLE(page->on_value_entry), 0, -1);
577 g_free(acpiprefs.off_param);
578 acpiprefs.off_param = gtk_editable_get_chars(
579 GTK_EDITABLE(page->off_value_entry), 0, -1);
581 if (gtk_toggle_button_get_active(
582 GTK_TOGGLE_BUTTON(page->no_mail_off_btn)))
583 acpiprefs.no_mail_action = OFF;
584 else if (gtk_toggle_button_get_active(
585 GTK_TOGGLE_BUTTON(page->no_mail_blink_btn)))
586 acpiprefs.no_mail_action = BLINK;
587 else if (gtk_toggle_button_get_active(
588 GTK_TOGGLE_BUTTON(page->no_mail_on_btn)))
589 acpiprefs.no_mail_action = ON;
591 if (gtk_toggle_button_get_active(
592 GTK_TOGGLE_BUTTON(page->unread_mail_off_btn)))
593 acpiprefs.unread_mail_action = OFF;
594 else if (gtk_toggle_button_get_active(
595 GTK_TOGGLE_BUTTON(page->unread_mail_blink_btn)))
596 acpiprefs.unread_mail_action = BLINK;
597 else if (gtk_toggle_button_get_active(
598 GTK_TOGGLE_BUTTON(page->unread_mail_on_btn)))
599 acpiprefs.unread_mail_action = ON;
601 if (gtk_toggle_button_get_active(
602 GTK_TOGGLE_BUTTON(page->new_mail_off_btn)))
603 acpiprefs.new_mail_action = OFF;
604 else if (gtk_toggle_button_get_active(
605 GTK_TOGGLE_BUTTON(page->new_mail_blink_btn)))
606 acpiprefs.new_mail_action = BLINK;
607 else if (gtk_toggle_button_get_active(
608 GTK_TOGGLE_BUTTON(page->new_mail_on_btn)))
609 acpiprefs.new_mail_action = ON;
611 acpiprefs.blink_on_err = gtk_toggle_button_get_active(
612 GTK_TOGGLE_BUTTON(page->blink_on_err_chkbtn));
614 menu = gtk_cmoption_menu_get_menu(
615 GTK_CMOPTION_MENU(page->default_implementations_optmenu));
616 menuitem = gtk_menu_get_active(GTK_MENU(menu));
617 selected = GPOINTER_TO_INT
618 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
621 g_free(acpiprefs.file_path);
622 acpiprefs.file_path = g_strdup(
623 known_implementations[selected].file_path);
624 g_free(acpiprefs.on_param);
625 acpiprefs.on_param = g_strdup(
626 known_implementations[selected].on_param);
627 g_free(acpiprefs.off_param);
628 acpiprefs.off_param = g_strdup(
629 known_implementations[selected].off_param);
632 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
633 pfile = prefs_write_open(rcpath);
635 if (!pfile || (prefs_set_block_label(pfile, PREFS_BLOCK_NAME) < 0))
638 if (prefs_write_param(param, pfile->fp) < 0) {
639 g_warning("failed to write " PREFS_BLOCK_NAME
640 " configuration to file\n");
641 prefs_file_close_revert(pfile);
644 if (fprintf(pfile->fp, "\n") < 0) {
645 FILE_OP_ERROR(rcpath, "fprintf");
646 prefs_file_close_revert(pfile);
648 prefs_file_close(pfile);
651 static void acpi_set(gboolean on)
655 if (!acpiprefs.file_path) {
656 debug_print("acpiprefs.file_path NULL\n");
659 if (!check_impl(acpiprefs.file_path)) {
660 debug_print("acpiprefs.file_path not implemented\n");
663 if (!acpiprefs.on_param || !acpiprefs.off_param) {
664 debug_print("no param\n");
668 if (!is_program(acpiprefs.file_path)) {
669 fp = fopen(acpiprefs.file_path, "wb");
674 fwrite(acpiprefs.on_param, 1, strlen(acpiprefs.on_param), fp);
676 fwrite(acpiprefs.off_param, 1, strlen(acpiprefs.off_param), fp);
680 gchar *cmd = g_strdup_printf("%s %s",
682 on ? acpiprefs.on_param:acpiprefs.off_param);
683 execute_command_line(cmd, TRUE);
688 static guint should_quit = FALSE;
689 static int last_blink = 0;
691 static gint acpi_blink(gpointer data)
694 acpi_set(last_blink);
695 last_blink = !last_blink;
703 static int blink_timeout_id = 0;
704 static int alertpanel_blink_timeout_id = 0;
705 static gint my_new = -1, my_unread = -1;
706 static int my_action = -1;
708 static gboolean acpi_update_hook(gpointer source, gpointer data)
711 guint new, unread, unreadmarked, marked, total;
712 guint replied, forwarded, locked, ignored, watched;
714 if (alertpanel_blink_timeout_id)
717 folder_count_total_msgs(&new, &unread, &unreadmarked, &marked, &total,
718 &replied, &forwarded, &locked, &ignored, &watched);
720 if (my_new != new || my_unread != unread) {
724 action = acpiprefs.new_mail_action;
725 } else if (my_unread > 0) {
726 action = acpiprefs.unread_mail_action;
728 action = acpiprefs.no_mail_action;
731 if (action != my_action) {
734 if (action != BLINK && blink_timeout_id != 0) {
735 g_source_remove(blink_timeout_id);
736 blink_timeout_id = 0;
746 blink_timeout_id = g_timeout_add(1000, acpi_blink, NULL);
758 static gboolean acpi_alertpanel_hook(gpointer source, gpointer data)
760 gboolean *opened = (gboolean *)source;
762 if (*opened == TRUE) {
763 if (blink_timeout_id)
764 g_source_remove(blink_timeout_id);
765 blink_timeout_id = 0;
767 if (alertpanel_blink_timeout_id)
772 alertpanel_blink_timeout_id = g_timeout_add(250, acpi_blink, NULL);
774 if (alertpanel_blink_timeout_id)
775 g_source_remove(alertpanel_blink_timeout_id);
776 alertpanel_blink_timeout_id = 0;
780 acpi_update_hook(NULL, NULL);
785 void acpi_prefs_init(void)
787 static gchar *path[3];
790 path[0] = _("Plugins");
791 path[1] = PLUGIN_NAME;
794 prefs_set_default(param);
795 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
796 prefs_read_config(param, PREFS_BLOCK_NAME, rcpath, NULL);
799 acpi_prefs_page.page.path = path;
800 acpi_prefs_page.page.create_widget = acpi_prefs_create_widget_func;
801 acpi_prefs_page.page.destroy_widget = acpi_prefs_destroy_widget_func;
802 acpi_prefs_page.page.save_page = acpi_prefs_save_func;
804 prefs_gtk_register_page((PrefsPage *) &acpi_prefs_page);
805 folder_hook_id = hooks_register_hook (FOLDER_ITEM_UPDATE_HOOKLIST,
806 acpi_update_hook, NULL);
807 alertpanel_hook_id = hooks_register_hook (ALERTPANEL_OPENED_HOOKLIST,
808 acpi_alertpanel_hook, NULL);
812 void acpi_prefs_done(void)
816 if (claws_is_exiting())
818 prefs_gtk_unregister_page((PrefsPage *) &acpi_prefs_page);
819 hooks_unregister_hook(FOLDER_ITEM_UPDATE_HOOKLIST, folder_hook_id);
820 hooks_unregister_hook(ALERTPANEL_OPENED_HOOKLIST, alertpanel_hook_id);
827 for (i = 0; acpi_help[i] != NULL; i++)
828 known_implementations[i].help =
829 *acpi_help[i] ? _(acpi_help[i]) : "";
838 gint plugin_init(gchar **error)
840 if( !check_plugin_version(MAKE_NUMERIC_VERSION(3,8,1,46),
841 VERSION_NUMERIC, PLUGIN_NAME, error) )
848 gboolean plugin_done(void)
850 if (blink_timeout_id)
851 g_source_remove(blink_timeout_id);
852 if (alertpanel_blink_timeout_id)
853 g_source_remove(alertpanel_blink_timeout_id);
859 const gchar *plugin_name(void)
864 const gchar *plugin_desc(void)
866 return _("This plugin handles various ACPI mail LEDs.");
869 const gchar *plugin_type(void)
874 const gchar *plugin_licence(void)
879 const gchar *plugin_version(void)
884 struct PluginFeature *plugin_provides(void)
886 static struct PluginFeature features[] =
887 { {PLUGIN_NOTIFIER, N_("Laptop LED")},
888 {PLUGIN_NOTHING, NULL}};