예제 #1
0
void set::unserialize(core::coll_helper _coll)
{
	set_id(_coll.get_value_as_int("id"));
	set_name(_coll.get_value_as_string("name"));

	if (_coll.is_value_exist("icon"))
	{
		core::istream* icon_stream = _coll.get_value_as_stream("icon");
		if (icon_stream)
		{
			int32_t icon_size = icon_stream->size();
			if (icon_size > 0)
			{
				load_icon((char*)icon_stream->read(icon_size), icon_size);
			}
		}
	}

	core::iarray* sticks = _coll.get_value_as_array("stickers");

	stickers_.reserve(sticks->size());

	for (int32_t i = 0; i < sticks->size(); i++)
	{
		core::coll_helper coll_sticker(sticks->get_at(i)->get_as_collection(), false);

		auto inserted_sticker = std::make_shared<sticker>();
		inserted_sticker->unserialize(coll_sticker);
		inserted_sticker->set_set_id(get_id());
		stickers_.push_back(inserted_sticker);
	}
}
void search_contacts_response::serialize(core::coll_helper _root_coll) const
{
    serialize_contacts(_root_coll);
    serialize_chats(_root_coll);

    _root_coll.set_value_as_bool("finish", finish_);
    _root_coll.set_value_as_string("next_tag", next_tag_);
}
예제 #3
0
    void qt_gui_settings::unserialize(core::coll_helper _collection)
    {
        core::iarray* values_array = _collection.get_value_as_array("values");
        if (!values_array)
        {
            assert(false);
            return;
        }

        for (int i = 0; i < values_array->size(); ++i)
        {
            const core::ivalue* val = values_array->get_at(i);

            gui_coll_helper coll_val(val->get_as_collection(), false);

            core::istream* idata = coll_val.get_value_as_stream("value");

            int len = idata->size();

            set_value_simple_data(coll_val.get_value_as_string("name"), (const char*) idata->read(len), len, false);
        }

        emit received();
        setIsLoaded(true);
    }
