static void
on_bus_acquired (GDBusConnection *connection,
                 const gchar     *name,
                 gpointer         user_data)
{
  GError *error = NULL;

  if (!file_chooser_init (connection, &error))
    {
      g_warning ("error: %s\n", error->message);
      g_clear_error (&error);
    }

  if (!app_chooser_init (connection, &error))
    {
      g_warning ("error: %s\n", error->message);
      g_clear_error (&error);
    }

  if (!print_init (connection, &error))
    {
      g_warning ("error: %s\n", error->message);
      g_clear_error (&error);
    }

  if (!screenshot_init (connection, &error))
    {
      g_warning ("error: %s\n", error->message);
      g_clear_error (&error);
    }

  if (!notification_init (connection, &error))
    {
      g_warning ("error: %s\n", error->message);
      g_clear_error (&error);
    }
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{

    history = g_queue_new();
    displayed = g_queue_new();
    queue = g_queue_new();

    cmdline_load(argc, argv);

    if (cmdline_get_bool("-v/-version", false, "Print version")
            || cmdline_get_bool("--version", false, "Print version")) {
        print_version();
    }

    char *cmdline_config_path;
    cmdline_config_path =
        cmdline_get_string("-conf/-config", NULL,
                           "Path to configuration file");
    load_settings(cmdline_config_path);

    if (cmdline_get_bool("-h/-help", false, "Print help")
            || cmdline_get_bool("--help", false, "Print help")) {
        usage(EXIT_SUCCESS);
    }

    int owner_id = initdbus();

    x_setup();

    if (settings.startup_notification) {
        notification *n = malloc(sizeof(notification));
        if(n == NULL) {
            die("Unable to allocate memory", EXIT_FAILURE);
        }
        n->appname = strdup("dunst");
        n->summary = strdup("startup");
        n->body = strdup("dunst is up and running");
        n->progress = 0;
        n->timeout = 10;
        n->allow_markup = false;
        n->plain_text = true;
        n->urgency = LOW;
        n->icon = NULL;
        n->raw_icon = NULL;
        n->category = NULL;
        n->msg = NULL;
        n->dbus_client = NULL;
        n->color_strings[0] = NULL;
        n->color_strings[1] = NULL;
        n->actions = NULL;
        n->urls = NULL;
        notification_init(n, 0);
    }

    mainloop = g_main_loop_new(NULL, FALSE);

    GPollFD dpy_pollfd = { xctx.dpy->fd,
                           G_IO_IN | G_IO_HUP | G_IO_ERR, 0
                         };

    GSourceFuncs x11_source_funcs = {
        x_mainloop_fd_prepare,
        x_mainloop_fd_check,
        x_mainloop_fd_dispatch,
        NULL,
        NULL,
        NULL
    };

    GSource *x11_source =
        g_source_new(&x11_source_funcs, sizeof(x11_source_t));
    ((x11_source_t *) x11_source)->dpy = xctx.dpy;
    ((x11_source_t *) x11_source)->w = xctx.win;
    g_source_add_poll(x11_source, &dpy_pollfd);

    g_source_attach(x11_source, NULL);

    g_unix_signal_add(SIGUSR1, pause_signal, NULL);
    g_unix_signal_add(SIGUSR2, unpause_signal, NULL);

    run(NULL);
    g_main_loop_run(mainloop);

    dbus_tear_down(owner_id);

    return 0;
}
Exemplo n.º 3
0
static int uc_send_notification (const char *name)
{
  cache_entry_t *ce = NULL;
  int status;

  char *name_copy;
  char *host;
  char *plugin;
  char *plugin_instance;
  char *type;
  char *type_instance;

  notification_t n;

  name_copy = strdup (name);
  if (name_copy == NULL)
  {
    ERROR ("uc_send_notification: strdup failed.");
    return (-1);
  }

  status = parse_identifier (name_copy, &host,
      &plugin, &plugin_instance,
      &type, &type_instance);
  if (status != 0)
  {
    ERROR ("uc_send_notification: Cannot parse name `%s'", name);
    return (-1);
  }

  /* Copy the associative members */
  notification_init (&n, NOTIF_FAILURE, /* host = */ NULL,
      host, plugin, plugin_instance, type, type_instance);

  sfree (name_copy);
  name_copy = host = plugin = plugin_instance = type = type_instance = NULL;

  pthread_mutex_lock (&cache_lock);

  /*
   * Set the time _after_ getting the lock because we don't know how long
   * acquiring the lock takes and we will use this time later to decide
   * whether or not the state is OKAY.
   */
  n.time = time (NULL);

  status = c_avl_get (cache_tree, name, (void *) &ce);
  if (status != 0)
  {
    pthread_mutex_unlock (&cache_lock);
    sfree (name_copy);
    return (-1);
  }
    
  /* Check if the entry has been updated in the meantime */
  if ((n.time - ce->last_update) < (2 * ce->interval))
  {
    ce->state = STATE_OKAY;
    pthread_mutex_unlock (&cache_lock);
    sfree (name_copy);
    return (-1);
  }

  ssnprintf (n.message, sizeof (n.message),
      "%s has not been updated for %i seconds.", name,
      (int) (n.time - ce->last_update));

  pthread_mutex_unlock (&cache_lock);

  plugin_dispatch_notification (&n);

  return (0);
} /* int uc_send_notification */
int main(int argc, char *argv[])
{
	struct stream_data	stream;
	struct stream_header	hdr;
	char const		*program = "/bin/false";
	struct signature_options sigopts = {
		.min_strength	=  0,
	};
	char			build_time[8*3 + 2];
	char			revision[8*3 + 2];
	int			notify_port = -1;

	while (1) {
		int         c = getopt_long(argc, argv, "vx:S:",
					    CMDLINE_OPTIONS, NULL);

		if (c==-1)
			break;

		switch (c) {
		case CMD_HELP     :  show_help();
		case CMD_VERSION  :  show_version();
		case 'x' :  program = optarg; break;
		case 'v' :  sigopts.min_strength = 1; break;
		case 'S':   sigopts.min_strength = atoi(optarg); break;

		case CMD_CAFILE:
			if (!add_filename(&sigopts.ca_files, optarg))
				return EX_OSERR;
			break;

		case CMD_CRLFILE:
			if (!add_filename(&sigopts.crl_files, optarg))
				return EX_OSERR;
			break;

		case CMD_NOTIFY_PORT:
			notify_port = atoi(optarg);
			break;

		default:
			fprintf(stderr, "Try --help for more information\n");
			return EX_USAGE;
		}
	}

	if (!notification_init(&stream.notify, notify_port))
		return EX_OSERR;

	if (!stream_data_open(&stream, 0))
		signal_return(&stream, EX_OSERR);

	if (!stream_data_read_params(&stream))
		signal_return(&stream, EX_DATAERR);

	if (!stream_data_read(&stream, &hdr, sizeof hdr, false))
		signal_return(&stream, EX_DATAERR);

	if (be32toh(hdr.magic) != STREAM_HEADER_MAGIC) {
		fprintf(stderr, "bad stream magic\n");
		signal_return(&stream, EX_DATAERR);
	}

	if (!read_hdr_ext(&stream, be32toh(hdr.version),
			  be32toh(hdr.extra_header)))
		signal_return(&stream, EX_DATAERR);

	sprintf(build_time, "%" PRIu64, be64toh(hdr.build_time));
	setenv("STREAM_BUILD_TIME", build_time, 1);

	sprintf(revision, "%" PRIx64, be64toh(stream.revision));
	setenv("STREAM_REVISION", revision, 1);

	notification_send_length(&stream.notify, stream.total_len);

	if (!stage_transaction(program, "start"))
		signal_return(&stream, EX_OSERR);

	for (;;) {
		struct stream_hunk_header	hhdr;
		struct memory_block_data	payload;
		struct memory_block_signature	signature;

		if (!stream_data_read(&stream, &hhdr, sizeof hhdr, true))
			signal_return(&stream, EX_DATAERR);

		if (stream.is_eos)
			break;

		payload.mem.stream   = &stream;
		payload.mem.len      = be32toh(hhdr.hunk_len);
		payload.mem.data     = NULL;
		payload.type         = be32toh(hhdr.type);
		payload.compression  = hhdr.compress_type;
		payload.len          = be32toh(hhdr.decompress_len);

		signature.opts       = &sigopts;
		signature.pre.stream = &stream;
		signature.pre.len    = be32toh(hhdr.prefix_len);
		signature.pre.data   = NULL;
		signature.mem.stream = &stream;
		signature.mem.len    = be32toh(hhdr.fixed_sign_len);
		signature.mem.data   = NULL;
		signature.type       = hhdr.sign_type;
		signature.shdr       = &hdr;
		signature.hhdr       = &hhdr;

		if (!process_hunk(program, &stream.notify, &payload, &signature))
			signal_return(&stream, EX_DATAERR);
	}

	stream_data_close(&stream);

	free(sigopts.ca_files.names);
	free(sigopts.crl_files.names);

	if (!stage_transaction(program, "end"))
		signal_return(&stream, EX_OSERR);

	signal_return(&stream, EX_OK);
}
Exemplo n.º 5
0
static void onNotify(GDBusConnection * connection,
                     const gchar * sender,
                     GVariant * parameters, GDBusMethodInvocation * invocation)
{

        gchar *appname = NULL;
        guint replaces_id = 0;
        gchar *icon = NULL;
        gchar *summary = NULL;
        gchar *body = NULL;
        Actions *actions = malloc(sizeof(Actions));
        gint timeout = -1;

        /* hints */
        gint urgency = 1;
        gint progress = -1;
        gchar *fgcolor = NULL;
        gchar *bgcolor = NULL;
        gchar *category = NULL;

        actions->actions = NULL;
        actions->count = 0;

        {
                GVariantIter *iter = g_variant_iter_new(parameters);
                GVariant *content;
                GVariant *dict_value;
                int idx = 0;
                while ((content = g_variant_iter_next_value(iter))) {

                        switch (idx) {
                        case 0:
                                if (g_variant_is_of_type
                                    (content, G_VARIANT_TYPE_STRING))
                                        appname =
                                            g_variant_dup_string(content, NULL);
                                break;
                        case 1:
                                if (g_variant_is_of_type
                                    (content, G_VARIANT_TYPE_UINT32))
                                        replaces_id =
                                            g_variant_get_uint32(content);
                                break;
                        case 2:
                                if (g_variant_is_of_type
                                    (content, G_VARIANT_TYPE_STRING))
                                        icon =
                                            g_variant_dup_string(content, NULL);
                                break;
                        case 3:
                                if (g_variant_is_of_type
                                    (content, G_VARIANT_TYPE_STRING))
                                        summary =
                                            g_variant_dup_string(content, NULL);
                                break;
                        case 4:
                                if (g_variant_is_of_type
                                    (content, G_VARIANT_TYPE_STRING))
                                        body =
                                            g_variant_dup_string(content, NULL);
                                break;
                        case 5:
                                if (g_variant_is_of_type
                                    (content, G_VARIANT_TYPE_STRING_ARRAY))
                                        actions->actions =
                                            g_variant_dup_strv(content,
                                                               &(actions->
                                                                 count));
                                break;
                        case 6:
                                if (g_variant_is_of_type
                                    (content, G_VARIANT_TYPE_DICTIONARY)) {

                                        dict_value =
                                            g_variant_lookup_value(content,
                                                                   "urgency",
                                                                   G_VARIANT_TYPE_BYTE);
                                        if (dict_value)
                                                urgency =
                                                    g_variant_get_byte
                                                    (dict_value);

                                        dict_value =
                                            g_variant_lookup_value(content,
                                                                   "fgcolor",
                                                                   G_VARIANT_TYPE_STRING);
                                        if (dict_value)
                                                fgcolor =
                                                    g_variant_dup_string
                                                    (dict_value, NULL);

                                        dict_value =
                                            g_variant_lookup_value(content,
                                                                   "bgcolor",
                                                                   G_VARIANT_TYPE_STRING);
                                        if (dict_value)
                                                bgcolor =
                                                    g_variant_dup_string
                                                    (dict_value, NULL);

                                        dict_value =
                                                g_variant_lookup_value(content,
                                                                "category",
                                                                G_VARIANT_TYPE_STRING);

                                        if (dict_value) {
                                                category =
                                                        g_variant_dup_string(
                                                                        dict_value, NULL);
                                        }

                                        dict_value =
                                                g_variant_lookup_value(content,
                                                                "value",
                                                                G_VARIANT_TYPE_INT32);

                                        if (dict_value) {
                                                progress =
                                                        g_variant_get_int32(dict_value);
                                        } else {
                                                dict_value =
                                                        g_variant_lookup_value(content,
                                                                        "value",
                                                                        G_VARIANT_TYPE_UINT32);

                                                if (dict_value)
                                                        progress =
                                                                g_variant_get_uint32(dict_value);
                                        }
                                }
                                break;
                        case 7:
                                if (g_variant_is_of_type
                                    (content, G_VARIANT_TYPE_INT32))
                                        timeout = g_variant_get_int32(content);
                                break;
                        }

                        idx++;
                }

                g_variant_iter_free(iter);
        }

        fflush(stdout);

        if (timeout > 0) {
                /* do some rounding */
                timeout = (timeout + 500) / 1000;
                if (timeout < 1) {
                        timeout = 1;
                }
        }

        notification *n = malloc(sizeof(notification));
        n->appname = appname;
        n->summary = summary;
        n->body = body;
        n->icon = icon;
        n->timeout = timeout;
        n->progress = (progress < 0 || progress > 100) ? 0 : progress + 1;
        n->urgency = urgency;
        n->category = category;
        n->dbus_client = strdup(sender);
        if (actions->count > 0) {
                n->actions = actions;
        } else {
                n->actions = NULL;
                free(actions);
        }

        for (int i = 0; i < ColLast; i++) {
                n->color_strings[i] = NULL;
        }
        n->color_strings[ColFG] = fgcolor;
        n->color_strings[ColBG] = bgcolor;

        int id = notification_init(n, replaces_id);
        wake_up();

        GVariant *reply = g_variant_new("(u)", id);
        g_dbus_method_invocation_return_value(invocation, reply);
        g_dbus_connection_flush(connection, NULL, NULL, NULL);

        run(NULL);
}
Exemplo n.º 6
0
static void init(void)
{
    system_init();
    kernel_init();
#ifdef APPLICATION
    paths_init();
#endif
    buffer_init();
    enable_irq();
    lcd_init();
#ifdef HAVE_REMOTE_LCD
    lcd_remote_init();
#endif
    font_init();
    show_logo();
    button_init();
    backlight_init();
#if (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO))
    sim_tasks_init();
#endif
#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
    notification_init();
#endif
    lang_init(core_language_builtin, language_strings, 
              LANG_LAST_INDEX_IN_ARRAY);
#ifdef DEBUG
    debug_init();
#endif
    /* Keep the order of this 3 (viewportmanager handles statusbars)
     * Must be done before any code uses the multi-screen API */
    gui_syncstatusbar_init(&statusbars);
    gui_sync_skin_init();
    sb_skin_init();
    viewportmanager_init();

    storage_init();
    settings_reset();
    settings_load(SETTINGS_ALL);
    settings_apply(true);
    init_dircache(true);
    init_dircache(false);
#ifdef HAVE_TAGCACHE
    init_tagcache();
#endif
    sleep(HZ/2);
    tree_mem_init();
    filetype_init();
    playlist_init();
    theme_init_buffer();

#if CONFIG_CODEC != SWCODEC
    mp3_init( global_settings.volume,
              global_settings.bass,
              global_settings.treble,
              global_settings.balance,
              global_settings.loudness,
              global_settings.avc,
              global_settings.channel_config,
              global_settings.stereo_width,
              global_settings.mdb_strength,
              global_settings.mdb_harmonics,
              global_settings.mdb_center,
              global_settings.mdb_shape,
              global_settings.mdb_enable,
              global_settings.superbass);

    /* audio_init must to know the size of voice buffer so init voice first */
    talk_init();
#endif /* CONFIG_CODEC != SWCODEC */

    scrobbler_init();
#if CONFIG_CODEC == SWCODEC && defined (HAVE_PITCHSCREEN)
    tdspeed_init();
#endif /* CONFIG_CODEC == SWCODEC */

    audio_init();
    button_clear_queue(); /* Empty the keyboard buffer */
    
    settings_apply_skins();
}