コード例 #1
0
ファイル: personitem.cpp プロジェクト: AlanHJ/TogetherHappy
void PersonItem::setUid(QString id)
{
    ItemEditor::setUid(id);

    // load sql
    QString er;
    SqlDB *db = Sql::instance()->open(er);
    if (db)
    {
        QString sql = "SELECT * FROM "+ MatchData().objectName() +
                " WHERE uid = '" + uid + "'";
        int rlt;
        QList<QObject *> objs = db->executeQuery(sql,
                                                 MatchData().metaObject(),
                                                 rlt, er);
        db->close();
        if (objs.size() >= 1)
        {
            MatchData *md = qobject_cast<MatchData *>(objs.first());
            if (md)
            {
                memoname = md->getEditname();
            }
        }
        auto it = objs.begin();
        while (it != objs.end())
        {
            QObject *obj = *it;
            delete obj;
            obj = nullptr;
            ++it;
        }
    }
}
コード例 #2
0
ファイル: friendinfo.cpp プロジェクト: AlanHJ/TogetherHappy
void FriendInfo::updateMemoName()
{
    QString er;
    SqlDB *db = Sql::instance()->open(er);
    if (db)
    {
        QString sql = "SELECT * FROM "+ MatchData().objectName() +
                " WHERE uid = '" + data->getUid() + "'";
        int rlt;
        QList<QObject *> objs = db->executeQuery(sql,
                                                 MatchData().metaObject(),
                                                  rlt, er);
        db->close();
        if (objs.size() >= 1)
        {
            MatchData *md = qobject_cast<MatchData *>(objs.first());
            if (md)
            {
                editLbl->setText(md->getEditname());
            }
        }
        auto it = objs.begin();
        while (it != objs.end())
        {
            QObject *obj = *it;
            delete obj;
            obj = nullptr;
            ++it;
        }
    }
}
コード例 #3
0
ファイル: regexp.cpp プロジェクト: jedisct1/rubinius
 static Object* get_match_data(STATE, OnigRegion *region, String* string, Regexp* regexp, int pos) {
   MatchData* md = state->new_object<MatchData>(G(matchdata));
   md->source(state, string->string_dup(state));
   md->regexp(state, regexp);
   Tuple* tup = Tuple::from(state, 2,
                            Fixnum::from(region->beg[0] + pos),
                            Fixnum::from(region->end[0] + pos));
   md->full(state, tup);
   md->region(state, _md_region_to_tuple(state, region, pos));
   return md;
 }
コード例 #4
0
ファイル: test_regexp.hpp プロジェクト: seejee/rubinius
  void test_match_region_without_matches() {
    String *pat = String::create(state, "d");
    Regexp* re = Regexp::create(state);
    re->initialize(state, pat, Fixnum::from(0));

    String *input = String::create(state, "abc");

    Fixnum* start = Fixnum::from(0);
    Fixnum* end =   Fixnum::from(3);
    Object* forward = cTrue;

    MatchData* matches = (MatchData*)re->match_region(state, input, start, end, forward);
    TS_ASSERT(matches->nil_p());
  }
コード例 #5
0
ファイル: test_regexp.hpp プロジェクト: seejee/rubinius
  void test_match_start() {
    String *pat = String::create(state, ".");
    Regexp* re = Regexp::create(state);
    re->initialize(state, pat, Fixnum::from(0));

    String *input = String::create(state, "abc");

    Fixnum* start = Fixnum::from(1);

    MatchData* matches = (MatchData*)re->match_start(state, input, start);
    TS_ASSERT(!matches->nil_p());
    TS_ASSERT_EQUALS(matches->region()->num_fields(), 0);
    TS_ASSERT_EQUALS(as<Integer>(matches->full()->at(state, 0))->to_native(), 1);
    TS_ASSERT_EQUALS(as<Integer>(matches->full()->at(state, 1))->to_native(), 2);
  }
コード例 #6
0
ファイル: regexp.cpp プロジェクト: thiagopradi/rubinius
  Object* Regexp::last_match(STATE, Arguments& args, CallFrame* call_frame) {
    MatchData* match = try_as<MatchData>(call_frame->scope->last_match(state));
    if(!match) return Qnil;

    if(args.total() == 0) return match;
    if(args.total() > 1) return Primitives::failure();

    native_int which = as<Fixnum>(args.get_argument(0))->to_native();

    if(which == 0) {
      return match->matched_string(state);
    } else {
      return match->nth_capture(state, which - 1);
    }
  }
コード例 #7
0
ファイル: test_regexp.hpp プロジェクト: marnen/rubinius
  void test_match_region() {
    String *pat = String::create(state, ".");
    Regexp* re = Regexp::create(state);
    re->initialize(state, pat, Fixnum::from(0), Qnil);

    String *input = String::create(state, "abc");

    Fixnum* start = Fixnum::from(0);
    Fixnum* end =   Fixnum::from(3);
    Object* forward = Qtrue;

    MatchData* matches = (MatchData*)re->match_region(state, input, start, end, forward);
    TS_ASSERT(!matches->nil_p());
    TS_ASSERT_EQUALS(matches->region()->num_fields(), 0U);
    TS_ASSERT_EQUALS(as<Integer>(matches->full()->at(state, 0))->to_native(), 0);
    TS_ASSERT_EQUALS(as<Integer>(matches->full()->at(state, 1))->to_native(), 1);
  }
