コード例 #1
0
ファイル: notify.c プロジェクト: aweltsch/toxic
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 */
}
コード例 #2
0
ファイル: notify.c プロジェクト: dardevelin/toxic
int box_silent_notify(ToxWindow* self, uint64_t flags, int* id_indicator, const char* title, const char* format, ...)
{
    /* Always do colored notify */
    if (self) {
        if (flags & NT_WNDALERT_0) self->alert = WINDOW_ALERT_0;
        else if ( (flags & NT_WNDALERT_1) && (!self->alert || self->alert > WINDOW_ALERT_0) ) self->alert = WINDOW_ALERT_1;
        else if ( (flags & NT_WNDALERT_2) && (!self->alert || self->alert > WINDOW_ALERT_1) ) self->alert = WINDOW_ALERT_2;
    }
    
    if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) ||
       ((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) ))
        return -1;
        
#ifdef _BOX_NOTIFY
    
    control_lock();
    
    int id;        
    for (id = 0; id < ACTIVE_NOTIFS_MAX && actives[id].active; id ++);
    if ( id == ACTIVE_NOTIFS_MAX ) {
        control_unlock();
        return -1; /* Full */
    }
    
    if (id_indicator) {
        actives[id].id_indicator = id_indicator;
        *id_indicator = id;
    }
    
    strncpy(actives[id].title, title, 24);
    if (strlen(title) > 23) strcpy(actives[id].title + 20, "...");
    
    va_list __ARGS__; va_start (__ARGS__, format);
    vsnprintf (actives[id].messages[0], 127, format, __ARGS__);
    va_end (__ARGS__);
    
    if (strlen(actives[id].messages[0]) > 124) 
        strcpy(actives[id].messages[0] + 124, "...");
    
    actives[id].active = 1;
    actives[id].box = notify_notification_new(actives[id].title, actives[id].messages[0], NULL);
    actives[id].size ++;
    actives[id].n_timeout = time(NULL) + 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 -1;
#endif
}
コード例 #3
0
ファイル: notify.c プロジェクト: dardevelin/toxic
int box_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_indicator, char* title, const char* format, ...)
{
    if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) ||
       ((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) ))
        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;
    }
