Beispiel #1
0
void AccountWindow::SplitOption::updateSplits()
{
  SplitWidgets *split_widgets = &account_entry->split_widgets;
  SplitWidgets::iterator split_widget = split_widgets->begin();
  SplitOption *widget = *split_widget;
  const char *val = widget->getValue();
  split_widget++;

  GString *username = g_string_new(val);
  PurplePluginProtocolInfo *prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(
      purple_find_prpl(purple_account_get_protocol_id(account)));

  for (GList *iter = prplinfo->user_splits;
      iter && split_widget != split_widgets->end();
      iter = iter->next, split_widget++) {
    PurpleAccountUserSplit *user_split
      = reinterpret_cast<PurpleAccountUserSplit*>(iter->data);
    widget = *split_widget;

    val = widget->getValue();
    if (!val || !*val)
      val = purple_account_user_split_get_default_value(user_split);
    g_string_append_printf(username, "%c%s",
        purple_account_user_split_get_separator(user_split), val);
  }

  purple_account_set_username(account, username->str);
  g_string_free(username, TRUE);
}
Beispiel #2
0
static void purple_init( account_t *acc )
{
	PurplePlugin *prpl = purple_plugins_find_with_id( (char*) acc->prpl->data );
	PurplePluginProtocolInfo *pi = prpl->info->extra_info;
	PurpleAccount *pa;
	GList *i, *st;
	set_t *s;
	char help_title[64];
	GString *help;
	static gboolean dir_fixed = FALSE;
	
	/* Layer violation coming up: Making an exception for libpurple here.
	   Dig in the IRC state a bit to get a username. Ideally we should
	   check if s/he identified but this info doesn't seem *that* important.
	   It's just that fecking libpurple can't *not* store this shit.
	   
	   Remember that libpurple is not really meant to be used on public
	   servers anyway! */
	if( !dir_fixed )
	{
		irc_t *irc = acc->bee->ui_data;
		char *dir;
		
		dir = g_strdup_printf( "%s/purple/%s", global.conf->configdir, irc->user->nick );
		purple_util_set_user_dir( dir );
		g_free( dir );
		
		purple_blist_load();
		purple_prefs_load();
		dir_fixed = TRUE;
	}
	
	help = g_string_new( "" );
	g_string_printf( help, "BitlBee libpurple module %s (%s).\n\nSupported settings:",
	                        (char*) acc->prpl->name, prpl->info->name );
	
	if( pi->user_splits )
	{
		GList *l;
		g_string_append_printf( help, "\n* username: Username" );
		for( l = pi->user_splits; l; l = l->next )
			g_string_append_printf( help, "%c%s",
			                        purple_account_user_split_get_separator( l->data ),
			                        purple_account_user_split_get_text( l->data ) );
	}
	
	/* Convert all protocol_options into per-account setting variables. */
	for( i = pi->protocol_options; i; i = i->next )
	{
		PurpleAccountOption *o = i->data;
		const char *name;
		char *def = NULL;
		set_eval eval = NULL;
		void *eval_data = NULL;
		GList *io = NULL;
		GSList *opts = NULL;
		
		name = purple_account_option_get_setting( o );
		
		switch( purple_account_option_get_type( o ) )
		{
		case PURPLE_PREF_STRING:
			def = g_strdup( purple_account_option_get_default_string( o ) );
			
			g_string_append_printf( help, "\n* %s (%s), %s, default: %s",
			                        name, purple_account_option_get_text( o ),
			                        "string", def );
			
			break;
		
		case PURPLE_PREF_INT:
			def = g_strdup_printf( "%d", purple_account_option_get_default_int( o ) );
			eval = set_eval_int;
			
			g_string_append_printf( help, "\n* %s (%s), %s, default: %s",
			                        name, purple_account_option_get_text( o ),
			                        "integer", def );
			
			break;
		
		case PURPLE_PREF_BOOLEAN:
			if( purple_account_option_get_default_bool( o ) )
				def = g_strdup( "true" );
			else
				def = g_strdup( "false" );
			eval = set_eval_bool;
			
			g_string_append_printf( help, "\n* %s (%s), %s, default: %s",
			                        name, purple_account_option_get_text( o ),
			                        "boolean", def );
			
			break;
		
		case PURPLE_PREF_STRING_LIST:
			def = g_strdup( purple_account_option_get_default_list_value( o ) );
			
			g_string_append_printf( help, "\n* %s (%s), %s, default: %s",
			                        name, purple_account_option_get_text( o ),
			                        "list", def );
			g_string_append( help, "\n  Possible values: " );
			
			for( io = purple_account_option_get_list( o ); io; io = io->next )
			{
				PurpleKeyValuePair *kv = io->data;
				opts = g_slist_append( opts, kv->value );
				/* TODO: kv->value is not a char*, WTF? */
				if( strcmp( kv->value, kv->key ) != 0 )
					g_string_append_printf( help, "%s (%s), ", (char*) kv->value, kv->key );
				else
					g_string_append_printf( help, "%s, ", (char*) kv->value );
			}
			g_string_truncate( help, help->len - 2 );
			eval = set_eval_list;
			eval_data = opts;
			
			break;
			
		default:
			/** No way to talk to the user right now, invent one when
			this becomes important.
			irc_rootmsg( acc->irc, "Setting with unknown type: %s (%d) Expect stuff to break..\n",
			             name, purple_account_option_get_type( o ) );
			*/
			g_string_append_printf( help, "\n* [%s] UNSUPPORTED (type %d)",
			                        name, purple_account_option_get_type( o ) );
			name = NULL;
		}
		
		if( name != NULL )
		{
			s = set_add( &acc->set, name, def, eval, acc );
			s->flags |= ACC_SET_OFFLINE_ONLY;
			s->eval_data = eval_data;
			g_free( def );
		}
	}
	
	g_snprintf( help_title, sizeof( help_title ), "purple %s", (char*) acc->prpl->name );
	help_add_mem( &global.help, help_title, help->str );
	g_string_free( help, TRUE );
	
	s = set_add( &acc->set, "display_name", NULL, set_eval_display_name, acc );
	s->flags |= ACC_SET_ONLINE_ONLY;
	
	if( pi->options & OPT_PROTO_MAIL_CHECK )
	{
		s = set_add( &acc->set, "mail_notifications", "false", set_eval_bool, acc );
		s->flags |= ACC_SET_OFFLINE_ONLY;
	}
	
	if( strcmp( prpl->info->name, "Gadu-Gadu" ) == 0 )
		s = set_add( &acc->set, "gg_sync_contacts", "true", set_eval_bool, acc );
	
	/* Go through all away states to figure out if away/status messages
	   are possible. */
	pa = purple_account_new( acc->user, (char*) acc->prpl->data );
	for( st = purple_account_get_status_types( pa ); st; st = st->next )
	{
		PurpleStatusPrimitive prim = purple_status_type_get_primitive( st->data );
		
		if( prim == PURPLE_STATUS_AVAILABLE )
		{
			if( purple_status_type_get_attr( st->data, "message" ) )
				acc->flags |= ACC_FLAG_STATUS_MESSAGE;
		}
		else if( prim != PURPLE_STATUS_OFFLINE )
		{
			if( purple_status_type_get_attr( st->data, "message" ) )
				acc->flags |= ACC_FLAG_AWAY_MESSAGE;
		}
	}
	purple_accounts_remove( pa );
}
Beispiel #3
0
void AccountWindow::populateAccount(PurpleAccount *account)
{
  if (account_entries.find(account) == account_entries.end()) {
    // no entry for this account, so add one
    AccountEntry entry;
    entry.parent = NULL;
    account_entries[account] = entry;
  }
  else {
    // the account exists, so clear all data
    clearAccount(account, false);
  }

  AccountEntry *account_entry = &account_entries[account];

  if (!account_entry->parent) {
    CppConsUI::TreeView::ToggleCollapseButton *button
      = new CppConsUI::TreeView::ToggleCollapseButton;
    CppConsUI::TreeView::NodeReference parent_reference
      = treeview->appendNode(treeview->getRootNode(), *button);
    treeview->setCollapsed(parent_reference, true);
    account_entry->parent = button;
    account_entry->parent_reference = parent_reference;
  }

  char *label = g_strdup_printf("[%s] %s",
      purple_account_get_protocol_name(account),
      purple_account_get_username(account));
  account_entry->parent->setText(label);
  g_free(label);

  const char *protocol_id = purple_account_get_protocol_id(account);
  PurplePlugin *prpl = purple_find_prpl(protocol_id);

  if (!prpl) {
    // we cannot change the settings of an unknown account
    CppConsUI::Label *label = new CppConsUI::Label(
        _("Invalid account or protocol plugin not loaded."));
    treeview->appendNode(account_entry->parent_reference, *label);
  }
  else {
    PurplePluginProtocolInfo *prplinfo = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);

    // protocols combobox
    ProtocolOption *combobox = new ProtocolOption(account, *this);
    CppConsUI::TreeView::NodeReference protocol_node
      = treeview->appendNode(account_entry->parent_reference, *combobox);
    combobox->grabFocus();

    /* The username must be treated in a special way because it can contain
     * multiple values (e.g. user@server:port/resource). */
    char *username = g_strdup(purple_account_get_username(account));

    for (GList *iter = g_list_last(prplinfo->user_splits); iter;
        iter = iter->prev) {
      PurpleAccountUserSplit *split
        = reinterpret_cast<PurpleAccountUserSplit*>(iter->data);

      char *s;
      if (purple_account_user_split_get_reverse(split))
        s = strrchr(username, purple_account_user_split_get_separator(split));
      else
        s = strchr(username, purple_account_user_split_get_separator(split));

      const char *value;
      if (s) {
        *s = '\0';
        value = s + 1;
      }
      else
        value = purple_account_user_split_get_default_value(split);

      // create widget for the username split and remember
      SplitOption *widget_split = new SplitOption(account, split,
          account_entry);
      widget_split->setValue(value);
      account_entry->split_widgets.push_front(widget_split);

      treeview->appendNode(account_entry->parent_reference, *widget_split);
    }

    SplitOption *widget_split = new SplitOption(account, NULL, account_entry);
    widget_split->setValue(username);
    account_entry->split_widgets.push_front(widget_split);
    treeview->insertNodeAfter(protocol_node, *widget_split);
    g_free(username);

    // password
    Widget *widget = new StringOption(account, StringOption::TYPE_PASSWORD);
    treeview->appendNode(account_entry->parent_reference, *widget);

    // remember password
    widget = new BoolOption(account, BoolOption::TYPE_REMEMBER_PASSWORD);
    treeview->appendNode(account_entry->parent_reference, *widget);

    // alias
    widget = new StringOption(account, StringOption::TYPE_ALIAS);
    treeview->appendNode(account_entry->parent_reference, *widget);

    for (GList *pref = prplinfo->protocol_options; pref; pref = pref->next) {
      PurpleAccountOption *option
        = reinterpret_cast<PurpleAccountOption*>(pref->data);
      PurplePrefType type = purple_account_option_get_type(option);

      switch (type) {
        case PURPLE_PREF_STRING:
          widget = new StringOption(account, option);
          treeview->appendNode(account_entry->parent_reference, *widget);
          break;
        case PURPLE_PREF_INT:
          widget = new IntegerOption(account, option);
          treeview->appendNode(account_entry->parent_reference, *widget);
          break;
        case PURPLE_PREF_BOOLEAN:
          widget = new BoolOption(account, option);
          treeview->appendNode(account_entry->parent_reference, *widget);
          break;
        case PURPLE_PREF_STRING_LIST:
          widget = new StringListOption(account, option);
          treeview->appendNode(account_entry->parent_reference, *widget);
          break;
        default:
          LOG->error(_("Unhandled account option type '%d'."), type);
          break;
      }
    }

    // enable/disable account
    widget = new BoolOption(account, BoolOption::TYPE_ENABLE_ACCOUNT);
    treeview->appendNode(account_entry->parent_reference, *widget);

    // coloring
    widget = new ColorOption(account);
    treeview->appendNode(account_entry->parent_reference, *widget);
  }

  // drop account
  CppConsUI::Button *drop_button = new CppConsUI::Button(_("Drop account"));
  drop_button->signal_activate.connect(sigc::bind(sigc::mem_fun(this,
          &AccountWindow::dropAccount), account));
  treeview->appendNode(account_entry->parent_reference, *drop_button);
}