예제 #4
0
void my_info::serialize(core::coll_helper _coll)
{
    _coll.set_value_as_string("aimId", aimId_);
    _coll.set_value_as_string("displayId", displayId_);
    _coll.set_value_as_string("friendly", friendlyName_);
    _coll.set_value_as_string("state", state_);
    _coll.set_value_as_string("userType", userType_);
    _coll.set_value_as_string("attachedPhoneNumber", phoneNumber_);
    _coll.set_value_as_uint("globalFlags", flags_);
    _coll.set_value_as_string("largeIconId", largeIconId_);
}
void search_contacts_response::serialize_contacts(core::coll_helper _root_coll) const
{
    if (contacts_data_.empty())
        return;

    ifptr<iarray> array(_root_coll->create_array());
    array->reserve((int32_t)contacts_data_.size());
    for (const auto& c : contacts_data_)
    {
        coll_helper coll(_root_coll->create_collection(), true);

        coll.set_value_as_string("aimid", c.aimid_);
        coll.set_value_as_string("stamp", c.stamp_);
        coll.set_value_as_string("type", c.type_);
        if (c.score_ >= 0)
        {
            coll.set_value_as_int("score", c.score_);
        }
        coll.set_value_as_string("first_name", c.first_name_);
        coll.set_value_as_string("last_name", c.last_name_);
        coll.set_value_as_string("nick_name", c.nick_name_);
        coll.set_value_as_string("city", c.city_);
        coll.set_value_as_string("state", c.state_);
        coll.set_value_as_string("country", c.country_);
        coll.set_value_as_string("gender", c.gender_);
        if (c.birthdate_.year_ >= 0 && c.birthdate_.month_ >= 0 && c.birthdate_.day_ >= 0)
        {
            coll_helper b(_root_coll->create_collection(), true);
            b.set_value_as_int("year", c.birthdate_.year_);
            b.set_value_as_int("month", c.birthdate_.month_);
            b.set_value_as_int("day", c.birthdate_.day_);
            coll.set_value_as_collection("birthdate", b.get());
        }
        coll.set_value_as_string("about", c.about_);
        coll.set_value_as_int("mutual_count", c.mutual_friend_count_);

        ifptr<ivalue> val(_root_coll->create_value());
        val->set_as_collection(coll.get());
        array->push_back(val.get());
    }

    _root_coll.set_value_as_array("data", array.get());
}
예제 #6
0
void cache::set_sticker_data(core::coll_helper _coll)
{
	const qint32 set_id = _coll.get_value_as_int("set_id");

	for (uint32_t i = 0; i < sets_.size(); i++)
	{
		auto &set = sets_[i];

		if (set->get_id() == set_id)
		{
			const qint32 sticker_id = _coll.get_value_as_int("sticker_id");

			const auto load_data =
				[&_coll, &set, sticker_id](const char *_id, const core::sticker_size _size)
				{
					if (!_coll->is_value_exist(_id))
					{
						return;
					}

					auto data = _coll.get_value_as_stream(_id);
					const auto data_size = data->size();

					QImage image;
					if (image.loadFromData(data->read(data_size), data_size))
					{
						set->set_sticker_image(sticker_id, _size, std::move(image));
					}
				};

			load_data("data/small", core::sticker_size::small);
			load_data("data/medium", core::sticker_size::medium);
			load_data("data/large", core::sticker_size::large);

			set->reset_flag_requested(sticker_id, core::sticker_size::small);
			set->reset_flag_requested(sticker_id, core::sticker_size::medium);
			set->reset_flag_requested(sticker_id, core::sticker_size::large);

			break;
		}
	}
}
void core::wim::search_contacts_response::serialize_chats(core::coll_helper _root_coll) const
{
    if (chats_data_.empty())
        return;

    ifptr<iarray> array(_root_coll->create_array());
    array->reserve((int32_t)chats_data_.size());

    for (const auto& c : chats_data_)
    {
        coll_helper coll(_root_coll->create_collection(), true);
        c.serialize(coll);

        ifptr<ivalue> val(_root_coll->create_value());
        val->set_as_collection(coll.get());
        array->push_back(val.get());
    }

    _root_coll.set_value_as_array("chats", array.get());
}
예제 #8
0
void gui_settings::serialize(core::coll_helper _collection) const
{
    ifptr<iarray> values_array(_collection->create_array(), true);

    for (auto iter = values_.begin(); iter != values_.end(); ++iter)
    {
        coll_helper coll_value(_collection->create_collection(), true);

        ifptr<istream> value_data_stream(_collection->create_stream(), true);
        auto bs_value_data = iter->second;
        int32_t len = bs_value_data.available();
        value_data_stream->write((const uint8_t*) bs_value_data.read(len), len);

        coll_value.set_value_as_string("name", iter->first);
        coll_value.set_value_as_stream("value", value_data_stream.get());

        ifptr<ivalue> ival(_collection->create_value(), true);
        ival->set_as_collection(coll_value.get());

        values_array->push_back(ival.get());
    }
    _collection.set_value_as_array("values", values_array.get());
}
예제 #9
0
 void proxy_settings::serialize(core::coll_helper _collection) const
 {
     _collection.set_value_as_int("settings_proxy_type", proxy_type_);
     _collection.set_value_as_string("settings_proxy_server", core::tools::from_utf16(proxy_server_));
     _collection.set_value_as_int("settings_proxy_port", proxy_port_);
     _collection.set_value_as_string("settings_proxy_username", core::tools::from_utf16(login_));
     _collection.set_value_as_string("settings_proxy_password", core::tools::from_utf16(password_));
     _collection.set_value_as_bool("settings_proxy_need_auth", need_auth_);
 }
예제 #10
0
void cache::unserialize(const core::coll_helper &_coll)
{
	core::iarray* sets = _coll.get_value_as_array("sets");
	if (!sets)
		return;

	sets_.reserve(sets->size());

	for (int32_t i = 0; i < sets->size(); i++)
	{
		core::coll_helper coll_set(sets->get_at(i)->get_as_collection(), false);

		auto inserted_set = std::make_shared<set>();

		inserted_set->unserialize(coll_set);

		sets_.push_back(inserted_set);
	}
}
예제 #11
0
    void qt_theme_settings::unserialize(core::coll_helper _collection)
    {
        core::iarray* values_array = _collection.get_value_as_array("values");
        if (!values_array)
        {
            assert(false);
            return;
        }
        
        QString tint_color;
        QByteArray imageDataArray;
        QByteArray thumbDataArray;
        QString contactsThemes;
        int theme_id = -1;
        bool tile = false;

        for (int i = 0; i < values_array->size(); ++i)
        {
            const core::ivalue* val = values_array->get_at(i);
            
            gui_coll_helper coll_val(val->get_as_collection(), false);
            std::string name = coll_val.get_value_as_string("name");
            core::istream* idata = coll_val.get_value_as_stream("value");
            int len = idata->size();
            
            const char* data = (char *)idata->read(len);
            
            if (name == "id")
            {
                if (len == 4)
                {
                    theme_id = *(data) | *(data+1) << 8 | *(data+2) << 16 | *(data+3) << 24;
                }
            }
            else if (name == "image")
            {
                imageDataArray = QByteArray(data, len);
            }
            else if (name == "thumb")
            {
                thumbDataArray = QByteArray(data, len);
            }
            else if (name == "tint_color")
            {
                tint_color = QString(std::string(data, len).c_str());
            }
            else if (name == "contacts_themes")
            {
                contactsThemes = QString(std::string(data, len).c_str());
            }
            else if (name == "tile")
            {
                if (len == 1)
                {
                    tile = *(data) & 0xFF;
                }
            }
        }
        
        if (theme_id != -1)
        {
            __INFO("themes", "unserialized default theme " << theme_id << "(tint_color " << tint_color << ")");
            default_theme_ = std::make_shared<themes::theme>(theme_id, tint_color, imageDataArray, thumbDataArray, tile);
        }
        if (contactsThemes.length() > 1)
        {
             __INFO("themes", "contactsThemes " << contactsThemes);
            QStringList list = contactsThemes.split(",");
            for (int i = 0; i < list.count(); ++i)
            {
                QString item = list[i];
                QStringList contactTheme = item.split(":");
                if (contactTheme.count() == 2)
                {
                    QString aimId = contactTheme[0];
                    int themeId = contactTheme[1].toInt();
                    if (themeId >= 0)
                    {
                        contactsThemes_[aimId] = themeId;
                        themesIdToLoad_.push_back(themeId);
                    }
                }
            }
        }
    }
