Пример #1
0
Request::FieldsDialog::LabelField::LabelField(PurpleRequestField *field)
    : field(field)
{
    g_assert(field);

    SetText(purple_request_field_get_label(field));
}
Пример #2
0
Request::FieldsDialog::AccountField::AccountField(PurpleRequestField *field)
    : field(field)
{
    g_assert(field);

    // TODO filter (purple_request_field_account_get_filter())
    // TODO signals (signed-on, signed-off, account-added, account-removed)

    char *text = g_strdup_printf("%s%s",
                                 purple_request_field_is_required(field) ? "*" : "",
                                 purple_request_field_get_label(field));
    SetText(text);
    g_free(text);

    gboolean show_all = purple_request_field_account_get_show_all(field);
    for (GList *list = purple_accounts_get_all(); list; list = list->next) {
        PurpleAccount *account = reinterpret_cast<PurpleAccount*>(list->data);
        if (!show_all && !purple_account_is_connected(account))
            continue;

        char *label = g_strdup_printf("[%s] %s",
                                      purple_account_get_protocol_name(account),
                                      purple_account_get_username(account));
        AddOptionPtr(label, account);
        g_free(label);
    }
    SetSelectedByDataPtr(purple_request_field_account_get_default_value(field));

    signal_selection_changed.connect(sigc::mem_fun(this,
                                     &AccountField::OnAccountChanged));
}
Пример #3
0
static GntWidget*
create_boolean_field(PurpleRequestField *field)
{
	const char *label = purple_request_field_get_label(field);
	GntWidget *check = gnt_check_box_new(label);
	gnt_check_box_set_checked(GNT_CHECK_BOX(check),
			purple_request_field_bool_get_default_value(field));
	return check;
}
Пример #4
0
void Request::FieldsDialog::StringField::OnActivate(CppConsUI::Button& activator)
{
    CppConsUI::InputDialog *dialog
        = new CppConsUI::InputDialog(purple_request_field_get_label(field),
                                     purple_request_field_string_get_value(field));
    dialog->signal_response.connect(sigc::mem_fun(this,
                                    &StringField::ResponseHandler));
    dialog->Show();
}
Пример #5
0
void Request::FieldsDialog::IntegerField::OnActivate(CppConsUI::Button& activator)
{
    char *value = g_strdup_printf("%d", purple_request_field_int_get_value(field));
    CppConsUI::InputDialog *dialog
        = new CppConsUI::InputDialog(purple_request_field_get_label(field),
                                     value);
    g_free(value);
    dialog->SetFlags(CppConsUI::TextEntry::FLAG_NUMERIC);
    dialog->signal_response.connect(sigc::mem_fun(this,
                                    &IntegerField::ResponseHandler));
    dialog->Show();
}
Пример #6
0
Request::FieldsDialog::BooleanField::BooleanField(PurpleRequestField *field)
    : field(field)
{
    g_assert(field);

    char *text = g_strdup_printf("%s%s",
                                 purple_request_field_is_required(field) ? "*" : "",
                                 purple_request_field_get_label(field));
    SetText(text);
    g_free(text);

    SetState(purple_request_field_bool_get_value(field));
    signal_toggle.connect(sigc::mem_fun(this, &BooleanField::OnToggle));
}
Пример #7
0
Request::FieldsDialog::IntegerField::IntegerField(PurpleRequestField *field)
    : Button(FLAG_VALUE), field(field)
{
    g_assert(field);

    char *text = g_strdup_printf("%s%s",
                                 purple_request_field_is_required(field) ? "*" : "",
                                 purple_request_field_get_label(field));
    SetText(text);
    g_free(text);

    SetValue(purple_request_field_int_get_value(field));
    signal_activate.connect(sigc::mem_fun(this, &IntegerField::OnActivate));
}
Пример #8
0
Request::FieldsDialog::ImageField::ImageField(PurpleRequestField *field)
    : field(field)
{
    g_assert(field);

    char *text = g_strdup_printf("%s%s",
                                 purple_request_field_is_required(field) ? "*" : "",
                                 purple_request_field_get_label(field));
    SetText(text);
    g_free(text);

    // TODO

    signal_activate.connect(sigc::mem_fun(this, &ImageField::OnActivate));
}
Пример #9
0
Request::FieldsDialog::ChoiceField::ChoiceField(PurpleRequestField *field)
    : field(field)
{
    g_assert(field);

    char *text = g_strdup_printf("%s%s",
                                 purple_request_field_is_required(field) ? "*" : "",
                                 purple_request_field_get_label(field));
    SetText(text);
    g_free(text);

    for (GList *list = purple_request_field_choice_get_labels(field); list;
            list = list->next)
        AddOption(reinterpret_cast<const char*>(list->data));
    SetSelected(purple_request_field_choice_get_default_value(field));

    signal_selection_changed.connect(sigc::mem_fun(this,
                                     &ChoiceField::OnSelectionChanged));
}
Пример #10
0
Request::FieldsDialog::ListFieldSingle::ListFieldSingle(
    PurpleRequestField *field)
    : field(field)
{
    g_assert(field);

    char *text = g_strdup_printf("%s%s",
                                 purple_request_field_is_required(field) ? "*" : "",
                                 purple_request_field_get_label(field));
    SetText(text);
    g_free(text);

    GList *list = purple_request_field_list_get_items(field);
    for (int i = 0; list; i++, list = list->next) {
        const char *text = reinterpret_cast<const char*>(list->data);
        AddOption(text);
        if (purple_request_field_list_is_selected(field, text))
            SetSelected(i);
    }

    signal_selection_changed.connect(sigc::mem_fun(this,
                                     &ListFieldSingle::OnSelectionChanged));
}
Пример #11
0
static void *
finch_request_fields(const char *title, const char *primary,
		const char *secondary, PurpleRequestFields *allfields,
		const char *ok, GCallback ok_cb,
		const char *cancel, GCallback cancel_cb,
		PurpleAccount *account, const char *who, PurpleConversation *conv,
		void *userdata)
{
	GntWidget *window, *box;
	GList *grlist;
	GntWidget *screenname = NULL, *accountlist = NULL;

	window = setup_request_window(title, primary, secondary, PURPLE_REQUEST_FIELDS);

	/* This is how it's going to work: the request-groups are going to be
	 * stacked vertically one after the other. A GntLine will be separating
	 * the groups. */
	box = gnt_vbox_new(FALSE);
	gnt_box_set_pad(GNT_BOX(box), 0);
	gnt_box_set_fill(GNT_BOX(box), TRUE);
	for (grlist = purple_request_fields_get_groups(allfields); grlist; grlist = grlist->next)
	{
		PurpleRequestFieldGroup *group = grlist->data;
		GList *fields = purple_request_field_group_get_fields(group);
		GntWidget *hbox;
		const char *title = purple_request_field_group_get_title(group);

		if (title)
			gnt_box_add_widget(GNT_BOX(box),
					gnt_label_new_with_format(title, GNT_TEXT_FLAG_BOLD));

		for (; fields ; fields = fields->next)
		{
			/* XXX: Break each of the fields into a separate function? */
			PurpleRequestField *field = fields->data;
			PurpleRequestFieldType type = purple_request_field_get_type(field);
			const char *label = purple_request_field_get_label(field);

			hbox = gnt_hbox_new(TRUE);   /* hrm */
			gnt_box_add_widget(GNT_BOX(box), hbox);

			if (type != PURPLE_REQUEST_FIELD_BOOLEAN && label)
			{
				GntWidget *l;
				if (purple_request_field_is_required(field))
					l = gnt_label_new_with_format(label, GNT_TEXT_FLAG_UNDERLINE);
				else
					l = gnt_label_new(label);
				gnt_widget_set_size(l, 0, 1);
				gnt_box_add_widget(GNT_BOX(hbox), l);
			}

			if (type == PURPLE_REQUEST_FIELD_BOOLEAN)
			{
				FINCH_SET_DATA(field, create_boolean_field(field));
			}
			else if (type == PURPLE_REQUEST_FIELD_STRING)
			{
				FINCH_SET_DATA(field, create_string_field(field, &screenname));
			}
			else if (type == PURPLE_REQUEST_FIELD_INTEGER)
			{
				FINCH_SET_DATA(field, create_integer_field(field));
			}
			else if (type == PURPLE_REQUEST_FIELD_CHOICE)
			{
				FINCH_SET_DATA(field, create_choice_field(field));
			}
			else if (type == PURPLE_REQUEST_FIELD_LIST)
			{
				FINCH_SET_DATA(field, create_list_field(field));
			}
			else if (type == PURPLE_REQUEST_FIELD_ACCOUNT)
			{
				accountlist = FINCH_SET_DATA(field, create_account_field(field));
			}
			else
			{
				FINCH_SET_DATA(field, gnt_label_new_with_format(_("Not implemented yet."),
						GNT_TEXT_FLAG_BOLD));
			}
			gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID);
			gnt_box_add_widget(GNT_BOX(hbox), GNT_WIDGET(FINCH_GET_DATA(field)));
		}
		if (grlist->next)
			gnt_box_add_widget(GNT_BOX(box), gnt_hline_new());
	}
	gnt_box_add_widget(GNT_BOX(window), box);

	box = setup_button_box(window, userdata, request_fields_cb, allfields,
			ok, ok_cb, cancel, cancel_cb, NULL);
	gnt_box_add_widget(GNT_BOX(window), box);

	setup_default_callback(window, cancel_cb, userdata);
	gnt_widget_show(window);

	if (screenname && accountlist) {
		g_signal_connect(screenname, "completion", G_CALLBACK(update_selected_account), accountlist);
	}

	g_object_set_data(G_OBJECT(window), "fields", allfields);

	return window;
}
Пример #12
0
QuetzalFieldsDialog::QuetzalFieldsDialog(const char *title, const char *primary,
										 const char *secondary, PurpleRequestFields *fields,
										 const char *ok_text, GCallback ok_cb,
										 const char *cancel_text, GCallback cancel_cb,
										 void *user_data, QWidget *parent)
											 : QuetzalRequestDialog(PURPLE_REQUEST_FIELDS, user_data, parent)
{
	m_ok_cb = (PurpleRequestFieldsCb) ok_cb;
	m_cancel_cb = (PurpleRequestFieldsCb) cancel_cb;
	m_fields = fields;
	DataItem root = createItem(title, primary, secondary);
	GList *group_it = purple_request_fields_get_groups(m_fields);
	bool useGroupBox = group_it->next;
	debug() << "useGroupBox" << useGroupBox;
	for (; group_it; group_it = group_it->next) {
		PurpleRequestFieldGroup *group = reinterpret_cast<PurpleRequestFieldGroup*>(group_it->data);
		DataItem groupItem;
		if (useGroupBox)
			groupItem = DataItem(purple_request_field_group_get_title(group));
		GList *field_it = purple_request_field_group_get_fields(group);
		for (; field_it; field_it = field_it->next) {
			PurpleRequestField *field = reinterpret_cast<PurpleRequestField*>(field_it->data);
			debug() << field->id << purple_request_field_is_visible(field)
					<< purple_request_field_get_type(field);
			if (!purple_request_field_is_visible(field))
				continue;
			DataItem item(purple_request_field_get_id(field),
						  purple_request_field_get_label(field),
						  QVariant());
			switch (purple_request_field_get_type(field)) {
			case PURPLE_REQUEST_FIELD_STRING:
				item.setData(QString::fromUtf8(purple_request_field_string_get_default_value(field)));
				item.setProperty("multiline", purple_request_field_string_is_multiline(field));
				item.setProperty("password", bool(purple_request_field_string_is_masked(field)));
				item.setReadOnly(!purple_request_field_string_is_editable(field));
				debug() << item.name() << item.data() << item.property("password") << item.isReadOnly();
				break;
			case PURPLE_REQUEST_FIELD_INTEGER:
				item.setData(purple_request_field_int_get_default_value(field));
				item.setProperty("minValue", G_MININT);
				item.setProperty("maxValue", G_MAXINT);
				break;
			case PURPLE_REQUEST_FIELD_BOOLEAN:
				item.setData(bool(purple_request_field_bool_get_default_value(field)));
				break;
			case PURPLE_REQUEST_FIELD_CHOICE:
				{
					GList *labels = purple_request_field_choice_get_labels(field);
					QStringList alternatives;
					for (; labels; labels = labels->next)
						alternatives << QString::fromUtf8(reinterpret_cast<char*>(labels->data));
					item.setData(alternatives.value(purple_request_field_choice_get_default_value(field)));
					item.setProperty("alternatives", alternatives);
				}
				break;
			case PURPLE_REQUEST_FIELD_LIST:
				break;
			case PURPLE_REQUEST_FIELD_LABEL:
				item.setData(purple_request_field_get_label(field));
				item.setReadOnly(true);
				item.setProperty("hideTitle", true);
				break;
			case PURPLE_REQUEST_FIELD_IMAGE:
				{
					QImageReader reader;
					QByteArray data = QByteArray::fromRawData(purple_request_field_image_get_buffer(field),
															  purple_request_field_image_get_size(field));
					QBuffer buffer(&data);
					reader.setDevice(&buffer);
					QSize imageSize = reader.size();
					if (imageSize.isValid()) {
						imageSize.setWidth(imageSize.width() * purple_request_field_image_get_scale_x(field));
						imageSize.setHeight(imageSize.height() * purple_request_field_image_get_scale_y(field));
						reader.setScaledSize(imageSize);
					}
					item.setData(qVariantFromValue(reader.read()));
					item.setProperty("imageSize", qVariantFromValue(imageSize));
					item.setReadOnly(true);
				}
				break;
			case PURPLE_REQUEST_FIELD_ACCOUNT:
				break;
			case PURPLE_REQUEST_FIELD_NONE:
			default:
				continue;
			}
			item.setProperty("mandatory", purple_request_field_is_required(field));
			if (useGroupBox)
				groupItem.addSubitem(item);
			else
				root.addSubitem(item);
		}
		if (useGroupBox)
			root.addSubitem(groupItem);
	}
	createItem(root, ok_text, cancel_text);
	return;
}