Пример #1
0
/*! \brief Save the positions of Peer Widgets
 *
 * Save the positions of all Peer Widgets to the settings.
 */
void XletSwitchBoard::savePositions() const
{
    // qDebug() << Q_FUNC_INFO << m_peerhash.count();
    QSettings * settings = b_engine->getSettings();
    settings->beginGroup("layout");
    QHashIterator<QString, PeerItem *> it(m_peerhash);
    while (it.hasNext()) {
        it.next();
        const QString userid = it.key();
        PeerItem *peeritem = it.value();
        if (peeritem->getWidget()) {
            settings->setValue(userid,
                               m_layout->getItemPosition(peeritem->getWidget()));
        } else {
            settings->remove(userid);
        }
    }

    settings->beginWriteArray("externalphone");
    int i, index = 0;
    for (i=0;i<m_layout->count();i++) {
        QLayoutItem *item = m_layout->itemAt(i);
        if ((item) && (item->widget()) &&
            ((item->widget()->inherits("ExternalPhonePeerWidget")) ||
             (item->widget()->inherits("DetailedExternalPhonePeerWidget")))) {
            BasePeerWidget *w = static_cast<BasePeerWidget *>(item->widget());
            settings->setArrayIndex(index++);
            settings->setValue("position", m_layout->getItemPosition(w));
            settings->setValue("name", w->name());
            settings->setValue("number", w->number());
        }
    }
    settings->endArray();
    settings->endGroup();
}
Пример #2
0
/*! \brief Receives drop events
 * 
 * This method recieve drop events. It is currently used to 
 * move PeerWidgets arount :)
 *
 * \sa dragEnterEvent()
 */
void XletSwitchBoard::dropEvent(QDropEvent *event)
{
    // qDebug() << Q_FUNC_INFO;
    if (event->mimeData()->hasFormat(USERID_MIMETYPE)) {
        QString userid = event->mimeData()->data(USERID_MIMETYPE);
        if (m_peerhash.contains(userid)) {
            PeerItem *peeritem = m_peerhash[userid];
            BasePeerWidget *peerwidget = peeritem->getWidget();
            if (peerwidget) {
                m_layout->setItemPosition(peerwidget, m_layout->getPosInGrid(event->pos()));
            } else {
                peerwidget = addPeerWidget(peeritem, m_layout->getPosInGrid(event->pos()));
            }
            updateGeometry();
            event->acceptProposedAction();
            savePositions();
            update();
        }
    } else if (event->mimeData()->hasFormat(NUMBER_MIMETYPE)) {
        QString number = event->mimeData()->data(NUMBER_MIMETYPE);
        BasePeerWidget *w = getExternalPhonePeerWidget(number);
        if (w) {
            m_layout->setItemPosition(w, m_layout->getPosInGrid(event->pos()));
            updateGeometry();
            event->acceptProposedAction();
            savePositions();
            update();
        }
    }
}
Пример #3
0
bool SearchPanel::isShown(const QString &xuserid) const
{
    PeerItem *peer = m_peerhash.value(xuserid, NULL);
    if (peer) {
        if (BasePeerWidget *widget = peer->getWidget()) {
            return widget->isVisible();
        }
    }
    return false;
}
Пример #4
0
/*! \brief remove a PeerItem
 *
 * Find the peer and remove it from the list
 * and the widget.
 *
 * \sa updatePeer
 * \sa removePeers
 */
void XletSwitchBoard::removePeer(const QString &userid)
{
    // qDebug() << Q_FUNC_INFO << userid;
    if (m_peerhash.contains(userid)) {
        PeerItem *peeritem = m_peerhash.value(userid);
        BasePeerWidget *peerwidget = peeritem->getWidget();
        m_layout->removeWidget(peerwidget);
        peerwidget->deleteLater();
        delete m_peerhash.take(userid);
        update();
    }
}
Пример #5
0
/*! \brief remove all peers
 *
 * remove all peers and widget.
 *
 * \sa removePeer
 */
void XletSwitchBoard::removePeers(void)
{
    // qDebug() << Q_FUNC_INFO;
    QHashIterator<QString, PeerItem *> peeriter(m_peerhash);
    while (peeriter.hasNext()) {
        peeriter.next();
        PeerItem *peeritem = peeriter.value();
        //PeerWidget * peerwidget = peeritem->getWidget();
        BasePeerWidget *peerwidget = peeritem->getWidget();
        if (peerwidget != NULL) {
            m_layout->removeWidget(peerwidget);
            // this disconnect() step takes time, whether explicitly or implicitly,
            // so we should be careful to avoid too much connect's (anyway)
            disconnect(peerwidget, SIGNAL(removeFromPanel()),
                       this, SLOT(removePeerFromLayout()) );
            peerwidget->deleteLater();
        }
        delete peeritem;
    }
    m_peerhash.clear();
    update();
}
Пример #6
0
/*! \brief remove the peer from the layout
 *
 * the peer is moved to position (-1, -1) so it
 * wont be displayed anymore
 *
 * \sa dropEvent()
 */
void XletSwitchBoard::removePeerFromLayout()
{
    const QString userid = sender()->property("userid" ).toString();
    // qDebug() << Q_FUNC_INFO << userid << m_peerhash.keys();
    if (m_peerhash.contains(userid)) {
        PeerItem *peeritem = m_peerhash[userid];
        BasePeerWidget *peerwidget = peeritem->getWidget();
        m_layout->removeWidget(peerwidget);

        m_layout->setItemPosition(peerwidget, QPoint(-1, -1));
        //savePositions();
        // this disconnect() step takes time, whether explicitly or implicitly,
        // so we should be careful to avoid too much connect's (anyway)
        disconnect(peerwidget, SIGNAL(removeFromPanel()),
                   this, SLOT(removePeerFromLayout()));
        peerwidget->deleteLater();
        peeritem->setWidget(NULL);
        update();
    } else {
        m_layout->removeWidget(static_cast<QWidget *>(sender()));
        sender()->deleteLater();
    }
}
Пример #7
0
/*! \brief update the list of Persons displayed
 */
void SearchPanel::updateDisplay()
{
    if (m_live_reload_enabled == false) {
        return;
    }

    // max number of peers displayed on the search panel
    unsigned maxdisplay = maxDisplay();
    // number of columns (0 = auto)
    unsigned ncolumns = 0;
    ncolumns = m_scrollarea->width() / (PeerWidget::max_width + 2 * SearchPanel::peer_spacing);
    // Prevent arithmetic exception
    if (ncolumns == 0) {
        ncolumns = 1;
    }

    // first hide/delete everyonedisplayed
    QHashIterator<QString, PeerItem *> i(m_peerhash);
    while (i.hasNext()) {
        i.next();
        PeerItem *peeritem = i.value();
        BasePeerWidget *peerwidget = peeritem->getWidget();
        if ((peerwidget != NULL) &&
            (m_peerlayout->indexOf(peerwidget) > -1)) {
            m_peerlayout->removeWidget(peerwidget);
            peerwidget->hide();
            peeritem->setWidget(NULL);
            peerwidget->deleteLater();
        }
    }

    // then display all users whose name match the search pattern
    unsigned naff = 0;
    i.toFront();
    while (i.hasNext()) {
        i.next();
        PeerItem * peeritem = i.value();
        BasePeerWidget * peerwidget = peeritem->getWidget();
        const UserInfo * userinfo = peeritem->userinfo();
        if (userinfo == NULL)
            continue;
        if (peeritem->matchPattern(m_searchpattern) && (naff < maxdisplay)) {
            if (peerwidget == NULL) {
                peerwidget = new PeerWidget(userinfo);
                if (! userinfo->agentid().isEmpty()) {
                    peerwidget->updateAgentConfig(userinfo->xagentid());
                    peerwidget->updateAgentStatus(userinfo->xagentid());
                }
                foreach (const QString &xphoneid, userinfo->phonelist()) {
                    peerwidget->updatePhoneConfig(xphoneid);
                    peerwidget->updatePhoneStatus(xphoneid);
                }
                peeritem->setWidget(peerwidget);
                peeritem->updateDisplayedStatus();
                peeritem->updateDisplayedName();

                m_peerlayout->addWidget(peerwidget,
                                        naff / ncolumns,
                                        naff % ncolumns);

                naff++;
                peerwidget->show();
            }
        }
    }