disabled notification at program start.
This commit is contained in:
parent
55a2f23594
commit
6fae1665b3
1 changed files with 47 additions and 50 deletions
45
spacetray.c
45
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,10 +73,6 @@ 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;
|
||||||
|
|
@ -198,14 +195,13 @@ void set_status() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
|
@ -213,7 +209,7 @@ int main(int argc, char **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);
|
||||||
|
|
||||||
|
|
@ -224,7 +220,7 @@ int main(int argc, char **argv) {
|
||||||
//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);
|
||||||
|
|
||||||
|
|
@ -232,3 +228,4 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue