Esempio n. 1
0
QStringList LXQt::Wallet::walletList( LXQt::Wallet::BackEnd bk )
{
	if( bk == LXQt::Wallet::BackEnd::internal ){

		char path[ 4096 ] ;

		lxqt_wallet_application_wallet_path( path,4096,"" ) ;

		QDir d( path ) ;

		auto l = d.entryList() ;

		l.removeOne( "." ) ;
		l.removeOne( ".." ) ;

		return l ;

	}else if( bk == LXQt::Wallet::BackEnd::kwallet ){

		#if HAS_KWALLET_SUPPORT
			return KWallet::Wallet::walletList() ;
		#else
			return QStringList() ;
		#endif

	}else if( bk == LXQt::Wallet::BackEnd::libsecret ){

		return QStringList() ;
	}else{
		return QStringList() ;
	}
}
Esempio n. 2
0
int SkIntersections::intersect(const SkDCubic& c1, const SkDCubic& c2) {
    ::intersect(c1, 0, 1, c2, 0, 1, 1, *this);
    // FIXME: pass in cached bounds from caller
    SkDRect c1Bounds, c2Bounds;
    c1Bounds.setBounds(c1);  // OPTIMIZE use setRawBounds ?
    c2Bounds.setBounds(c2);
    intersectEnd(c1, false, c2, c2Bounds, *this);
    intersectEnd(c1, true, c2, c2Bounds, *this);
    bool selfIntersect = &c1 == &c2;
    if (!selfIntersect) {
        swap();
        intersectEnd(c2, false, c1, c1Bounds, *this);
        intersectEnd(c2, true, c1, c1Bounds, *this);
        swap();
    }
    // If an end point and a second point very close to the end is returned, the second
    // point may have been detected because the approximate quads
    // intersected at the end and close to it. Verify that the second point is valid.
    if (fUsed <= 1 || coincidentUsed()) {
        return fUsed;
    }
    SkDPoint pt[2];
    if (closeStart(c1, 0, *this, pt[0]) && closeStart(c2, 1, *this, pt[1])
            && pt[0].approximatelyEqual(pt[1])) {
        removeOne(1);
    }
    if (closeEnd(c1, 0, *this, pt[0]) && closeEnd(c2, 1, *this, pt[1])
            && pt[0].approximatelyEqual(pt[1])) {
        removeOne(used() - 2);
    }
    return fUsed;
}
Esempio n. 3
0
void SkIntersections::cleanUpParallelLines(bool parallel) {
    while (fUsed > 2) {
        removeOne(1);
    }
    if (fUsed == 2 && !parallel) {
        bool startMatch = fT[0][0] == 0 || fT[1][0] == 0 || fT[1][0] == 1;
        bool endMatch = fT[0][1] == 1 || fT[1][1] == 0 || fT[1][1] == 1;
        if ((!startMatch && !endMatch) || approximately_equal(fT[0][0], fT[0][1])) {
            SkASSERT(startMatch || endMatch);
            removeOne(endMatch);
        }
    }
}
Esempio n. 4
0
void SkIntersections::cleanUpCoincidence() {
    SkASSERT(fUsed == 2);
    // both t values are good
    bool startMatch = fT[0][0] == 0 && (fT[1][0] == 0 || fT[1][0] == 1);
    bool endMatch = fT[0][1] == 1 && (fT[1][1] == 0 || fT[1][1] == 1);
    if (startMatch || endMatch) {
        removeOne(startMatch);
        return;
    }
    // either t value is good
    bool pStartMatch = fT[0][0] == 0 || fT[1][0] == 0 || fT[1][0] == 1;
    bool pEndMatch = fT[0][1] == 1 || fT[1][1] == 0 || fT[1][1] == 1;
    removeOne(pStartMatch || !pEndMatch);
}
// Remove a node from tree
void BST::remove(Entry *node) {
    if(node->left != NULL && node->right != NULL) {
        removeTwo(node, 0);
    } else {
        removeOne(node);
    }
}
Esempio n. 6
0
HistoryDialog::HistoryDialog(QWidget *parent, HistoryManager *setHistory) : QDialog(parent)
{
    HistoryManager *history = setHistory;
    if (!history)
        history = BrowserApplication::historyManager();
    setupUi(this);
    tree->setUniformRowHeights(true);
    tree->setSelectionBehavior(QAbstractItemView::SelectRows);
    tree->setTextElideMode(Qt::ElideMiddle);
    QAbstractItemModel *model = history->historyTreeModel();
    TreeProxyModel *proxyModel = new TreeProxyModel(this);
    connect(search, SIGNAL(textChanged(QString)),
            proxyModel, SLOT(setFilterFixedString(QString)));
    connect(removeButton, SIGNAL(clicked()), tree, SLOT(removeOne()));
    connect(removeAllButton, SIGNAL(clicked()), history, SLOT(clear()));
    proxyModel->setSourceModel(model);
    tree->setModel(proxyModel);
    tree->setExpanded(proxyModel->index(0, 0), true);
    tree->setAlternatingRowColors(true);
    QFontMetrics fm(font());
    int header = fm.width(QLatin1Char('m')) * 40;
    tree->header()->resizeSection(0, header);
    tree->header()->setStretchLastSection(true);
    connect(tree, SIGNAL(activated(QModelIndex)),
            this, SLOT(open()));
    tree->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(tree, SIGNAL(customContextMenuRequested(QPoint)),
            this, SLOT(customContextMenuRequested(QPoint)));
}
Esempio n. 7
0
void ImageList::clear() {
    QList<Image *>::iterator it;

    beginResetModel();
    for (Image *img : *this) {
        delete img;
        removeOne(img);
    }
    endResetModel();
}
Esempio n. 8
0
int SkIntersections::cleanUpCoincidence() {
    do {
        int last = fUsed - 1;
        for (int index = 0; index < last; ++index) {
            if (fT[0][index] == fT[0][index + 1]) {
                removeOne(index + (int) (fT[1][index] == 0 || fT[1][index] == 1));
                goto tryAgain;
            }
        }
        for (int index = 0; index < last; ++index) {
            if (fT[1][index] == fT[1][index + 1]) {
                removeOne(index + (int) (fT[0][index] == 0 || fT[0][index] == 1));
                goto tryAgain;
            }
        }
        return fUsed;
tryAgain: ;
    } while (true);
}
GraphConnectionEndpoint GraphDraw::mousedEndpoint(const QPoint &pos)
{
    auto objs = this->items(pos);
    if (_connectLineItem) objs.removeOne(_connectLineItem.get());
    if (objs.empty()) return GraphConnectionEndpoint();
    auto topObj = dynamic_cast<GraphObject *>(objs.front());
    if (topObj == nullptr) return GraphConnectionEndpoint();
    const auto point = topObj->mapFromParent(this->mapToScene(pos));
    return GraphConnectionEndpoint(topObj, topObj->isPointingToConnectable(point));
}
Esempio n. 10
0
void EditTreeView::keyPressEvent(QKeyEvent *event)
{
    if ((event->key() == Qt::Key_Delete
        || event->key() == Qt::Key_Backspace)
        && model()) {
        removeOne();
    } else {
        QAbstractItemView::keyPressEvent(event);
    }
}
// remove node that has two children
void BST::removeTwo(Entry *node, bool r_l) {
    //case 1. minRight
    if(r_l){
        Entry *minRight = node->right;
        while(minRight->left != NULL) {
            minRight = minRight->left;
        }
        node->element = minRight->element;
        removeOne(minRight);
    }
    //case 2. maxLeft
    else{
        Entry *maxLeft = node->left;
        while(maxLeft->right != NULL) {
            maxLeft = maxLeft->right;
        }
        node->element = maxLeft->element;
        removeOne(maxLeft);
    }
}
void SkIntersections::cleanUpParallelLines(bool parallel) {
    while (fUsed > 2) {
        removeOne(1);
    }
    if (fUsed == 2 && !parallel) {
        bool startMatch = fT[0][0] == 0 || zero_or_one(fT[1][0]);
        bool endMatch = fT[0][1] == 1 || zero_or_one(fT[1][1]);
        if ((!startMatch && !endMatch) || approximately_equal(fT[0][0], fT[0][1])) {
            SkASSERT(startMatch || endMatch);
            if (startMatch && endMatch && (fT[0][0] != 0 || !zero_or_one(fT[1][0]))
                    && fT[0][1] == 1 && zero_or_one(fT[1][1])) {
                removeOne(0);
            } else {
                removeOne(endMatch);
            }
        }
    }
    if (fUsed == 2) {
        fIsCoincident[0] = fIsCoincident[1] = 0x03;
    }
}
Esempio n. 13
0
void BookmarksDialog::customContextMenuRequested(const QPoint &pos)
{
    QMenu menu;
    QModelIndex index = tree->indexAt(pos);
    index = index.sibling(index.row(), 0);
    if (index.isValid() && !tree->model()->hasChildren(index)) {
        menu.addAction(tr("Open"), this, SLOT(open()));
        menu.addSeparator();
    }
    menu.addAction(tr("Delete"), tree, SLOT(removeOne()));
    menu.exec(QCursor::pos());
}
Esempio n. 14
0
void clear(const char *dir)
{
	char fnm[_MAX_PATH+1];
	struct _finddata_t finfo;
	long h;
	int dirnmlen;
	strcpy(fnm, dir);
	dirnmlen = strlen(fnm);
	if ( fnm[dirnmlen-1] != '/' && fnm[dirnmlen-1] != '\\' ) {
		strcat(fnm, "\\");
		dirnmlen++;
	}
	strcat(fnm, "*");
	h = _findfirst(fnm, &finfo);
	if (h != -1) {
		removeOne(fnm, dirnmlen, finfo);
		while ( _findnext(h, &finfo) == 0 )
			removeOne(fnm, dirnmlen, finfo);
		_findclose(h);
	}
	rmdir(dir);
}
Esempio n. 15
0
void MpvHandler::AddAudioTrack(QString f)
{
    if(f == QString())
        return;
    const QByteArray tmp = f.toUtf8();
    const char *args[] = {"audio-add", tmp.constData(), NULL};
    Command(args);
    auto old = fileInfo.tracks;
    LoadTracks();
    auto current = fileInfo.tracks;
    for(auto track : old)
        current.removeOne(track);
    Mpv::Track &track = current.first();
    ShowText(QString("%0: %1 (%2)").arg(QString::number(track.id), track.title, track.external ? "external" : track.lang));
}
Esempio n. 16
0
PassExWidget::PassExWidget(QWidget *parent)
    : QWidget(parent)
{
    setupUi(this);

    setAttribute(Qt::WA_DeleteOnClose, true);

    connect(removeOneButton, SIGNAL(clicked()), this, SLOT(removeOne()));
    connect(removeAllButton, SIGNAL(clicked()), this, SLOT(removeAll()));

    QStringList exList = ReKonfig::walletBlackList();
    Q_FOREACH(const QString & str, exList)
    {
        QListWidgetItem *item = new QListWidgetItem(str, listWidget);
        listWidget->addItem(item);
    }
Esempio n. 17
0
void MpvHandler::AddSubtitleTrack(QString f)
{
    if(f == QString())
        return;
    const QByteArray tmp = f.toUtf8();
    const char *args[] = {"sub-add", tmp.constData(), NULL};
    Command(args);
    // this could be more efficient if we saved tracks in a bst
    auto old = fileInfo.tracks; // save the current track-list
    LoadTracks(); // load the new track list
    auto current = fileInfo.tracks;
    for(auto track : old) // remove the old tracks in current
        current.removeOne(track);
    Mpv::Track &track = current.first();
    ShowText(QString("%0: %1 (%2)").arg(QString::number(track.id), track.title, track.external ? "external" : track.lang));
}
Esempio n. 18
0
Passwords::Passwords(QWidget *parent)
	: QDialog(parent)
{
    setupUi(this);
    setWindowFlags(Qt::Sheet);

	s_show_passwords = false;

	PasswordsModel *model = new PasswordsModel(this);
    m_proxyModel = new QSortFilterProxyModel(this);
    connect(search, SIGNAL(textChanged(QString)),
            m_proxyModel, SLOT(setFilterFixedString(QString)));
    connect(removeButton, SIGNAL(clicked()), PasswordsTable, SLOT(removeOne()));
    connect(removeAllButton, SIGNAL(clicked()), PasswordsTable, SLOT(removeAll()));
    connect(buttonShowPasswords, SIGNAL(clicked()), this, SLOT(showPasswords()));
    connect(buttonMaster, SIGNAL(clicked()), this, SLOT(masterPassword()));
    m_proxyModel->setSourceModel(model);
    PasswordsTable->verticalHeader()->hide();
    PasswordsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
    PasswordsTable->setModel(m_proxyModel);
    PasswordsTable->setAlternatingRowColors(true);
    PasswordsTable->setTextElideMode(Qt::ElideMiddle);
    PasswordsTable->setShowGrid(false);
    PasswordsTable->setSortingEnabled(true);
    QFont f = font();
    f.setPointSize(10);
    QFontMetrics fm(f);
    int height = fm.height() + fm.height()/3;
    PasswordsTable->verticalHeader()->setDefaultSectionSize(height);
    PasswordsTable->verticalHeader()->setMinimumSectionSize(-1);
    for (int i = 0; i < model->columnCount(); ++i){
        int header = PasswordsTable->horizontalHeader()->sectionSizeHint(i);
        switch (i) {
        case 0:
            header = fm.width(QString(40, 'X'));
            break;
        case 1:
            header = fm.width(QString(12, 'X'));
            break;
        }
        int buffer = fm.width(QLatin1String("xx"));
        header += buffer;
        PasswordsTable->horizontalHeader()->resizeSection(i, header);
    }
    PasswordsTable->horizontalHeader()->setStretchLastSection(true);

}
Esempio n. 19
0
void clear(const char *dir)
{
	char fnm[_MAX_PATH+1];
	DIR *ds;
	struct dirent *finfo;
	int dirnmlen;

	strcpy(fnm, dir);
	dirnmlen = strlen(fnm);
	if ( fnm[dirnmlen-1] != '/' ) {
		strcat(fnm, "/");
		dirnmlen++;
	}
	ds = opendir(dir);
	finfo = readdir(ds);
	while (finfo) {
		removeOne(fnm, dirnmlen, finfo->d_name);
		finfo = readdir(ds);
	}
	closedir(ds);
	rmdir(dir);
}
//Called when a client connects, subscribes, or unsubscribes.
void WebSocketSource::checkSubscriptions()
{
	while (queuedRequests.size() > 0)
	{
		VehicleProperty::Property prop = queuedRequests.front();
		removeOne(&queuedRequests,prop);
		if (contains(activeRequests,prop))
		{
			return;
		}
		activeRequests.push_back(prop);

		QVariantMap reply;

		reply["type"] = "method";
		reply["name"] = "subscribe";
		reply["property"] = prop.c_str();
		reply["transactionid"] = "d293f670-f0b3-11e1-aff1-0800200c9a66";

		lwsWriteVariant(clientsocket, reply);
	}
}
Esempio n. 21
0
ExportDirectoryDialog::ExportDirectoryDialog(QWidget *parent, const QString &dirPath) :
    QDialog(parent, Qt::WindowTitleHint|Qt::WindowSystemMenuHint),
    ui(new Ui::ExportDirectoryDialog)
{
    ui->setupUi(this);
    webView = new QWebView;
    timer = new QTimer(this);
    timer->setSingleShot(true);
    if(!dirPath.isEmpty()){
        ui->dirPathLineEdit->setText(dirPath);
        ui->browerPushButton->setEnabled(false);
    }
    ui->dirPathLineEdit->setReadOnly(true);
    ui->seperateHtmlRadioButton->setChecked(true);
    ui->seperateCssAndHtmlcheckBox->setEnabled(false);
    ui->keepDirCheckBox->setChecked(true);
    ui->exportPathWidget->setHidden(true);
    m_model = new QStandardItemModel(this);
    clearModel();
    ui->filesTreeView->setModel(m_model);
    ui->filesTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    m_conf = Configuration::getInstance();

    connect(ui->browerPushButton, SIGNAL(clicked()), this, SLOT(browerSourceDirSlot()));
    connect(ui->upPushButton, SIGNAL(clicked()), this, SLOT(moveUp()));
    connect(ui->downPushButton, SIGNAL(clicked()), this, SLOT(moveDown()));
    connect(ui->removePushButton, SIGNAL(clicked()), this, SLOT(removeOne()));
    connect(ui->suddirCheckBox, SIGNAL(clicked()), this, SLOT(fillData()));
    connect(ui->seperatePDFRadioButton, SIGNAL(toggled(bool)), ui->seperateCssAndHtmlcheckBox, SLOT(setDisabled(bool)));
    connect(ui->singlePDFRadioButton, SIGNAL(toggled(bool)), ui->seperateCssAndHtmlcheckBox, SLOT(setDisabled(bool)));
    connect(ui->keepDirCheckBox, SIGNAL(toggled(bool)), ui->exportPathWidget, SLOT(setHidden(bool)));
    connect(ui->exportPushButton, SIGNAL(clicked()), this, SLOT(exportBtnSlot()));
    connect(ui->exportPathBrowerPushButton, SIGNAL(clicked()), this, SLOT(exportPathBrowerSlot()));
    connect(this, SIGNAL(exportFinish()), this, SLOT(exportFinishSlot()));
    connect(this, SIGNAL(exportNext()), this, SLOT(exportOneByOne()));
}
Esempio n. 22
0
BookmarksDialog::BookmarksDialog(QWidget *parent, BookmarksManager *manager)
    : QDialog(parent)
{
    m_bookmarksManager = manager;
    if (!m_bookmarksManager)
        m_bookmarksManager = BrowserApplication::bookmarksManager();
    setupUi(this);

    tree->setUniformRowHeights(true);
    tree->setSelectionBehavior(QAbstractItemView::SelectRows);
    tree->setSelectionMode(QAbstractItemView::ContiguousSelection);
    tree->setTextElideMode(Qt::ElideMiddle);
    m_bookmarksModel = m_bookmarksManager->bookmarksModel();
    m_proxyModel = new TreeProxyModel(this);
    connect(search, SIGNAL(textChanged(QString)),
            m_proxyModel, SLOT(setFilterFixedString(QString)));
    connect(removeButton, SIGNAL(clicked()), tree, SLOT(removeOne()));
    m_proxyModel->setSourceModel(m_bookmarksModel);
    tree->setModel(m_proxyModel);
    tree->setDragDropMode(QAbstractItemView::InternalMove);
    tree->setExpanded(m_proxyModel->index(0, 0), true);
    tree->setAlternatingRowColors(true);
    QFontMetrics fm(font());
    int header = fm.width(QLatin1Char('m')) * 40;
    tree->header()->resizeSection(0, header);
    tree->header()->setStretchLastSection(true);
    connect(tree, SIGNAL(activated(QModelIndex)),
            this, SLOT(open()));
    tree->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(tree, SIGNAL(customContextMenuRequested(QPoint)),
            this, SLOT(customContextMenuRequested(QPoint)));
    connect(addFolderButton, SIGNAL(clicked()),
            this, SLOT(newFolder()));
    expandNodes(m_bookmarksManager->bookmarks());
    setAttribute(Qt::WA_DeleteOnClose);
}
Esempio n. 23
0
bool BDDElement::retirerAttribut(QString attribut)
{
	return removeOne(attribut);
}
Esempio n. 24
0
void Configuration::removeZone(Zone& z)
{
	removeOne(z);
}
Esempio n. 25
0
/*1. 收到come报文:
 *   { 加入用户列表,返回receiveCome报文 }
 *2. 收到receiveCome报文:
 *   { 将对方用户名和ip加入用户列表 }
 *3. 收到leave报文:
 *   { 根据对方ip从用户列表去除 }
 *4. 收到talk报文:
 *   { 更新聊天内容 }
*/
void ChatWindow::onReadyRead()
{
    QByteArray bytes;
    bytes.resize(_receiver->pendingDatagramSize());
    _receiver->readDatagram(bytes.data(),bytes.size());
    QDataStream in(&bytes,QIODevice::ReadOnly);
    quint16 size; int type;
    in>>size>>type;
    switch(type)
    {
    case _TypeCome:{
        //收到 某人进入聊天室的消息
        QString user,ip;
        in>>user>>ip;
        if(ip!=getIPv4()){
            //不把本机加入聊天室的消息再次显示到聊天文本块
            //不然就显示两次了
            updateAllContents("",QString("!report: ").append(user).append(" join"));
            addOne(user,ip);
            QByteArray response=pack_ResponseCome(_username,getIPv4());
            _sender->writeDatagram(response,response.length(),QHostAddress::Broadcast,_port);
        }
        break;
    }
    case _TypeResponseCome:{
        //收到 某人响应你的进入 的消息(因为你进入聊天室时会广播消息给所有人)
        QString user,ip;
        in>>user>>ip;
        int N=static_cast<int>(_ipList.size());
        int index=-1;
        for(int i=0;i<N;i++)
        {
            if(QString(_ipList[i])==ip)
            {
                index=i;
                break;
            }
        }
        if(index==-1)
            addOne(user,ip);
        break;
    }
    case _TypeLeave:{
        //收到某人离开聊天室的消息
        QString user,ip;
        in>>user>>ip;
        if(user!="")
            removeOne(user,ip);
        break;
    }
    case _TypeTalk:{
        //收到某人说了什么话的消息
        QString user,str;
        in>>user>>str;
        if(user!=_username)
            updateAllContents(user,str);
        break;
    }
    }
    //递归接收消息
    if(_receiver->pendingDatagramSize()>0)
        onReadyRead();
}
rpl::producer<SparseIdsSlice> SearchController::simpleIdsSlice(
		PeerId peerId,
		MsgId aroundId,
		const Query &query,
		int limitBefore,
		int limitAfter) {
	Expects(peerId != 0);
	Expects(IsServerMsgId(aroundId) || (aroundId == 0));
	Expects((aroundId != 0)
		|| (limitBefore == 0 && limitAfter == 0));
	Expects((query.peerId == peerId)
		|| (query.migratedPeerId == peerId));

	auto it = _cache.find(query);
	if (it == _cache.end()) {
		return [=](auto) { return rpl::lifetime(); };
	}

	auto listData = (peerId == query.peerId)
		? &it->second->peerData
		: &*it->second->migratedData;
	return [=](auto consumer) {
		auto lifetime = rpl::lifetime();
		auto builder = lifetime.make_state<SparseIdsSliceBuilder>(
			aroundId,
			limitBefore,
			limitAfter);
		builder->insufficientAround(
		) | rpl::start_with_next([=](
				const SparseIdsSliceBuilder::AroundData &data) {
			requestMore(data, query, listData);
		}, lifetime);

		auto pushNextSnapshot = [=] {
			consumer.put_next(builder->snapshot());
		};

		listData->list.sliceUpdated(
		) | rpl::filter([=](const SliceUpdate &update) {
			return builder->applyUpdate(update);
		}) | rpl::start_with_next(pushNextSnapshot, lifetime);

		Auth().data().itemRemoved(
		) | rpl::filter([=](not_null<const HistoryItem*> item) {
			return (item->history()->peer->id == peerId);
		}) | rpl::filter([=](not_null<const HistoryItem*> item) {
			return builder->removeOne(item->id);
		}) | rpl::start_with_next(pushNextSnapshot, lifetime);

		Auth().data().historyCleared(
		) | rpl::filter([=](not_null<const History*> history) {
			return (history->peer->id == peerId);
		}) | rpl::filter([=] {
			return builder->removeAll();
		}) | rpl::start_with_next(pushNextSnapshot, lifetime);

		using Result = Storage::SparseIdsListResult;
		listData->list.query(Storage::SparseIdsListQuery(
			aroundId,
			limitBefore,
			limitAfter
		)) | rpl::filter([=](const Result &result) {
			return builder->applyInitial(result);
		}) | rpl::start_with_next_done(
			pushNextSnapshot,
			[=] { builder->checkInsufficient(); },
			lifetime);

		return lifetime;
	};
}
rpl::producer<SparseIdsSlice> SharedMediaViewer(
		Storage::SharedMediaKey key,
		int limitBefore,
		int limitAfter) {
	Expects(IsServerMsgId(key.messageId) || (key.messageId == 0));
	Expects((key.messageId != 0) || (limitBefore == 0 && limitAfter == 0));

	return [=](auto consumer) {
		auto lifetime = rpl::lifetime();
		auto builder = lifetime.make_state<SparseIdsSliceBuilder>(
			key.messageId,
			limitBefore,
			limitAfter);
		auto requestMediaAround = [
			peer = App::peer(key.peerId),
			type = key.type
		](const SparseIdsSliceBuilder::AroundData &data) {
			Auth().api().requestSharedMedia(
				peer,
				type,
				data.aroundId,
				data.direction);
		};
		builder->insufficientAround(
		) | rpl::start_with_next(requestMediaAround, lifetime);

		auto pushNextSnapshot = [=] {
			consumer.put_next(builder->snapshot());
		};

		using SliceUpdate = Storage::SharedMediaSliceUpdate;
		Auth().storage().sharedMediaSliceUpdated(
		) | rpl::filter([=](const SliceUpdate &update) {
			return (update.peerId == key.peerId)
				&& (update.type == key.type);
		}) | rpl::filter([=](const SliceUpdate &update) {
			return builder->applyUpdate(update.data);
		}) | rpl::start_with_next(pushNextSnapshot, lifetime);

		using OneRemoved = Storage::SharedMediaRemoveOne;
		Auth().storage().sharedMediaOneRemoved(
		) | rpl::filter([=](const OneRemoved &update) {
			return (update.peerId == key.peerId)
				&& update.types.test(key.type);
		}) | rpl::filter([=](const OneRemoved &update) {
			return builder->removeOne(update.messageId);
		}) | rpl::start_with_next(pushNextSnapshot, lifetime);

		using AllRemoved = Storage::SharedMediaRemoveAll;
		Auth().storage().sharedMediaAllRemoved(
		) | rpl::filter([=](const AllRemoved &update) {
			return (update.peerId == key.peerId);
		}) | rpl::filter([=] {
			return builder->removeAll();
		}) | rpl::start_with_next(pushNextSnapshot, lifetime);

		using InvalidateBottom = Storage::SharedMediaInvalidateBottom;
		Auth().storage().sharedMediaBottomInvalidated(
		) | rpl::filter([=](const InvalidateBottom &update) {
			return (update.peerId == key.peerId);
		}) | rpl::filter([=] {
			return builder->invalidateBottom();
		}) | rpl::start_with_next(pushNextSnapshot, lifetime);

		using Result = Storage::SharedMediaResult;
		Auth().storage().query(Storage::SharedMediaQuery(
			key,
			limitBefore,
			limitAfter
		)) | rpl::filter([=](const Result &result) {
			return builder->applyInitial(result);
		}) | rpl::start_with_next_done(
			pushNextSnapshot,
			[=] { builder->checkInsufficient(); },
			lifetime);

		return lifetime;
	};
}
Esempio n. 28
0
bool GuiCombat::CheckUserInput(JButton key)
{
    if (NONE == cursor_pos)
        return false;
    DamagerDamaged* oldActive = active;
    
    int x,y;
    if(observer->getInput()->GetLeftClickCoordinates(x, y))
    {
        // determine if OK button was clicked on
        if (ok.width)
        {
            if (didClickOnButton(ok, x, y))
            {
                cursor_pos = OK;
            }
        }
        // position selected card
        if (BLK == cursor_pos)
        {
            DamagerDamaged* selectedCard = closest<True> (activeAtk->blockers, NULL, static_cast<float> (x), static_cast<float> (y));
            // find the index into the vector where the current selected card is.
            int c1 = 0, c2 = 0;
            int i = 0;
            for ( vector<DamagerDamaged*>::iterator it = activeAtk->blockers.begin(); it != activeAtk->blockers.end(); ++it)
            {
                if ( *it == selectedCard )
                    c2 = i;
                else if ( *it == active)
                    c1 = i;
                i++;
            }
            // simulate pressing the "Left/Right D-Pad" control c1 - c2 times
            if ( c1 > c2 ) // card selected is to the left of the current active card
            {
                for (int x = 0; x < c1 - c2; x++)
                    shiftLeft();
            }
            else if ( c1 < c2 )
            {
                for (int x = 0; x < c2 - c1; x++)
                    shiftRight( oldActive );
            }
        }
    }
    
    switch (key)
    {
        case JGE_BTN_OK:
            if (BLK == cursor_pos)
            {
                if (ORDER == step)
                    observer->cardClick(active->card); //  { activeAtk->card->raiseBlockerRankOrder(active->card); }
                else
                {
                    signed damage = activeAtk->card->stepPower(step);
                    for (vector<DamagerDamaged*>::iterator it = activeAtk->blockers.begin(); *it != active; ++it)
                        damage -= (*it)->sumDamages();
                    signed now = active->sumDamages();
                    damage -= now;
                    if (damage > 0)
                        addOne(active, step);
                    else if (activeAtk->card->has(Constants::DEATHTOUCH))
                        for (; now >= 1; --now)
                            removeOne(active, step);
                    else
                        for (now -= active->card->toughness; now >= 0; --now)
                            removeOne(active, step);
                }
            }
            else if (ATK == cursor_pos)
            {
                active = activeAtk->blockers.front();
                active->zoom = kZoom_level3;
                cursor_pos = BLK;
            }
            else if (OK == cursor_pos)
            {
                clickOK();
            }
            break;
        case JGE_BTN_CANCEL:
            if (BLK == cursor_pos)
            {
                oldActive->zoom = kZoom_level2;
                active = activeAtk;
                cursor_pos = ATK;
            }
            return true;
        case JGE_BTN_LEFT:
            shiftLeft();
            break;
            
        case JGE_BTN_RIGHT:
            shiftRight( oldActive );
            break;
            
        case JGE_BTN_DOWN:
            if (ORDER == step || BLK != cursor_pos || active->sumDamages() <= 0)
                break;
            removeOne(active, step);
            break;
        case JGE_BTN_UP:
            if (ORDER == step || BLK != cursor_pos)
                break;
            addOne(active, step);
            break;
        case JGE_BTN_PRI:
            active = activeAtk = NULL;
            cursor_pos = OK;
            break;
        case JGE_BTN_NEXT:
            if (!options[Options::REVERSETRIGGERS].number)
                return false;
            active = activeAtk = NULL;
            cursor_pos = OK;
            break;
        case JGE_BTN_PREV:
            if (options[Options::REVERSETRIGGERS].number)
                return false;
            active = activeAtk = NULL;
            cursor_pos = OK;
            break;
        default:
            ;
    }
    if (oldActive != active)
    {
        if (oldActive && oldActive != activeAtk)
            oldActive->zoom = kZoom_level2;
        if (active)
            active->zoom = kZoom_level3;
        if (ATK == cursor_pos)
            remaskBlkViews(dynamic_cast<AttackerDamaged*> (oldActive), static_cast<AttackerDamaged*> (active));
    }
    if (OK == cursor_pos)
        ok.zoom = 1.5;
    else
        ok.zoom = kZoom_none;
    return true;
}