disabled notification at program start.
This commit is contained in:
parent
55a2f23594
commit
6fae1665b3
1 changed files with 47 additions and 50 deletions
97
spacetray.c
97
spacetray.c
|
|
@ -1,23 +1,20 @@
|
||||||
/*
|
/*
|
||||||
* SpaceAPI based panel applet for UNIX using GTK2
|
* SpaceAPI based tray applet for BSD* / Linux / UNIX etc. using GTK2
|
||||||
*
|
*
|
||||||
* Author: hanez <you@hanez.org>
|
* Author: hanez <you@hanez.org>
|
||||||
* Contributors: Haeger, atari, beh and eisbaer
|
* Website: https://hanez.org/project/spacetray/
|
||||||
*
|
* Contributors: atari, beh, eisbaer and Haeger
|
||||||
|
*
|
||||||
* License (Beerware License):
|
* License (Beerware License):
|
||||||
* As long as you retain this notice you can do whatever you want with this
|
* As long as you retain this notice you can do whatever you want with this
|
||||||
* stuff. If we meet some day, and you think this stuff is worth it, you can buy
|
* stuff. If we meet some day, and you think this stuff is worth it, you can
|
||||||
* me a beer in return hanez and all other contributers
|
* buy me a beer in return hanez and all other contributers
|
||||||
*
|
*
|
||||||
* TODO:
|
* TODO:
|
||||||
* - Add door open/close date to notification and status
|
* - Add door open/close date to notification and status
|
||||||
* - Fix: not show notification twice at start when status "open"
|
* - Fix: not show notification twice at start when status "open"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <gdk-pixbuf/gdk-pixdata.h>
|
#include <gdk-pixbuf/gdk-pixdata.h>
|
||||||
|
|
@ -25,6 +22,10 @@
|
||||||
#if LIBNOTIFY
|
#if LIBNOTIFY
|
||||||
#include <libnotify/notify.h>
|
#include <libnotify/notify.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "pesthoernchen.h"
|
#include "pesthoernchen.h"
|
||||||
|
|
||||||
|
|
@ -33,21 +34,21 @@ struct string {
|
||||||
size_t len;
|
size_t len;
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *name = "Dooris for UNIX";
|
static char *name = "SpaceAPI widget for UNIX";
|
||||||
static char *statusurl = "https://www.hamburg.ccc.de/dooris/status.json";
|
static char *statusurl = "https://www.hamburg.ccc.de/dooris/status.json";
|
||||||
static char *agent = "Dooris-for-UNIX/0.42";
|
static char *agent = "Spacetray/0.42";
|
||||||
|
|
||||||
// The delay for polling the dooris service. Adjust this before compiling
|
// The delay for polling the dooris service. Adjust this before compiling
|
||||||
int delay = 900000; // ms. aka 15 minutes
|
static int delay = 900000; // ms. aka 15 minutes
|
||||||
|
|
||||||
bool door_open = false;
|
bool door_open = false;
|
||||||
bool old_door_open = false;
|
bool old_door_open = false;
|
||||||
|
|
||||||
|
void do_it();
|
||||||
|
void invoke_notification();
|
||||||
|
|
||||||
GtkStatusIcon *tray_icon;
|
GtkStatusIcon *tray_icon;
|
||||||
|
|
||||||
bool do_it();
|
|
||||||
void invoke_notification();
|
|
||||||
|
|
||||||
void init_string(struct string *s) {
|
void init_string(struct string *s) {
|
||||||
s->len = 0;
|
s->len = 0;
|
||||||
s->ptr = malloc(s->len+1);
|
s->ptr = malloc(s->len+1);
|
||||||
|
|
@ -72,18 +73,14 @@ size_t writefunc(void *ptr, size_t size, size_t nmemb, struct string *s) {
|
||||||
return size*nmemb;
|
return size*nmemb;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tray_icon_on_click(GtkStatusIcon *status_icon, gpointer user_data) {
|
|
||||||
do_it();
|
|
||||||
}
|
|
||||||
|
|
||||||
void get_bouncer_data() {
|
void get_bouncer_data() {
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
|
|
||||||
struct json_object *response_json_object;
|
struct json_object *response_json_object;
|
||||||
struct json_object *door_json_object;
|
struct json_object *door_json_object;
|
||||||
struct json_object *leaf_json_object;
|
struct json_object *leaf_json_object;
|
||||||
|
|
||||||
bool door_status;
|
bool door_status;
|
||||||
int door_last_change;
|
int door_last_change;
|
||||||
|
|
||||||
|
|
@ -94,7 +91,7 @@ void get_bouncer_data() {
|
||||||
old_door_open = door_open;
|
old_door_open = door_open;
|
||||||
|
|
||||||
init_string(&s);
|
init_string(&s);
|
||||||
|
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
if(!curl) {
|
if(!curl) {
|
||||||
fprintf(stderr, "curl_easy_init() failed.\n");
|
fprintf(stderr, "curl_easy_init() failed.\n");
|
||||||
|
|
@ -134,10 +131,10 @@ void get_bouncer_data() {
|
||||||
|
|
||||||
// free leaf object
|
// free leaf object
|
||||||
//json_object_put(leaf_json_object);
|
//json_object_put(leaf_json_object);
|
||||||
|
|
||||||
// free response object
|
// free response object
|
||||||
// json_object_put(response_json_object);
|
// json_object_put(response_json_object);
|
||||||
|
|
||||||
printf("Door status: = %d\n", door_status);
|
printf("Door status: = %d\n", door_status);
|
||||||
printf("Door last change: = %d\n", door_last_change);
|
printf("Door last change: = %d\n", door_last_change);
|
||||||
|
|
||||||
|
|
@ -150,13 +147,13 @@ void get_bouncer_data() {
|
||||||
|
|
||||||
void invoke_notification() {
|
void invoke_notification() {
|
||||||
char door[20];
|
char door[20];
|
||||||
|
|
||||||
if (door_open == true) {
|
if (door_open == true) {
|
||||||
snprintf(door, 20, "Door open...");
|
snprintf(door, 20, "Door open...");
|
||||||
} else {
|
} else {
|
||||||
snprintf(door, 20, "Door closed...");
|
snprintf(door, 20, "Door closed...");
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_status_icon_set_tooltip(tray_icon, door);
|
gtk_status_icon_set_tooltip(tray_icon, door);
|
||||||
|
|
||||||
#if LIBNOTIFY
|
#if LIBNOTIFY
|
||||||
|
|
@ -168,13 +165,13 @@ void invoke_notification() {
|
||||||
|
|
||||||
if (door_open == true) {
|
if (door_open == true) {
|
||||||
notify_notification_set_icon_from_pixbuf(n, gdk_pixbuf_from_pixdata(
|
notify_notification_set_icon_from_pixbuf(n, gdk_pixbuf_from_pixdata(
|
||||||
&icon_yellow_pixbuf,
|
&icon_yellow_pixbuf,
|
||||||
true,
|
true,
|
||||||
NULL));
|
NULL));
|
||||||
} else {
|
} else {
|
||||||
notify_notification_set_icon_from_pixbuf(n, gdk_pixbuf_from_pixdata(
|
notify_notification_set_icon_from_pixbuf(n, gdk_pixbuf_from_pixdata(
|
||||||
&icon_red_pixbuf,
|
&icon_red_pixbuf,
|
||||||
true,
|
true,
|
||||||
NULL));
|
NULL));
|
||||||
}
|
}
|
||||||
notify_notification_show(n, NULL);
|
notify_notification_show(n, NULL);
|
||||||
|
|
@ -185,50 +182,50 @@ void invoke_notification() {
|
||||||
void set_status() {
|
void set_status() {
|
||||||
if (door_open == true) {
|
if (door_open == true) {
|
||||||
printf("Set to status: open\n");
|
printf("Set to status: open\n");
|
||||||
gtk_status_icon_set_from_pixbuf(tray_icon,
|
gtk_status_icon_set_from_pixbuf(tray_icon,
|
||||||
gdk_pixbuf_from_pixdata(&icon_yellow_pixbuf,
|
gdk_pixbuf_from_pixdata(&icon_yellow_pixbuf,
|
||||||
true,
|
true,
|
||||||
NULL));
|
NULL));
|
||||||
} else {
|
} else {
|
||||||
printf("Set to status: closed\n");
|
printf("Set to status: closed\n");
|
||||||
gtk_status_icon_set_from_pixbuf(tray_icon,
|
gtk_status_icon_set_from_pixbuf(tray_icon,
|
||||||
gdk_pixbuf_from_pixdata(&icon_red_pixbuf,
|
gdk_pixbuf_from_pixdata(&icon_red_pixbuf,
|
||||||
true,
|
true,
|
||||||
NULL));
|
NULL));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool do_it() {
|
void do_it() {
|
||||||
get_bouncer_data();
|
get_bouncer_data();
|
||||||
set_status();
|
set_status();
|
||||||
|
|
||||||
if (door_open != old_door_open) {
|
if (door_open != old_door_open) {
|
||||||
invoke_notification();
|
invoke_notification();
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
gtk_init(&argc, &argv);
|
gtk_init(&argc, &argv);
|
||||||
|
|
||||||
tray_icon = gtk_status_icon_new();
|
tray_icon = gtk_status_icon_new();
|
||||||
g_signal_connect(G_OBJECT(tray_icon), "activate",
|
g_signal_connect(G_OBJECT(tray_icon), "activate",
|
||||||
G_CALLBACK(tray_icon_on_click), NULL);
|
G_CALLBACK(do_it), NULL);
|
||||||
|
|
||||||
gtk_status_icon_set_visible(tray_icon, true);
|
gtk_status_icon_set_visible(tray_icon, true);
|
||||||
|
|
||||||
do_it();
|
do_it();
|
||||||
|
|
||||||
// DEBUG STUFF
|
// DEBUG STUFF
|
||||||
//door_open = true;
|
//door_open = true;
|
||||||
//set_status();
|
//set_status();
|
||||||
// END DEBUG STUFF
|
// END DEBUG STUFF
|
||||||
|
|
||||||
invoke_notification();
|
//invoke_notification();
|
||||||
|
|
||||||
gtk_timeout_add(delay, (GtkFunction)do_it, (gpointer)NULL);
|
gtk_timeout_add(delay, (GtkFunction)do_it, (gpointer)NULL);
|
||||||
|
|
||||||
gtk_main();
|
gtk_main();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue