Ejemplo n.º 1
0
void BuddyEditor::widgetRemoved(QWidget *widget)
{
    QList<QWidget*> child_list = widget->findChildren<QWidget*>();
    child_list.prepend(widget);

    ConnectionSet remove_set;
    foreach (QWidget *w, child_list) {
        const ConnectionList &cl = connectionList();
        foreach (Connection *con, cl) {
            if (con->widget(EndPoint::Source) == w || con->widget(EndPoint::Target) == w)
                remove_set.insert(con, con);
        }
    }

    if (!remove_set.isEmpty()) {
        undoStack()->beginMacro(tr("Remove buddies"));
        foreach (Connection *con, remove_set) {
            setSelected(con, false);
            con->update();
            QWidget *source = con->widget(EndPoint::Source);
            if (qobject_cast<QLabel*>(source) == 0) {
                qDebug("BuddyConnection::widgetRemoved(): not a label");
            } else {
                ResetPropertyCommand *command = new ResetPropertyCommand(formWindow());
                command->init(source, QLatin1String(buddyPropertyC));
                undoStack()->push(command);
            }
            delete takeConnection(con);
        }
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	int listenfd, c;
	struct sockaddr_in  servaddr;

	int connfd;
	struct sockaddr_in  cliaddr;

	char *pidfile_path;
	int given_pid;

	pid_t childpid;
	socklen_t clilen;

	given_pid = 0;
	pidfile_path = (char)'\0';

	while ((c = getopt(argc, argv, "p:")) != EOF) {
		switch(c) {
			case 'p':
			    pidfile_path = optarg;
			    given_pid = 1;
			    break;
		}
	}

	daemonInit(message(MSG_DAEMON_NAME), SYSLOG_FACILITY);

	listenfd = socket(AF_INET, SOCK_STREAM, 0);

	memset((void *) &servaddr, '\0', (size_t) sizeof(servaddr));

	servaddr.sin_family = AF_INET;
	servaddr.sin_addr.s_addr = htonl(0x7F000001);
	/*servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");*/
	servaddr.sin_port = htons(SERVER_LISTEN_PORT);

	if (bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0) {
		say(message(MSG_ERROR_BIND), strerror(errno));
		exit(errno);
	}

	if (listen(listenfd, MAX_LISTENQ) < 0) {
		say(message(MSG_ERROR_LISTEN), strerror(errno));
		exit(errno);
	}

	say("%s", message(MSG_DAEMON_VER));

	tv_rcv = (struct timeval *) calloc(1, sizeof(struct timeval));
	tv_snd = (struct timeval *) calloc(1, sizeof(struct timeval));

	memset(tv_rcv, '\0', sizeof(struct timeval));
	memset(tv_snd, '\0', sizeof(struct timeval));

	tv_rcv -> tv_sec = 30;
	tv_rcv -> tv_usec = 0;

	tv_snd -> tv_sec = 30;
	tv_snd -> tv_usec = 0;

	signal(SIGCHLD, sigChild);
	signal(SIGPIPE, sigPipe);

	if(given_pid) {
		FILE *file = fopen(pidfile_path, "w");
		fprintf(file, "%ld", (long)getpid());
		fclose(file);
	}

	for (;;) {
		memset((void *) &cliaddr, '\0', sizeof(cliaddr));
		clilen = (socklen_t) sizeof(cliaddr);

		if ((connfd = accept(listenfd, (struct sockaddr *) &cliaddr, &clilen)) < 0) {
			if (errno == EINTR) {
				continue;
			} else {
				say(message(MSG_ERROR_ACCEPT), strerror(errno));
				exit(errno);
			}
		}

		setsockopt(connfd, SOL_SOCKET, SO_RCVTIMEO, tv_rcv, sizeof(struct timeval));
		setsockopt(connfd, SOL_SOCKET, SO_SNDTIMEO, tv_snd, sizeof(struct timeval));

		memset(client_ip, '\0', MAX_MSG_SIZE);

		inet_ntop(AF_INET, &cliaddr.sin_addr, client_ip, MAX_MSG_SIZE);

		if ( ( childpid = fork() ) == 0) {
			char *nmb = calloc(50, sizeof(char));

			close(listenfd);

			childpid = getpid();

			sprintf(nmb, "%d", childpid);

			say(message(MSG_START_CHILD), nmb);

			takeConnection(connfd);
            free(nmb);

			exit(0);
		}

		close(connfd);
	}

	closelog();

	return (NO_ERROR);
}
Ejemplo n.º 3
0
void BuddyEditor::updateBackground()
{
    if (m_updating || background() == 0)
        return;
    ConnectionEdit::updateBackground();

    m_updating = true;
    QList<Connection *> newList;
    const LabelList label_list = background()->findChildren<QLabel*>();
    foreach (QLabel *label, label_list) {
        const QString buddy_name = buddy(label, m_formWindow->core());
        if (buddy_name.isEmpty())
            continue;

        const QList<QWidget *> targets = background()->findChildren<QWidget*>(buddy_name);
        if (targets.isEmpty())
            continue;

        QWidget *target = 0;

        QListIterator<QWidget *> it(targets);
        while (it.hasNext()) {
            QWidget *widget = it.next();
            if (widget && !widget->isHidden()) {
                target = widget;
                break;
            }
        }

        if (target == 0)
            continue;

        Connection *con = new Connection(this);
        con->setEndPoint(EndPoint::Source, label, widgetRect(label).center());
        con->setEndPoint(EndPoint::Target, target, widgetRect(target).center());
        newList.append(con);
    }

    QList<Connection *> toRemove;

    const int c = connectionCount();
    for (int i = 0; i < c; i++) {
        Connection *con = connection(i);
        QObject *source = con->object(EndPoint::Source);
        QObject *target = con->object(EndPoint::Target);
        bool found = false;
        QListIterator<Connection *> it(newList);
        while (it.hasNext()) {
            Connection *newConn = it.next();
            if (newConn->object(EndPoint::Source) == source && newConn->object(EndPoint::Target) == target) {
                found = true;
                break;
            }
        }
        if (found == false)
            toRemove.append(con);
    }
    if (!toRemove.isEmpty()) {
        DeleteConnectionsCommand command(this, toRemove);
        command.redo();
        foreach (Connection *con, toRemove)
            delete takeConnection(con);
    }

    QListIterator<Connection *> it(newList);
    while (it.hasNext()) {
        Connection *newConn = it.next();

        bool found = false;
        const int c = connectionCount();
        for (int i = 0; i < c; i++) {
            Connection *con = connection(i);
            if (con->object(EndPoint::Source) == newConn->object(EndPoint::Source) &&
                            con->object(EndPoint::Target) == newConn->object(EndPoint::Target)) {
                found = true;
                break;
            }
        }
        if (found == false) {
            AddConnectionCommand command(this, newConn);
            command.redo();
        } else {
            delete newConn;
        }
    }
    m_updating = false;
}