示例#1
0
void
skypeweb_search_users_text_cb(SkypeWebAccount *sa, JsonNode *node, gpointer user_data)
{
	JsonArray *resultsarray = NULL;
	gint index, length;
	GString *userids;
	gchar *search_term = user_data;

	PurpleNotifySearchResults *results;
	PurpleNotifySearchColumn *column;
	
	resultsarray = json_node_get_array(node);
	length = json_array_get_length(resultsarray);
	
	if (length == 0)
	{
		gchar *primary_text = g_strdup_printf("Your search for the user \"%s\" returned no results", search_term);
		purple_notify_warning(sa->pc, "No users found", primary_text, "");
		g_free(primary_text);
		g_free(search_term);
		return;
	}
	
	userids = g_string_new("");
	
	resultsarray = json_node_get_array(node);
	for(index = 0; index < length; index++)
	{
		JsonObject *result = json_array_get_object_element(resultsarray, index);
		g_string_append_printf(userids, "%s,", json_object_get_string_member(result, "skypewebid"));
	}

	
	results = purple_notify_searchresults_new();
	if (results == NULL)
	{
		g_free(search_term);
		return;
	}
		
	/* columns: Friend ID, Name, Network */
	column = purple_notify_searchresults_column_new(_("Skype Name"));
	purple_notify_searchresults_column_add(results, column);
	column = purple_notify_searchresults_column_new(_("Display Name"));
	purple_notify_searchresults_column_add(results, column);
	column = purple_notify_searchresults_column_new(_("City"));
	purple_notify_searchresults_column_add(results, column);
	column = purple_notify_searchresults_column_new(_("Country"));
	purple_notify_searchresults_column_add(results, column);
	
	purple_notify_searchresults_button_add(results,
			PURPLE_NOTIFY_BUTTON_ADD,
			skypeweb_search_results_add_buddy);
	
	for(index = 0; index < length; index++)
	{
		JsonObject *contact = json_array_get_object_element(resultsarray, index);
		JsonObject *contactcards = json_object_get_object_member(contact, "ContactCards");
		JsonObject *skypecontact = json_object_get_object_member(contactcards, "Skype");
		JsonObject *currentlocation = json_object_get_object_member(contactcards, "CurrentLocation");
		
		/* the row in the search results table */
		/* prepend to it backwards then reverse to speed up adds */
		GList *row = NULL;
		
		row = g_list_prepend(row, g_strdup(json_object_get_string_member(skypecontact, "SkypeName")));
		row = g_list_prepend(row, g_strdup(json_object_get_string_member(skypecontact, "DisplayName")));
		row = g_list_prepend(row, g_strdup(json_object_get_string_member(currentlocation, "City")));
		row = g_list_prepend(row, g_strdup(json_object_get_string_member(currentlocation, "Country")));
		
		row = g_list_reverse(row);
		
		purple_notify_searchresults_row_add(results, row);
	}
	
	purple_notify_searchresults(sa->pc, NULL, search_term, NULL,
			results, NULL, NULL);
}
int
cc_rfkill_glib_open (CcRfkillGlib *rfkill)
{
	CcRfkillGlibPrivate *priv;
	int fd;
	int ret;
	GList *events;

	g_return_val_if_fail (RFKILL_IS_GLIB (rfkill), -1);
	g_return_val_if_fail (rfkill->priv->fd == -1, -1);

	priv = rfkill->priv;

	fd = open("/dev/rfkill", O_RDWR);
	if (fd < 0) {
		if (errno == EACCES)
			g_warning ("Could not open RFKILL control device, please verify your installation");
		return fd;
	}

	ret = fcntl(fd, F_SETFL, O_NONBLOCK);
	if (ret < 0) {
		g_debug ("Can't set RFKILL control device to non-blocking");
		close(fd);
		return ret;
	}

	events = NULL;

	while (1) {
		struct rfkill_event event;
		struct rfkill_event *event_ptr;
		ssize_t len;

		len = read(fd, &event, sizeof(event));
		if (len < 0) {
			if (errno == EAGAIN)
				break;
			g_debug ("Reading of RFKILL events failed");
			break;
		}

		if (len != RFKILL_EVENT_SIZE_V1) {
			g_warning ("Wrong size of RFKILL event\n");
			continue;
		}

		if (event.op != RFKILL_OP_ADD)
			continue;

		g_debug ("Read killswitch of type '%s' (idx=%d): soft %d hard %d",
			 type_to_string (event.type),
			 event.idx, event.soft, event.hard);

		event_ptr = g_memdup (&event, sizeof(event));
		events = g_list_prepend (events, event_ptr);
	}

	/* Setup monitoring */
	priv->fd = fd;
	priv->channel = g_io_channel_unix_new (priv->fd);
	priv->watch_id = g_io_add_watch (priv->channel,
					 G_IO_IN | G_IO_HUP | G_IO_ERR,
					 (GIOFunc) event_cb,
					 rfkill);

	events = g_list_reverse (events);
	emit_changed_signal_and_free (rfkill, events);

	return fd;
}
示例#3
0
GList*
seaf_share_manager_list_org_share_repos (SeafShareManager *mgr,
                                         int org_id,
                                         const char *email,
                                         const char *type,
                                         int start, int limit)
{
    GList *ret = NULL, *p;
    char sql[512];

    if (start == -1 && limit == -1) {
        if (g_strcmp0 (type, "from_email") == 0) {
            snprintf (sql, sizeof(sql),
                      "SELECT SharedRepo.repo_id, VirtualRepo.repo_id, "
                      "to_email, permission, commit_id FROM "
                      "SharedRepo LEFT JOIN VirtualRepo ON "
                      "SharedRepo.repo_id = VirtualRepo.repo_id, "
                      "OrgRepo, Branch "
                      "WHERE from_email='%s' AND "
                      "OrgRepo.org_id=%d AND "
                      "SharedRepo.repo_id=OrgRepo.repo_id AND "
                      "SharedRepo.repo_id = Branch.repo_id AND "
                      "Branch.name = 'master'",
                      email, org_id);
        } else if (g_strcmp0 (type, "to_email") == 0) {
            snprintf (sql, sizeof(sql),
                      "SELECT SharedRepo.repo_id, NULL, "
                      "from_email, permission, commit_id FROM "
                      "SharedRepo, OrgRepo, Branch "
                      "WHERE to_email='%s' AND "
                      "OrgRepo.org_id=%d AND "
                      "SharedRepo.repo_id=OrgRepo.repo_id AND "
                      "SharedRepo.repo_id = Branch.repo_id AND "
                      "Branch.name = 'master'",
                      email, org_id);
        } else {
            /* should never reach here */
            g_warning ("[share mgr] Wrong column type");
            return NULL;
        }
    }
    else {
        if (g_strcmp0 (type, "from_email") == 0) {
            snprintf (sql, sizeof(sql),
                      "SELECT SharedRepo.repo_id, VirtualRepo.repo_id, "
                      "to_email, permission, commit_id FROM "
                      "SharedRepo LEFT JOIN VirtualRepo ON "
                      "SharedRepo.repo_id = VirtualRepo.repo_id, "
                      "OrgRepo, Branch "
                      "WHERE from_email='%s' AND "
                      "OrgRepo.org_id=%d AND "
                      "SharedRepo.repo_id=OrgRepo.repo_id AND "
                      "SharedRepo.repo_id = Branch.repo_id AND "
                      "Branch.name = 'master' "
                      "ORDER BY SharedRepo.repo_id "
                      "LIMIT %d OFFSET %d",
                      email, org_id, limit, start);
        } else if (g_strcmp0 (type, "to_email") == 0) {
            snprintf (sql, sizeof(sql),
                      "SELECT SharedRepo.repo_id, NULL, "
                      "from_email, permission FROM "
                      "SharedRepo, OrgRepo, Branch WHERE "
                      "to_email='%s' AND "
                      "OrgRepo.org_id=%d AND "
                      "SharedRepo.repo_id=OrgRepo.repo_id "
                      "SharedRepo.repo_id = Branch.repo_id AND "
                      "Branch.name = 'master' "
                      "ORDER BY SharedRepo.repo_id "
                      "LIMIT %d OFFSET %d",
                      email, org_id, limit, start);
        } else {
            /* should never reach here */
            g_warning ("[share mgr] Wrong column type");
            return NULL;
        }
    }

    if (seaf_db_foreach_selected_row (mgr->seaf->db, sql,
                                      collect_repos, &ret) < 0) {
        g_warning ("[share mgr] DB error when get shared repo id and email "
                   "for %s.\n", email);
        for (p = ret; p; p = p->next)
            g_object_unref (p->data);
        g_list_free (ret);
        return NULL;
    }

    return g_list_reverse (ret);
}
/**
 * ags_recall_ladspa_load_ports:
 * @recall_ladspa: an #AgsRecallLadspa
 *
 * Set up LADSPA ports.
 *
 * Returns: a #GList containing #AgsPort.
 * 
 * Since: 0.4.2
 */
