예제 #1
0
파일: authdlg.cpp 프로젝트: j0wl/licq
void AuthDlg::send()
{
  Licq::UserId userId = myUserId;
  if (!userId.isValid())
    userId = Licq::UserId(myOwnerCombo->currentOwnerId(), myAccountIdEdit->text().toUtf8().constData());

  if (userId.isValid())
  {
    QByteArray messageText = myMessageEdit->toPlainText().toUtf8();

    switch (myType)
    {
      default:
      case RequestAuth:
        gProtocolManager.requestAuthorization(userId, messageText.constData());
        break;
      case GrantAuth:
        gProtocolManager.authorizeReply(userId, true, messageText.constData());
        break;
      case RefuseAuth:
        gProtocolManager.authorizeReply(userId, false, messageText.constData());
        break;
    }

    close();
  }
}
예제 #2
0
파일: authdlg.cpp 프로젝트: j0wl/licq
AuthDlg::AuthDlg(enum AuthDlgType type, const Licq::UserId& userId, QWidget* parent)
  : QDialog(parent),
    myType(type),
    myUserId(userId)
{
  Support::setWidgetProps(this, "AuthDialog");
  setAttribute(Qt::WA_DeleteOnClose, true);

  QString messageTitle;
  switch (myType)
  {
    default:
    case RequestAuth:
      setWindowTitle(tr("Licq - Request Authorization"));
      messageTitle = tr("Request");
      break;
    case GrantAuth:
      setWindowTitle(tr("Licq - Grant Authorization"));
      messageTitle = tr("Response");
      break;
    case RefuseAuth:
      setWindowTitle(tr("Licq - Refuse Authorization"));
      messageTitle = tr("Response");
      break;
  }

  QVBoxLayout* dialogLayout = new QVBoxLayout(this);
  QHBoxLayout* userIdLayout = new QHBoxLayout();

  QLabel* ownerLabel = new QLabel(this);
  ownerLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
  ownerLabel->setText(tr("&Account:"));
  myOwnerCombo = new OwnerComboBox();
  ownerLabel->setBuddy(myOwnerCombo);
  userIdLayout->addWidget(ownerLabel);
  userIdLayout->addWidget(myOwnerCombo);

  QLabel* accountIdLabel = new QLabel(this);
  accountIdLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
  accountIdLabel->setText(tr("&User ID:"));
  myAccountIdEdit = new QLineEdit(this);
  myAccountIdEdit->setMinimumWidth(90);
  accountIdLabel->setBuddy(myAccountIdEdit);
  connect(myAccountIdEdit, SIGNAL(returnPressed()), SLOT(send()) );
  userIdLayout->addWidget(accountIdLabel);
  userIdLayout->addWidget(myAccountIdEdit);

  dialogLayout->addLayout(userIdLayout);
  dialogLayout->addSpacing(6);

  QGroupBox* messageBox = new QGroupBox(messageTitle, this);
  dialogLayout->addWidget(messageBox);
  dialogLayout->setStretchFactor(messageBox, 2);

  QVBoxLayout* messageLayout = new QVBoxLayout(messageBox);
  myMessageEdit = new MLEdit(true);
  myMessageEdit->setSizeHintLines(5);
  messageLayout->addWidget(myMessageEdit);

  QDialogButtonBox* buttons = new QDialogButtonBox();
  QPushButton* okButton = buttons->addButton(QDialogButtonBox::Ok);
  QPushButton* cancelButton = buttons->addButton(QDialogButtonBox::Cancel);

  connect(myMessageEdit, SIGNAL(ctrlEnterPressed()), this, SLOT(send()));
  connect(okButton, SIGNAL(clicked()), SLOT(send()) );
  connect(cancelButton, SIGNAL(clicked()), SLOT(close()) );

  dialogLayout->addWidget(buttons);

  if (userId.isValid())
  {
    myOwnerCombo->setCurrentOwnerId(userId.ownerId());
    myOwnerCombo->setEnabled(false);
    myAccountIdEdit->setText(userId.accountId().c_str());
    myAccountIdEdit->setEnabled(false);
    myMessageEdit->setFocus();
  }
  else
  {
    myOwnerCombo->setFocus();
  }

  show();
}
예제 #3
0
파일: mmsenddlg.cpp 프로젝트: root42/licq
void MMSendDlg::SendNext()
{
  if (mmv->contacts().empty())
  {
    accept();
    return;
  }

  Licq::UserId userId = *mmv->contacts().begin();

  if (!userId.isValid())
    return;

  switch (myEventType)
  {
    case Licq::UserEvent::TypeMessage:
    {
      {
        Licq::UserReadGuard u(userId);
        if (!u.isLocked())
          return;
        grpSending->setTitle(tr("Sending mass message to %1...")
            .arg(QString::fromUtf8(u->getAlias().c_str())));
      }

      // create initial strings (implicit copying, no allocation impact :)
      QByteArray wholeMessageRaw(Licq::gTranslator.returnToDos(s1.toUtf8().data()).c_str());
      int wholeMessagePos = 0;

      bool needsSplitting = false;
      // If we send through server (= have message limit), and we've crossed the limit
      if ((wholeMessageRaw.length() - wholeMessagePos) > CICQDaemon::MaxMessageSize)
      {
        needsSplitting = true;
      }

      QString message;
      QByteArray messageRaw;

      while (wholeMessageRaw.length() > wholeMessagePos)
      {
        if (needsSplitting)
        {
          // This is a bit ugly but adds safety. We don't simply search
          // for a whitespace to cut at in the encoded text (since we don't
          // really know how spaces are represented in its encoding), so
          // we take the maximum length, then convert back to a Unicode string
          // and then search for Unicode whitespaces.
          messageRaw = Licq::gTranslator.returnToUnix(wholeMessageRaw.mid(wholeMessagePos, CICQDaemon::MaxMessageSize).data()).c_str();
          message = QString::fromUtf8(messageRaw);

          if ((wholeMessageRaw.length() - wholeMessagePos) > CICQDaemon::MaxMessageSize)
          {
            // We try to find the optimal place to cut
            // (according to our narrow-minded Latin1 idea of optimal :)
            // prefer keeping sentences intact 1st
            int foundIndex = message.lastIndexOf(QRegExp("[\\.\\n]"));
            // slicing at 0 position would be useless
            if (foundIndex <= 0)
              foundIndex = message.lastIndexOf(QRegExp("\\s"));

            if (foundIndex > 0)
            {
              message.truncate(foundIndex);
              messageRaw = message.toUtf8();
            }
          }
        }
        else
        {
          messageRaw = s1.toUtf8();
        }

        icqEventTag = gProtocolManager.sendMessage(userId, messageRaw.data(),
            Licq::ProtocolSignal::SendToMultiple);

        wholeMessagePos += Licq::gTranslator.returnToDos(messageRaw.constData()).size();
      }

      break;
    }
    case Licq::UserEvent::TypeUrl:
    {
      {
        Licq::UserReadGuard u(userId);
        if (!u.isLocked())
          return;
        grpSending->setTitle(tr("Sending mass URL to %1...")
            .arg(QString::fromUtf8(u->getAlias().c_str())));
      }

      icqEventTag = gProtocolManager.sendUrl(userId, s2.toUtf8().constData(),
          s1.toUtf8().constData(), Licq::ProtocolSignal::SendToMultiple);
      break;
    }
    case Licq::UserEvent::TypeContactList:
    {
      {
        Licq::UserReadGuard u(userId);
        if (!u.isLocked())
          return;
        grpSending->setTitle(tr("Sending mass list to %1...")
            .arg(QString::fromUtf8(u->getAlias().c_str())));
      }

      icqEventTag = gLicqDaemon->icqSendContactList(userId, *myUsers);
      break;
    }
  }

  if (icqEventTag == 0) slot_done(NULL);
}