JID QtUserSearchWindow::getServerToSearch() { if (type_ == AddContact) { return firstPage_->byRemoteSearch_->isChecked() ? JID(Q2PSTRING(firstPage_->service_->currentText().trimmed())) : myServer_; } else { return firstMultiJIDPage_->byRemoteSearch_->isChecked() ? JID(Q2PSTRING(firstMultiJIDPage_->service_->currentText().trimmed())) : myServer_; } }
void QtChatWindow::beginCorrection() { boost::optional<AlertID> newCorrectingAlert; if (correctionEnabled_ == Maybe) { newCorrectingAlert = addAlert(Q2PSTRING(tr("This chat may not support message correction. If you send a correction anyway, it may appear as a duplicate message"))); } else if (correctionEnabled_ == No) { newCorrectingAlert = addAlert(Q2PSTRING(tr("This chat does not support message correction. If you send a correction anyway, it will appear as a duplicate message"))); } if (newCorrectingAlert) { if (correctingAlert_) { removeAlert(*correctingAlert_); } correctingAlert_ = newCorrectingAlert; } QTextCursor cursor = input_->textCursor(); cursor.select(QTextCursor::Document); cursor.beginEditBlock(); cursor.insertText(QString(lastSentMessage_)); cursor.endEditBlock(); isCorrection_ = true; correctingLabel_->show(); input_->setStyleSheet(alertStyleSheet_); labelsWidget_->setEnabled(false); }
bool QtUserSearchFirstPage::isComplete() const { bool complete = false; if (byJID_->isChecked()) { complete = JID(Q2PSTRING(jid_->text().trimmed())).isValid() && jidWarning_->toolTip().isEmpty(); } else if (byLocalSearch_->isChecked()) { complete = true; } else if (byRemoteSearch_->isChecked()) { complete = JID(Q2PSTRING(service_->currentText().trimmed())).isValid(); } return complete; }
JID QtTreeWidget::jidFromIndex(const QModelIndex& index) const { JID target; if (messageTarget_ == MessageDisplayJID) { target = JID(Q2PSTRING(index.data(DisplayJIDRole).toString())); target = target.toBare(); } if (!target.isValid()) { target = JID(Q2PSTRING(index.data(JIDRole).toString())); } return target; }
std::string QtContactEditWidget::getName() const { std::string name; QList<QRadioButton*> buttons = findChildren<QRadioButton*>(); foreach(const QRadioButton* button, buttons) { if (button->isChecked()) { if (button == nameRadioButton_) { name = Q2PSTRING(name_->text()); } else { name = Q2PSTRING(button->text()); } break; } } return name; }
void QtJoinMUCWindow::handleJoin() { if (ui.room->text().isEmpty()) { // TODO: Error return; } if (ui.nickName->text().isEmpty()) { // TODO: Error return; } lastSetNick = Q2PSTRING(ui.nickName->text()); std::string password = Q2PSTRING(ui.password->text()); JID room(Q2PSTRING(ui.room->text())); uiEventStream->send(boost::make_shared<JoinMUCUIEvent>(room, password, lastSetNick, ui.joinAutomatically->isChecked(), !ui.instantRoom->isChecked())); hide(); }
QString QtScaledAvatarCache::getScaledAvatarPath(const QString& path) { QFileInfo avatarFile(path); if (avatarFile.exists()) { if (!avatarFile.dir().exists(QString::number(size))) { if (!avatarFile.dir().mkdir(QString::number(size))) { return path; } } QDir targetDir(avatarFile.dir().absoluteFilePath(QString::number(size))); QString targetFile = targetDir.absoluteFilePath(avatarFile.baseName()); if (!QFileInfo(targetFile).exists()) { QPixmap avatarPixmap; if (avatarPixmap.load(path)) { QPixmap maskedAvatar(avatarPixmap.size()); maskedAvatar.fill(QColor(0, 0, 0, 0)); QPainter maskPainter(&maskedAvatar); maskPainter.setBrush(Qt::black); maskPainter.drawRoundedRect(maskedAvatar.rect(), 25.0, 25.0, Qt::RelativeSize); maskPainter.setCompositionMode(QPainter::CompositionMode_SourceIn); maskPainter.drawPixmap(0, 0, avatarPixmap); maskPainter.end(); if (!maskedAvatar.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation).save(targetFile, "PNG")) { return path; } } else { SWIFT_LOG(debug) << "Failed to load " << Q2PSTRING(path) << std::endl; } } return targetFile; } else { return path; } }
void QtProfileWindow::handleSave() { assert(vcard); vcard->setNickname(Q2PSTRING(nickname->text())); vcard->setPhoto(avatar->getAvatarData()); vcard->setPhotoType(avatar->getAvatarType()); onVCardChangeRequest(vcard); }
void QtRosterWidget::renameGroup(GroupRosterItem* group) { bool ok; QString newName = QInputDialog::getText(NULL, tr("Rename group"), tr("Enter a new name for group '%1':").arg(P2QSTRING(group->getDisplayName())), QLineEdit::Normal, P2QSTRING(group->getDisplayName()), &ok); if (ok) { eventStream_->send(boost::make_shared<RenameGroupUIEvent>(group->getDisplayName(), Q2PSTRING(newName))); } }
void QtChatWindow::tabComplete() { if (!completer_) { return; } QTextCursor cursor; if (tabCompleteCursor_.hasSelection()) { cursor = tabCompleteCursor_; } else { cursor = input_->textCursor(); while(cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor) && cursor.document()->characterAt(cursor.position() - 1) != ' ') { } } QString root = cursor.selectedText(); if (root.isEmpty()) { return; } QString suggestion = P2QSTRING(completer_->completeWord(Q2PSTRING(root))); if (root == suggestion) { return; } tabCompletion_ = true; cursor.beginEditBlock(); cursor.removeSelectedText(); int oldPosition = cursor.position(); cursor.insertText(suggestion); tabCompleteCursor_ = cursor; tabCompleteCursor_.setPosition(oldPosition, QTextCursor::KeepAnchor); cursor.endEditBlock(); tabCompletion_ = false; }
void QtUserSearchWindow::handleAccepted() { JID jid; std::vector<JID> jids; switch(type_) { case AddContact: jid = getContactJID(); eventStream_->send(boost::make_shared<AddContactUIEvent>(jid, detailsPage_->getName(), detailsPage_->getSelectedGroups())); break; case ChatToContact: if (contactVector_.size() == 1) { boost::shared_ptr<UIEvent> event(new RequestChatUIEvent(contactVector_[0]->jid)); eventStream_->send(event); break; } foreach(Contact::ref contact, contactVector_) { jids.push_back(contact->jid); } eventStream_->send(boost::make_shared<CreateImpromptuMUCUIEvent>(jids, JID(), Q2PSTRING(firstMultiJIDPage_->reason_->text()))); break; case InviteToChat: foreach(Contact::ref contact, contactVector_) { jids.push_back(contact->jid); }
void QtUserSearchWindow::handleSearch() { boost::shared_ptr<SearchPayload> search(new SearchPayload()); if (fieldsPage_->nickInput_->isEnabled()) { search->setNick(Q2PSTRING(fieldsPage_->nickInput_->text())); } if (fieldsPage_->firstInput_->isEnabled()) { search->setFirst(Q2PSTRING(fieldsPage_->firstInput_->text())); } if (fieldsPage_->lastInput_->isEnabled()) { search->setLast(Q2PSTRING(fieldsPage_->lastInput_->text())); } if (fieldsPage_->emailInput_->isEnabled()) { search->setEMail(Q2PSTRING(fieldsPage_->emailInput_->text())); } onSearchRequested(search, getServerToSearch()); }
void QtJoinMUCWindow::handleJoin() { if (ui.room->text().isEmpty() || !ui.room->hasAcceptableInput()) { QToolTip::showText(ui.room->mapToGlobal(QPoint()), tr("Please enter a valid room address."), ui.room); return; } if (ui.nickName->text().isEmpty() || !ui.nickName->hasAcceptableInput()) { QToolTip::showText(ui.nickName->mapToGlobal(QPoint()), tr("Please enter a valid nickname."), ui.nickName); return; } lastSetNick = Q2PSTRING(ui.nickName->text()); std::string password = Q2PSTRING(ui.password->text()); JID room(Q2PSTRING(ui.room->text())); uiEventStream->send(boost::make_shared<JoinMUCUIEvent>(room, password, lastSetNick, ui.joinAutomatically->isChecked(), !ui.instantRoom->isChecked())); hide(); }
void QtSpellCheckerWindow::handleApply() { settings_->storeSetting(SettingConstants::SPELL_CHECKER, ui_.spellChecker->isChecked()); QList<QListWidgetItem* > selectedLanguage = ui_.languageView->selectedItems(); if (!selectedLanguage.empty()) { settings_->storeSetting(SettingConstants::DICT_FILE, Q2PSTRING((selectedLanguage.first())->text())); } this->done(0); }
void QtSwift::loadEmoticonsFile(const QString& fileName, std::map<std::string, std::string>& emoticons) { QFile file(fileName); if (file.exists() && file.open(QIODevice::ReadOnly)) { while (!file.atEnd()) { QString line = file.readLine(); line.replace("\n", ""); line.replace("\r", ""); QStringList tokens = line.split(" "); if (tokens.size() == 2) { QString emoticonFile = tokens[1]; if (!emoticonFile.startsWith(":/") && !emoticonFile.startsWith("qrc:/")) { emoticonFile = "file://" + emoticonFile; } emoticons[Q2PSTRING(tokens[0])] = Q2PSTRING(emoticonFile); } } } }
bool QtSkillModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int /*column*/, const QModelIndex& parent) { SkillPlanList::ref plans = boost::dynamic_pointer_cast<SkillPlanList>(root_); if (action == Qt::IgnoreAction || !data->hasFormat("application/vnd.evexin.skilllevel") || !plans) { qDebug() << "Reject drop"; return false; } QModelIndex adjustedParent(parent); SkillItem::ref parentItem(getItem(parent)); SkillPlan::ref plan = boost::dynamic_pointer_cast<SkillPlan>(parentItem); if (parentItem && !plan) { //We're being dropped in an item, but it's not a plan. Maybe it's a child of a plan SkillItem::ref grandParent = parentItem->getParent(); plan = boost::dynamic_pointer_cast<SkillPlan>(grandParent); row = parent.row(); // qDebug() << "Going up to look for plan"; } if (!plan) { if (plans->getChildren().empty()) { //We're empty, we need somewhere to go plans->createPlan("Default"); } size_t rowT = static_cast<size_t>(row); if (row == 0) { // Before first plan, let into first plan. } else if (row < 0) { // Dropping off after the final plan rowT = root_->getChildren().size() - 1; } else { //If we're dropping after a plan, insert into the one before rowT--; } if (rowT >= root_->getChildren().size()) { rowT = root_->getChildren().size() - 1; } SkillItem::ref item = root_->getChildren()[rowT]; plan = boost::dynamic_pointer_cast<SkillPlan>(item); row = plan->getChildren().size(); } adjustedParent = index(plan); QByteArray encodedData = data->data("application/vnd.evexin.skilllevel"); QDataStream stream(&encodedData, QIODevice::ReadOnly); QString id; stream >> id; int level; stream >> level; std::string skillID = Q2PSTRING(id); size_t rowT = row >= 0 ? static_cast<size_t>(row) : plan->getChildren().size(); aboutToChangeSkills(plan); // plan->setDebug(true); plan->addSkill(skillID, level, rowT); // plan->setDebug(false); finishedChangingSkills(plan); return true; }
void QtUserSearchWindow::handleSearch() { std::shared_ptr<SearchPayload> search(new SearchPayload()); if (fieldsPage_->getFormWidget()) { search->setForm(fieldsPage_->getFormWidget()->getCompletedForm()); search->getForm()->clearEmptyTextFields(); } else { if (fieldsPage_->nickInput_->isEnabled() && !fieldsPage_->nickInput_->text().isEmpty()) { search->setNick(Q2PSTRING(fieldsPage_->nickInput_->text())); } if (fieldsPage_->firstInput_->isEnabled() && !fieldsPage_->firstInput_->text().isEmpty()) { search->setFirst(Q2PSTRING(fieldsPage_->firstInput_->text())); } if (fieldsPage_->lastInput_->isEnabled() && !fieldsPage_->lastInput_->text().isEmpty()) { search->setLast(Q2PSTRING(fieldsPage_->lastInput_->text())); } if (fieldsPage_->emailInput_->isEnabled() && !fieldsPage_->emailInput_->text().isEmpty()) { search->setEMail(Q2PSTRING(fieldsPage_->emailInput_->text())); } } onSearchRequested(search, getServerToSearch()); }
XMLSettingsProvider* QtSwift::loadSettingsFile(const QString& fileName) { QFile configFile(fileName); if (configFile.exists() && configFile.open(QIODevice::ReadOnly)) { QString xmlString; while (!configFile.atEnd()) { QByteArray line = configFile.readLine(); xmlString += line + "\n"; } return new XMLSettingsProvider(Q2PSTRING(xmlString)); } return new XMLSettingsProvider(""); }
void QtChatWindow::returnPressed() { if (!isOnline_ || (blockingState_ == IsBlocked)) { return; } messageLog_->scrollToBottom(); lastSentMessage_ = QString(input_->toPlainText()); onSendMessageRequest(Q2PSTRING(input_->toPlainText()), isCorrection_); inputClearing_ = true; input_->clear(); cancelCorrection(); inputClearing_ = false; }
void QtUserSearchFirstMultiJIDPage::dropEvent(QDropEvent *event) { if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) { QByteArray dataBytes = event->mimeData()->data("application/vnd.swift.contact-jid-list"); QDataStream dataStream(&dataBytes, QIODevice::ReadOnly); std::vector<JID> jids; while (!dataStream.atEnd()) { QString jidString; dataStream >> jidString; jids.push_back(Q2PSTRING(jidString)); } onJIDsDropped(jids); } else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-muc")) {
VCard::AddressLabel QtVCardAddressLabelField::getAddressLabel() const { VCard::AddressLabel addressLabel; addressLabel.isPreferred = getPreferred(); addressLabel.isHome = getHome(); addressLabel.isWork = getWork(); addressLabel.deliveryType = domesticRadioButton->isChecked() ? VCard::DomesticDelivery : (internationalRadioButton->isChecked() ? VCard::InternationalDelivery : VCard::None); addressLabel.isPostal = getTagComboBox()->isTagSet("postal"); addressLabel.isParcel = getTagComboBox()->isTagSet("parcel"); std::string lines = Q2PSTRING(addressLabelPlainTextEdit->toPlainText()); boost::split(addressLabel.lines, lines, boost::is_any_of("\n")); return addressLabel; }
void QtChatWindow::dropEvent(QDropEvent *event) { if (fileTransferEnabled_ == Yes && event->mimeData()->hasUrls()) { if (event->mimeData()->urls().size() == 1) { onSendFileRequest(Q2PSTRING(event->mimeData()->urls().at(0).toLocalFile())); } else { std::string messageText(Q2PSTRING(tr("Sending of multiple files at once isn't supported at this time."))); ChatMessage message; message.append(boost::make_shared<ChatTextMessagePart>(messageText)); addSystemMessage(message, DefaultDirection); } } else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) { QByteArray dataBytes = event->mimeData()->data("application/vnd.swift.contact-jid-list"); QDataStream dataStream(&dataBytes, QIODevice::ReadOnly); std::vector<JID> invites; while (!dataStream.atEnd()) { QString jidString; dataStream >> jidString; invites.push_back(Q2PSTRING(jidString)); } onInviteToChat(invites); }
void QtLoginWindow::loginClicked() { if (username_->isEnabled()) { std::string banner = settings_->getSetting(QtUISettingConstants::CLICKTHROUGH_BANNER); if (!banner.empty()) { QMessageBox msgBox; msgBox.setWindowTitle(tr("Confirm terms of use")); msgBox.setText(""); msgBox.setInformativeText(P2QSTRING(banner)); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox.setDefaultButton(QMessageBox::No); if (msgBox.exec() != QMessageBox::Yes) { return; } } CertificateWithKey::ref certificate; std::string certificateString = Q2PSTRING(certificateFile_); if (!certificateString.empty()) { #if defined(HAVE_SCHANNEL) if (isCAPIURI(certificateString)) { certificate = std::make_shared<CAPICertificate>(certificateString, timerFactory_); } else { certificate = std::make_shared<PKCS12Certificate>(certificateString, createSafeByteArray(Q2PSTRING(password_->text()))); } #else certificate = std::make_shared<PKCS12Certificate>(certificateString, createSafeByteArray(Q2PSTRING(password_->text()))); #endif } onLoginRequest(Q2PSTRING(username_->currentText()), Q2PSTRING(password_->text()), certificateString, certificate, currentOptions_, remember_->isChecked(), loginAutomatically_->isChecked()); if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { /* Mustn't remember logins */ username_->clearEditText(); password_->setText(""); } } else { onCancelLoginRequest(); } }
VCard::Address QtVCardAddressField::getAddress() const { VCard::Address address; address.isPreferred = getPreferred(); address.isHome = getHome(); address.isWork = getWork(); address.deliveryType = domesticRadioButton->isChecked() ? VCard::DomesticDelivery : (internationalRadioButton->isChecked() ? VCard::InternationalDelivery : VCard::None); address.isPostal = getTagComboBox()->isTagSet("postal"); address.isParcel = getTagComboBox()->isTagSet("parcel"); address.street = Q2PSTRING(streetLineEdit->text()); address.poBox = Q2PSTRING(poboxLineEdit->text()); address.addressExtension = Q2PSTRING(addressextLineEdit->text()); address.locality = Q2PSTRING(cityLineEdit->text()); address.postalCode = Q2PSTRING(pocodeLineEdit->text()); address.region = Q2PSTRING(regionLineEdit->text()); address.country = Q2PSTRING(countryLineEdit->text()); return address; }
void QtRosterWidget::contextMenuEvent(QContextMenuEvent* event) { QModelIndex index = indexAt(event->pos()); if (!index.isValid()) { return; } RosterItem* item = static_cast<RosterItem*>(index.internalPointer()); QMenu contextMenu; if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) { QAction* editContact = contextMenu.addAction(tr("Edit")); QAction* removeContact = contextMenu.addAction(tr("Remove")); #ifdef SWIFT_EXPERIMENTAL_FT QAction* sendFile = NULL; if (contact->supportsFeature(ContactRosterItem::FileTransferFeature)) { sendFile = contextMenu.addAction(tr("Send File")); } #endif QAction* result = contextMenu.exec(event->globalPos()); if (result == editContact) { eventStream_->send(boost::make_shared<RequestContactEditorUIEvent>(contact->getJID())); } else if (result == removeContact) { if (QtContactEditWindow::confirmContactDeletion(contact->getJID())) { eventStream_->send(boost::make_shared<RemoveRosterItemUIEvent>(contact->getJID())); } } #ifdef SWIFT_EXPERIMENTAL_FT else if (sendFile && result == sendFile) { QString fileName = QFileDialog::getOpenFileName(this, tr("Send File"), "", tr("All Files (*);;")); if (!fileName.isEmpty()) { eventStream_->send(boost::make_shared<SendFileUIEvent>(contact->getJID(), Q2PSTRING(fileName))); } } #endif } else if (GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item)) { QAction* renameGroupAction = contextMenu.addAction(tr("Rename")); QAction* result = contextMenu.exec(event->globalPos()); if (result == renameGroupAction) { renameGroup(group); } } }
void QtSpellCheckerWindow::handlePathButton() { std::string currentPath = settings_->getSetting(SettingConstants::DICT_PATH); QString dirpath = QFileDialog::getExistingDirectory(this, tr("Dictionary Path"), P2QSTRING(currentPath)); if (dirpath != P2QSTRING(currentPath)) { ui_.languageView->clear(); settings_->storeSetting(SettingConstants::DICT_FILE, ""); ui_.currentLanguageValue->setText(" "); } if (!dirpath.isEmpty()) { if (!dirpath.endsWith("/")) { dirpath.append("/"); } settings_->storeSetting(SettingConstants::DICT_PATH, Q2PSTRING(dirpath)); QDir dictDirectory = QDir(dirpath); ui_.pathContent->setText(dirpath); QString filename = "*.dic"; QStringList files = dictDirectory.entryList(QStringList(filename), QDir::Files); showFiles(files); } }
JID QtUserSearchWindow::getContactJID() const { JID jid; bool useSearchResult; if (type_ == AddContact) { useSearchResult = !firstPage_->byJID_->isChecked(); } else { useSearchResult = true; } if (useSearchResult) { if (dynamic_cast<UserSearchModel*>(model_)) { UserSearchResult* userItem = static_cast<UserSearchResult*>(resultsPage_->results_->currentIndex().internalPointer()); if (userItem) { /* Remember to leave this if we change to dynamic cast */ jid = userItem->getJID(); } } else if (dynamic_cast<QtFormResultItemModel*>(model_)) { int row = resultsPage_->results_->currentIndex().row(); Form::FormItem item = dynamic_cast<QtFormResultItemModel*>(model_)->getForm()->getItems().at(row); JID fallbackJid; for (FormField::ref field : item) { if (field->getType() == FormField::JIDSingleType) { jid = JID(field->getJIDSingleValue()); break; } if (field->getName() == "jid") { fallbackJid = field->getValues()[0]; } } if (!jid.isValid()) { jid = fallbackJid; } } } else { jid = JID(Q2PSTRING(firstPage_->jid_->text().trimmed())); } return jid; }
bool QtLoginWindow::eventFilter(QObject *obj, QEvent *event) { if (obj == username_->view() && event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); if (keyEvent->key() == Qt::Key_Delete || keyEvent->key() == Qt::Key_Backspace) { QString jid(username_->view()->currentIndex().data().toString()); int result = QMessageBox::question(this, tr("Remove profile"), tr("Remove the profile '%1'?").arg(jid), QMessageBox::Yes | QMessageBox::No); if (result == QMessageBox::Yes) { onPurgeSavedLoginRequest(Q2PSTRING(jid)); } return true; } } #ifdef SWIFTEN_PLATFORM_MACOSX // Dock clicked // Temporary workaround for case 501. Could be that this code is still // needed when Qt provides a proper fix if (obj == qApp && event->type() == QEvent::ApplicationActivate && !isVisible()) { bringToFront(); } #endif return QObject::eventFilter(obj, event); }
JID QtVCardJIDField::getJID() const { return JID(Q2PSTRING(jidLineEdit->text())); }
std::string QtVCardTitleField::getTitle() const { return Q2PSTRING(titleLineEdit->text()); }