int box_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_indicator, const char* title, const char* format, ...) { if (notifications_are_disabled(flags)) { tab_notify(self, flags); return -1; } #ifdef BOX_NOTIFY int id = sound_notify(self, notif, flags, id_indicator); control_lock(); #ifdef SOUND_NOTIFY if (id == -1) { /* Could not play */ for (id = 0; id < ACTIVE_NOTIFS_MAX && actives[id].active; id ++); if ( id == ACTIVE_NOTIFS_MAX ) { control_unlock(); return -1; /* Full */ } actives[id].active = 1; actives[id].id_indicator = id_indicator; if (id_indicator) *id_indicator = id; } #else if (id == -1) return -1; #endif /* SOUND_NOTIFY */ snprintf(actives[id].title, sizeof(actives[id].title), "%s", title); if (strlen(title) > 23) strcpy(actives[id].title + 20, "..."); va_list __ARGS__; va_start (__ARGS__, format); vsnprintf (actives[id].messages[0], MAX_BOX_MSG_LEN, format, __ARGS__); va_end (__ARGS__); if (strlen(actives[id].messages[0]) > MAX_BOX_MSG_LEN - 3) strcpy(actives[id].messages[0] + MAX_BOX_MSG_LEN - 3, "..."); actives[id].box = notify_notification_new(actives[id].title, actives[id].messages[0], NULL); actives[id].size++; actives[id].n_timeout = get_unix_time() + Control.notif_timeout / 1000; notify_notification_set_timeout(actives[id].box, Control.notif_timeout); notify_notification_set_app_name(actives[id].box, "toxic"); /*notify_notification_add_action(actives[id].box, "lel", "default", m_notify_action, self, NULL);*/ notify_notification_show(actives[id].box, NULL); control_unlock(); return id; #else return sound_notify(self, notif, flags, id_indicator); #endif /* BOX_NOTIFY */ }
int box_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id, const char* format, ...) { if (notifications_are_disabled(flags)) { tab_notify(self, flags); return -1; } #ifdef BOX_NOTIFY if (sound_notify2(self, notif, flags, id) == -1) return -1; control_lock(); if (!actives[id].box || actives[id].size >= MAX_BOX_MSG_LEN + 1) { control_unlock(); return -1; } va_list __ARGS__; va_start (__ARGS__, format); vsnprintf (actives[id].messages[actives[id].size], MAX_BOX_MSG_LEN, format, __ARGS__); va_end (__ARGS__); if (strlen(actives[id].messages[actives[id].size]) > MAX_BOX_MSG_LEN - 3) strcpy(actives[id].messages[actives[id].size] + MAX_BOX_MSG_LEN - 3, "..."); actives[id].size++; actives[id].n_timeout = get_unix_time() + Control.notif_timeout / 1000; char formated[128 * 129] = {'\0'}; int i = 0; for (; i <actives[id].size; i ++) { strcat(formated, actives[id].messages[i]); strcat(formated, "\n"); } formated[strlen(formated) - 1] = '\0'; notify_notification_update(actives[id].box, actives[id].title, formated, NULL); notify_notification_show(actives[id].box, NULL); control_unlock(); return id; #else return sound_notify2(self, notif, flags, id); #endif }
void ui_tab_print_message(const char *jid, const char *msg) { /* Called by xmpp_mesg_handler(), prints the incoming message * to the approprate chat tab */ Chattab *tab = NULL; GSList *elem; char *str, *shortjid, *slash, *emsg; Buddy *sb = NULL; /* We need to obtain the jid itself, w/o resource */ slash = strchr(jid, '/'); shortjid = (slash) ? g_strndup(jid, slash-jid) : g_strdup(jid); sb = xmpp_roster_find_by_jid(shortjid); for(elem = tabs; elem; elem = elem->next) { Chattab *t = (Chattab *)elem->data; if(g_strcmp0(t->jid, jid) == 0) { tab = t; break; } } if(!tab) { if (sb == NULL) { tab = ui_tab_create(jid, jid, 0); } else { tab = ui_tab_create(jid, sb->name, 0); } g_free(shortjid); } /* actual message printing - two lines of this whole function! */ emsg = g_markup_escape_text(msg, -1); str = lua_msg_markup((sb) ? sb->name : jid, emsg); if (str == NULL) str = g_strdup_printf("<b>%s</b>: %s\n", (sb) ? sb->name : jid, emsg); ui_tab_append_markup(tab, str); /* bolding tab title if it's not the status tab * (the function will check whether the tab is active or not, * we don't care about this) */ if (tab->jid) tab_notify(tab); g_free(str); g_free(emsg); } /* ui_tab_print_message */
int sound_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id) { tab_notify(self, flags); if (notifications_are_disabled(flags)) return -1; if (id < 0 || id >= ACTIVE_NOTIFS_MAX) return -1; #ifdef SOUND_NOTIFY control_lock(); if (!actives[id].active || !Control.sounds[notif]) { control_unlock(); return -1; } m_open_device(); alSourceStop(actives[id].source); alDeleteSources(1, &actives[id].source); alDeleteBuffers(1,&actives[id].buffer); alGenSources(1, &actives[id].source); alGenBuffers(1, &actives[id].buffer); actives[id].buffer = alutCreateBufferFromFile(Control.sounds[notif]); alSourcei(actives[id].source, AL_BUFFER, actives[id].buffer); alSourcei(actives[id].source, AL_LOOPING, flags & NT_LOOP); alSourcePlay(actives[id].source); control_unlock(); return id; #else if (notif != silent) beep(); return 0; #endif /* SOUND_NOTIFY */ }
int sound_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_indicator) { tab_notify(self, flags); if (notifications_are_disabled(flags)) return -1; int id = -1; control_lock(); if (self && (!self->stb || self->stb->status != TOX_USER_STATUS_BUSY)) id = m_play_sound(notif, flags); else if (flags & NT_ALWAYS) id = m_play_sound(notif, flags); #if defined(BOX_NOTIFY) && !defined(SOUND_NOTIFY) if (id == -1) { for (id = 0; id < ACTIVE_NOTIFS_MAX && actives[id].box; id++); if ( id == ACTIVE_NOTIFS_MAX ) { control_unlock(); return -1; /* Full */ } } #endif if ( id_indicator && id != -1 ) { actives[id].id_indicator = id_indicator; *id_indicator = id; } control_unlock(); return id; }