Permalink
Browse files

First commit

  • Loading branch information...
gentoo-root committed Mar 8, 2012
0 parents commit 0b43ac077e4e89e32e9a73216c0e5c28c1da23c7
Showing with 1,127 additions and 0 deletions.
  1. +1 −0 AUTHORS
  2. +674 −0 COPYING
  3. +6 −0 ChangeLog
  4. +8 −0 INSTALL
  5. +47 −0 Makefile
  6. 0 NEWS
  7. 0 README
  8. 0 TODO
  9. +144 −0 dbus.c
  10. +23 −0 dbus.h
  11. +27 −0 gettext.c
  12. +25 −0 gettext.h
  13. +47 −0 main.c
  14. +43 −0 notify.c
  15. +23 −0 notify.h
  16. +59 −0 po/ru.po
@@ -0,0 +1 @@
+Maxim A. Mikityanskiy - gentoo_root - <maxtram95@gmail.com>
674 COPYING

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,6 @@
+jacknotifier changelog:
+
+08/03/12 - 0.1:
+ - Initial release. Jacknotifier daemon shows notifications
+ about inserted or pulled headphones and microphone.
+ - Gettext support.
@@ -0,0 +1,8 @@
+To install jacknotifier run:
+
+$ make
+# make install
+
+To uninstall jacknotifier run:
+
+# make uninstall
@@ -0,0 +1,47 @@
+.PHONY: first all clean install
+
+SOURCES = main.c dbus.c notify.c gettext.c
+OBJECTS = $(patsubst %.c,%.o,$(SOURCES))
+DEPS = $(patsubst %.c,%.dep,$(SOURCES))
+
+TRANSLATIONS = po/ru.po
+TRANS_COMPILED = $(patsubst %.po,%.mo,$(TRANSLATIONS))
+
+SHELL = sh
+CC = gcc
+LD = gcc
+MSGFMT = msgfmt
+INSTALL = install -v
+RM = rm -f
+
+CFLAGS = -O3 -Wall -fomit-frame-pointer `pkg-config --cflags dbus-1 libnotify`
+LDFLAGS =
+LIBS = `pkg-config --libs dbus-1 libnotify`
+
+first: all
+
+-include $(DEPS)
+
+all: jacknotifierd $(TRANS_COMPILED)
+
+jacknotifierd: $(OBJECTS)
+ $(LD) $(LDFLAGS) $^ -o $@ $(LIBS)
+
+%.dep: %.c Makefile
+ $(SHELL) -ec "$(CC) -x c $(CFLAGS) -MM $< | sed -re 's|([^:]+.o)( *:+)|$(<:.c=.o) $@\2|;'" > $@
+
+%.o: %.c %.dep Makefile
+ $(CC) -x c $(CFLAGS) -c $< -o $@
+
+%.mo: %.po
+ $(MSGFMT) $^ -o $@
+
+clean:
+ $(RM) jacknotifierd *.o *.dep po/*.mo
+
+install:
+ $(INSTALL) jacknotifierd /usr/bin
+ cd po; for mo in *.mo; do $(INSTALL) -v $$mo /usr/share/locale/$${mo%.mo}/LC_MESSAGES/jacknotifier.mo; done
+
+uninstall:
+ $(RM) /usr/bin/jacknotifierd
0 NEWS
No changes.
0 README
No changes.
0 TODO
No changes.
144 dbus.c
@@ -0,0 +1,144 @@
+/*
+ * This file is part of jacknotifier - Jack Notification Daemon
+ * Copyright (C) 2012 Maxim A. Mikityanskiy - <maxtram95@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * 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/>.
+ */
+
+#include <dbus/dbus.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "notify.h"
+#include "gettext.h"
+
+static DBusError error;
+static DBusConnection *connection;
+static DBusConnection *session_connection;
+
+static void process_event(const char *codename, int state);
+
+int jn_dbus_init()
+{
+ dbus_error_init(&error);
+
+ // Connect
+ connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+ if (dbus_error_is_set(&error)) {
+ fprintf(stderr, "DBus: dbus_bus_get: %s\n", error.message);
+ dbus_error_free(&error);
+ return 0;
+ }
+ if (connection == NULL) {
+ fprintf(stderr, "DBus: connection to system bus failed\n");
+ dbus_error_free(&error);
+ return 0;
+ }
+
+ session_connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
+ if (dbus_error_is_set(&error)) {
+ fprintf(stderr, "DBus: dbus_bus_get: %s\n", error.message);
+ dbus_connection_close(connection);
+ dbus_error_free(&error);
+ return 0;
+ }
+ if (session_connection == NULL) {
+ fprintf(stderr, "DBus: connection to session bus failed\n");
+ dbus_connection_close(connection);
+ dbus_error_free(&error);
+ return 0;
+ }
+
+ // Connect to jacklistener
+ dbus_bus_add_match(connection, "type='signal',interface='org.ude.jacklistener'", &error);
+ dbus_connection_flush(connection);
+ if (dbus_error_is_set(&error)) {
+ fprintf(stderr, "DBus: dbus_bus_add_match: %s\n", error.message);
+ dbus_connection_close(connection);
+ dbus_connection_close(session_connection);
+ dbus_error_free(&error);
+ return 0;
+ }
+
+ return 1;
+}
+
+void jn_dbus_fini()
+{
+ dbus_connection_close(connection);
+ dbus_connection_close(session_connection);
+ dbus_error_free(&error);
+}
+
+void jn_dbus_listen_events()
+{
+ for (;;) {
+ // Event loop
+ dbus_connection_read_write(connection, -1);
+ DBusMessage *msg;
+ while ((msg = dbus_connection_pop_message(connection)) != NULL) {
+ // Filter signals
+ if (dbus_message_is_signal(msg, "org.ude.jacklistener", "statechanged")) {
+ DBusMessageIter args;
+ if (!dbus_message_iter_init(msg, &args)) {
+ goto final;
+ }
+
+ // Get first argument
+ if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_STRING) {
+ goto final;
+ }
+ const char *str;
+ dbus_message_iter_get_basic(&args, &str);
+
+ // Get second argument
+ if (!dbus_message_iter_next(&args)) {
+ goto final;
+ }
+ if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_UINT32) {
+ goto final;
+ }
+ int value;
+ dbus_message_iter_get_basic(&args, &value);
+
+ // Process them
+ process_event(str, value);
+ }
+final:
+ dbus_message_unref(msg);
+ }
+ }
+}
+
+static void process_event(const char *codename, int state)
+{
+ char *message = NULL;
+ if (!strcmp(codename, "headphone")) {
+ message = state ? _("Headphones plugged in") : _("Headphones plugged out");
+ } else
+ if (!strcmp(codename, "microphone")) {
+ message = state ? _("Microphone plugged in") : _("Microphone plugged out");
+ } else
+ if (!strcmp(codename, "lineout")) {
+ message = state ? _("Line out plugged in") : _("Line out plugged out");
+ } else
+ if (!strcmp(codename, "videoout")) {
+ message = state ? _("Video out plugged in") : _("Video out plugged out");
+ } else
+ if (!strcmp(codename, "linein")) {
+ message = state ? _("Line in plugged in") : _("Line in plugged out");
+ }
+
+ jn_notify_send(message);
+}
23 dbus.h
@@ -0,0 +1,23 @@
+/*
+ * This file is part of jacknotifier - Jack Notification Daemon
+ * Copyright (C) 2012 Maxim A. Mikityanskiy - <maxtram95@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * 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/>.
+ */
+
+#pragma once
+
+int jn_dbus_init();
+void jn_dbus_fini();
+void jn_dbus_listen_events();
@@ -0,0 +1,27 @@
+/*
+ * This file is part of jacknotifier - Jack Notification Daemon
+ * Copyright (C) 2012 Maxim A. Mikityanskiy - <maxtram95@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * 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/>.
+ */
+
+#include <libintl.h>
+#include <locale.h>
+
+void gettext_init()
+{
+ setlocale(LC_ALL, "");
+ bindtextdomain("jacknotifier", "/usr/share/locale");
+ textdomain("jacknotifier");
+}
@@ -0,0 +1,25 @@
+/*
+ * This file is part of jacknotifier - Jack Notification Daemon
+ * Copyright (C) 2012 Maxim A. Mikityanskiy - <maxtram95@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * 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/>.
+ */
+
+#pragma once
+
+#include <libintl.h>
+
+#define _(a) gettext(a)
+
+void gettext_init();
47 main.c
@@ -0,0 +1,47 @@
+/*
+ * This file is part of jacknotifier - Jack Notification Daemon
+ * Copyright (C) 2012 Maxim A. Mikityanskiy - <maxtram95@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * 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/>.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "dbus.h"
+#include "notify.h"
+#include "gettext.h"
+
+int main(int argc, char *argv[])
+{
+ gettext_init();
+
+ if (argc != 1) {
+ printf("Usage: %s\n", argv[0]);
+ exit(254);
+ }
+ if (!jn_notify_init()) {
+ fprintf(stderr, "Unable to initialize libnotify\n");
+ exit(1);
+ }
+ if (!jn_dbus_init()) {
+ fprintf(stderr, "Unable to initialize D-Bus\n");
+ exit(1);
+ }
+ jn_dbus_listen_events();
+ jn_dbus_fini();
+ jn_notify_fini();
+
+ return 0;
+}
@@ -0,0 +1,43 @@
+/*
+ * This file is part of jacknotifier - Jack Notification Daemon
+ * Copyright (C) 2012 Maxim A. Mikityanskiy - <maxtram95@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * 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/>.
+ */
+
+#include <libnotify/notify.h>
+#include <stdio.h>
+
+NotifyNotification *notify = NULL;
+
+int jn_notify_init()
+{
+ return notify_init("Jack Notifier");
+}
+
+void jn_notify_fini()
+{
+ notify_uninit();
+}
+
+void jn_notify_send(const char *message)
+{
+ if (notify == NULL) {
+ notify = notify_notification_new(message, NULL, "audio-headset");
+ } else {
+ notify_notification_update(notify, message, NULL, "audio-headset");
+ }
+ notify_notification_show(notify, NULL);
+ printf("%s\n", message);
+}
Oops, something went wrong.

0 comments on commit 0b43ac0

Please sign in to comment.