Beispiel #1
0
void VInfoRequest::addItem(DataType type, DataItem &group, const QVariant &data) const
{
	DataItem item(names()->at(type), titles()->at(type), data);
	if (type == BDate && data.canConvert<QDate>()
			&& data.value<QDate>().year() == 1900)
		item.setProperty("hideYear", true);
	group.addSubitem(item);
}
DataItem QuickContactInfo::filterItems(const DataItem &item, bool readOnly)
{
	DataItem result = item;
	result.setSubitems(QList<DataItem>());
	foreach (const DataItem &subitem, item.subitems()) {
		if (subitem.isAllowedModifySubitems()) {
			if (!readOnly || subitem.hasSubitems())
				result.addSubitem(subitem);
		} else if (subitem.hasSubitems()) {
			filterItemsHelper(subitem, result, readOnly);
		} else {
			if (readOnly && isItemEmpty(subitem))
				continue;
			result.addSubitem(subitem);
		}
	}
	return result;
}
Beispiel #3
0
void MainWindow::onSaveButton()
{
	DataItem items;
	if (avatarWidget) {
		DataItem avatarItem = avatarWidget->item();
		items.addSubitem(avatarItem);
	}
	for (int i = 0; i < ui.detailsStackedWidget->count(); ++i) {
		QWidget *widget = ui.detailsStackedWidget->widget(i);
		Q_ASSERT(qobject_cast<QScrollArea*>(widget));
		QScrollArea *scrollArea = static_cast<QScrollArea*>(widget);
		AbstractDataForm *dataFrom = qobject_cast<AbstractDataForm*>(scrollArea->widget());
		if (!dataFrom)
			continue;
		if (dataFrom->objectName() == "General") {
			foreach (const DataItem &item, dataFrom->item().subitems())
				items.addSubitem(item);
		} else {
void QuickContactInfo::filterItemsHelper(const DataItem &item, DataItem &result, bool readOnly)
{
	Q_ASSERT(item.hasSubitems());
	DataItem group = item;
	group.setSubitems(QList<DataItem>());
	foreach (const DataItem &subitem, item.subitems()) {
		if (subitem.isAllowedModifySubitems()) {
			if (!readOnly || subitem.hasSubitems())
				result.addSubitem(subitem);
		} else if (subitem.hasSubitems()) {
			filterItemsHelper(subitem, result, readOnly);
		} else {
			if (readOnly && isItemEmpty(subitem))
				continue;
			group.addSubitem(subitem);
		}
	}
	if (group.hasSubitems())
		result.addSubitem(group);
}
Beispiel #5
0
DataItem VInfoRequest::createDataItem() const
{
	DataItem item;
	// General page
	{
		DataItem general(QT_TRANSLATE_NOOP("ContactInfo", "General"));
		{
			DataItem person(QT_TRANSLATE_NOOP("ContactInfo", "Person"));
			addItem(NickName, person, "nickname");
			addItem(FirstName, person, "first_name");
			addItem(LastName, person, "last_name");
			addItem(Sex, person, genders()->value(m_data.value("sex", 0).toInt()).toString());
			QString bdate = m_data.value("bdate").toString();
			QDate birthday;
			if (bdate.count('.') == 2)
				birthday = QDate::fromString(bdate, "d.M.yyyy");
			else if (bdate.count('.') == 1)
				birthday = QDate::fromString(bdate, "d.M");
			addItem(BDate, person, birthday);
			general.addSubitem(person);
		}
		{
			DataItem address(QT_TRANSLATE_NOOP("ContactInfo", "Home address"));
			addItem(Country, address, "country");
			addItem(City, address, "city");
			addItem(HomePhone, address, "home_phone");
			addItem(MobilePhone, address, "mobile_phone");
			general.addSubitem(address);
		}
		{
			DataItem education(QT_TRANSLATE_NOOP("ContactInfo", "Education"));
			addItem(University, education, "university_name");
			addItem(Faculty, education, "faculty_name");
			addItem(Graduation, education, "graduation");
			general.addSubitem(education);
		}
		item.addSubitem(general);
	}
	return item;
}
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;
}