コード例 #8
0
ファイル: test_regexp.hpp プロジェクト: Azzurrio/rubinius
  void test_match_region_with_backward_captures() {
    String *pat = String::create(state, ".(.)");
    Regexp* re = Regexp::create(state);
    re->initialize(state, pat, Fixnum::from(0));

    String *input = String::create(state, "abc");

    Fixnum* start = Fixnum::from(0);
    Fixnum* end =   Fixnum::from(3);
    Object* forward = cFalse;

    MatchData* matches = re->match_region(state, input, start, end, forward);
    TS_ASSERT(!matches->nil_p());
    TS_ASSERT_EQUALS(as<Integer>(matches->full()->at(state, 0))->to_native(), 1);
    TS_ASSERT_EQUALS(as<Integer>(matches->full()->at(state, 1))->to_native(), 3);

    TS_ASSERT_EQUALS(matches->region()->num_fields(), 1);
    TS_ASSERT_EQUALS(as<Integer>(as<Tuple>(matches->region()->at(state, 0))->at(state, 0))->to_native(), 2);
    TS_ASSERT_EQUALS(as<Integer>(as<Tuple>(matches->region()->at(state, 0))->at(state, 1))->to_native(), 3);
  }
コード例 #9
0
ファイル: regexp.cpp プロジェクト: thiagopradi/rubinius
  static Object* get_match_data(STATE, OnigRegion *region, String* string, Regexp* regexp, int pos) {
    MatchData* md = state->new_object<MatchData>(G(matchdata));
    md->source(state, string->string_dup(state));
    md->regexp(state, regexp);
    // Unsure if the first region (the full match) can be less than 0 (meaning
    // the match was length length but did still match). We have to support
    // that for the > 0 case, so we'll do the same for 0.
    //

    if(region->beg[0] < 0) {
      Tuple* tup = Tuple::from(state, 2,
                               Fixnum::from(region->beg[0]),
                               Fixnum::from(region->end[0]));
      md->full(state, tup);
    } else {
      Tuple* tup = Tuple::from(state, 2,
                               Fixnum::from(region->beg[0] + pos),
                               Fixnum::from(region->end[0] + pos));
      md->full(state, tup);
    }
    md->region(state, _md_region_to_tuple(state, region, pos));
    return md;
  }
