Exemple #1
0
void lmcMessaging::updateGroup(GroupOp op, QVariant value1, QVariant value2) {
	switch(op) {
	case GO_New:
		groupList.append(Group(value1.toString(), value2.toString()));
		break;
	case GO_Rename:
		for(int index = 0; index < groupList.count(); index++) {
			if(groupList[index].id.compare(value1.toString()) == 0) {
				groupList[index].name = value2.toString();
				break;
			}
		}
		break;
	case GO_Move:
		for(int index = 0; index < groupList.count(); index++) {
			if(groupList[index].id.compare(value1.toString()) == 0) {
				groupList.move(index, value2.toInt());
				break;
			}
		}
		break;
	case GO_Delete:
		for(int index = 0; index < groupList.count(); index++) {
			if(groupList[index].id.compare(value1.toString()) == 0) {
				groupList.removeAt(index);
				break;
			}
		}
		break;
	default:
		break;
	}

	saveGroups();
}
Exemple #2
0
void lmcMessaging::updateUser(MessageType type, QString szUserId, QString szUserData) {
	User* pUser = getUser(&szUserId);
	if(!pUser)
		return;

	XmlMessage updateMsg;	
	switch(type) {
	case MT_Status:
		if(pUser->status.compare(szUserData) != 0) {
			QString oldStatus = pUser->status;
			pUser->status = szUserData;

			int statusIndex = Helper::statusIndexFromCode(oldStatus);
			if(statusType[statusIndex] == StatusTypeOffline) // old status is offline
				emit messageReceived(MT_Announce, &szUserId, NULL);
				
			updateMsg.addData(XN_STATUS, pUser->status);
			emit messageReceived(MT_Status, &szUserId, &updateMsg);

			statusIndex = Helper::statusIndexFromCode(pUser->status);
			if(statusType[statusIndex] == StatusTypeOffline) { // new status is offline
				// Send a dummy xml message. A non null xml message implies that the
				// user is only in offline status, and not actually offline.
				XmlMessage xmlMessage;
				emit messageReceived(MT_Depart, &szUserId, &xmlMessage);
			}
		}
		break;
	case MT_UserName:
		if(pUser->name.compare(szUserData) != 0) {
			pUser->name = szUserData;
			updateMsg.addData(XN_NAME, pUser->name);
			emit messageReceived(MT_UserName, &szUserId, &updateMsg);
		}
		break;
	case MT_Note:
		if(pUser->note.compare(szUserData) != 0) {
			pUser->note = szUserData;
			updateMsg.addData(XN_NOTE, pUser->note);
			emit messageReceived(MT_Note, &szUserId, &updateMsg);
		}
		break;
	case MT_Group:
		pUser->group = szUserData;
		userGroupMap.insert(pUser->id, pUser->group);
		saveGroups();
		break;
    case MT_Avatar:
        pUser->avatarPath = szUserData;
        break;
	default:
		break;
	}
}
Exemple #3
0
void lmcMessaging::stop(void) {
    sendBroadcast(MT_Depart, NULL);
	pNetwork->stop();

	pSettings->setValue(IDS_STATUS, localUser->status);
	pSettings->setValue(IDS_AVATAR, localUser->avatar);

	saveGroups();

	lmcTrace::write("Messaging stopped");
}
Exemple #4
0
bool saveScriptStates(const char *filename)
{
	WzConfig ini(filename);
	if (!ini.isWritable())
	{
		debug(LOG_ERROR, "Savegame file not writable: %s", filename);
		return false;
	}
	for (int i = 0; i < scripts.size(); ++i)
	{
		QScriptEngine *engine = scripts.at(i);
		QScriptValueIterator it(engine->globalObject());
		ini.beginGroup(QString("globals_") + QString::number(i));
		// we save 'scriptName' and 'me' implicitly
		while (it.hasNext())
		{
			it.next();
			if (!internalNamespace.contains(it.name()) && !it.value().isFunction())
			{
				ini.setValue(it.name(), it.value().toVariant());
			}
		}
		ini.endGroup();
		ini.beginGroup(QString("groups_") + QString::number(i));
		// we have to save 'scriptName' and 'me' explicitly
		ini.setValue("me", engine->globalObject().property("me").toInt32());
		ini.setValue("scriptName", engine->globalObject().property("scriptName").toString());
		saveGroups(ini, engine);
		ini.endGroup();
	}
	for (int i = 0; i < timers.size(); ++i)
	{
		timerNode node = timers.at(i);
		ini.beginGroup(QString("triggers_") + QString::number(i));
		// we have to save 'scriptName' and 'me' explicitly
		ini.setValue("me", node.player);
		ini.setValue("scriptName", node.engine->globalObject().property("scriptName").toString());
		ini.setValue("function", node.function);
		if (!node.baseobj >= 0)
		{
			ini.setValue("object", QVariant(node.baseobj));
		}
		ini.setValue("frame", node.frameTime);
		ini.setValue("type", (int)node.type);
		ini.setValue("ms", node.ms);
		ini.endGroup();
	}
	return true;
}
void XletSwitchBoard::mouseReleaseEvent(QMouseEvent *)
{
    // qDebug() << Q_FUNC_INFO;
    if (m_trace_box) {
        QRect rect = QRect(m_first_corner, m_second_corner).normalized();

        QRect gridRect = m_layout->getGridRect(rect);
        if ((gridRect.top() != gridRect.bottom()) &&
           (gridRect.right() != gridRect.left())) {
            QString name;
            QDialog dialog;
            dialog.setWindowTitle(tr("New group"));
            QVBoxLayout *layout = new QVBoxLayout(&dialog);
            layout->addWidget(new QLabel(tr("Please enter a name for the new group"), &dialog));
            QLineEdit *lineedit = new QLineEdit(&dialog);
            layout->addWidget(lineedit);
            layout->addWidget(new QLabel(tr("Please choose a color for the new group"), &dialog));
            QtColorPicker *colorpicker = new QtColorPicker(&dialog);
            colorpicker->setStandardColors();
            colorpicker->setCurrentColor(QColor(63, 63, 255));
            layout->addWidget(colorpicker);
            QDialogButtonBox *buttonbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
                                                               Qt::Horizontal, &dialog);
            layout->addWidget(buttonbox);
            connect(buttonbox, SIGNAL(accepted()),
                    &dialog, SLOT(accept()) );
            connect(buttonbox, SIGNAL(rejected()),
                    &dialog, SLOT(reject()) );
            dialog.exec();
            if (dialog.result() == QDialog::Accepted)
                name = lineedit->text();
            if (!name.isEmpty()) {
                Group *group = new Group(this);
                group->setRect(gridRect);
                group->setName(name);
                group->setColor(colorpicker->currentColor());
                m_group_list.append(group);
                saveGroups();
            }
        }
        m_trace_box = false;
        update();
    }
    if (m_group_to_resize) {
        unsetCursor();
        m_group_to_resize = NULL;
    }
}
/*! 
 * Save the positions in the grid of the peer widgets.
 */
XletSwitchBoard::~XletSwitchBoard()
{
    savePositions();
    saveGroups();
    removePeers();
}