GList*
ags_recall_ladspa_load_ports(AgsRecallLadspa *recall_ladspa)
{
  AgsLadspaPlugin *ladspa_plugin;
  AgsPort *current;
  GList *port;
  unsigned long port_count;
  unsigned long i;

  void *plugin_so;
  LADSPA_Descriptor_Function ladspa_descriptor;
  LADSPA_Descriptor *plugin_descriptor;
  LADSPA_PortDescriptor *port_descriptor;
  LADSPA_PortRangeHintDescriptor hint_descriptor;

  ags_ladspa_manager_load_file(recall_ladspa->filename);
  ladspa_plugin = ags_ladspa_manager_find_ladspa_plugin(recall_ladspa->filename);
  port = NULL;
  
  plugin_so = ladspa_plugin->plugin_so;

  if(plugin_so != NULL){
    ladspa_descriptor = (LADSPA_Descriptor_Function) dlsym(plugin_so,
							   "ladspa_descriptor\0");

    if(dlerror() == NULL && ladspa_descriptor){
      recall_ladspa->plugin_descriptor = 
	plugin_descriptor = ladspa_descriptor(recall_ladspa->effect_index);

      port_count = plugin_descriptor->PortCount;
      port_descriptor = plugin_descriptor->PortDescriptors;

      for(i = 0; i < port_count; i++){
	if(LADSPA_IS_PORT_CONTROL(port_descriptor[i])){
	  if(LADSPA_IS_PORT_INPUT(port_descriptor[i]) ||
	     LADSPA_IS_PORT_OUTPUT(port_descriptor[i])){
	    gchar *plugin_name;
	    gchar *specifier;

	    hint_descriptor = plugin_descriptor->PortRangeHints[i].HintDescriptor;

	    plugin_name = g_strdup_printf("ladspa-%lu\0", plugin_descriptor->UniqueID);
	    specifier = g_strdup(plugin_descriptor->PortNames[i]);

	    current = g_object_new(AGS_TYPE_PORT,
				   "plugin-name\0", plugin_name,
				   "specifier\0", specifier,
				   "control-port\0", g_strdup_printf("%d/%d\0",
								     i,
								     port_count),
				   "port-value-is-pointer\0", FALSE,
				   "port-value-type\0", G_TYPE_FLOAT,
				   NULL);
	    current->port_value.ags_port_float = plugin_descriptor->PortRangeHints[i].LowerBound;

	    g_message("connecting port: %d/%d\0", i, port_count);

	    port = g_list_prepend(port,
				  current);
	  }
	}else if(LADSPA_IS_PORT_AUDIO(port_descriptor[i])){
	  if(LADSPA_IS_PORT_INPUT(port_descriptor[i])){
	    if(recall_ladspa->input_port == NULL){
	      recall_ladspa->input_port = (unsigned long *) malloc(sizeof(unsigned long));
	      recall_ladspa->input_port[0] = i;
	    }else{
	      recall_ladspa->input_port = (unsigned long *) realloc(recall_ladspa->input_port,
								    (recall_ladspa->input_lines + 1) * sizeof(unsigned long));
	      recall_ladspa->input_port[recall_ladspa->input_lines] = i;
	    }

	    recall_ladspa->input_lines += 1;
	  }else if(LADSPA_IS_PORT_OUTPUT(port_descriptor[i])){
	    if(recall_ladspa->output_port == NULL){
	      recall_ladspa->output_port = (unsigned long *) malloc(sizeof(unsigned long));
	      recall_ladspa->output_port[0] = i;
	    }else{
	      recall_ladspa->output_port = (unsigned long *) realloc(recall_ladspa->output_port,
								     (recall_ladspa->output_lines + 1) * sizeof(unsigned long));
	      recall_ladspa->output_port[recall_ladspa->output_lines] = i;
	    }

	    recall_ladspa->output_lines += 1;
	  }
	}
      }

      AGS_RECALL(recall_ladspa)->port = g_list_reverse(port);
    }
  }

  return(AGS_RECALL(recall_ladspa)->port);
}
void
ags_recall_ladspa_set_ports(AgsPlugin *plugin, GList *port)
{
  AgsRecallLadspa *recall_ladspa;
  AgsLadspaPlugin *ladspa_plugin;
  AgsPort *current;
  GList *list;
  unsigned long port_count;
  unsigned long i;

  void *plugin_so;
  LADSPA_Descriptor_Function ladspa_descriptor;
  LADSPA_Descriptor *plugin_descriptor;
  LADSPA_PortDescriptor *port_descriptor;
  LADSPA_PortRangeHintDescriptor hint_descriptor;

  recall_ladspa = AGS_RECALL_LADSPA(plugin);

  ags_ladspa_manager_load_file(recall_ladspa->filename);
  ladspa_plugin = ags_ladspa_manager_find_ladspa_plugin(recall_ladspa->filename);
  
  plugin_so = ladspa_plugin->plugin_so;

  if(plugin_so != NULL){
    ladspa_descriptor = (LADSPA_Descriptor_Function) dlsym(plugin_so,
							   "ladspa_descriptor\0");

    if(dlerror() == NULL && ladspa_descriptor){
      recall_ladspa->plugin_descriptor = 
	plugin_descriptor = ladspa_descriptor(recall_ladspa->effect_index);

      port_count = plugin_descriptor->PortCount;
      port_descriptor = plugin_descriptor->PortDescriptors;

      for(i = 0; i < port_count; i++){
	if(LADSPA_IS_PORT_CONTROL(port_descriptor[i])){
	  if(LADSPA_IS_PORT_INPUT(port_descriptor[i]) ||
	     LADSPA_IS_PORT_OUTPUT(port_descriptor[i])){
	    gchar *plugin_name;
	    gchar *specifier;

	    hint_descriptor = plugin_descriptor->PortRangeHints[i].HintDescriptor;

	    plugin_name = g_strdup_printf("ladspa-%lu\0", plugin_descriptor->UniqueID);
	    specifier = g_strdup(plugin_descriptor->PortNames[i]);

	    list = port;
	    current = NULL;

	    while(list != NULL){
	      if(!g_strcmp0(specifier,
			    AGS_PORT(list->data)->specifier)){
		current = list->data;
		break;
	      }

	      list = list->next;
	    }
	    
	    current->port_value.ags_port_float = plugin_descriptor->PortRangeHints[i].LowerBound;

	    g_message("connecting port: %d/%d\0", i, port_count);
	  }
	}else if(LADSPA_IS_PORT_AUDIO(port_descriptor[i])){
	  if(LADSPA_IS_PORT_INPUT(port_descriptor[i])){
	    if(recall_ladspa->input_port == NULL){
	      recall_ladspa->input_port = (unsigned long *) malloc(sizeof(unsigned long));
	      recall_ladspa->input_port[0] = i;
	    }else{
	      recall_ladspa->input_port = (unsigned long *) realloc(recall_ladspa->input_port,
							    (recall_ladspa->input_lines + 1) * sizeof(unsigned long));
	      recall_ladspa->input_port[recall_ladspa->input_lines] = i;
	    }

	    recall_ladspa->input_lines += 1;
	  }else if(LADSPA_IS_PORT_OUTPUT(port_descriptor[i])){
	    if(recall_ladspa->output_port == NULL){
	      recall_ladspa->output_port = (unsigned long *) malloc(sizeof(unsigned long));
	      recall_ladspa->output_port[0] = i;
	    }else{
	      recall_ladspa->output_port = (unsigned long *) realloc(recall_ladspa->output_port,
							    (recall_ladspa->output_lines + 1) * sizeof(unsigned long));
	      recall_ladspa->output_port[recall_ladspa->output_lines] = i;
	    }

	    recall_ladspa->output_lines += 1;
	  }
	}
      }

      AGS_RECALL(recall_ladspa)->port = g_list_reverse(port);
    }
  }
}
示例#6
0
static void
load_formats (void)
{
	static struct {
		char const *left_format;
		char const *middle_format;
		char const *right_format;
	} const predefined_formats [] = {
		{ "",                 "",                             "" },
		{ "",                 N_("Page &[PAGE]"),             "" },
		{ "",                 N_("Page &[PAGE] of &[PAGES]"), "" },
		{ "",                 N_("&[TAB]"),                   "" },
		{ N_("Page &[PAGE]"), N_("&[TAB]"),                   "" },
		{ N_("Page &[PAGE]"), N_("&[TAB]"),                   N_("&[DATE]") },
		{ "",                 N_("&[DATE]"),                  "" },
		{ N_("&[TAB]"),       N_("Page &[PAGE] of &[PAGES]"), N_("&[DATE]") },
		{ NULL, NULL, NULL }
	};

	/* Fetch header/footer formats */
	{
		int i;

		for (i = 0; predefined_formats [i].left_format; i++) {
			GnmPrintHF *format;

			format = gnm_print_hf_new (
				predefined_formats [i].left_format[0]?
				_(predefined_formats [i].left_format):"",
				predefined_formats [i].middle_format[0]?
				_(predefined_formats [i].middle_format):"",
				predefined_formats [i].right_format[0]?
				_(predefined_formats [i].right_format):"");

			gnm_print_hf_formats = g_list_prepend (gnm_print_hf_formats, format);
			hf_formats_base_num++;
		}
	}

	/* Now append the custom formats */
	{
		GSList const *left;
		GSList const *middle;
		GSList const *right;

		left = gnm_conf_get_printsetup_hf_left ();
		middle = gnm_conf_get_printsetup_hf_middle ();
		right = gnm_conf_get_printsetup_hf_right ();

		while (left != NULL && middle != NULL && right != NULL)
		{
			GnmPrintHF *format;

			format = gnm_print_hf_new
				(left->data ? left->data : "",
				 middle->data ? middle->data : "",
				 right->data ? right->data : "");

			gnm_print_hf_formats = g_list_prepend (gnm_print_hf_formats, format);

			left = left->next;
			middle = middle->next;
			right = right->next;
		}
	}

	gnm_print_hf_formats = g_list_reverse (gnm_print_hf_formats);
}