コード例 #10
0
ファイル: personitem.cpp プロジェクト: AlanHJ/TogetherHappy
PersonItem::PersonItem(BroadcastRecever *recever,
                       QTreeWidgetItem *it,
                       SelfTabWidget *t, QWidget *parent)
    : ItemEditor(parent)
{
    jsondata = nullptr;
    item = nullptr;
    this->recever = nullptr;
    chat = nullptr;
    shakeabled = true;
    rejectShake = false;
    memoname.clear();
    item = it;
    tab = t;
    showMaxMin(ConfigureData::getInstance()->IsTrue("item_show"));


    GsoapCallOperation *sender = GsoapCallOperation::Sender();
    GsoapMessageInstance *msgrecever = GsoapMessageInstance::GetInstance();

    connect(msgrecever, &GsoapMessageInstance::signalGetResource,
            this, [=] (QString srcUid, QString type, QString res) {
        if (srcUid != jsondata->getUid())
            return;
        if (type == "photo")
        {
            if (QFile::exists(res))
            {
                emoji->setMoiveRes(res,
                                   QSize(emojiSize - 10, emojiSize - 10));

            }
        }
        else if (type =="image")
        {
            if (QFile::exists(res))
            {
                image = res;
            }
        }
    });

    jsondata = new BroadcastJsonData(this);

    connect(jsondata, &BroadcastJsonData::versionChanged,
            this, [=] () {
        if (!jsondata->getTcpenabled())
            return;
        tab->updateMsg(jsondata->getVersion(),
                       jsondata->getVersioninfo(),
                       jsondata->getGsoapip());
    });

    connect(jsondata, &BroadcastJsonData::nicknameChanged,
            this, [=] () {
        showMemoName();
    });
    connect(jsondata, &BroadcastJsonData::statusChanged,
            this, [=] () {
        if (itemType != realityBody)
            return;
        int id = jsondata->getStatus();
        if (id == 3)
        {
            emit ItemClose(jsondata->getUid());
            // left close this;
            delete item;
            item = nullptr;
        }
        else
        {
            other->setText(StatusStr[jsondata->getStatus()]);
        }
    });
    connect(jsondata, &BroadcastJsonData::feelChanged,
            this, [=] () {
        QFontMetrics fm(cn("微软雅黑"));
        introduce->setText(fm.elidedText(jsondata->getFeel(), Qt::ElideMiddle, 200));
    });
    connect(jsondata, &BroadcastJsonData::photoChanged,
            this, [=] () {
        // gsoap get photo
        QString file1 = QFileInfo(emoji->ImagePath()).fileName();
        QString file2 = QFileInfo(jsondata->getPhoto()).fileName();
        if (file1 == file2)
            return;
        emit sender->signalGetResource(jsondata->getUid(),
                                       jsondata->getGsoapip(),
                                       "photo", jsondata->getPhoto());
    });
    connect(jsondata, &BroadcastJsonData::imageChanged,
            this, [=] () {
        // gsoap get image
        QString file1 = QFileInfo(image).fileName();
        QString file2 = QFileInfo(jsondata->getImage()).fileName();
        if (file1 == file2)
            return;
        emit sender->signalGetResource(jsondata->getUid(),
                                       jsondata->getGsoapip(),
                                       "image", jsondata->getImage());
    });
    BroadcastReceverJson *jsonrecever = qobject_cast<BroadcastReceverJson*>(recever);
    if (jsonrecever)
    {
        this->recever = jsonrecever;
        connect(this->recever, &BroadcastReceverJson::jsonMsg,
                this, [=] (QString uid, QJsonObject json) {
            if (uid != this->uid)
                return;
            jsondata->parserJson(json);
        });
    }

    connect(this, &PersonItem::handlePaser, this, [=] (QJsonObject json) {
        jsondata->parserJson(json);
    });

    connect(emoji, &EmojiLabel::enterEmoji, this, [=] () {
        CardUI *ui = new CardUI();
        ui->setPicture(image);
        ui->setFirstTxt(jsondata->getNickname());
        ui->setSecondTxt(memoname);
        ui->setVersion(jsondata->getVersion());
        ui->setThirdTxt(jsondata->getGsoapip());
        ui->setIntroduceTxt(jsondata->getFeel());
        ui->showAnimation();
//        ui->activateWindow();
        ui->move(mapToGlobal(this->pos()).x() - 360, QCursor::pos().y() - 50);
        connect(emoji, &EmojiLabel::leaveEmoji, ui, [=] () {
//            disconnect(emoji, &EmojiLabel::leaveEmoji, 0, 0);
            ui->hideAnimation();
        });
    });
    menu = new SelfMenu(this);
    connect(menu->addAction(cns("备注名")), &QAction::triggered, this, [=] () {
        bool ok;
        QString name = InputBox::GetInput(cns("输入备注名"), &ok);
        if (!ok)
            return;
        if (name.trimmed().isEmpty())
        {
            MsgBox::ShowMsgBox(cn("提示"), cn("不能为空"), cn("确定"));
            return;
        }
        if (name.trimmed().length() >= 18)
        {
            MsgBox::ShowMsgBox(cn("错误"), cn("昵称长度18限制"), cn("确定"));
            return;
        }
        QString er;
        SqlDB *db = Sql::instance()->open(er);
        if (!db)
        {
            MsgBox::ShowMsgBox(cn("失败"), cn("数据库错误\n") + er, cn("确定"));
            return;
        }
        QString sql = "SELECT * FROM "+ MatchData().objectName() +
                " WHERE uid = '" + uid + "'";
        int rlt;
        QList<QObject *> objs = db->executeQuery(sql,
                                                 MatchData().metaObject(),
                                                 rlt, er);
        if (rlt != 0)
        {
            MsgBox::ShowMsgBox(cn("失败"), cn("数据库读取错误\n") + er, cn("确定"));
            return;
        }
        bool b  = true;
        if (objs.isEmpty())
        {
            // insert
            MatchData md;
            md.setUid(uid);
            md.setEditname(name);
            md.setNickname(jsondata->getNickname());
            md.setEdittime(QDateTime::currentDateTime().toTime_t());
            md.setIp(jsondata->getGsoapip());
            md.setModifycounts(1);
            b = db->insert(&md, er);
        }
        else
        {
            // update
            MatchData *md = qobject_cast<MatchData *>(objs.first());
            if (md)
            {
                md->setEditname(name);
                md->setNickname(jsondata->getNickname());
                md->setEdittime(QDateTime::currentDateTime().toTime_t());
                md->setIp(jsondata->getGsoapip());
                md->setModifycounts(md->getModifycounts() + 1);
                b = db->update(md, "uid", er);
            }
            else
            {
                b = false;
                er = cn("无法修改,读取错误!!!");
            }

            auto it = objs.begin();
            while (it != objs.end())
            {
                QObject *obj = *it;
                delete obj;
                obj = nullptr;
                ++it;
            }
        }
        db->close();
        if (!b)
        {
            MsgBox::ShowMsgBox(cn("修改失败"), er, cn("确定"));
        }
        else
        {
            memoname = name;
        }
        showMemoName();
    });
}