예제 #12
0
	ChatEventInfoSptr ChatEventInfo::Make(const core::coll_helper &info, const bool isOutgoing, const QString &myAimid)
	{
		assert(!myAimid.isEmpty());

		const auto type = info.get_value_as_enum<chat_event_type>("type");

		ChatEventInfoSptr eventInfo(new ChatEventInfo(
			type, isOutgoing, myAimid
		));

        const auto isGeneric = (type == core::chat_event_type::generic);
        if (isGeneric)
        {
            assert(!info.is_value_exist("sender_friendly"));

            eventInfo->setGenericText(
                info.get<QString>("generic")
            );

            return eventInfo;
        }

		const auto isBuddyReg = (type == core::chat_event_type::buddy_reg);
		const auto isBuddyFound = (type == core::chat_event_type::buddy_found);
		const auto isBirthday = (type == core::chat_event_type::birthday);
		if (isBuddyReg || isBuddyFound || isBirthday)
		{
			assert(!info.is_value_exist("sender_friendly"));
			return eventInfo;
		}

		eventInfo->setSenderFriendly	(
			info.get<QString>("sender_friendly")
		);

		const auto isAddedToBuddyList = (type == core::chat_event_type::added_to_buddy_list);
        const auto isAvatarModified = (type == core::chat_event_type::avatar_modified);
		if (isAddedToBuddyList || isAvatarModified)
		{
			return eventInfo;
		}

		const auto isChatNameModified = (type == core::chat_event_type::chat_name_modified);
		if (isChatNameModified)
		{
			const auto newChatName = info.get<QString>("chat/new_name");
			assert(!newChatName.isEmpty());

			eventInfo->setNewName(newChatName);

			return eventInfo;
		}

        const auto isChatDescriptionModified = (type == core::chat_event_type::chat_description_modified);
        if (isChatDescriptionModified)
        {
            const auto newDescription = info.get<QString>("chat/new_description");

            eventInfo->setNewDescription(newDescription);

            return eventInfo;
        }

		const auto isMchatAddMembers = (type == core::chat_event_type::mchat_add_members);
		const auto isMchatInvite = (type == core::chat_event_type::mchat_invite);
		const auto isMchatLeave = (type == core::chat_event_type::mchat_leave);
		const auto isMchatDelMembers = (type == core::chat_event_type::mchat_del_members);
		const auto isMchatKicked = (type == core::chat_event_type::mchat_kicked);
		const auto hasMchatMembers = (isMchatAddMembers || isMchatInvite || isMchatLeave || isMchatDelMembers || isMchatKicked);
		if (hasMchatMembers)
		{
			const auto membersArray = info.get_value_as_array("mchat/members");
			assert(membersArray);

			eventInfo->setMchatMembers(*membersArray);

			return eventInfo;
		}

		assert(!"unexpected event type");
		return eventInfo;
	}
예제 #13
0
void not_sent_message::serialize(core::coll_helper& _coll, const time_t _offset) const
{
	get_message()->serialize(_coll.get(), _offset);
}
예제 #14
0
void sticker::unserialize(core::coll_helper _coll)
{
	id_ = _coll.get_value_as_int("id");
}