#endif
        
    strncpy(actives[id].title, title, 24);
    if (strlen(title) > 23) strcpy(actives[id].title + 20, "...");

    va_list __ARGS__; va_start (__ARGS__, format);
    vsnprintf (actives[id].messages[0], 127, format, __ARGS__);
    va_end (__ARGS__);
    
    if (strlen(actives[id].messages[0]) > 124) 
        strcpy(actives[id].messages[0] + 124, "...");
    
    actives[id].box = notify_notification_new(actives[id].title, actives[id].messages[0], NULL);
    actives[id].size ++;
    actives[id].n_timeout = time(NULL) + 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
}
コード例 #4
0
ファイル: notify.c プロジェクト: gabrield/lnotify
static int
setappname (lua_State * L)
{
  const char *name;
  NotifyNotification *notify;

  if (lua_gettop(L) < 2) {
    /* if there are less than two args, assume we're trying to set the default app name */
    name = luaL_checkstring(L, 1);
    if (notify_is_initted())
      notify_set_app_name(name);
    else
      notify_init(name);
  }
  else {
    notify = (NotifyNotification *) lua_touserdata(L, 1);
    if (!notify) luaL_argerror(L, 1, "Unknown type");
    name = luaL_checkstring(L, 2);
    notify_notification_set_app_name(notify, name);
  }

  return 0;
}
コード例 #5
0
ファイル: notify-send.c プロジェクト: Distrotech/libnotify
int
main (int argc, char *argv[])
{
        static const char  *summary = NULL;
        char               *body;
        static const char  *type = NULL;
        static char        *app_name = NULL;
        static char        *icon_str = NULL;
        static char        *icons = NULL;
        static char       **n_text = NULL;
        static char       **hints = NULL;
        static gboolean     do_version = FALSE;
        static gboolean     hint_error = FALSE;
        static glong        expire_timeout = NOTIFY_EXPIRES_DEFAULT;
        GOptionContext     *opt_ctx;
        NotifyNotification *notify;
        GError             *error = NULL;
        gboolean            retval;

        static const GOptionEntry entries[] = {
                {"urgency", 'u', 0, G_OPTION_ARG_CALLBACK,
                 g_option_arg_urgency_cb,
                 N_("Specifies the urgency level (low, normal, critical)."),
                 N_("LEVEL")},
                {"expire-time", 't', 0, G_OPTION_ARG_INT, &expire_timeout,
                 N_
                 ("Specifies the timeout in milliseconds at which to expire the "
                  "notification."), N_("TIME")},
                {"app-name", 'a', 0, G_OPTION_ARG_STRING, &app_name,
                 N_("Specifies the app name for the icon"), N_("APP_NAME")},
                {"icon", 'i', 0, G_OPTION_ARG_FILENAME, &icons,
                 N_("Specifies an icon filename or stock icon to display."),
                 N_("ICON[,ICON...]")},
                {"category", 'c', 0, G_OPTION_ARG_FILENAME, &type,
                 N_("Specifies the notification category."),
                 N_("TYPE[,TYPE...]")},
                {"hint", 'h', 0, G_OPTION_ARG_FILENAME_ARRAY, &hints,
                 N_
                 ("Specifies basic extra data to pass. Valid types are int, double, string and byte."),
                 N_("TYPE:NAME:VALUE")},
                {"version", 'v', 0, G_OPTION_ARG_NONE, &do_version,
                 N_("Version of the package."),
                 NULL},
                {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY,
                 &n_text, NULL,
                 NULL},
                {NULL}
        };

        body = NULL;

        g_type_init ();

        g_set_prgname (argv[0]);
        g_log_set_always_fatal (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);

        opt_ctx = g_option_context_new (N_("<SUMMARY> [BODY] - "
                                           "create a notification"));
        g_option_context_add_main_entries (opt_ctx, entries, GETTEXT_PACKAGE);
        retval = g_option_context_parse (opt_ctx, &argc, &argv, &error);
        g_option_context_free (opt_ctx);

        if (!retval) {
                fprintf (stderr, "%s\n", error->message);
                g_error_free (error);
                exit (1);
        }

        if (do_version) {
                g_printf ("%s %s\n", g_get_prgname (), VERSION);
                exit (0);
        }

        if (n_text != NULL && n_text[0] != NULL && *n_text[0] != '\0')
                summary = n_text[0];

        if (summary == NULL) {
                fprintf (stderr, "%s\n", N_("No summary specified."));
                exit (1);
        }

        if (n_text[1] != NULL) {
                body = g_strcompress (n_text[1]);

                if (n_text[2] != NULL) {
                        fprintf (stderr, "%s\n",
                                 N_("Invalid number of options."));
                        exit (1);
                }
        }

        if (icons != NULL) {
                char           *c;

                /* XXX */
                if ((c = strchr (icons, ',')) != NULL)
                        *c = '\0';

                icon_str = icons;
        }

        if (!notify_init ("notify-send"))
                exit (1);

        notify = notify_notification_new (summary,
                                          body,
                                          icon_str);
        notify_notification_set_category (notify, type);
        notify_notification_set_urgency (notify, urgency);
        notify_notification_set_timeout (notify, expire_timeout);
        notify_notification_set_app_name (notify, app_name);

        g_free (body);

        /* Set hints */
        if (hints != NULL) {
                gint            i = 0;
                gint            l;
                char          *hint = NULL;
                char         **tokens = NULL;

                while ((hint = hints[i++])) {
                        tokens = g_strsplit (hint, ":", -1);
                        l = g_strv_length (tokens);

                        if (l != 3) {
                                fprintf (stderr, "%s\n",
                                         N_("Invalid hint syntax specified. "
                                            "Use TYPE:NAME:VALUE."));
                                hint_error = TRUE;
                        } else {
                                retval = notify_notification_set_hint_variant (notify,
                                                                               tokens[0],
                                                                               tokens[1],
                                                                               tokens[2],
                                                                               &error);

                                if (!retval) {
                                        fprintf (stderr, "%s\n", error->message);
                                        g_error_free (error);
                                        hint_error = TRUE;
                                }
                        }

                        g_strfreev (tokens);
                        if (hint_error)
                                break;
                }
        }

        if (!hint_error)
                notify_notification_show (notify, NULL);

        g_object_unref (G_OBJECT (notify));

        notify_uninit ();

        exit (hint_error);
}
コード例 #6
0
static gboolean
ldsm_notify_for_mount (LdsmMountInfo *mount,
                       gboolean       multiple_volumes,
                       gboolean       other_usable_volumes)
{
        gchar  *name, *program;
        gint64 free_space;
        gint response;
        gboolean has_trash;
        gboolean has_disk_analyzer;
        gboolean retval = TRUE;
        gchar *path;

        /* Don't show a notice if one is already displayed */
        if (dialog != NULL || notification != NULL)
                return retval;

        name = g_unix_mount_guess_name (mount->mount);
        free_space = (gint64) mount->buf.f_frsize * (gint64) mount->buf.f_bavail;
        has_trash = ldsm_mount_has_trash (mount);
        path = g_strdup (g_unix_mount_get_mount_path (mount->mount));

        program = g_find_program_in_path (DISK_SPACE_ANALYZER);
        has_disk_analyzer = (program != NULL);
        g_free (program);

        if (server_has_actions ()) {
                char *free_space_str;
                char *summary;
                char *body;

                free_space_str = g_format_size (free_space);

                if (multiple_volumes) {
                        summary = g_strdup_printf (_("Low Disk Space on \"%s\""), name);
                        if (has_trash) {
                                body = g_strdup_printf (_("The volume \"%s\" has only %s disk space remaining.  You may free up some space by emptying the trash."),
                                                        name,
                                                        free_space_str);
                        } else {
                                body = g_strdup_printf (_("The volume \"%s\" has only %s disk space remaining."),
                                                        name,
                                                        free_space_str);
                        }
                } else {
                        summary = g_strdup (_("Low Disk Space"));
                        if (has_trash) {
                                body = g_strdup_printf (_("This computer has only %s disk space remaining.  You may free up some space by emptying the trash."),
                                                        free_space_str);
                        } else {
                                body = g_strdup_printf (_("This computer has only %s disk space remaining."),
                                                        free_space_str);
                        }
                }
                g_free (free_space_str);

                notification = notify_notification_new (summary, body, "drive-harddisk-symbolic");
                g_free (summary);
                g_free (body);

                g_signal_connect (notification,
                                  "closed",
                                  G_CALLBACK (on_notification_closed),
                                  NULL);

                notify_notification_set_app_name (notification, _("Disk space"));
                notify_notification_set_hint (notification, "transient", g_variant_new_boolean (TRUE));
                notify_notification_set_urgency (notification, NOTIFY_URGENCY_CRITICAL);
                notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
                if (has_disk_analyzer) {
                        notify_notification_add_action (notification,
                                                        "examine",
                                                        _("Examine"),
                                                        (NotifyActionCallback) examine_callback,
                                                        g_strdup (path),
                                                        g_free);
                }
                if (has_trash) {
                        notify_notification_add_action (notification,
                                                        "empty-trash",
                                                        _("Empty Trash"),
                                                        (NotifyActionCallback) empty_trash_callback,
                                                        NULL,
                                                        NULL);
                }
                notify_notification_add_action (notification,
                                                "ignore",
                                                _("Ignore"),
                                                (NotifyActionCallback) ignore_callback,
                                                NULL,
                                                NULL);
                notify_notification_set_category (notification, "device");

                if (!notify_notification_show (notification, NULL)) {
                        g_warning ("failed to send disk space notification\n");
                }

        } else {
                dialog = csd_ldsm_dialog_new (other_usable_volumes,
                                              multiple_volumes,
                                              has_disk_analyzer,
                                              has_trash,
                                              free_space,
                                              name,
                                              path);

                g_object_ref (G_OBJECT (dialog));
                response = gtk_dialog_run (GTK_DIALOG (dialog));

                gtk_widget_destroy (GTK_WIDGET (dialog));
                dialog = NULL;

                switch (response) {
                case GTK_RESPONSE_CANCEL:
                        retval = FALSE;
                        break;
                case CSD_LDSM_DIALOG_RESPONSE_ANALYZE:
                        retval = FALSE;
                        ldsm_analyze_path (path);
                        break;
                case CSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH:
                        retval = TRUE;
                        csd_ldsm_show_empty_trash ();
                        break;
                case GTK_RESPONSE_NONE:
                case GTK_RESPONSE_DELETE_EVENT:
                        retval = TRUE;
                        break;
                default:
                        g_assert_not_reached ();
                }
        }

        g_free (name);
        g_free (path);

        return retval;
}