bool MsgEdit::send() { unsigned i; Contact *contact = getContacts()->contact(m_msg->contact()); string client_str = m_msg->client(); bool bSent = false; void *data = NULL; if (contact){ if (client_str.empty()){ Client *c = client(data, true, false, m_msg->contact()); if (c){ m_msg->setClient(c->dataName(data).c_str()); bSent = c->send(m_msg, data); }else{ data = NULL; for (i = 0; i < getContacts()->nClients(); i++){ Client *client = getContacts()->getClient(i); if (client->send(m_msg, NULL)){ bSent = true; break; } } } }else{ ClientDataIterator it(contact->clientData); while ((data = ++it) != NULL){ if (it.client()->dataName(data) == client_str){ if (it.client()->send(m_msg, data)) bSent = true; break; } } } } if (bSent){ if (data){ time_t now; time(&now); ((clientData*)data)->LastSend = now; } }else{ if (m_msg){ delete m_msg; m_msg = NULL; } stopSend(); CToolButton *btnSend = NULL; Command cmd; cmd->id = CmdSend; cmd->param = this; Event e(EventCommandWidget, cmd); btnSend = (CToolButton*)(e.process()); QWidget *msgWidget = btnSend; if (msgWidget == NULL) msgWidget = this; BalloonMsg::message(i18n("No such client for send message"), msgWidget); return false; } return true; }
bool MsgEdit::sendMessage(Message *msg) { if (m_retry.msg){ delete m_retry.msg; m_retry.msg = NULL; } if (m_msg){ delete msg; Event e(EventMessageCancel, m_msg); if (e.process()) m_msg = NULL; stopSend(false); return false; } bool bClose = true; if (CorePlugin::m_plugin->getContainerMode()){ bClose = false; Command cmd; cmd->id = CmdSendClose; cmd->param = this; Event e(EventCommandWidget, cmd); QToolButton *btnClose = (QToolButton*)(e.process()); if (btnClose) bClose = btnClose->isOn(); } CorePlugin::m_plugin->setCloseSend(bClose); Contact *contact = getContacts()->contact(m_userWnd->id()); if (contact){ TranslitUserData *data = (TranslitUserData*)(contact->getUserData(CorePlugin::m_plugin->translit_data_id)); if (data && data->Translit) msg->setFlags(msg->getFlags() | MESSAGE_TRANSLIT); } msg->setFlags(msg->getFlags() | m_flags); m_flags = 0; if (m_userWnd->m_list){ multiply = m_userWnd->m_list->selected; if (multiply.empty()) return false; multiply_it = multiply.begin(); msg->setContact(*multiply_it); msg->setClient(NULL); ++multiply_it; if (multiply_it != multiply.end()) msg->setFlags(msg->getFlags() | MESSAGE_MULTIPLY); } editLostFocus(); Command cmd; cmd->id = CmdSend; cmd->text = I18N_NOOP("Cancel"); cmd->icon = "cancel"; cmd->flags = BTN_PICT; cmd->param = this; Event eCmd(EventCommandChange, cmd); eCmd.process(); m_msg = msg; return send(); }
bool MsgEdit::sendMessage(Message *msg) { if (m_retry.msg){ delete m_retry.msg; m_retry.msg = NULL; } if (m_msg){ delete msg; Event e(EventMessageCancel, m_msg); if (e.process()) m_msg = NULL; stopSend(false); return false; } bool bClose = true; if (CorePlugin::m_plugin->getContainerMode()){ bClose = false; Command cmd; cmd->id = CmdSendClose; cmd->param = this; Event e(EventCommandWidget, cmd); QToolButton *btnClose = (QToolButton*)(e.process()); if (btnClose) bClose = btnClose->isOn(); } CorePlugin::m_plugin->setCloseSend(bClose); Contact *contact = getContacts()->contact(m_userWnd->id()); if (contact){ TranslitUserData *data = (TranslitUserData*)(contact->getUserData(CorePlugin::m_plugin->translit_data_id)); if (data && data->Translit.bValue) msg->setFlags(msg->getFlags() | MESSAGE_TRANSLIT); } msg->setFlags(msg->getFlags() | m_flags); m_flags = 0; if (m_userWnd->m_list){ multiply = m_userWnd->m_list->selected; if (multiply.empty()) return false; multiply_it = multiply.begin(); msg->setContact(*multiply_it); msg->setClient(NULL); ++multiply_it; if (multiply_it != multiply.end()) msg->setFlags(msg->getFlags() | MESSAGE_MULTIPLY); }else if (!m_resource.isEmpty()){ void *data = NULL; Client *c = client(data, true, false, msg->contact(), true); if (c){ string resources = c->resources(data); while (!resources.empty()){ string res = getToken(resources, ';'); getToken(res, ','); if (m_resource == QString::fromUtf8(res.c_str())){ msg->setResource(m_resource); break; } } } } editLostFocus(); Command cmd; cmd->id = CmdSend; cmd->text = I18N_NOOP("Cancel"); cmd->icon = "cancel"; cmd->flags = BTN_PICT; cmd->param = this; Event eCmd(EventCommandChange, cmd); eCmd.process(); m_msg = msg; return send(); }
void FileUI::sendsuccess() { stopSend(); }
FileUI::FileUI(QWidget *parent) : QWidget(parent) { mData = new PrivData(); // 开始创建界面UI // 先创建接收界面 QFrame *frame1 = new QFrame(this); frame1->setWindowIconText(cns("接收")); QVBoxLayout *v1 = new QVBoxLayout(); QLabel *l1 = new QLabel(cns("接收总进度"), frame1); QLabel *l2 = new QLabel(cns("当前文件进度"), frame1); QProgressBar *bar1 = new QProgressBar(frame1); bar1->setMaximum(100); bar1->setMinimum(0); bar1->setValue(0); connect(this, SIGNAL(signalRecvTotalProgress(int)), bar1, SLOT(setValue(int))); QProgressBar *bar2 = new QProgressBar(frame1); bar2->setMaximum(100); bar2->setMinimum(0); bar2->setValue(0); connect(this, SIGNAL(signalRecvCurrentProgress(int)), bar2, SLOT(setValue(int))); mRecvMsg = new QLabel(cns("接收消息..."), frame1); QFont f; f.setPixelSize(10); mRecvMsg->setFont(f); QPushButton *pb1 = new QPushButton(cns("停止接收"), frame1); connect(pb1, SIGNAL(clicked()), this, SLOT(stopRecv())); QPushButton *pb4 = new QPushButton(cns("打开文件夹"), frame1); connect(pb4, SIGNAL(clicked()), this, SLOT(openPath())); mRecvList = new QListWidget(frame1); QHBoxLayout *rhb1 = new QHBoxLayout(); QHBoxLayout *rhb2 = new QHBoxLayout(); rhb1->addWidget(l1, 0, Qt::AlignCenter); rhb1->addWidget(bar1, 0, Qt::AlignCenter); rhb2->addWidget(l2, 0, Qt::AlignCenter); rhb2->addWidget(bar2, 0, Qt::AlignCenter); v1->addLayout(rhb1); v1->addLayout(rhb2); v1->addWidget(mRecvMsg, 0, Qt::AlignLeft | Qt::AlignTop); v1->addWidget(mRecvList); QHBoxLayout *h2 = new QHBoxLayout(); h2->addWidget(pb1); h2->addWidget(pb4); v1->addLayout(h2); frame1->setLayout(v1); QStatusBar *status1 = new QStatusBar(frame1); mRecvLabel = new QLabel(cns("接收速度:0MB/s"), frame1); status1->addPermanentWidget(mRecvLabel); frame1->layout()->addWidget(status1); // 再创建发送界面 QFrame *frame2 = new QFrame(this); frame2->setWindowIconText(cns("发送")); QLabel *l4 = new QLabel(cns("发送总进度"), frame2); QLabel *l5 = new QLabel(cns("当前文件进度"), frame2); QProgressBar *bar3 = new QProgressBar(frame2); bar3->setMaximum(100); bar3->setMinimum(0); bar3->setValue(0); connect(this, SIGNAL(signalSendTotalProgress(int)), bar3, SLOT(setValue(int))); QProgressBar *bar4 = new QProgressBar(frame2); bar4->setMaximum(100); bar4->setMinimum(0); bar4->setValue(0); connect(this, SIGNAL(signalSendCurrentProgress(int)), bar4, SLOT(setValue(int))); mSendMsg = new QLabel(cns("发送消息..."), frame2); mSendMsg->setFont(f); QPushButton *pb2 = new QPushButton(cns("开始发送"), frame2); connect(pb2, SIGNAL(clicked()), this, SLOT(askSend())); QPushButton *pb3 = new QPushButton(cns("停止发送"), frame2); connect(pb3, SIGNAL(clicked()), this, SLOT(stopSend())); mClear = new QPushButton(cns("清空列表"), frame2); connect(mClear, SIGNAL(clicked()), this, SLOT(clearList())); mList = new QListWidget(frame2); connect(mList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(itemDoubleClicked(QListWidgetItem*))); QVBoxLayout *v2 = new QVBoxLayout(); QHBoxLayout *shb1 = new QHBoxLayout(); QHBoxLayout *shb2 = new QHBoxLayout(); shb1->addWidget(l4, 0, Qt::AlignCenter); shb1->addWidget(bar3, 0, Qt::AlignCenter); shb2->addWidget(l5, 0, Qt::AlignCenter); shb2->addWidget(bar4, 0, Qt::AlignCenter); v2->addLayout(shb1); v2->addLayout(shb2); v2->addWidget(mSendMsg, 0, Qt::AlignLeft | Qt::AlignTop); QHBoxLayout *h1 = new QHBoxLayout(); h1->addWidget(pb2); h1->addWidget(pb3); h1->addWidget(mClear); v2->addWidget(mList); v2->addLayout(h1); frame2->setLayout(v2); QStatusBar *status2 = new QStatusBar(frame2); mSendLabel = new QLabel(cns("发送速度:0MB/s"), frame2); status2->addPermanentWidget(mSendLabel); frame2->layout()->addWidget(status2); QVBoxLayout *v3 = new QVBoxLayout(); v3->addWidget(frame1); QSpacerItem *item = new QSpacerItem(192, 10); v3->addSpacerItem(item); v3->addWidget(frame2); setLayout(v3); // resize(192, 372); // 连接信息 connect(mData->opt, SIGNAL(recvInformation(QString,QString)), this, SLOT(recvInfo(QString,QString))); connect(mData->opt, SIGNAL(sendInformation(QString,QString)), this, SLOT(sendInfo(QString,QString))); connect(mData->opt, SIGNAL(recvFilesProgress(int)), this, SIGNAL(signalRecvTotalProgress(int))); connect(mData->opt, SIGNAL(recvCurrentFileProgress(int)), this, SIGNAL(signalRecvCurrentProgress(int))); connect(mData->opt, SIGNAL(sendFilesProgress(int)), this, SIGNAL(signalSendTotalProgress(int))); connect(mData->opt, SIGNAL(sendCurrentFileProgress(int)), this, SIGNAL(signalSendCurrentProgress(int))); connect(this, SIGNAL(signalStartSend()), this, SLOT(startSend())); connect(mData->opt, SIGNAL(signalRecvPreInfo(QStringList)), this, SLOT(insertRecvFile(QStringList))); connect(mData->opt, SIGNAL(signalRecvStart()), this, SLOT(recvstart())); connect(mData->opt, SIGNAL(signalRecvSuccess()), this, SLOT(recvsuccess())); connect(mData->opt, SIGNAL(signalSendStart()), this, SLOT(sendstart())); connect(mData->opt, SIGNAL(signalSendSuccess()), this, SLOT(sendsuccess())); connect(mData->opt, SIGNAL(sendFileSpeed(float)), this, SLOT(sendSpeed(float))); connect(mData->opt, SIGNAL(recvFileSpeed(float)), this, SLOT(recvSpeed(float))); }
void Channel::onSendCompleted() { Assert(mBundles.size() == 0 && sending()); stopSend(); }