summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/ChatList/ChatListGroupItem.h5
-rw-r--r--Swift/QtUI/ChatList/ChatListModel.cpp5
-rw-r--r--Swift/QtUI/ChatList/QtChatListWindow.cpp2
-rw-r--r--Swift/QtUI/ChatSnippet.cpp2
-rw-r--r--Swift/QtUI/ChatSnippet.h2
-rw-r--r--Swift/QtUI/CocoaUIHelpers.mm6
-rw-r--r--Swift/QtUI/EventViewer/EventModel.cpp4
-rw-r--r--Swift/QtUI/QtAdHocCommandWindow.cpp4
-rw-r--r--Swift/QtUI/QtAffiliationEditor.cpp2
-rw-r--r--Swift/QtUI/QtBlockListEditorWindow.cpp3
-rw-r--r--Swift/QtUI/QtCertificateViewerDialog.cpp8
-rw-r--r--Swift/QtUI/QtChatTabs.cpp2
-rw-r--r--Swift/QtUI/QtChatTabsShortcutOnlySubstitute.cpp3
-rw-r--r--Swift/QtUI/QtChatWindow.cpp5
-rw-r--r--Swift/QtUI/QtContactEditWidget.cpp12
-rw-r--r--Swift/QtUI/QtContactEditWidget.h4
-rw-r--r--Swift/QtUI/QtEmoticonsGrid.cpp10
-rw-r--r--Swift/QtUI/QtFormResultItemModel.cpp4
-rw-r--r--Swift/QtUI/QtFormWidget.cpp16
-rw-r--r--Swift/QtUI/QtHistoryWindow.cpp2
-rw-r--r--Swift/QtUI/QtLoginWindow.cpp2
-rw-r--r--Swift/QtUI/QtPlainChatView.cpp3
-rw-r--r--Swift/QtUI/QtProfileWindow.cpp2
-rw-r--r--Swift/QtUI/QtSettingsProvider.cpp4
-rw-r--r--Swift/QtUI/QtSingleWindow.cpp6
-rw-r--r--Swift/QtUI/QtSpellCheckHighlighter.cpp4
-rw-r--r--Swift/QtUI/QtStatusWidget.cpp8
-rw-r--r--Swift/QtUI/QtSubscriptionRequestWindow.cpp2
-rw-r--r--Swift/QtUI/QtTabbable.cpp1
-rw-r--r--Swift/QtUI/QtVCardWidget/QtTagComboBox.cpp6
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp4
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp2
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp4
-rw-r--r--Swift/QtUI/QtWebKitChatView.cpp2
-rw-r--r--Swift/QtUI/Roster/QtFilterWidget.cpp4
-rw-r--r--Swift/QtUI/Roster/QtOccupantListWidget.cpp2
-rw-r--r--Swift/QtUI/Roster/RosterModel.cpp2
-rw-r--r--Swift/QtUI/Roster/RosterTooltip.cpp8
-rw-r--r--Swift/QtUI/UserSearch/ContactListModel.cpp1
-rw-r--r--Swift/QtUI/UserSearch/QtContactListWidget.cpp4
-rw-r--r--Swift/QtUI/WinUIHelpers.cpp2
41 files changed, 74 insertions, 100 deletions
diff --git a/Swift/QtUI/ChatList/ChatListGroupItem.h b/Swift/QtUI/ChatList/ChatListGroupItem.h
index 427f00b..a9bb9b1 100644
--- a/Swift/QtUI/ChatList/ChatListGroupItem.h
+++ b/Swift/QtUI/ChatList/ChatListGroupItem.h
@@ -1,45 +1,42 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
#include <QList>
-#include <Swiften/Base/foreach.h>
-
#include <Swift/QtUI/ChatList/ChatListItem.h>
namespace Swift {
class ChatListGroupItem : public ChatListItem {
public:
ChatListGroupItem(const QString& name, ChatListGroupItem* parent, bool sorted = true) : ChatListItem(parent), name_(name), sorted_(sorted) {}
virtual ~ChatListGroupItem() {clear();}
void addItem(ChatListItem* item) {items_.push_back(item); if (sorted_) {qStableSort(items_.begin(), items_.end(), pointerItemLessThan);}}
void remove(int index) {items_.removeAt(index);}
int rowCount() {return items_.size();}
ChatListItem* item(int i) {return items_[i];}
int row(ChatListItem* item) {return items_.indexOf(item);}
QVariant data(int role) const {return (role == Qt::DisplayRole) ? name_ : QVariant();}
void clear() {
- foreach (ChatListItem* item, items_) {
+ for (auto item : items_) {
delete item;
}
items_.clear();
}
-
private:
static bool pointerItemLessThan(const ChatListItem* first, const ChatListItem* second) {
QString myName = first->data(Qt::DisplayRole).toString().toLower();
QString theirName = second->data(Qt::DisplayRole).toString().toLower();
return myName < theirName;
}
QString name_;
QList<ChatListItem*> items_;
bool sorted_;
};
}
diff --git a/Swift/QtUI/ChatList/ChatListModel.cpp b/Swift/QtUI/ChatList/ChatListModel.cpp
index e5e8963..416b786 100644
--- a/Swift/QtUI/ChatList/ChatListModel.cpp
+++ b/Swift/QtUI/ChatList/ChatListModel.cpp
@@ -69,87 +69,86 @@ void ChatListModel::removeMUCBookmark(const Swift::MUCBookmark& bookmark) {
mucBookmarks_->remove(i);
endRemoveRows();
break;
}
}
}
void ChatListModel::addWhiteboardSession(const ChatListWindow::Chat& chat) {
beginInsertRows(whiteboardsIndex_, 0, whiteboards_->rowCount());
whiteboards_->addItem(new ChatListWhiteboardItem(chat, whiteboards_));
endInsertRows();
}
void ChatListModel::removeWhiteboardSession(const JID& jid) {
for (int i = 0; i < whiteboards_->rowCount(); i++) {
ChatListWhiteboardItem* item = dynamic_cast<ChatListWhiteboardItem*>(whiteboards_->item(i));
if (item->getChat().jid == jid) {
beginRemoveRows(whiteboardsIndex_, i, i+1);
whiteboards_->remove(i);
endRemoveRows();
break;
}
}
}
void ChatListModel::setRecents(const std::list<ChatListWindow::Chat>& recents) {
beginRemoveRows(recentsIndex_, 0, recents_->rowCount());
recents_->clear();
endRemoveRows();
beginInsertRows(recentsIndex_, 0, recents.size());
- foreach (const ChatListWindow::Chat chat, recents) {
+ for (const auto& chat : recents) {
recents_->addItem(new ChatListRecentItem(chat, recents_));
//whiteboards_->addItem(new ChatListRecentItem(chat, whiteboards_));
}
endInsertRows();
}
QMimeData* ChatListModel::mimeData(const QModelIndexList& indexes) const {
QMimeData* data = QAbstractItemModel::mimeData(indexes);
ChatListRecentItem *item = dynamic_cast<ChatListRecentItem*>(getItemForIndex(indexes.first()));
if (item == nullptr) {
return data;
}
QByteArray itemData;
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
const ChatListWindow::Chat& chat = item->getChat();
QString mimeType = "application/vnd.swift.contact-jid-list";
if (!chat.impromptuJIDs.size()) {
if (chat.isMUC) {
mimeType = "application/vnd.swift.contact-jid-muc";
}
dataStream << P2QSTRING(chat.jid.toString());
} else {
- typedef std::map<std::string, JID> JIDMap;
- foreach (const JIDMap::value_type& jid, chat.impromptuJIDs) {
+ for (const auto& jid : chat.impromptuJIDs) {
dataStream << P2QSTRING(jid.second.toString());
}
}
data->setData(mimeType, itemData);
return data;
}
const ChatListMUCItem* ChatListModel::getChatListMUCItem(const JID& roomJID) const {
const ChatListMUCItem* mucItem = nullptr;
for (int i = 0; i < mucBookmarks_->rowCount(); i++) {
ChatListMUCItem* item = dynamic_cast<ChatListMUCItem*>(mucBookmarks_->item(i));
if (item->getBookmark().getRoom() == roomJID) {
mucItem = item;
break;
}
}
return mucItem;
}
int ChatListModel::columnCount(const QModelIndex& /*parent*/) const {
return 1;
}
ChatListItem* ChatListModel::getItemForIndex(const QModelIndex& index) const {
return index.isValid() ? static_cast<ChatListItem*>(index.internalPointer()) : nullptr;
}
QVariant ChatListModel::data(const QModelIndex& index, int role) const {
ChatListItem* item = getItemForIndex(index);
diff --git a/Swift/QtUI/ChatList/QtChatListWindow.cpp b/Swift/QtUI/ChatList/QtChatListWindow.cpp
index 3fe462a..3caed57 100644
--- a/Swift/QtUI/ChatList/QtChatListWindow.cpp
+++ b/Swift/QtUI/ChatList/QtChatListWindow.cpp
@@ -153,61 +153,61 @@ void QtChatListWindow::handleAddBookmarkFromRecents() {
MUCBookmark bookmark(chat.jid, chat.jid.toBare().toString());
bookmark.setNick(chat.nick);
bookmark.setPassword(chat.password);
eventStream_->send(std::make_shared<AddMUCBookmarkUIEvent>(bookmark));
}
}
void QtChatListWindow::handleAddBookmark() {
(new QtAddBookmarkWindow(eventStream_))->show();
}
void QtChatListWindow::handleEditBookmark() {
const ChatListMUCItem* mucItem = dynamic_cast<const ChatListMUCItem*>(contextMenuItem_);
if (!mucItem) return;
QtEditBookmarkWindow* window = new QtEditBookmarkWindow(eventStream_, mucItem->getBookmark());
window->show();
}
void QtChatListWindow::dragEnterEvent(QDragEnterEvent *event) {
if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1) {
event->acceptProposedAction();
}
}
void QtChatListWindow::contextMenuEvent(QContextMenuEvent* event) {
QModelIndex index = indexAt(event->pos());
ChatListItem* baseItem = index.isValid() ? static_cast<ChatListItem*>(index.internalPointer()) : nullptr;
contextMenuItem_ = baseItem;
- foreach(QAction* action, onlineOnlyActions_) {
+ for (auto action : onlineOnlyActions_) {
action->setEnabled(isOnline_);
}
if (!baseItem) {
emptyMenu_->exec(QCursor::pos());
return;
}
ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(baseItem);
if (mucItem) {
if (!bookmarksEnabled_) {
return;
}
mucMenu_->exec(QCursor::pos());
return;
}
ChatListRecentItem* recentItem = dynamic_cast<ChatListRecentItem*>(baseItem);
if (recentItem) {
const ChatListWindow::Chat& chat = recentItem->getChat();
if (chat.isMUC) {
QMenu mucRecentsMenu;
QAction* bookmarkAction = nullptr;
const ChatListMUCItem* mucItem = model_->getChatListMUCItem(chat.jid);
if (mucItem) {
contextMenuItem_ = mucItem;
bookmarkAction = mucRecentsMenu.addAction(tr("Edit Bookmark"), this, SLOT(handleEditBookmark()));
}
else {
bookmarkAction = mucRecentsMenu.addAction(tr("Add to Bookmarks"), this, SLOT(handleAddBookmarkFromRecents()));
diff --git a/Swift/QtUI/ChatSnippet.cpp b/Swift/QtUI/ChatSnippet.cpp
index 0369d0a..87dfac2 100644
--- a/Swift/QtUI/ChatSnippet.cpp
+++ b/Swift/QtUI/ChatSnippet.cpp
@@ -21,61 +21,61 @@ ChatSnippet::~ChatSnippet() {
QString ChatSnippet::timeToEscapedString(const QDateTime& time) {
QDate now(QDate::currentDate());
QString date = "";
if (time.date().daysTo(now) > 0) {
date = "ddd ";
}
if (time.date().month() != now.month()) {
date = date + "MMMM ";
}
if (time.date().daysTo(now) > 6) {
date = date + "d ";
}
if (time.date().year() != now.year()) {
date = date + "yy ";
}
date += "h:mm";
return escape(time.toString(date));
}
QString ChatSnippet::wrapResizable(const QString& text) {
return "<span class='swift_resizable'>" + text + "</span>";
}
QString ChatSnippet::directionToCSS(Direction direction) {
return direction == RTL ? QString("rtl") : QString("ltr");
}
ChatSnippet::Direction ChatSnippet::getDirection(const ChatWindow::ChatMessage& message) {
std::shared_ptr<ChatWindow::ChatTextMessagePart> textPart;
std::string text = "";
- foreach (std::shared_ptr<ChatWindow::ChatMessagePart> part, message.getParts()) {
+ for (auto&& part : message.getParts()) {
if ((textPart = std::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) {
text = textPart->text;
break;
}
}
return getDirection(text);
}
ChatSnippet::Direction ChatSnippet::getDirection(const std::string& message) {
return getDirection(P2QSTRING(message));
}
ChatSnippet::Direction ChatSnippet::getDirection(const QString& message) {
/*
for (int i = 0; i < message.size(); ++i) {
switch (message.at(i).direction()) {
case QChar::DirL:
case QChar::DirLRE:
case QChar::DirLRO:
return ChatSnippet::LTR;
case QChar::DirR:
case QChar::DirAL:
case QChar::DirRLE:
case QChar::DirRLO:
return ChatSnippet::RTL;
case QChar::DirEN:
case QChar::DirES:
case QChar::DirET:
case QChar::DirAN:
case QChar::DirCS:
diff --git a/Swift/QtUI/ChatSnippet.h b/Swift/QtUI/ChatSnippet.h
index f715cbf..d8bc209 100644
--- a/Swift/QtUI/ChatSnippet.h
+++ b/Swift/QtUI/ChatSnippet.h
@@ -1,45 +1,43 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
#include <memory>
#include <QDateTime>
#include <QString>
-#include <Swiften/Base/foreach.h>
-
#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
#include <Swift/QtUI/QtChatTheme.h>
namespace Swift {
class ChatSnippet {
public:
enum Direction {
RTL,
LTR
};
ChatSnippet(bool appendToPrevious);
virtual ~ChatSnippet();
virtual const QString& getContent() const = 0;
virtual QString getContinuationElementID() const { return ""; }
std::shared_ptr<ChatSnippet> getContinuationFallbackSnippet() const {return continuationFallback_;}
bool getAppendToPrevious() const {
return appendToPrevious_;
}
static QString escape(const QString& original) {
QString result(original);
result.replace("%message%", "&#37;message&#37;");
result.replace("%sender%", "&#37;sender&#37;");
result.replace("%wrapped_sender%", "&#37;wrapped_sender&#37;");
result.replace("%time%", "%&#37;time&#37;");
diff --git a/Swift/QtUI/CocoaUIHelpers.mm b/Swift/QtUI/CocoaUIHelpers.mm
index 3ffa72c..1f4ffc1 100644
--- a/Swift/QtUI/CocoaUIHelpers.mm
+++ b/Swift/QtUI/CocoaUIHelpers.mm
@@ -1,53 +1,51 @@
/*
* Copyright (c) 2012 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include "CocoaUIHelpers.h"
#include <memory>
+
#include <boost/type_traits.hpp>
#include <Cocoa/Cocoa.h>
#include <Security/Security.h>
#include <SecurityInterface/SFCertificatePanel.h>
-#include <Swiften/Base/foreach.h>
-
#pragma GCC diagnostic ignored "-Wold-style-cast"
namespace Swift {
void CocoaUIHelpers::displayCertificateChainAsSheet(QWidget* parent, const std::vector<Certificate::ref>& chain) {
NSWindow* parentWindow = [((NSView*)parent->winId()) window];
NSMutableArray* certificates = [[NSMutableArray alloc] init];
- foreach(Certificate::ref cert, chain) {
+ for (auto&& cert : chain) {
// convert chain to SecCertificateRef
ByteArray certAsDER = cert->toDER();
std::shared_ptr<boost::remove_pointer<CFDataRef>::type> certData(CFDataCreate(nullptr, certAsDER.data(), certAsDER.size()), CFRelease);
std::shared_ptr<OpaqueSecCertificateRef> macCert(SecCertificateCreateWithData(nullptr, certData.get()), CFRelease);
// add to NSMutable array
[certificates addObject: (id)macCert.get()];
}
-
SFCertificatePanel* panel = [[SFCertificatePanel alloc] init];
//[panel setPolicies:(id)policies.get()];
[panel beginSheetForWindow:parentWindow modalDelegate:nil didEndSelector:nullptr contextInfo:nullptr certificates:certificates showGroup:YES];
[certificates release];
}
void CocoaUIHelpers::sendCocoaApplicationWillTerminateNotification() {
[[NSNotificationCenter defaultCenter] postNotificationName:@"NSApplicationWillTerminateNotification" object:nil];
}
}
diff --git a/Swift/QtUI/EventViewer/EventModel.cpp b/Swift/QtUI/EventViewer/EventModel.cpp
index e242003..5b97b3e 100644
--- a/Swift/QtUI/EventViewer/EventModel.cpp
+++ b/Swift/QtUI/EventViewer/EventModel.cpp
@@ -1,55 +1,55 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/EventViewer/EventModel.h>
#include <Swiften/Base/Log.h>
namespace Swift {
namespace {
const int inactiveEventsLimit = 50;
}
EventModel::EventModel() {
}
EventModel::~EventModel() {
- foreach (QtEvent* event, activeEvents_) {
+ for (auto event : activeEvents_) {
delete event;
}
- foreach (QtEvent* event, inactiveEvents_) {
+ for (auto event : inactiveEvents_) {
delete event;
}
}
QtEvent* EventModel::getItem(int row) const {
QtEvent* event = nullptr;
if (row < activeEvents_.size()) {
event = activeEvents_[row];
}
else {
int inactiveRow = row - activeEvents_.size();
if (inactiveRow < inactiveEvents_.size()) {
event = inactiveEvents_[inactiveRow];
}
else {
SWIFT_LOG(error) << "Misbehaving EventModel requests row index outside of range";
}
}
return event;
}
int EventModel::getNewEventCount() {
return activeEvents_.size();
}
QVariant EventModel::data(const QModelIndex& index, int role) const {
if (!index.isValid()) {
return QVariant();
}
QtEvent* item = getItem(index.row());
diff --git a/Swift/QtUI/QtAdHocCommandWindow.cpp b/Swift/QtUI/QtAdHocCommandWindow.cpp
index 6b982b1..65dac91 100644
--- a/Swift/QtUI/QtAdHocCommandWindow.cpp
+++ b/Swift/QtUI/QtAdHocCommandWindow.cpp
@@ -77,98 +77,98 @@ void QtAdHocCommandWindow::setOnline(bool online) {
nextButton_->setEnabled(false);
backButton_->setEnabled(false);
completeButton_->setEnabled(false);
errorLabel_->setVisible(true);
}
}
void QtAdHocCommandWindow::closeEvent(QCloseEvent*) {
onClosing();
}
void QtAdHocCommandWindow::handleCancelClicked() {
command_->cancel();
close();
}
void QtAdHocCommandWindow::handlePrevClicked() {
command_->goBack();
}
void QtAdHocCommandWindow::handleNextClicked() {
command_->goNext(formWidget_ ? formWidget_->getCompletedForm() : Form::ref());
}
void QtAdHocCommandWindow::handleCompleteClicked() {
command_->complete(formWidget_ ? formWidget_->getCompletedForm() : Form::ref());
}
void QtAdHocCommandWindow::handleNextStageReceived(Command::ref command) {
QString notes;
- foreach (Command::Note note, command->getNotes()) {
+ for (const auto& note : command->getNotes()) {
if (!notes.isEmpty()) {
notes += "\n";
}
QString qNote(P2QSTRING(note.note));
switch (note.type) {
case Command::Note::Error: notes += tr("Error: %1").arg(qNote); break;
case Command::Note::Warn: notes += tr("Warning: %1").arg(qNote); break;
case Command::Note::Info: notes += qNote; break;
}
}
label_->setText(notes);
if (command->getForm()) {
setForm(command->getForm());
} else {
setNoForm(notes.isEmpty());
}
setAvailableActions(command);
}
void QtAdHocCommandWindow::handleError(ErrorPayload::ref /*error*/) {
nextButton_->setEnabled(false);
backButton_->setEnabled(false);
completeButton_->setEnabled(false);
label_->setText(tr("Error executing command"));
}
void QtAdHocCommandWindow::setForm(Form::ref form) {
form_ = form;
delete formWidget_;
formWidget_ = new QtFormWidget(form, this);
layout_->insertWidget(FormLayoutIndex, formWidget_);
show();
}
void QtAdHocCommandWindow::setNoForm(bool andHide) {
form_.reset();
delete formWidget_;
formWidget_ = nullptr;
resize(minimumSize());
setVisible(!andHide);
}
typedef std::pair<Command::Action, QPushButton*> ActionButton;
void QtAdHocCommandWindow::setAvailableActions(Command::ref /*commandResult*/) {
okButton_->show();
okButton_->setEnabled(true);
- foreach (ActionButton pair, actions_) {
+ for (auto&& pair : actions_) {
OutgoingAdHocCommandSession::ActionState state = command_->getActionState(pair.first);
if (state & OutgoingAdHocCommandSession::Present) {
okButton_->hide();
okButton_->setEnabled(false);
pair.second->show();
}
else {
pair.second->hide();
}
if (state & OutgoingAdHocCommandSession::Enabled) {
pair.second->setEnabled(true);
}
else {
pair.second->setEnabled(false);
}
}
}
}
diff --git a/Swift/QtUI/QtAffiliationEditor.cpp b/Swift/QtUI/QtAffiliationEditor.cpp
index 980b26a..92b6aff 100644
--- a/Swift/QtUI/QtAffiliationEditor.cpp
+++ b/Swift/QtUI/QtAffiliationEditor.cpp
@@ -10,61 +10,61 @@
#include <QListWidgetItem>
#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
QtAffiliationEditor::QtAffiliationEditor(QWidget* parent) : QDialog(parent){
ui_.setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
connect(ui_.affiliation, SIGNAL(currentIndexChanged(int)), this, SLOT(handleCurrentIndexChanged(int)));
connect(ui_.addJID, SIGNAL(clicked()), this, SLOT(handleAddClicked()));
connect(ui_.removeJID, SIGNAL(clicked()), this, SLOT(handleRemoveClicked()));
}
QtAffiliationEditor::~QtAffiliationEditor() {
}
void QtAffiliationEditor::setAffiliations(MUCOccupant::Affiliation affiliation, const std::vector<JID>& jids) {
affiliations_[affiliation] = jids;
if (affiliationFromIndex(ui_.affiliation->currentIndex()) == affiliation) {
handleCurrentIndexChanged(ui_.affiliation->currentIndex());
}
}
const std::vector<std::pair<MUCOccupant::Affiliation, JID> >& QtAffiliationEditor::getChanges() const {
return changes_;
}
void QtAffiliationEditor::handleCurrentIndexChanged(int index) {
ui_.list->clear();
- foreach (const JID& jid, affiliations_[affiliationFromIndex(index)]) {
+ for (const auto& jid : affiliations_[affiliationFromIndex(index)]) {
ui_.list->addItem(P2QSTRING(jid.toString()));
}
}
void QtAffiliationEditor::handleAddClicked() {
bool ok = false;
JID jid = JID(Q2PSTRING(QInputDialog::getText(this, tr("Add User"), tr("Added User's Address:"), QLineEdit::Normal, "", &ok)));
if (ok && jid.isValid()) {
//FIXME: validation
MUCOccupant::Affiliation affiliation = affiliationFromIndex(ui_.affiliation->currentIndex());
changes_.push_back(ChangePair(affiliation, jid));
ui_.list->addItem(P2QSTRING(jid.toString()));
affiliations_[affiliation].push_back(jid);
}
}
void QtAffiliationEditor::handleRemoveClicked() {
QListWidgetItem* item = ui_.list->currentItem();
if (item) {
JID jid(Q2PSTRING(item->text()));
changes_.push_back(ChangePair(MUCOccupant::NoAffiliation, jid));
std::vector<JID>& jids = affiliations_[affiliationFromIndex(ui_.affiliation->currentIndex())];
jids.erase(std::remove(jids.begin(), jids.end(), jid), jids.end());
handleCurrentIndexChanged(ui_.affiliation->currentIndex());
}
}
MUCOccupant::Affiliation QtAffiliationEditor::affiliationFromIndex(int affiliation) {
switch (affiliation) {
case 0: return MUCOccupant::Owner;
diff --git a/Swift/QtUI/QtBlockListEditorWindow.cpp b/Swift/QtUI/QtBlockListEditorWindow.cpp
index 9e13943..30c939f 100644
--- a/Swift/QtUI/QtBlockListEditorWindow.cpp
+++ b/Swift/QtUI/QtBlockListEditorWindow.cpp
@@ -1,53 +1,52 @@
/*
* Copyright (c) 2013 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2014-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/QtBlockListEditorWindow.h>
#include <boost/bind.hpp>
#include <QLineEdit>
#include <QMovie>
#include <QShortcut>
#include <QStyledItemDelegate>
#include <QValidator>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Client/ClientBlockListManager.h>
#include <Swiften/JID/JID.h>
#include <Swift/QtUI/QtSwiftUtil.h>
#include <Swift/QtUI/QtUtilities.h>
#include <Swift/QtUI/ui_QtBlockListEditorWindow.h>
namespace Swift {
class QtJIDValidator : public QValidator {
public:
QtJIDValidator(QObject* parent) : QValidator(parent) {}
virtual ~QtJIDValidator() {}
virtual QValidator::State validate(QString& input, int&) const {
return JID(Q2PSTRING(input)).isValid() ? Acceptable : Intermediate;
}
};
class QtJIDValidatedItemDelegate : public QItemDelegate {
public:
QtJIDValidatedItemDelegate(QObject* parent) : QItemDelegate(parent) {}
virtual ~QtJIDValidatedItemDelegate() {}
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem&, const QModelIndex&) const {
QLineEdit *editor = new QLineEdit(parent);
editor->setValidator(new QtJIDValidator(editor));
return editor;
}
void setEditorData(QWidget *editor, const QModelIndex &index) const {
@@ -131,61 +130,61 @@ void QtBlockListEditorWindow::handleItemChanged(QTreeWidgetItem *item, int) {
// check for empty rows and add an empty one so the user can add items
bool hasEmptyRow = false;
for( int i = 0; i < ui->blockListTreeWidget->topLevelItemCount(); ++i ) {
QTreeWidgetItem* row = ui->blockListTreeWidget->topLevelItem(i);
if (row->text(0) == freshBlockListTemplate) {
hasEmptyRow = true;
}
else if (row->text(0).isEmpty()) {
ui->blockListTreeWidget->removeItemWidget(row, 0);
}
}
if (!hasEmptyRow) {
QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(freshBlockListTemplate) << "x");
item->setFlags(item->flags() | Qt::ItemIsEditable);
ui->blockListTreeWidget->addTopLevelItem(item);
}
if (!item) {
ui->blockListTreeWidget->setCurrentItem(ui->blockListTreeWidget->topLevelItem(0));
}
}
void QtBlockListEditorWindow::applyChanges() {
onSetNewBlockList(getCurrentBlockList());
}
void QtBlockListEditorWindow::setCurrentBlockList(const std::vector<JID> &blockedJIDs) {
ui->blockListTreeWidget->clear();
- foreach(const JID& jid, blockedJIDs) {
+ for (const auto& jid : blockedJIDs) {
QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(P2QSTRING(jid.toString())) << "");
item->setFlags(item->flags() | Qt::ItemIsEditable);
ui->blockListTreeWidget->addTopLevelItem(item);
}
handleItemChanged(nullptr,0);
}
void QtBlockListEditorWindow::setBusy(bool isBusy) {
if (isBusy) {
ui->throbberLabel->movie()->start();
ui->throbberLabel->show();
ui->blockListTreeWidget->setEnabled(false);
ui->savePushButton->setEnabled(false);
} else {
ui->throbberLabel->movie()->stop();
ui->throbberLabel->hide();
ui->blockListTreeWidget->setEnabled(true);
ui->savePushButton->setEnabled(true);
}
}
void QtBlockListEditorWindow::setError(const std::string& error) {
if (!error.empty()) {
ui->errorLabel->setText("<font color='red'>" + QtUtilities::htmlEscape(P2QSTRING(error)) + "</font>");
}
else {
ui->errorLabel->setText("");
}
}
diff --git a/Swift/QtUI/QtCertificateViewerDialog.cpp b/Swift/QtUI/QtCertificateViewerDialog.cpp
index a99c29a..6454d82 100644
--- a/Swift/QtUI/QtCertificateViewerDialog.cpp
+++ b/Swift/QtUI/QtCertificateViewerDialog.cpp
@@ -1,76 +1,74 @@
/*
* Copyright (c) 2012 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2015-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/QtCertificateViewerDialog.h>
#include <QDateTime>
#include <QLabel>
#include <QString>
#include <QStringList>
#include <QTreeWidgetItem>
-#include <Swiften/Base/foreach.h>
-
#include <Swift/QtUI/ui_QtCertificateViewerDialog.h>
namespace Swift {
QtCertificateViewerDialog::QtCertificateViewerDialog(QWidget* parent) : QDialog(parent), ui(new Ui::QtCertificateViewerDialog) {
ui->setupUi(this);
connect(ui->certChainTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), SLOT(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
setAttribute(Qt::WA_DeleteOnClose);
}
QtCertificateViewerDialog::~QtCertificateViewerDialog() {
delete ui;
}
void QtCertificateViewerDialog::setCertificateChain(const std::vector<Certificate::ref>& chain) {
// clean widgets
ui->certChainTreeWidget->clear();
if (chain.empty()) return;
// convert Swift certificate chain to qt certificate chain (root goes first)
currentChain.clear();
- foreach(Certificate::ref cert, chain) {
+ for (auto&& cert : chain) {
ByteArray certAsDer = cert->toDER();
QByteArray dataArray(reinterpret_cast<const char*>(certAsDer.data()), certAsDer.size());
currentChain.push_front(QSslCertificate(dataArray, QSsl::Der));
}
// fill treeWidget
QTreeWidgetItem* root = new QTreeWidgetItem(ui->certChainTreeWidget, QStringList(currentChain.at(0).subjectInfo(QSslCertificate::CommonName)));
root->setData(0, Qt::UserRole, QVariant(0));
root->setExpanded(true);
ui->certChainTreeWidget->addTopLevelItem(root);
if (currentChain.size() > 1) {
QTreeWidgetItem* parent = root;
for (int n = 1; n < currentChain.size(); n++) {
QTreeWidgetItem* link = new QTreeWidgetItem(parent, QStringList(QString("↳ ") + (QStringList(currentChain.at(n).subjectInfo(QSslCertificate::CommonName)).join(", "))));
link->setExpanded(true);
link->setData(0, Qt::UserRole, QVariant(n));
parent = link;
}
ui->certChainTreeWidget->setCurrentItem(parent);
} else {
ui->certChainTreeWidget->setCurrentItem(root);
}
}
void QtCertificateViewerDialog::displayCertificateChainAsSheet(QWidget* parent, const std::vector<Certificate::ref>& chain) {
QtCertificateViewerDialog* dialog = new QtCertificateViewerDialog(parent);
dialog->setCertificateChain(chain);
dialog->show();
}
@@ -98,53 +96,53 @@ void QtCertificateViewerDialog::setCertificateDetails(const QSslCertificate& cer
int rowCount = 0;
ui->certGridLayout->setColumnStretch(2, 1);
QLabel* valueLabel = 0;
ADD_SECTION(tr("General"));
ADD_FIELD(tr("Valid From"), cert.effectiveDate().toString(Qt::TextDate));
ADD_FIELD(tr("Valid To"), cert.expiryDate().toString(Qt::TextDate));
ADD_FIELD(tr("Serial Number"), QString(cert.serialNumber().toHex()));
ADD_FIELD(tr("Version"), QString(cert.version()));
ADD_SECTION(tr("Subject"));
ADD_FIELD(tr("Organization"), cert.subjectInfo(QSslCertificate::Organization));
ADD_FIELD(tr("Common Name"), cert.subjectInfo(QSslCertificate::CommonName));
ADD_FIELD(tr("Locality"), cert.subjectInfo(QSslCertificate::LocalityName));
ADD_FIELD(tr("Organizational Unit"), cert.subjectInfo(QSslCertificate::OrganizationalUnitName));
ADD_FIELD(tr("Country"), cert.subjectInfo(QSslCertificate::CountryName));
ADD_FIELD(tr("State"), cert.subjectInfo(QSslCertificate::StateOrProvinceName));
#if QT_VERSION < 0x050000
QMultiMap<QSsl::AlternateNameEntryType, QString> altNames = cert.alternateSubjectNames();
#define SANTYPE QSsl::AlternateNameEntryType
#else
QMultiMap<QSsl::AlternativeNameEntryType, QString> altNames = cert.subjectAlternativeNames();
#define SANTYPE QSsl::AlternativeNameEntryType
#endif
if (!altNames.empty()) {
ADD_SECTION(tr("Alternate Subject Names"));
- foreach (const SANTYPE &type, altNames.uniqueKeys()) {
- foreach (QString name, altNames.values(type)) {
+ for (const auto& type : altNames.uniqueKeys()) {
+ for (auto&& name : altNames.values(type)) {
if (type == QSsl::EmailEntry) {
ADD_FIELD(tr("E-mail Address"), name);
} else {
ADD_FIELD(tr("DNS Name"), name);
}
}
}
}
ADD_SECTION(tr("Issuer"));
ADD_FIELD(tr("Organization"), cert.issuerInfo(QSslCertificate::Organization));
ADD_FIELD(tr("Common Name"), cert.issuerInfo(QSslCertificate::CommonName));
ADD_FIELD(tr("Locality"), cert.issuerInfo(QSslCertificate::LocalityName));
ADD_FIELD(tr("Organizational Unit"), cert.issuerInfo(QSslCertificate::OrganizationalUnitName));
ADD_FIELD(tr("Country"), cert.issuerInfo(QSslCertificate::CountryName));
ADD_FIELD(tr("State"), cert.issuerInfo(QSslCertificate::StateOrProvinceName));
ui->certGridLayout->setRowStretch(rowCount + 1, 1);
}
}
diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp
index bb9c005..3241858 100644
--- a/Swift/QtUI/QtChatTabs.cpp
+++ b/Swift/QtUI/QtChatTabs.cpp
@@ -53,61 +53,61 @@ QtChatTabs::QtChatTabs(bool singleWindow, SettingsProvider* settingsProvider, bo
std::string gridSizeString = settingsProvider->getSetting(QtUISettingConstants::TRELLIS_GRID_SIZE);
if (!gridSizeString.empty()) {
QByteArray gridSizeData = QByteArray::fromBase64(P2QSTRING(gridSizeString).toUtf8());
QDataStream dataStreamGridSize(&gridSizeData, QIODevice::ReadWrite);
QSize gridSize(1,1);
dataStreamGridSize >> gridSize;
dynamicGrid_->setDimensions(gridSize);
}
// restore positions
std::string tabPositionsString = settingsProvider->getSetting(QtUISettingConstants::TRELLIS_GRID_POSITIONS);
if (!tabPositionsString.empty()) {
QByteArray tabPositionsData = QByteArray::fromBase64(P2QSTRING(tabPositionsString).toUtf8());
QDataStream inTabPositions(&tabPositionsData, QIODevice::ReadWrite);
QHash<QString, QPoint> tabPositions;
inTabPositions >> tabPositions;
dynamicGrid_->setTabPositions(tabPositions);
}
}
gridSelectionDialog_ = new QtGridSelectionDialog();
// setup shortcuts
shortcuts_ << new QShortcut(QKeySequence(tr("CTRL+W", "Close chat tab.")), window(), SLOT(handleCloseTabShortcut()));
shortcuts_ << new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageUp), window(), SLOT(handleRequestedPreviousTab()));
shortcuts_ << new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageDown), window(), SLOT(handleRequestedNextTab()));
shortcuts_ << new QShortcut(QKeySequence(Qt::ALT + Qt::Key_A), window(), SLOT(handleRequestedActiveTab()));
}
QtChatTabs::~QtChatTabs() {
- foreach (QShortcut* shortcut, shortcuts_) {
+ for (auto shortcut : shortcuts_) {
delete shortcut;
}
if (trellisMode_) {
storeTabPositions();
}
delete gridSelectionDialog_;
}
void QtChatTabs::closeEvent(QCloseEvent* event) {
//Hide first to prevent flickering as each tab is removed.
hide();
if (trellisMode_) {
storeTabPositions();
}
for (int i = dynamicGrid_->count() - 1; i >= 0; i--) {
dynamicGrid_->widget(i)->close();
}
event->accept();
}
QtTabbable* QtChatTabs::getCurrentTab() {
return qobject_cast<QtTabbable*>(dynamicGrid_->currentWidget());
}
void QtChatTabs::setViewMenu(QMenu* viewMenu) {
if (trellisMode_) {
viewMenu->addSeparator();
QAction* action = new QAction(tr("Change &layout"), this);
diff --git a/Swift/QtUI/QtChatTabsShortcutOnlySubstitute.cpp b/Swift/QtUI/QtChatTabsShortcutOnlySubstitute.cpp
index fb41446..40ab17f 100644
--- a/Swift/QtUI/QtChatTabsShortcutOnlySubstitute.cpp
+++ b/Swift/QtUI/QtChatTabsShortcutOnlySubstitute.cpp
@@ -1,45 +1,44 @@
/*
* Copyright (c) 2015-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/QtChatTabsShortcutOnlySubstitute.h>
#include <cassert>
#include <QApplication>
#include <QShortcut>
#include <Swiften/Base/Log.h>
-#include <Swiften/Base/foreach.h>
#include <Swift/QtUI/QtTabbable.h>
namespace Swift {
QtChatTabsShortcutOnlySubstitute::QtChatTabsShortcutOnlySubstitute() : QWidget() {
}
QtChatTabsShortcutOnlySubstitute::~QtChatTabsShortcutOnlySubstitute() {
}
void QtChatTabsShortcutOnlySubstitute::addTab(QtTabbable* tab) {
connect(tab, SIGNAL(requestNextTab()), this, SLOT(handleRequestedNextTab()), Qt::UniqueConnection);
connect(tab, SIGNAL(requestActiveTab()), this, SLOT(handleRequestedActiveTab()), Qt::UniqueConnection);
connect(tab, SIGNAL(requestPreviousTab()), this, SLOT(handleRequestedPreviousTab()), Qt::UniqueConnection);
connect(new QShortcut(QKeySequence(tr("CTRL+W", "Close chat tab.")), tab), SIGNAL(activated()), this, SLOT(handleCloseTabShortcut()));
connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageUp), tab), SIGNAL(activated()), tab, SIGNAL(requestPreviousTab()));
connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageDown), tab), SIGNAL(activated()), tab, SIGNAL(requestNextTab()));
connect(new QShortcut(QKeySequence(Qt::ALT + Qt::Key_A), tab), SIGNAL(activated()), tab, SIGNAL(requestActiveTab()));
}
void QtChatTabsShortcutOnlySubstitute::handleCloseTabShortcut() {
QtTabbable* senderTab = dynamic_cast<QtTabbable*>(sender()->parent());
SWIFT_LOG_ASSERT(senderTab, debug) << "No window to close." << std::endl;
if (senderTab) {
senderTab->close();
}
@@ -68,42 +67,42 @@ void QtChatTabsShortcutOnlySubstitute::handleRequestedActiveTab() {
int startIndex = tabs.indexOf(senderTab);
int currentIndex = startIndex;
do {
currentIndex = (currentIndex + 1) % tabs.size();
QtTabbable* currentTab = tabs.at(currentIndex);
if (currentTab->getWidgetAlertState() == type) {
currentTab->activateWindow();
return;
}
} while (startIndex != currentIndex);
}
}
void QtChatTabsShortcutOnlySubstitute::handleRequestedPreviousTab() {
QtTabbable* senderTab = dynamic_cast<QtTabbable*>(sender());
QList<QtTabbable*> tabs = tabbableWindows();
int currentIndex = tabs.indexOf(senderTab);
assert(currentIndex >= 0);
QtTabbable* previousTab = tabs.at((currentIndex + tabs.size() - 1) % tabs.size());
previousTab->activateWindow();
}
QList<QtTabbable*> QtChatTabsShortcutOnlySubstitute::tabbableWindows() const {
QList<QWidget*> windows = qApp->topLevelWidgets();
QList<QtTabbable*> tabbables;
- foreach(QWidget* topLevelWidget, windows) {
+ for (auto topLevelWidget : windows) {
QtTabbable* tabbable = dynamic_cast<QtTabbable*>(topLevelWidget);
if (tabbable) {
tabbables << tabbable;
}
}
return tabbables;
}
}
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index bda6b3e..d799e19 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -359,61 +359,61 @@ void QtChatWindow::tabComplete() {
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 QtChatWindow::setRosterModel(Roster* roster) {
treeWidget_->setRosterModel(roster);
}
void QtChatWindow::setAvailableSecurityLabels(const std::vector<SecurityLabelsCatalog::Item>& labels) {
delete labelModel_;
labelModel_ = new LabelModel();
labelModel_->availableLabels_ = labels;
int i = 0;
int defaultIndex = 0;
labelsWidget_->setModel(labelModel_);
- foreach (SecurityLabelsCatalog::Item label, labels) {
+ for (const auto& label : labels) {
if (label.getIsDefault()) {
defaultIndex = i;
break;
}
i++;
}
labelsWidget_->setCurrentIndex(defaultIndex);
}
void QtChatWindow::handleCurrentLabelChanged(int index) {
if (static_cast<size_t>(index) >= labelModel_->availableLabels_.size()) {
SWIFT_LOG(debug) << "User selected a label that doesn't exist";
return;
}
const SecurityLabelsCatalog::Item& label = labelModel_->availableLabels_[index];
if (label.getLabel()) {
QPalette palette = labelsWidget_->palette();
//palette.setColor(QPalette::Base, P2QSTRING(label.getLabel()->getBackgroundColor()));
palette.setColor(labelsWidget_->backgroundRole(), P2QSTRING(label.getLabel()->getBackgroundColor()));
palette.setColor(labelsWidget_->foregroundRole(), P2QSTRING(label.getLabel()->getForegroundColor()));
labelsWidget_->setPalette(palette);
midBar_->setPalette(palette);
labelsWidget_->setAutoFillBackground(true);
}
else {
labelsWidget_->setAutoFillBackground(false);
labelsWidget_->setPalette(defaultLabelsPalette_);
midBar_->setPalette(defaultLabelsPalette_);
}
}
@@ -685,62 +685,61 @@ void QtChatWindow::handleTextInputLostFocus() {
}
void QtChatWindow::handleActionButtonClicked() {
QMenu contextMenu;
QAction* changeSubject = nullptr;
QAction* configure = nullptr;
QAction* affiliations = nullptr;
QAction* destroy = nullptr;
QAction* invite = nullptr;
QAction* block = nullptr;
QAction* unblock = nullptr;
if (availableRoomActions_.empty()) {
if (blockingState_ == IsBlocked) {
unblock = contextMenu.addAction(tr("Unblock"));
unblock->setEnabled(isOnline_);
}
else if (!isMUC_ && blockingState_ == IsUnblocked) {
block = contextMenu.addAction(tr("Block"));
block->setEnabled(isOnline_);
}
if (supportsImpromptuChat_) {
invite = contextMenu.addAction(tr("Invite person to this chat…"));
invite->setEnabled(isOnline_ && (blockingState_ != IsBlocked));
}
}
else {
- foreach(ChatWindow::RoomAction availableAction, availableRoomActions_)
- {
+ for (auto&& availableAction : availableRoomActions_) {
if (impromptu_) {
// hide options we don't need in impromptu chats
if (availableAction == ChatWindow::ChangeSubject ||
availableAction == ChatWindow::Configure ||
availableAction == ChatWindow::Affiliations ||
availableAction == ChatWindow::Destroy) {
continue;
}
}
switch(availableAction)
{
case ChatWindow::ChangeSubject:
changeSubject = contextMenu.addAction(tr("Change subject…"));
changeSubject->setEnabled(isOnline_);
break;
case ChatWindow::Configure:
configure = contextMenu.addAction(tr("Configure room…"));
configure->setEnabled(isOnline_);
break;
case ChatWindow::Affiliations:
affiliations = contextMenu.addAction(tr("Edit affiliations…"));
affiliations->setEnabled(isOnline_);
break;
case ChatWindow::Destroy:
destroy = contextMenu.addAction(tr("Destroy room"));
destroy->setEnabled(isOnline_);
break;
case ChatWindow::Invite:
invite = contextMenu.addAction(tr("Invite person to this room…"));
invite->setEnabled(isOnline_);
diff --git a/Swift/QtUI/QtContactEditWidget.cpp b/Swift/QtUI/QtContactEditWidget.cpp
index 4e9a7fe..17f5ccf 100644
--- a/Swift/QtUI/QtContactEditWidget.cpp
+++ b/Swift/QtUI/QtContactEditWidget.cpp
@@ -24,143 +24,143 @@ QtContactEditWidget::QtContactEditWidget(const std::set<std::string>& allGroups,
QBoxLayout* layout = new QVBoxLayout(this);
setContentsMargins(0,0,0,0);
layout->setContentsMargins(0,0,0,0);
nameLayout_ = new QHBoxLayout();
suggestionsLayout_ = new QHBoxLayout();
nameLayout_->addLayout(suggestionsLayout_);
name_ = new QLineEdit(this);
nameLayout_->addWidget(name_);
throbberLabel_ = new QLabel(this);
throbberLabel_->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this));
throbberLabel_->movie()->start();
nameLayout_->addWidget(throbberLabel_);
layout->addLayout(nameLayout_);
layout->addWidget(new QLabel(tr("Groups:"), this));
QScrollArea* groupsArea = new QScrollArea(this);
layout->addWidget(groupsArea);
groupsArea->setWidgetResizable(true);
groupsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
groupsArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
QWidget* groups = new QWidget(groupsArea);
groupsArea->setWidget(groups);
QVBoxLayout* scrollLayout = new QVBoxLayout(groups);
- foreach (std::string group, allGroups) {
+ for (const auto& group : allGroups) {
QString groupName = doubleAmpersand(group);
QCheckBox* check = new QCheckBox(groups);
check->setText(groupName);
check->setCheckState(Qt::Unchecked);
checkBoxes_[group] = check;
scrollLayout->addWidget(check);
}
QHBoxLayout* newGroupLayout = new QHBoxLayout();
newGroup_ = new QCheckBox(groups);
newGroup_->setText(tr("New Group:"));
newGroup_->setCheckState(Qt::Unchecked);
newGroupLayout->addWidget(newGroup_);
newGroupName_ = new QLineEdit(groups);
newGroupLayout->addWidget(newGroupName_);
scrollLayout->addLayout(newGroupLayout);
scrollLayout->addItem(new QSpacerItem(20, 73, QSizePolicy::Minimum, QSizePolicy::Expanding));
}
void QtContactEditWidget::setName(const std::string& name) {
name_->setText(P2QSTRING(name));
}
std::string QtContactEditWidget::getName() const {
std::string name = Q2PSTRING(name_->text());
QList<QRadioButton*> buttons = findChildren<QRadioButton*>();
- foreach(const QRadioButton* button, buttons) {
+ for (const auto button : buttons) {
if (button->isChecked()) {
if (button == nameRadioButton_) {
name = Q2PSTRING(name_->text());
} else {
name = singleAmpersand(button->text());
}
break;
}
}
return name;
}
void QtContactEditWidget::setSelectedGroups(const std::vector<std::string>& groups) {
- foreach (std::string group, groups) {
+ for (auto&& group : groups) {
checkBoxes_[group]->setCheckState(Qt::Checked);
}
}
std::set<std::string> QtContactEditWidget::getSelectedGroups() const {
std::set<std::string> groups;
- foreach(const CheckBoxMap::value_type& group, checkBoxes_) {
+ for (const auto& group : checkBoxes_) {
if (group.second->checkState() == Qt::Checked) {
groups.insert(group.first);
}
}
if (newGroup_->checkState() == Qt::Checked && !newGroupName_->text().isEmpty()) {
groups.insert(Q2PSTRING(newGroupName_->text()));
}
return groups;
}
void QtContactEditWidget::setNameSuggestions(const std::vector<std::string>& suggestions) {
throbberLabel_->movie()->stop();
throbberLabel_->hide();
// remove old suggestions except for the user input text field
QLayoutItem* suggestionItem = nullptr;
while ((suggestionItem = suggestionsLayout_->itemAt(0)) && suggestionItem->widget() != name_) {
QWidget* suggestionWidget = suggestionItem->widget();
suggestionsLayout_->removeWidget(suggestionWidget);
delete suggestionWidget;
}
// populate new suggestions
- foreach(const std::string& name, suggestions) {
+ for (const auto& name : suggestions) {
suggestionsLayout_->insertWidget(nameLayout_->count() - 2, new QRadioButton(doubleAmpersand(name), this));
}
nameRadioButton_ = new QRadioButton(tr("Name:"), this);
suggestionsLayout_->insertWidget(nameLayout_->count(), nameRadioButton_);
QRadioButton* suggestedRadioButton = nullptr;
QList<QRadioButton*> radioButtons = findChildren<QRadioButton*>();
- foreach (QRadioButton* candidate, radioButtons) {
+ for (auto candidate : radioButtons) {
if (candidate->text() == name_->text()) {
suggestedRadioButton = candidate;
break;
}
}
if (suggestedRadioButton) {
suggestedRadioButton->setChecked(true);
} else {
nameRadioButton_->setChecked(true);
}
}
QString QtContactEditWidget::doubleAmpersand(const std::string& name) const {
return P2QSTRING(name).replace("&", "&&");
}
std::string QtContactEditWidget::singleAmpersand(const QString& name) const {
return Q2PSTRING(QString(name).replace("&&", "&"));
}
void QtContactEditWidget::clear() {
name_->clear();
setSelectedGroups(std::vector<std::string>());
newGroup_->setChecked(false);
newGroupName_->clear();
throbberLabel_->movie()->start();
throbberLabel_->show();
// clear suggestions
diff --git a/Swift/QtUI/QtContactEditWidget.h b/Swift/QtUI/QtContactEditWidget.h
index d4ea609..0718fee 100644
--- a/Swift/QtUI/QtContactEditWidget.h
+++ b/Swift/QtUI/QtContactEditWidget.h
@@ -14,44 +14,44 @@
#include <QWidget>
class QLabel;
class QLineEdit;
class QCheckBox;
class QHBoxLayout;
class QRadioButton;
namespace Swift {
class QtContactEditWidget : public QWidget {
Q_OBJECT
public:
QtContactEditWidget(const std::set<std::string>& allGroups, QWidget* parent);
void setName(const std::string&);
std::string getName() const;
void setSelectedGroups(const std::vector<std::string>& groups);
std::set<std::string> getSelectedGroups() const;
void setNameSuggestions(const std::vector<std::string>& suggestions);
void clear();
private:
QString doubleAmpersand(const std::string& name) const;
std::string singleAmpersand(const QString& name) const;
+
private:
- typedef std::map<std::string, QCheckBox*> CheckBoxMap;
- CheckBoxMap checkBoxes_;
+ std::map<std::string, QCheckBox*> checkBoxes_;
QHBoxLayout* nameLayout_;
QHBoxLayout* suggestionsLayout_;
QRadioButton* nameRadioButton_;
QLineEdit* name_;
QWidget* groups_;
QCheckBox* newGroup_;
QLineEdit* newGroupName_;
QLabel* throbberLabel_;
};
}
diff --git a/Swift/QtUI/QtEmoticonsGrid.cpp b/Swift/QtUI/QtEmoticonsGrid.cpp
index a81f516..4c8c024 100644
--- a/Swift/QtUI/QtEmoticonsGrid.cpp
+++ b/Swift/QtUI/QtEmoticonsGrid.cpp
@@ -1,65 +1,63 @@
/*
* Copyright (c) 2015 Daniel Baczynski
* Licensed under the Simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/QtEmoticonsGrid.h>
#include <set>
-#include <QPushButton>
+#include <boost/range/adaptor/reversed.hpp>
-#include <Swiften/Base/foreach.h>
+#include <QPushButton>
#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
-typedef std::map<std::string, std::string> EmoticonsMap; // Without this typedef compiler complains when using foreach
-
QtEmoticonsGrid::QtEmoticonsGrid(const std::map<std::string, std::string>& emoticons, QWidget* parent) : QGridLayout(parent) {
makeUniqueEmoticonsMap(emoticons);
// Create grid: 3 columns, [uniqueEmoticons_.size()/3] rows
int row = 0;
int column = 0;
- foreach(EmoticonsMap::value_type emoticon, uniqueEmoticons_) {
+ for (auto&& emoticon : uniqueEmoticons_) {
QtEmoticonCell* newCell = new QtEmoticonCell(P2QSTRING(emoticon.first), P2QSTRING(emoticon.second));
addWidget(newCell, row, column);
connect(newCell, SIGNAL(emoticonClicked(QString)), this, SLOT(emoticonClickedSlot(QString)));
column++;
if (column >= 3) {
column = 0;
row++;
}
}
}
QtEmoticonsGrid::~QtEmoticonsGrid() {
}
void QtEmoticonsGrid::makeUniqueEmoticonsMap(const std::map<std::string, std::string>& emoticons) {
std::set<std::string> paths;
- reverse_foreach(EmoticonsMap::value_type emoticon, emoticons) {
+ for (auto&& emoticon : boost::adaptors::reverse(emoticons)) {
if (paths.find(emoticon.second) == paths.end()) {
uniqueEmoticons_.insert(emoticon);
paths.insert(emoticon.second);
}
}
}
void QtEmoticonsGrid::emoticonClickedSlot(QString emoticonAsText) {
emit emoticonClicked(emoticonAsText);
}
}
diff --git a/Swift/QtUI/QtFormResultItemModel.cpp b/Swift/QtUI/QtFormResultItemModel.cpp
index 60cf0c0..b35bb4f 100644
--- a/Swift/QtUI/QtFormResultItemModel.cpp
+++ b/Swift/QtUI/QtFormResultItemModel.cpp
@@ -1,95 +1,93 @@
/*
* Copyright (c) 2012 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/QtFormResultItemModel.h>
#include <boost/algorithm/string/join.hpp>
-#include <Swiften/Base/foreach.h>
-
#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
QtFormResultItemModel::QtFormResultItemModel(QObject *parent) : QAbstractTableModel(parent) {
}
QtFormResultItemModel::QtFormResultItemModel(QObject* parent, Form::ref formResult) : QAbstractTableModel(parent), formResult_(formResult) {
}
void QtFormResultItemModel::setForm(Form::ref formResult) {
emit layoutAboutToBeChanged();
formResult_ = formResult;
emit layoutChanged();
}
const Form::ref QtFormResultItemModel::getForm() const {
return formResult_;
}
QVariant QtFormResultItemModel::headerData(int section, Qt::Orientation /*orientation*/, int role) const {
if (!formResult_) return QVariant();
if (role != Qt::DisplayRole) return QVariant();
if (static_cast<size_t>(section) >= formResult_->getReportedFields().size()) return QVariant();
return QVariant(P2QSTRING(formResult_->getReportedFields().at(section)->getLabel()));
}
int QtFormResultItemModel::rowCount(const QModelIndex &/*parent*/) const {
if (!formResult_) return 0;
return formResult_->getItems().size();
}
int QtFormResultItemModel::columnCount(const QModelIndex &/*parent*/) const {
if (!formResult_) return 0;
return formResult_->getReportedFields().size();
}
QVariant QtFormResultItemModel::data(const QModelIndex &index, int role) const {
if (!formResult_) return QVariant();
if (role != Qt::DisplayRole || !index.isValid()) {
return QVariant();
}
if (static_cast<size_t>(index.row()) >= formResult_->getItems().size()) return QVariant();
if (static_cast<size_t>(index.column()) >= formResult_->getReportedFields().size()) return QVariant();
Form::FormItem item = formResult_->getItems().at(index.row());
return QVariant(P2QSTRING(getFieldValue(item, index.column())));
}
const std::string QtFormResultItemModel::getFieldValue(const Form::FormItem& item, const int column) const {
// determine field name
std::string name = formResult_->getReportedFields().at(column)->getName();
- foreach(FormField::ref field, item) {
+ for (auto&& field : item) {
if (field->getName() == name) {
std::string delimiter = "";
if (field->getType() == FormField::TextMultiType) {
delimiter = "\n";
}
else if (field->getType() == FormField::JIDMultiType) {
delimiter = ", ";
}
else if (field->getType() == FormField::ListMultiType) {
delimiter = ", ";
}
return boost::algorithm::join(field->getValues(), delimiter);
}
}
return "";
}
}
diff --git a/Swift/QtUI/QtFormWidget.cpp b/Swift/QtUI/QtFormWidget.cpp
index 1d26815..96c2da0 100644
--- a/Swift/QtUI/QtFormWidget.cpp
+++ b/Swift/QtUI/QtFormWidget.cpp
@@ -1,118 +1,116 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/QtFormWidget.h>
#include <memory>
#include <boost/algorithm/string/join.hpp>
#include <QCheckBox>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QScrollArea>
#include <QTextEdit>
#include <qdebug.h>
-#include <Swiften/Base/foreach.h>
-
#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
QtFormWidget::QtFormWidget(Form::ref form, QWidget* parent) : QWidget(parent), form_(form) {
QGridLayout* thisLayout = new QGridLayout(this);
int row = 0;
if (!form->getTitle().empty()) {
QLabel* instructions = new QLabel(("<b>" + form->getTitle() + "</b>").c_str(), this);
thisLayout->addWidget(instructions, row++, 0, 1, 2);
}
if (!form->getInstructions().empty()) {
QLabel* instructions = new QLabel(form->getInstructions().c_str(), this);
thisLayout->addWidget(instructions, row++, 0, 1, 2);
}
QScrollArea* scrollArea = new QScrollArea(this);
thisLayout->addWidget(scrollArea);
QWidget* scroll = new QWidget(this);
QGridLayout* layout = new QGridLayout(scroll);
const std::vector<Form::FormItem> items = form->getItems();
if (items.empty()) { /* single item forms */
- foreach (FormField::ref field, form->getFields()) {
+ for (auto&& field : form->getFields()) {
QWidget* widget = createWidget(field, field->getType(), 0);
if (widget) {
layout->addWidget(new QLabel(field->getLabel().c_str(), this), row, 0);
layout->addWidget(widget, row++, 1);
}
}
} else { /* multi-item forms */
const Form::FormItem& headers = form->getFields();
for (size_t i = 0; i < items.size(); ++i) {
const Form::FormItem& item = items[i];
assert(item.size() == headers.size());
for (size_t j = 0; j < item.size(); ++j) {
QWidget* widget = createWidget(item[j], headers[j]->getType(), i);
if (widget) {
layout->addWidget(new QLabel(item[j]->getLabel().c_str(), this), row, 0);
layout->addWidget(widget, row++, 1);
}
}
}
}
scrollArea->setWidget(scroll);
scrollArea->setWidgetResizable(true);
setEditable(form->getType() != Form::CancelType && form->getType() != Form::ResultType);
}
QtFormWidget::~QtFormWidget() {
}
QListWidget* QtFormWidget::createList(FormField::ref field) {
QListWidget* listWidget = new QListWidget(this);
listWidget->setSortingEnabled(false);
listWidget->setSelectionMode(field->getType() == FormField::ListMultiType ? QAbstractItemView::MultiSelection : QAbstractItemView::SingleSelection);
std::vector<bool> selected;
/* if this is an editable form, use the 'options' list, otherwise use the 'values' list */
if (form_->getType() != Form::FormType) {
- foreach (const std::string& value, field->getValues()) {
+ for (const auto& value : field->getValues()) {
listWidget->addItem(P2QSTRING(value));
selected.push_back(false);
}
} else {
- foreach (FormField::Option option, field->getOptions()) {
+ for (auto&& option : field->getOptions()) {
listWidget->addItem(option.label.c_str());
if (field->getType() == FormField::ListSingleType) {
selected.push_back(!field->getValues().empty() && option.value == field->getValues()[0]);
}
else if (field->getType() == FormField::ListMultiType) {
std::string text = option.value;
selected.push_back(std::find(field->getValues().begin(), field->getValues().end(), text) != field->getValues().end());
}
}
}
for (int i = 0; i < listWidget->count(); i++) {
QListWidgetItem* item = listWidget->item(i);
item->setSelected(selected[i]);
}
return listWidget;
}
QWidget* QtFormWidget::createWidget(FormField::ref field, const FormField::Type type, const size_t index) {
QWidget* widget = nullptr;
if (type == FormField::BooleanType) {
QCheckBox* checkWidget = new QCheckBox(this);
checkWidget->setCheckState(field->getBoolValue() ? Qt::Checked : Qt::Unchecked);
widget = checkWidget;
}
if (type == FormField::FixedType) {
QString value = field->getFixedValue().c_str();
widget = new QLabel(value, this);
}
if (type == FormField::ListSingleType) {
widget = createList(field);
@@ -130,112 +128,112 @@ QWidget* QtFormWidget::createWidget(FormField::ref field, const FormField::Type
widget = lineWidget;
}
if (type == FormField::TextSingleType) {
QString value = field->getTextSingleValue().c_str();
widget = new QLineEdit(value, this);
}
if (type == FormField::JIDSingleType) {
QString value = field->getJIDSingleValue().toString().c_str();
widget = new QLineEdit(value, this);
}
if (type == FormField::JIDMultiType) {
QString text = boost::join(field->getValues(), "\n").c_str();
QTextEdit* textWidget = new QTextEdit(this);
textWidget->setPlainText(text);
widget = textWidget;
}
if (type == FormField::ListMultiType) {
widget = createList(field);
}
std::string indexString;
if (index) {
/* for multi-item forms we need to distinguish between the different rows */
indexString = boost::lexical_cast<std::string>(index);
}
fields_[field->getName() + indexString] = widget;
return widget;
}
Form::ref QtFormWidget::getCompletedForm() {
Form::ref result(new Form(Form::SubmitType));
- foreach (std::shared_ptr<FormField> field, form_->getFields()) {
+ for (auto&& field : form_->getFields()) {
std::shared_ptr<FormField> resultField = std::make_shared<FormField>(field->getType());
if (field->getType() == FormField::BooleanType) {
resultField->setBoolValue(qobject_cast<QCheckBox*>(fields_[field->getName()])->checkState() == Qt::Checked);
}
if (field->getType() == FormField::FixedType || field->getType() == FormField::HiddenType) {
resultField->addValue(field->getValues().empty() ? "" : field->getValues()[0]);
}
if (field->getType() == FormField::ListSingleType) {
QListWidget* listWidget = qobject_cast<QListWidget*>(fields_[field->getName()]);
if (listWidget->selectedItems().size() > 0) {
int i = listWidget->row(listWidget->selectedItems()[0]);
resultField->addValue(field->getOptions()[i].value);
}
}
if (field->getType() == FormField::TextMultiType) {
QTextEdit* widget = qobject_cast<QTextEdit*>(fields_[field->getName()]);
QString string = widget->toPlainText();
if (!string.isEmpty()) {
resultField->setTextMultiValue(Q2PSTRING(string));
}
}
if (field->getType() == FormField::TextPrivateType || field->getType() == FormField::TextSingleType || field->getType() == FormField::JIDSingleType) {
QLineEdit* widget = qobject_cast<QLineEdit*>(fields_[field->getName()]);
QString string = widget->text();
if (!string.isEmpty()) {
resultField->addValue(Q2PSTRING(string));
}
}
if (field->getType() == FormField::JIDMultiType) {
QTextEdit* widget = qobject_cast<QTextEdit*>(fields_[field->getName()]);
QString string = widget->toPlainText();
if (!string.isEmpty()) {
QStringList lines = string.split("\n");
- foreach (QString line, lines) {
+ for (auto&& line : lines) {
resultField->addValue(Q2PSTRING(line));
}
}
}
if (field->getType() == FormField::ListMultiType) {
QListWidget* listWidget = qobject_cast<QListWidget*>(fields_[field->getName()]);
- foreach (QListWidgetItem* item, listWidget->selectedItems()) {
+ for (auto item : listWidget->selectedItems()) {
resultField->addValue(field->getOptions()[listWidget->row(item)].value);
}
}
resultField->setName(field->getName());
result->addField(resultField);
}
return result;
}
template<class T> void QtFormWidget::setEnabled(QWidget* rawWidget, bool editable) {
T* widget = qobject_cast<T*>(rawWidget);
if (widget) {
widget->setEnabled(editable);
}
}
template<class T> void QtFormWidget::setEditable(QWidget* rawWidget, bool editable) {
T* widget = qobject_cast<T*>(rawWidget);
if (widget) {
widget->setReadOnly(!editable);
}
}
void QtFormWidget::setEditable(bool editable) {
if (!form_) {
return;
}
- foreach (std::shared_ptr<FormField> field, form_->getFields()) {
+ for (auto&& field : form_->getFields()) {
QWidget* widget = nullptr;
if (field) {
widget = fields_[field->getName()];
}
setEnabled<QCheckBox>(widget, editable);
setEnabled<QListWidget>(widget, editable);
setEditable<QTextEdit>(widget, editable);
setEditable<QLineEdit>(widget, editable);
}
}
}
diff --git a/Swift/QtUI/QtHistoryWindow.cpp b/Swift/QtUI/QtHistoryWindow.cpp
index 53e7ffe..77a7f12 100644
--- a/Swift/QtUI/QtHistoryWindow.cpp
+++ b/Swift/QtUI/QtHistoryWindow.cpp
@@ -149,61 +149,61 @@ void QtHistoryWindow::addMessage(const std::string &message, const std::string &
previousBottomSenderName_ = P2QSTRING(senderName);
}
// keep track of the days viewable in the chatView
if (!dates_.count(date)) {
dates_.insert(date);
}
}
void QtHistoryWindow::handleSomethingSelectedChanged(RosterItem* item) {
onSelectedContactChanged(item);
}
void QtHistoryWindow::resetConversationView() {
previousTopMessageWasSelf_ = false;
previousBottomMessageWasSelf_ = false;
previousTopSenderName_.clear();
previousBottomSenderName_.clear();
dates_.clear();
conversation_->resetView();
}
void QtHistoryWindow::handleScrollRequested(int pos) {
// first message starts with offset 5
if (pos < 5) {
pos = 5;
}
QDate currentDate;
- foreach (const QDate& date, dates_) {
+ for (const auto& date : dates_) {
int snippetPosition = conversation_->getSnippetPositionByDate(date);
if (snippetPosition <= pos) {
currentDate = date;
}
}
if (ui_.calendarWidget_->selectedDate() != currentDate) {
ui_.calendarWidget_->setSelectedDate(currentDate);
}
}
void QtHistoryWindow::handleScrollReachedTop() {
if (dates_.empty()) {
return;
}
int year, month, day;
QDate firstDate = *dates_.begin();
firstDate.getDate(&year, &month, &day);
onScrollReachedTop(boost::gregorian::date(boost::numeric_cast<unsigned short>(year), boost::numeric_cast<unsigned short>(month), boost::numeric_cast<unsigned short>(day)));
}
void QtHistoryWindow::handleScrollReachedBottom() {
if (dates_.empty()) {
return;
}
int year, month, day;
QDate lastDate = *dates_.rbegin();
lastDate.getDate(&year, &month, &day);
diff --git a/Swift/QtUI/QtLoginWindow.cpp b/Swift/QtUI/QtLoginWindow.cpp
index d91f694..865d8b5 100644
--- a/Swift/QtUI/QtLoginWindow.cpp
+++ b/Swift/QtUI/QtLoginWindow.cpp
@@ -472,61 +472,61 @@ void QtLoginWindow::handleToggleNotifications(bool enabled) {
settings_->storeSetting(SettingConstants::SHOW_NOTIFICATIONS, enabled);
}
void QtLoginWindow::handleQuit() {
onQuitRequest();
}
void QtLoginWindow::quit() {
QApplication::quit();
}
void QtLoginWindow::setInitialMenus() {
menuBar_->clear();
menuBar_->addMenu(swiftMenu_);
#ifdef SWIFTEN_PLATFORM_MACOSX
menuBar_->addMenu(generalMenu_);
#endif
}
void QtLoginWindow::morphInto(MainWindow *mainWindow) {
setEnabled(false);
QtMainWindow *qtMainWindow = dynamic_cast<QtMainWindow*>(mainWindow);
assert(qtMainWindow);
stack_->removeWidget(loginWidgetWrapper_);
stack_->addWidget(qtMainWindow);
stack_->setCurrentWidget(qtMainWindow);
setEnabled(true);
setInitialMenus();
std::vector<QMenu*> mainWindowMenus = qtMainWindow->getMenus();
viewMenu_ = mainWindowMenus[0];
- foreach (QMenu* menu, mainWindowMenus) {
+ for (auto menu : mainWindowMenus) {
menuBar_->addMenu(menu);
}
setFocus();
}
void QtLoginWindow::setMessage(const std::string& message) {
if (!message.empty()) {
message_->setText("<center><font color=\"red\">" + P2QSTRING(message) + "</font></center>");
}
else {
message_->setText("");
}
}
void QtLoginWindow::toggleBringToFront() {
if (!isVisible()) {
bringToFront();
}
else {
window()->hide();
}
}
void QtLoginWindow::bringToFront() {
window()->showNormal();
window()->raise();
window()->activateWindow();
}
void QtLoginWindow::hide() {
diff --git a/Swift/QtUI/QtPlainChatView.cpp b/Swift/QtUI/QtPlainChatView.cpp
index d682cfa..05a2eb0 100644
--- a/Swift/QtUI/QtPlainChatView.cpp
+++ b/Swift/QtUI/QtPlainChatView.cpp
@@ -1,78 +1,77 @@
/*
* Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/QtPlainChatView.h>
#include <QDialog>
#include <QFileDialog>
#include <QInputDialog>
#include <QLabel>
#include <QMenu>
#include <QProgressBar>
#include <QPushButton>
#include <QScrollBar>
#include <QTextEdit>
#include <QVBoxLayout>
#include <Swiften/Base/FileSize.h>
-#include <Swiften/Base/foreach.h>
#include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h>
#include <Swift/Controllers/UIEvents/UIEventStream.h>
#include <Swift/QtUI/ChatSnippet.h>
#include <Swift/QtUI/QtSwiftUtil.h>
#include <Swift/QtUI/QtUtilities.h>
namespace Swift {
QtPlainChatView::QtPlainChatView(QtChatWindow *window, UIEventStream* eventStream)
: QtChatView(window), window_(window), eventStream_(eventStream), idGenerator_(0) {
QVBoxLayout* mainLayout = new QVBoxLayout(this);
mainLayout->setSpacing(0);
mainLayout->setContentsMargins(0,0,0,0);
log_ = new LogTextEdit(this);
log_->setReadOnly(true);
log_->setAccessibleName(tr("Chat Messages"));
mainLayout->addWidget(log_);
}
QtPlainChatView::~QtPlainChatView() {
}
QString chatMessageToString(const ChatWindow::ChatMessage& message) {
QString result;
- foreach (std::shared_ptr<ChatWindow::ChatMessagePart> part, message.getParts()) {
+ for (auto&& part : message.getParts()) {
std::shared_ptr<ChatWindow::ChatTextMessagePart> textPart;
std::shared_ptr<ChatWindow::ChatURIMessagePart> uriPart;
std::shared_ptr<ChatWindow::ChatEmoticonMessagePart> emoticonPart;
std::shared_ptr<ChatWindow::ChatHighlightingMessagePart> highlightPart;
if ((textPart = std::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) {
QString text = QtUtilities::htmlEscape(P2QSTRING(textPart->text));
text.replace("\n","<br/>");
result += text;
continue;
}
if ((uriPart = std::dynamic_pointer_cast<ChatWindow::ChatURIMessagePart>(part))) {
QString uri = QtUtilities::htmlEscape(P2QSTRING(uriPart->target));
result += "<a href='" + uri + "' >" + uri + "</a>";
continue;
}
if ((emoticonPart = std::dynamic_pointer_cast<ChatWindow::ChatEmoticonMessagePart>(part))) {
result += P2QSTRING(emoticonPart->alternativeText);
continue;
}
if ((highlightPart = std::dynamic_pointer_cast<ChatWindow::ChatHighlightingMessagePart>(part))) {
//FIXME: Maybe do something here. Anything, really.
continue;
}
}
return result;
}
std::string QtPlainChatView::addMessage(const ChatWindow::ChatMessage& message, const std::string& senderName, bool senderIsSelf, std::shared_ptr<SecurityLabel> label, const std::string& /*avatarPath*/, const boost::posix_time::ptime& time) {
QString text = "<p>";
diff --git a/Swift/QtUI/QtProfileWindow.cpp b/Swift/QtUI/QtProfileWindow.cpp
index 461ea38..80e275b 100644
--- a/Swift/QtUI/QtProfileWindow.cpp
+++ b/Swift/QtUI/QtProfileWindow.cpp
@@ -129,39 +129,39 @@ void QtProfileWindow::updateTitle() {
setWindowTitle(tr("Edit Profile") + jidString);
} else {
setWindowTitle(tr("Show Profile") + jidString);
}
}
void QtProfileWindow::updateWindowSize() {
// Delay resizing to the end of the event loop, because Qt calculates the correct layout asynchronously.
// Qt will post LayoutRequests for widgets on the event loop on show and widgets will recaluclate their
// layout as they process these events.
// We use the complete and correct size hint from the freshly calculated layout by delaying execution of
// the resize code to the end of Qt's event loop.
if (!adjustSizeTimer.isActive()) {
adjustSizeTimer.start(0);
}
}
void QtProfileWindow::closeEvent(QCloseEvent* event) {
event->accept();
onWindowAboutToBeClosed(jid);
}
void QtProfileWindow::handleSave() {
onVCardChangeRequest(ui->vcard->getVCard());
}
void QtProfileWindow::handleAdjustSizeTimeout() {
// Force recaluclation of all layout geometry in children widgets.
// This is required on Windows to have the correct size even on first show.
QList<QWidget *> children = findChildren<QWidget*>();
- foreach(QWidget* child, children) {
+ for (auto child : children) {
child->updateGeometry();
}
updateGeometry();
adjustSize();
}
}
diff --git a/Swift/QtUI/QtSettingsProvider.cpp b/Swift/QtUI/QtSettingsProvider.cpp
index 3c32dc8..42ac22d 100644
--- a/Swift/QtUI/QtSettingsProvider.cpp
+++ b/Swift/QtUI/QtSettingsProvider.cpp
@@ -50,75 +50,75 @@ void QtSettingsProvider::storeSetting(const Setting<bool>& setting, const bool&
if (getSetting(setting) != settingValue) {
changed = true;
}
settings_.setValue(setting.getKey().c_str(), settingValue);
if (changed) {
onSettingChanged(setting.getKey());
}
updatePermissions();
}
int QtSettingsProvider::getSetting(const Setting<int>& setting) {
QVariant variant = settings_.value(setting.getKey().c_str());
return variant.isNull() ? setting.getDefaultValue() : variant.toInt();
}
void QtSettingsProvider::storeSetting(const Setting<int>& setting, const int& settingValue) {
bool changed = false;
if (getSetting(setting) != settingValue) {
changed = true;
}
settings_.setValue(setting.getKey().c_str(), settingValue);
if (changed) {
onSettingChanged(setting.getKey());
}
updatePermissions();
}
std::vector<std::string> QtSettingsProvider::getAvailableProfiles() {
std::vector<std::string> profiles;
QVariant profilesVariant = settings_.value("profileList");
- foreach(QString profileQString, profilesVariant.toStringList()) {
+ for (const auto& profileQString : profilesVariant.toStringList()) {
profiles.push_back(std::string(profileQString.toUtf8()));
}
return profiles;
}
void QtSettingsProvider::createProfile(const std::string& profile) {
QStringList stringList = settings_.value("profileList").toStringList();
stringList.append(profile.c_str());
settings_.setValue("profileList", stringList);
updatePermissions();
}
void QtSettingsProvider::removeProfile(const std::string& profile) {
QString profileStart(QString(profile.c_str()) + ":");
- foreach (QString key, settings_.allKeys()) {
+ for (auto&& key : settings_.allKeys()) {
if (key.startsWith(profileStart)) {
settings_.remove(key);
}
}
QStringList stringList = settings_.value("profileList").toStringList();
stringList.removeAll(profile.c_str());
settings_.setValue("profileList", stringList);
updatePermissions();
}
QSettings* QtSettingsProvider::getQSettings() {
return &settings_;
}
void QtSettingsProvider::updatePermissions() {
#if !defined(Q_OS_WIN) && !defined(Q_OS_MAC)
QFile file(settings_.fileName());
if (file.exists()) {
file.setPermissions(QFile::ReadOwner|QFile::WriteOwner);
}
#endif
}
bool QtSettingsProvider::getIsSettingFinal(const std::string& /*settingPath*/) {
return false;
}
}
diff --git a/Swift/QtUI/QtSingleWindow.cpp b/Swift/QtUI/QtSingleWindow.cpp
index ab7e81e..1fba497 100644
--- a/Swift/QtUI/QtSingleWindow.cpp
+++ b/Swift/QtUI/QtSingleWindow.cpp
@@ -1,81 +1,79 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/QtSingleWindow.h>
-#include <Swiften/Base/foreach.h>
-
#include <Swift/QtUI/QtChatTabs.h>
#include <Swift/QtUI/QtSettingsProvider.h>
namespace Swift {
static const QString SINGLE_WINDOW_GEOMETRY = QString("SINGLE_WINDOW_GEOMETRY");
static const QString SINGLE_WINDOW_SPLITS = QString("SINGLE_WINDOW_SPLITS");
QtSingleWindow::QtSingleWindow(QtSettingsProvider* settings) : QSplitter() {
settings_ = settings;
QVariant geometryVariant = settings_->getQSettings()->value(SINGLE_WINDOW_GEOMETRY);
if (geometryVariant.isValid()) {
restoreGeometry(geometryVariant.toByteArray());
}
connect(this, SIGNAL(splitterMoved(int, int)), this, SLOT(handleSplitterMoved(int, int)));
restoreSplitters();
}
QtSingleWindow::~QtSingleWindow() {
}
void QtSingleWindow::addWidget(QWidget* widget) {
QtChatTabs* tabs = dynamic_cast<QtChatTabs*>(widget);
if (tabs) {
connect(tabs, SIGNAL(onTitleChanged(const QString&)), this, SLOT(handleTabsTitleChanged(const QString&)));
}
QSplitter::addWidget(widget);
}
void QtSingleWindow::handleTabsTitleChanged(const QString& title) {
setWindowTitle(title);
}
void QtSingleWindow::handleSplitterMoved(int, int) {
QList<QVariant> variantValues;
QList<int> intValues = sizes();
- foreach (int value, intValues) {
+ for (const auto& value : intValues) {
variantValues.append(QVariant(value));
}
settings_->getQSettings()->setValue(SINGLE_WINDOW_SPLITS, QVariant(variantValues));
}
void QtSingleWindow::restoreSplitters() {
QList<QVariant> variantValues = settings_->getQSettings()->value(SINGLE_WINDOW_SPLITS).toList();
QList<int> intValues;
- foreach (QVariant value, variantValues) {
+ for (auto&& value : variantValues) {
intValues.append(value.toInt());
}
setSizes(intValues);
}
void QtSingleWindow::insertAtFront(QWidget* widget) {
insertWidget(0, widget);
restoreSplitters();
}
void QtSingleWindow::handleGeometryChanged() {
settings_->getQSettings()->setValue(SINGLE_WINDOW_GEOMETRY, saveGeometry());
}
void QtSingleWindow::resizeEvent(QResizeEvent* event) {
handleGeometryChanged();
QSplitter::resizeEvent(event);
}
void QtSingleWindow::moveEvent(QMoveEvent*) {
handleGeometryChanged();
}
}
diff --git a/Swift/QtUI/QtSpellCheckHighlighter.cpp b/Swift/QtUI/QtSpellCheckHighlighter.cpp
index 6565b06..cb467e2 100644
--- a/Swift/QtUI/QtSpellCheckHighlighter.cpp
+++ b/Swift/QtUI/QtSpellCheckHighlighter.cpp
@@ -1,41 +1,41 @@
/*
- * Copyright (c) 2014 Isode Limited.
+ * Copyright (c) 2014-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/QtSpellCheckHighlighter.h>
#include <SwifTools/SpellChecker.h>
#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
QtSpellCheckHighlighter::QtSpellCheckHighlighter(QTextDocument* parent, SpellChecker* spellChecker) : QSyntaxHighlighter(parent), checker_(spellChecker) {
}
QtSpellCheckHighlighter::~QtSpellCheckHighlighter() {
}
void QtSpellCheckHighlighter::highlightBlock(const QString& text) {
misspelledPositions_.clear();
std::string fragment = Q2PSTRING(text);
checker_->checkFragment(fragment, misspelledPositions_);
QTextCharFormat spellingErrorFormat;
spellingErrorFormat.setUnderlineColor(QColor(Qt::red));
spellingErrorFormat.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline);
- foreach (PositionPair position, misspelledPositions_) {
+ for (auto&& position : misspelledPositions_) {
setFormat(boost::get<0>(position), boost::get<1>(position) - boost::get<0>(position), spellingErrorFormat);
};
}
PositionPairList QtSpellCheckHighlighter::getMisspelledPositions() const {
return misspelledPositions_;
}
}
diff --git a/Swift/QtUI/QtStatusWidget.cpp b/Swift/QtUI/QtStatusWidget.cpp
index 2e9e4cc..b175e5c 100644
--- a/Swift/QtUI/QtStatusWidget.cpp
+++ b/Swift/QtUI/QtStatusWidget.cpp
@@ -117,120 +117,120 @@ QtStatusWidget::QtStatusWidget(StatusCache* statusCache, QWidget *parent) : QWid
QtStatusWidget::~QtStatusWidget() {
delete menu_;
delete connectingMovie_;
}
void QtStatusWidget::handleApplicationFocusChanged(QWidget* /*old*/, QWidget* /*now*/) {
QWidget* now = qApp->focusWidget();
if (!editing_ || stack_->currentIndex() == 0) {
return;
}
if (!now || (now != menu_ && now != statusEdit_ && !now->isAncestorOf(statusEdit_) && !now->isAncestorOf(menu_) && !statusEdit_->isAncestorOf(now) && !menu_->isAncestorOf(now))) {
handleEditCancelled();
}
}
void QtStatusWidget::mousePressEvent(QMouseEvent*) {
if (stack_->currentIndex() == 0) {
handleClicked();
}
}
void QtStatusWidget::generateList() {
if (!editing_) {
return;
}
QString text = statusEdit_->text();
newStatusText_ = text;
menu_->clear();
- foreach (StatusShow::Type type, icons_.keys()) {
+ for (const auto& type : icons_.keys()) {
QListWidgetItem* item = new QListWidgetItem(text == "" ? getNoMessage() : text, menu_);
item->setIcon(icons_[type]);
item->setToolTip(P2QSTRING(statusShowTypeToFriendlyName(type)) + ": " + item->text());
item->setStatusTip(item->toolTip());
item->setData(Qt::UserRole, QVariant(type));
}
std::vector<StatusCache::PreviousStatus> previousStatuses = statusCache_->getMatches(Q2PSTRING(text), 8);
- foreach (StatusCache::PreviousStatus savedStatus, previousStatuses) {
+ for (const auto& savedStatus : previousStatuses) {
if (savedStatus.first.empty() || std::find_if(allTypes_.begin(), allTypes_.end(),
savedStatus.second == lambda::_1 && savedStatus.first == lambda::bind(&statusShowTypeToFriendlyName, lambda::_1)) != allTypes_.end()) {
continue;
}
QListWidgetItem* item = new QListWidgetItem(P2QSTRING(savedStatus.first), menu_);
item->setIcon(icons_[savedStatus.second]);
item->setToolTip(item->text());
item->setStatusTip(item->toolTip());
item->setData(Qt::UserRole, QVariant(savedStatus.second));
}
- foreach (StatusShow::Type type, icons_.keys()) {
+ for (const auto& type : icons_.keys()) {
if (Q2PSTRING(text) == statusShowTypeToFriendlyName(type)) {
continue;
}
QListWidgetItem* item = new QListWidgetItem(P2QSTRING(statusShowTypeToFriendlyName(type)), menu_);
item->setIcon(icons_[type]);
item->setToolTip(item->text());
item->setStatusTip(item->toolTip());
item->setData(Qt::UserRole, QVariant(type));
}
resizeMenu();
}
void QtStatusWidget::resizeMenu() {
int height = menu_->sizeHintForRow(0) * menu_->count();
int marginLeft;
int marginTop;
int marginRight;
int marginBottom;
menu_->getContentsMargins(&marginLeft, &marginTop, &marginRight, &marginBottom);
height += marginTop + marginBottom;
menu_->setGeometry(menu_->x(), menu_->y(), menu_->width(), height);
}
void QtStatusWidget::handleClicked() {
editing_ = true;
QDesktopWidget* desktop = QApplication::desktop();
int screen = desktop->screenNumber(this);
QPoint point = mapToGlobal(QPoint(0, height()));
QRect geometry = desktop->availableGeometry(screen);
int x = point.x();
int y = point.y();
int width = 200;
int height = 80;
int screenWidth = geometry.x() + geometry.width();
if (x + width > screenWidth) {
x = screenWidth - width;
}
- //foreach (StatusShow::Type type, allTypes_) {
+ //for (StatusShow::Type type : allTypes_) {
// if (statusEdit_->text() == P2QSTRING(statusShowTypeToFriendlyName(type))) {
statusEdit_->setText("");
// }
//}
generateList();
height = menu_->sizeHintForRow(0) * menu_->count();
int marginLeft;
int marginTop;
int marginRight;
int marginBottom;
menu_->getContentsMargins(&marginLeft, &marginTop, &marginRight, &marginBottom);
height += marginTop + marginBottom;
width += marginLeft + marginRight;
menu_->setGeometry(x, y, width, height);
menu_->move(x, y);
menu_->setMaximumWidth(width);
menu_->show();
activateWindow();
statusEdit_->selectAll();
stack_->setCurrentIndex(1);
statusEdit_->setFocus();
connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(handleApplicationFocusChanged(QWidget*, QWidget*)), Qt::QueuedConnection);
}
void QtStatusWidget::viewMode() {
disconnect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(handleApplicationFocusChanged(QWidget*, QWidget*)));
editing_ = false;
menu_->hide();
diff --git a/Swift/QtUI/QtSubscriptionRequestWindow.cpp b/Swift/QtUI/QtSubscriptionRequestWindow.cpp
index eea13f2..c8c4178 100644
--- a/Swift/QtUI/QtSubscriptionRequestWindow.cpp
+++ b/Swift/QtUI/QtSubscriptionRequestWindow.cpp
@@ -46,47 +46,47 @@ QtSubscriptionRequestWindow::QtSubscriptionRequestWindow(std::shared_ptr<Subscri
layout->addWidget(new QLabel);
layout->addLayout(buttonLayout);
layout->addWidget(new QLabel);
QLabel* footer = new QLabel(tr("(If you choose to defer this choice, you will be asked again when you next login.)"));
layout->addWidget(footer);
}
setLayout(layout);
}
void QtSubscriptionRequestWindow::handleYes() {
event_->accept();
delete this;
}
void QtSubscriptionRequestWindow::handleNo() {
event_->decline();
delete this;
}
void QtSubscriptionRequestWindow::handleDefer() {
event_->defer();
delete this;
}
QtSubscriptionRequestWindow::~QtSubscriptionRequestWindow() {
windows_.removeOne(this);
}
QtSubscriptionRequestWindow* QtSubscriptionRequestWindow::getWindow(std::shared_ptr<SubscriptionRequestEvent> event, QWidget* parent) {
- foreach (QtSubscriptionRequestWindow* window, windows_) {
+ for (auto window : windows_) {
if (window->getEvent() == event) {
return window;
}
}
QtSubscriptionRequestWindow* window = new QtSubscriptionRequestWindow(event, parent);
windows_.append(window);
return window;
}
std::shared_ptr<SubscriptionRequestEvent> QtSubscriptionRequestWindow::getEvent() {
return event_;
}
QList<QtSubscriptionRequestWindow*> QtSubscriptionRequestWindow::windows_;
}
diff --git a/Swift/QtUI/QtTabbable.cpp b/Swift/QtUI/QtTabbable.cpp
index bad6315..ed0963b 100644
--- a/Swift/QtUI/QtTabbable.cpp
+++ b/Swift/QtUI/QtTabbable.cpp
@@ -1,44 +1,43 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/QtTabbable.h>
#include <QApplication>
#include <QKeyEvent>
#include <QShortcut>
#include <Swiften/Base/Platform.h>
-#include <Swiften/Base/foreach.h>
#include <Swift/QtUI/QtChatTabs.h>
#include <Swift/QtUI/QtUtilities.h>
namespace Swift {
QtTabbable::QtTabbable() : QWidget() {
}
QtTabbable::~QtTabbable() {
emit windowClosing();
}
bool QtTabbable::isWidgetSelected() {
/*isActiveWindow() shouldn't be necessary, but I don't trust it as far as I can throw it*/
if (!isActiveWindow()) {
return false;
}
QtChatTabs* parent = qobject_cast<QtChatTabs*>(window());
return parent ? parent->getCurrentTab() == this : isAncestorOf(QApplication::focusWidget());
}
bool QtTabbable::event(QEvent* event) {
QKeyEvent* keyEvent = dynamic_cast<QKeyEvent*>(event);
if (keyEvent) {
// According to Qt's focus documentation, one can only override CTRL+TAB via reimplementing QWidget::event().
if (keyEvent->modifiers().testFlag(QtUtilities::ctrlHardwareKeyModifier) && keyEvent->key() == Qt::Key_Tab) {
// Only handle KeyRelease event as Linux also generate KeyPress event in case of CTRL+TAB being pressed
// in the roster of a MUC.
diff --git a/Swift/QtUI/QtVCardWidget/QtTagComboBox.cpp b/Swift/QtUI/QtVCardWidget/QtTagComboBox.cpp
index ed36580..02ceb0a 100644
--- a/Swift/QtUI/QtVCardWidget/QtTagComboBox.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtTagComboBox.cpp
@@ -23,86 +23,86 @@ QtTagComboBox::QtTagComboBox(QWidget* parent) : QComboBox(parent) {
displayItem = new QStandardItem();
displayItem->setText("");
displayModel->insertRow(0, displayItem);
editMenu = new QMenu(this);
this->setModel(displayModel);
editable = true;
}
QtTagComboBox::~QtTagComboBox() {
}
bool QtTagComboBox::isEditable() const {
return editable;
}
void QtTagComboBox::setEditable(const bool editable) {
this->editable = editable;
}
void QtTagComboBox::addTag(const QString &id, const QString &label) {
QAction* tagAction = new QAction(editMenu);
tagAction->setText(label);
tagAction->setCheckable(true);
tagAction->setData(QString(id));
editMenu->addAction(tagAction);
}
void QtTagComboBox::setTag(const QString &id, bool value) {
QList<QAction*> tagActions = editMenu->actions();
- foreach(QAction* action, tagActions) {
+ for (auto action : tagActions) {
if (action->data() == id) {
action->setChecked(value);
updateDisplayItem();
return;
}
}
}
bool QtTagComboBox::isTagSet(const QString &id) const {
QList<QAction*> tagActions = editMenu->actions();
- foreach(QAction* action, tagActions) {
+ for (auto action : tagActions) {
if (action->data() == id) {
return action->isChecked();
}
}
return false;
}
void QtTagComboBox::showPopup() {
}
void QtTagComboBox::hidePopup() {
}
bool QtTagComboBox::event(QEvent* event) {
if (event->type() == QEvent::MouseButtonPress ||
event->type() == QEvent::KeyRelease) {
if (!editable) return true;
QPoint p = mapToGlobal(QPoint(0,0));
p += QPoint(0, height());
editMenu->exec(p);
updateDisplayItem();
return true;
}
return QComboBox::event(event);
}
void QtTagComboBox::updateDisplayItem() {
QList<QAction*> tagActions = editMenu->actions();
QString text = "";
- foreach(QAction* action, tagActions) {
+ for (auto action : tagActions) {
if (action->isChecked()) {
if (text != "") {
text += ", ";
}
text += action->text();
}
}
setItemText(0, text);
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp
index 4043dbc..596006a 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp
@@ -63,61 +63,61 @@ void QtVCardAddressField::setupContentWidgets() {
pocodeLineEdit->setPlaceholderText(tr("Postal Code"));
regionLineEdit->setPlaceholderText(tr("Region"));
countryLineEdit->setPlaceholderText(tr("Country"));
#endif
deliveryTypeLabel = new QtElidingLabel(this);
deliveryTypeLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
getGridLayout()->addWidget(deliveryTypeLabel, getGridLayout()->rowCount()-3, 4, Qt::AlignVCenter);
domesticRadioButton = new QRadioButton(tr("Domestic Delivery"), this);
getGridLayout()->addWidget(domesticRadioButton, getGridLayout()->rowCount()-2, 4, Qt::AlignVCenter);
internationalRadioButton = new QRadioButton(tr("International Delivery"), this);
getGridLayout()->addWidget(internationalRadioButton, getGridLayout()->rowCount()-1, 4, Qt::AlignVCenter);
buttonGroup = new QButtonGroup(this);
buttonGroup->addButton(domesticRadioButton);
buttonGroup->addButton(internationalRadioButton);
setTabOrder(internationalRadioButton, getTagComboBox());
getTagComboBox()->addTag("postal", tr("Postal"));
getTagComboBox()->addTag("parcel", tr("Parcel"));
QtVCardHomeWork::setTagComboBox(getTagComboBox());
textFields << streetLineEdit << poboxLineEdit << addressextLineEdit << cityLineEdit << pocodeLineEdit << regionLineEdit << countryLineEdit;
childWidgets << deliveryTypeLabel << domesticRadioButton << internationalRadioButton;
}
void QtVCardAddressField::customCleanup() {
- foreach(QWidget* widget, textFields) {
+ for (auto widget : textFields) {
widget->hide();
textFieldGridLayout->removeWidget(widget);
}
getGridLayout()->removeItem(textFieldGridLayoutItem);
}
bool QtVCardAddressField::isEmpty() const {
return streetLineEdit->text().isEmpty() &&
poboxLineEdit->text().isEmpty() &&
addressextLineEdit->text().isEmpty() &&
cityLineEdit->text().isEmpty() &&
pocodeLineEdit->text().isEmpty() &&
regionLineEdit->text().isEmpty() &&
countryLineEdit->text().isEmpty();
}
void QtVCardAddressField::setAddress(const VCard::Address& address) {
setPreferred(address.isPreferred);
setHome(address.isHome);
setWork(address.isWork);
getTagComboBox()->setTag("postal", address.isPostal);
getTagComboBox()->setTag("parcel", address.isParcel);
domesticRadioButton->setChecked(address.deliveryType == VCard::DomesticDelivery);
internationalRadioButton->setChecked(address.deliveryType == VCard::InternationalDelivery);
streetLineEdit->setText(P2QSTRING(address.street));
poboxLineEdit->setText(P2QSTRING(address.poBox));
addressextLineEdit->setText(P2QSTRING(address.addressExtension));
cityLineEdit->setText(P2QSTRING(address.locality));
@@ -143,40 +143,40 @@ VCard::Address QtVCardAddressField::getAddress() const {
address.country = Q2PSTRING(countryLineEdit->text());
return address;
}
void QtVCardAddressField::handleEditibleChanged(bool isEditable) {
assert(streetLineEdit);
assert(poboxLineEdit);
assert(addressextLineEdit);
assert(cityLineEdit);
assert(pocodeLineEdit);
assert(regionLineEdit);
assert(countryLineEdit);
assert(deliveryTypeLabel);
assert(domesticRadioButton);
assert(internationalRadioButton);
streetLineEdit->setEditable(isEditable);
poboxLineEdit->setEditable(isEditable);
addressextLineEdit->setEditable(isEditable);
cityLineEdit->setEditable(isEditable);
pocodeLineEdit->setEditable(isEditable);
regionLineEdit->setEditable(isEditable);
countryLineEdit->setEditable(isEditable);
deliveryTypeLabel->setText(buttonGroup->checkedButton() == nullptr ? "" : buttonGroup->checkedButton()->text());
deliveryTypeLabel->setVisible(!isEditable);
domesticRadioButton->setVisible(isEditable);
internationalRadioButton->setVisible(isEditable);
- foreach (QWidget* widget, textFields) {
+ for (auto widget : textFields) {
QtResizableLineEdit* lineEdit;
if ((lineEdit = dynamic_cast<QtResizableLineEdit*>(widget))) {
lineEdit->setVisible(isEditable ? true : !lineEdit->text().isEmpty());
lineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }");
}
}
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp
index ab69cba..9bb6a35 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp
@@ -94,61 +94,61 @@ void QtVCardGeneralField::setStarVisible(const bool isVisible) {
starVisible = isVisible;
updatePreferredStarVisibility();
}
bool QtVCardGeneralField::getStarVisible() const {
return starVisible;
}
void QtVCardGeneralField::setPreferred(const bool preferred) {
if (preferredCheckBox) preferredCheckBox->setChecked(preferred);
updatePreferredStarVisibility();
}
bool QtVCardGeneralField::getPreferred() const {
return preferredCheckBox ? preferredCheckBox->isChecked() : false;
}
void QtVCardGeneralField::customCleanup() {
}
QtTagComboBox* QtVCardGeneralField::getTagComboBox() const {
return tagComboBox;
}
QGridLayout* QtVCardGeneralField::getGridLayout() const {
return layout;
}
void QtVCardGeneralField::handleCloseButtonClicked() {
customCleanup();
- foreach(QWidget* widget, childWidgets) {
+ for (auto widget : childWidgets) {
widget->hide();
layout->removeWidget(widget);
}
deleteField(this);
}
void QtVCardGeneralField::handlePreferredStarStateChanged(int state) {
if (state == Qt::Checked) {
QToolTip::showText(QCursor::pos(), tr("Marked as your preferred %1. Click again to undo.").arg(labelText));
}
}
void QtVCardGeneralField::updatePreferredStarVisibility() {
if (preferredCheckBox) {
bool showStar = false;
if (editable) {
if (starVisible) {
showStar = true;
}
else {
showStar = preferredCheckBox->isChecked();
}
}
else {
showStar = preferredCheckBox->isChecked();
}
preferredCheckBox->setVisible(showStar);
preferredCheckBox->setEnabled(editable);
}
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp
index 9e303b7..5162c73 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp
@@ -51,101 +51,101 @@ void QtVCardOrganizationField::setupContentWidgets() {
#if QT_VERSION >= 0x050000
unitsTreeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
#else
unitsTreeWidget->header()->setResizeMode(0, QHeaderView::Stretch);
#endif
unitsTreeWidget->setHeaderHidden(true);
unitsTreeWidget->setRootIsDecorated(false);
unitsTreeWidget->setEditTriggers(QAbstractItemView::DoubleClicked);
unitsTreeWidget->setItemDelegateForColumn(1, itemDelegate);
connect(unitsTreeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)), SLOT(handleItemChanged(QTreeWidgetItem*,int)));
getGridLayout()->addWidget(unitsTreeWidget, getGridLayout()->rowCount()-1, 4, 2, 1);
QTreeWidgetItem* item = new QTreeWidgetItem(QStringList("") << "");
item->setFlags(item->flags() | Qt::ItemIsEditable);
unitsTreeWidget->addTopLevelItem(item);
getTagComboBox()->hide();
organizationLabel->hide();
childWidgets << organizationLabel << organizationLineEdit << unitsTreeWidget;
}
bool QtVCardOrganizationField::isEmpty() const {
return organizationLineEdit->text().isEmpty() && unitsTreeWidget->model()->rowCount() != 0;
}
void QtVCardOrganizationField::setOrganization(const VCard::Organization& organization) {
organizationLineEdit->setText(P2QSTRING(organization.name));
unitsTreeWidget->clear();
- foreach(std::string unit, organization.units) {
+ for (const auto& unit : organization.units) {
QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(P2QSTRING(unit)) << "");
item->setFlags(item->flags() | Qt::ItemIsEditable);
unitsTreeWidget->addTopLevelItem(item);
}
QTreeWidgetItem* item = new QTreeWidgetItem(QStringList("") << "");
item->setFlags(item->flags() | Qt::ItemIsEditable);
unitsTreeWidget->addTopLevelItem(item);
}
VCard::Organization QtVCardOrganizationField::getOrganization() const {
VCard::Organization organization;
organization.name = Q2PSTRING(organizationLineEdit->text());
for(int i=0; i < unitsTreeWidget->topLevelItemCount(); ++i) {
QTreeWidgetItem* row = unitsTreeWidget->topLevelItem(i);
if (!row->text(0).isEmpty()) {
organization.units.push_back(Q2PSTRING(row->text(0)));
}
}
return organization;
}
void QtVCardOrganizationField::handleEditibleChanged(bool isEditable) {
assert(organizationLineEdit);
assert(unitsTreeWidget);
organizationLineEdit->setVisible(isEditable);
organizationLabel->setVisible(!isEditable);
if (!isEditable) {
QString label;
for(int i=0; i < unitsTreeWidget->topLevelItemCount(); ++i) {
QTreeWidgetItem* row = unitsTreeWidget->topLevelItem(i);
if (!row->text(0).isEmpty()) {
label += row->text(0) + ", ";
}
}
label += organizationLineEdit->text();
organizationLabel->setText(label);
}
unitsTreeWidget->setVisible(isEditable);
}
void QtVCardOrganizationField::handleItemChanged(QTreeWidgetItem *, int) {
guaranteeEmptyRow();
}
void QtVCardOrganizationField::handleRowsRemoved(const QModelIndex&, int, int) {
guaranteeEmptyRow();
}
void QtVCardOrganizationField::guaranteeEmptyRow() {
bool hasEmptyRow = false;
QList<QTreeWidgetItem*> rows = unitsTreeWidget->findItems("", Qt::MatchFixedString);
- foreach(QTreeWidgetItem* row, rows) {
+ for (auto row : rows) {
if (row->text(0).isEmpty()) {
hasEmptyRow = true;
}
}
if (!hasEmptyRow) {
QTreeWidgetItem* item = new QTreeWidgetItem(QStringList("") << "");
item->setFlags(item->flags() | Qt::ItemIsEditable);
unitsTreeWidget->addTopLevelItem(item);
unitsTreeWidget->setCurrentItem(item);
}
}
}
diff --git a/Swift/QtUI/QtWebKitChatView.cpp b/Swift/QtUI/QtWebKitChatView.cpp
index c0ce3dc..6fe9397 100644
--- a/Swift/QtUI/QtWebKitChatView.cpp
+++ b/Swift/QtUI/QtWebKitChatView.cpp
@@ -472,61 +472,61 @@ void QtWebKitChatView::resetTopInsertPoint() {
}
std::string QtWebKitChatView::addMessage(
const ChatWindow::ChatMessage& message,
const std::string& senderName,
bool senderIsSelf,
std::shared_ptr<SecurityLabel> label,
const std::string& avatarPath,
const boost::posix_time::ptime& time) {
return addMessage(chatMessageToHTML(message), senderName, senderIsSelf, label, avatarPath, "", time, message.getFullMessageHighlightAction(), ChatSnippet::getDirection(message));
}
QString QtWebKitChatView::getHighlightSpanStart(const std::string& text, const std::string& background) {
QString ecsapeColor = QtUtilities::htmlEscape(P2QSTRING(text));
QString escapeBackground = QtUtilities::htmlEscape(P2QSTRING(background));
if (ecsapeColor.isEmpty()) {
ecsapeColor = "black";
}
if (escapeBackground.isEmpty()) {
escapeBackground = "yellow";
}
return QString("<span style=\"color: %1; background: %2\">").arg(ecsapeColor).arg(escapeBackground);
}
QString QtWebKitChatView::getHighlightSpanStart(const HighlightAction& highlight) {
return getHighlightSpanStart(highlight.getTextColor(), highlight.getTextBackground());
}
QString QtWebKitChatView::chatMessageToHTML(const ChatWindow::ChatMessage& message) {
QString result;
- foreach (std::shared_ptr<ChatWindow::ChatMessagePart> part, message.getParts()) {
+ for (const auto& part : message.getParts()) {
std::shared_ptr<ChatWindow::ChatTextMessagePart> textPart;
std::shared_ptr<ChatWindow::ChatURIMessagePart> uriPart;
std::shared_ptr<ChatWindow::ChatEmoticonMessagePart> emoticonPart;
std::shared_ptr<ChatWindow::ChatHighlightingMessagePart> highlightPart;
if ((textPart = std::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) {
QString text = QtUtilities::htmlEscape(P2QSTRING(textPart->text));
text.replace("\n","<br/>");
result += text;
continue;
}
if ((uriPart = std::dynamic_pointer_cast<ChatWindow::ChatURIMessagePart>(part))) {
QString uri = QtUtilities::htmlEscape(P2QSTRING(uriPart->target));
result += "<a href='" + uri + "' >" + uri + "</a>";
continue;
}
if ((emoticonPart = std::dynamic_pointer_cast<ChatWindow::ChatEmoticonMessagePart>(part))) {
QString textStyle = showEmoticons_ ? "style='display:none'" : "";
QString imageStyle = showEmoticons_ ? "" : "style='display:none'";
result += "<span class='swift_emoticon_image' " + imageStyle + "><img src='" + P2QSTRING(emoticonPart->imagePath) + "'/></span><span class='swift_emoticon_text' " + textStyle + ">" + QtUtilities::htmlEscape(P2QSTRING(emoticonPart->alternativeText)) + "</span>";
continue;
}
if ((highlightPart = std::dynamic_pointer_cast<ChatWindow::ChatHighlightingMessagePart>(part))) {
QString spanStart = getHighlightSpanStart(highlightPart->action.getTextColor(), highlightPart->action.getTextBackground());
result += spanStart + QtUtilities::htmlEscape(P2QSTRING(highlightPart->text)) + "</span>";
continue;
}
}
return result;
diff --git a/Swift/QtUI/Roster/QtFilterWidget.cpp b/Swift/QtUI/Roster/QtFilterWidget.cpp
index d2e4d09..2e1ead9 100644
--- a/Swift/QtUI/Roster/QtFilterWidget.cpp
+++ b/Swift/QtUI/Roster/QtFilterWidget.cpp
@@ -73,72 +73,72 @@ bool QtFilterWidget::eventFilter(QObject*, QEvent* event) {
QPoint itemOffset(2,2);
QPoint contextMenuPosition = treeView_->visualRect(treeView_->currentIndex()).topLeft() + itemOffset;;
QApplication::postEvent(treeView_, new QContextMenuEvent(QContextMenuEvent::Keyboard, contextMenuPosition, treeView_->mapToGlobal(contextMenuPosition)));
return true;
} else if (keyEvent->key() == Qt::Key_Return) {
JID target = treeView_->selectedJID();
if (target.isValid()) {
eventStream_->send(std::make_shared<RequestChatUIEvent>(target));
}
filterLineEdit_->setText("");
updateRosterFilters();
} else if (keyEvent->key() == Qt::Key_Escape) {
filterLineEdit_->setText("");
} else {
isModifierSinglePressed_ = false;
}
}
filterLineEdit_->event(event);
if (event->type() == QEvent::KeyRelease) {
updateRosterFilters();
}
return true;
}
return false;
}
void QtFilterWidget::popAllFilters() {
std::vector<RosterFilter*> filters = treeView_->getRoster()->getFilters();
- foreach(RosterFilter* filter, filters) {
+ for (auto filter : filters) {
filters_.push_back(filter);
treeView_->getRoster()->removeFilter(filter);
}
treeView_->getRoster()->onFilterAdded.connect(boost::bind(&QtFilterWidget::handleFilterAdded, this, _1));
treeView_->getRoster()->onFilterRemoved.connect(boost::bind(&QtFilterWidget::handleFilterRemoved, this, _1));
}
void QtFilterWidget::pushAllFilters() {
treeView_->getRoster()->onFilterAdded.disconnect(boost::bind(&QtFilterWidget::handleFilterAdded, this, _1));
treeView_->getRoster()->onFilterRemoved.disconnect(boost::bind(&QtFilterWidget::handleFilterRemoved, this, _1));
- foreach(RosterFilter* filter, filters_) {
+ for (auto filter : filters_) {
treeView_->getRoster()->addFilter(filter);
}
filters_.clear();
}
void QtFilterWidget::updateRosterFilters() {
if (fuzzyRosterFilter_) {
if (filterLineEdit_->text().isEmpty()) {
// remove currently installed search filter and put old filters back
treeView_->getRoster()->removeFilter(fuzzyRosterFilter_);
delete fuzzyRosterFilter_;
fuzzyRosterFilter_ = nullptr;
pushAllFilters();
} else {
// remove currently intsalled search filter and put new search filter in place
updateSearchFilter();
}
} else {
if (!filterLineEdit_->text().isEmpty()) {
// remove currently installed filters and put a search filter in place
popAllFilters();
updateSearchFilter();
}
}
filterLineEdit_->setVisible(!filterLineEdit_->text().isEmpty());
}
void QtFilterWidget::updateSearchFilter() {
if (fuzzyRosterFilter_) {
treeView_->getRoster()->removeFilter(fuzzyRosterFilter_);
diff --git a/Swift/QtUI/Roster/QtOccupantListWidget.cpp b/Swift/QtUI/Roster/QtOccupantListWidget.cpp
index 03c14fd..a12863d 100644
--- a/Swift/QtUI/Roster/QtOccupantListWidget.cpp
+++ b/Swift/QtUI/Roster/QtOccupantListWidget.cpp
@@ -23,54 +23,54 @@ namespace Swift {
QtOccupantListWidget::QtOccupantListWidget(UIEventStream* eventStream, SettingsProvider* settings, MessageTarget privateMessageTarget, QWidget* parent) : QtTreeWidget(eventStream, settings, privateMessageTarget, parent) {
}
QtOccupantListWidget::~QtOccupantListWidget() {
}
void QtOccupantListWidget::setAvailableOccupantActions(const std::vector<ChatWindow::OccupantAction>& actions) {
availableOccupantActions_ = actions;
}
void QtOccupantListWidget::contextMenuEvent(QContextMenuEvent* event) {
QModelIndex index = indexAt(event->pos());
if (!index.isValid()) {
return;
}
RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
if (contact) {
onSomethingSelectedChanged(contact);
QMenu contextMenu;
if (availableOccupantActions_.empty()) {
QAction* noAction = contextMenu.addAction(tr("No actions for this user"));
noAction->setEnabled(false);
contextMenu.exec(event->globalPos());
}
else {
std::map<QAction*, ChatWindow::OccupantAction> actions;
- foreach (ChatWindow::OccupantAction availableAction, availableOccupantActions_) {
+ for (const auto& availableAction : availableOccupantActions_) {
QString text = "Error: missing string";
switch (availableAction) {
case ChatWindow::Kick: text = tr("Kick user"); break;
case ChatWindow::Ban: text = tr("Kick and ban user"); break;
case ChatWindow::MakeModerator: text = tr("Make moderator"); break;
case ChatWindow::MakeParticipant: text = tr("Make participant"); break;
case ChatWindow::MakeVisitor: text = tr("Remove voice"); break;
case ChatWindow::AddContact: text = tr("Add to contacts"); break;
case ChatWindow::ShowProfile: text = tr("Show profile"); break;
}
QAction* action = contextMenu.addAction(text);
actions[action] = availableAction;
}
QAction* result = contextMenu.exec(event->globalPos());
if (result) {
onOccupantActionSelected(actions[result], contact);
}
}
}
}
}
diff --git a/Swift/QtUI/Roster/RosterModel.cpp b/Swift/QtUI/Roster/RosterModel.cpp
index 3f77c86..ef4d778 100644
--- a/Swift/QtUI/Roster/RosterModel.cpp
+++ b/Swift/QtUI/Roster/RosterModel.cpp
@@ -26,61 +26,61 @@
#include <Swift/QtUI/Roster/QtTreeWidget.h>
#include <Swift/QtUI/Roster/RosterTooltip.h>
namespace Swift {
RosterModel::RosterModel(QtTreeWidget* view, bool screenReaderMode) : roster_(nullptr), view_(view), screenReader_(screenReaderMode) {
const int tooltipAvatarSize = 96; // maximal suggested size according to XEP-0153
cachedImageScaler_ = new QtScaledAvatarCache(tooltipAvatarSize);
}
RosterModel::~RosterModel() {
delete cachedImageScaler_;
}
void RosterModel::setRoster(Roster* roster) {
roster_ = roster;
if (roster_) {
roster->onChildrenChanged.connect(boost::bind(&RosterModel::handleChildrenChanged, this, _1));
roster->onDataChanged.connect(boost::bind(&RosterModel::handleDataChanged, this, _1));
}
reLayout();
}
void RosterModel::reLayout() {
//emit layoutChanged();
beginResetModel();
endResetModel(); // TODO: Not sure if this isn't too early?
if (!roster_) {
return;
}
- foreach (RosterItem* item, roster_->getRoot()->getDisplayedChildren()) {
+ for (auto item : roster_->getRoot()->getDisplayedChildren()) {
GroupRosterItem* child = dynamic_cast<GroupRosterItem*>(item);
if (!child) continue;
emit itemExpanded(index(child), child->isExpanded());
}
}
void RosterModel::handleChildrenChanged(GroupRosterItem* /*group*/) {
reLayout();
}
void RosterModel::handleDataChanged(RosterItem* item) {
Q_ASSERT(item);
QModelIndex modelIndex = index(item);
if (modelIndex.isValid()) {
emit dataChanged(modelIndex, modelIndex);
view_->refreshTooltip();
}
}
Qt::ItemFlags RosterModel::flags(const QModelIndex& index) const {
Qt::ItemFlags flags = QAbstractItemModel::flags(index);
if (dynamic_cast<GroupRosterItem*>(getItem(index)) == nullptr) {
flags |= Qt::ItemIsDragEnabled;
}
return flags;
}
int RosterModel::columnCount(const QModelIndex& /*parent*/) const {
return 1;
}
diff --git a/Swift/QtUI/Roster/RosterTooltip.cpp b/Swift/QtUI/Roster/RosterTooltip.cpp
index 8d467fd..ea4c9cd 100644
--- a/Swift/QtUI/Roster/RosterTooltip.cpp
+++ b/Swift/QtUI/Roster/RosterTooltip.cpp
@@ -95,81 +95,81 @@ QString RosterTooltip::buildDetailedTooltip(ContactRosterItem* contact, QtScaled
QString statusMessage = contact->getStatusText().empty() ? QObject::tr("(No message)") : P2QSTRING(contact->getStatusText());
boost::posix_time::ptime idleTime = contact->getIdle();
QString idleString;
if (!idleTime.is_not_a_date_time()) {
idleString = QObject::tr("Idle since %1").arg(P2QSTRING(Swift::Translator::getInstance()->ptimeToHumanReadableString(idleTime)));
idleString = htmlEscape(idleString) + "<br/>";
}
boost::posix_time::ptime lastSeenTime = contact->getOfflineSince();
QString lastSeen;
if (!lastSeenTime.is_not_a_date_time()) {
lastSeen = QObject::tr("Last seen %1").arg(P2QSTRING(Swift::Translator::getInstance()->ptimeToHumanReadableString(lastSeenTime)));
lastSeen = htmlEscape(lastSeen) + "<br/>";
}
QString mucOccupant= P2QSTRING(contact->getMUCAffiliationText());
if (!mucOccupant.isEmpty()) {
mucOccupant = htmlEscape(mucOccupant) + "<br/>";
}
return tooltipTemplate.arg(scaledAvatarPath, htmlEscape(fullName), htmlEscape(bareJID), presenceIconTag, htmlEscape(statusMessage), mucOccupant, idleString, lastSeen, vCardSummary);
}
QString RosterTooltip::buildVCardSummary(VCard::ref vcard) {
QString summary;
summary = "<table>";
// star | name | content
QString currentBlock;
- foreach (const VCard::Telephone& tel, vcard->getTelephones()) {
+ for (const auto& tel : vcard->getTelephones()) {
QString type = tel.isFax ? QObject::tr("Fax") : QObject::tr("Telephone");
QString field = buildVCardField(tel.isPreferred, type, htmlEscape(P2QSTRING(tel.number)));
if (tel.isPreferred) {
currentBlock = field;
break;
}
currentBlock += field;
}
summary += currentBlock;
currentBlock = "";
- foreach (const VCard::EMailAddress& mail, vcard->getEMailAddresses()) {
+ for (const auto& mail : vcard->getEMailAddresses()) {
QString field = buildVCardField(mail.isPreferred, QObject::tr("E-Mail"), htmlEscape(P2QSTRING(mail.address)));
if (mail.isPreferred) {
currentBlock = field;
break;
}
currentBlock += field;
}
summary += currentBlock;
currentBlock = "";
- foreach (const VCard::Organization& org, vcard->getOrganizations()) {
+ for (const auto& org : vcard->getOrganizations()) {
QString field = buildVCardField(false, QObject::tr("Organization"), htmlEscape(P2QSTRING(org.name)));
currentBlock += field;
}
summary += currentBlock;
currentBlock = "";
- foreach(const std::string& title, vcard->getTitles()) {
+ for (const auto& title : vcard->getTitles()) {
QString field = buildVCardField(false, QObject::tr("Title"), htmlEscape(P2QSTRING(title)));
currentBlock += field;
}
summary += currentBlock;
summary += "</table>";
return summary;
}
QString RosterTooltip::buildVCardField(bool preferred, const QString& name, const QString& content) {
QString rowTemplate;
if (QApplication::layoutDirection() == Qt::RightToLeft) {
rowTemplate = QString("<tr><td>%3</td><td valign='middle'><strong>%2</strong></td><td valign='middle'>%1</td></tr>");
} else {
rowTemplate = QString("<tr><td>%1</td><td valign='middle'><strong>%2</strong></td><td valign='middle'>%3</td></tr>");
}
return rowTemplate.arg(preferred ? "<img src=':/icons/star-checked.png' />" : "", name, content);
}
}
diff --git a/Swift/QtUI/UserSearch/ContactListModel.cpp b/Swift/QtUI/UserSearch/ContactListModel.cpp
index 376d3b1..6ef85d7 100644
--- a/Swift/QtUI/UserSearch/ContactListModel.cpp
+++ b/Swift/QtUI/UserSearch/ContactListModel.cpp
@@ -1,48 +1,47 @@
/*
* Copyright (c) 2013 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2014-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/UserSearch/ContactListModel.h>
#include <QMimeData>
#include <Swiften/Base/Path.h>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Elements/StatusShow.h>
#include <Swift/QtUI/QtResourceHelper.h>
#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
QDataStream& operator >>(QDataStream& in, StatusShow::Type& e){
quint32 buffer;
in >> buffer;
switch(buffer) {
case StatusShow::Online:
e = StatusShow::Online;
break;
case StatusShow::Away:
e = StatusShow::Away;
break;
case StatusShow::FFC:
e = StatusShow::FFC;
break;
case StatusShow::XA:
e = StatusShow::XA;
break;
case StatusShow::DND:
e = StatusShow::DND;
break;
default:
e = StatusShow::None;
break;
}
diff --git a/Swift/QtUI/UserSearch/QtContactListWidget.cpp b/Swift/QtUI/UserSearch/QtContactListWidget.cpp
index 1dbfc1f..73a8482 100644
--- a/Swift/QtUI/UserSearch/QtContactListWidget.cpp
+++ b/Swift/QtUI/UserSearch/QtContactListWidget.cpp
@@ -58,46 +58,46 @@ QtContactListWidget::QtContactListWidget(QWidget* parent, SettingsProvider* sett
}
QtContactListWidget::~QtContactListWidget() {
delete contactListDelegate_;
delete removableItemDelegate_;
delete contactListModel_;
}
void QtContactListWidget::setList(const std::vector<Contact::ref>& list) {
contactListModel_->setList(list);
}
std::vector<Contact::ref> QtContactListWidget::getList() const {
return contactListModel_->getList();
}
Contact::ref QtContactListWidget::getContact(const size_t i) {
return contactListModel_->getContact(i);
}
void QtContactListWidget::setMaximumNoOfContactsToOne(bool limited) {
limited_ = limited;
}
bool QtContactListWidget::isFull() const {
return limited_ && (getList().size() == 1);
}
void QtContactListWidget::updateContacts(const std::vector<Contact::ref>& contactUpdates) {
std::vector<Contact::ref> contacts = contactListModel_->getList();
- foreach(const Contact::ref& contactUpdate, contactUpdates) {
- for(auto& contact : contacts) {
+ for (const auto& contactUpdate : contactUpdates) {
+ for (auto&& contact : contacts) {
if (contactUpdate->jid == contact->jid) {
contact = contactUpdate;
break;
}
}
}
contactListModel_->setList(contacts);
}
void QtContactListWidget::handleSettingsChanged(const std::string&) {
contactListDelegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
}
}
diff --git a/Swift/QtUI/WinUIHelpers.cpp b/Swift/QtUI/WinUIHelpers.cpp
index 4898916..ec39c38 100644
--- a/Swift/QtUI/WinUIHelpers.cpp
+++ b/Swift/QtUI/WinUIHelpers.cpp
@@ -1,53 +1,51 @@
/*
* Copyright (c) 2012 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/WinUIHelpers.h>
#include <windows.h>
#include <Wincrypt.h>
#include <cryptuiapi.h>
#pragma comment(lib, "cryptui.lib")
#include <memory>
-#include <Swiften/Base/foreach.h>
-
namespace Swift {
void WinUIHelpers::displayCertificateChainAsSheet(QWidget* parent, const std::vector<Certificate::ref>& chain) {
if (chain.empty()) {
return;
}
// create certificate store to store the certificate chain in
HCERTSTORE chainStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, NULL, CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG, NULL);
if (!chainStore) {
return;
}
ByteArray certAsDER = chain[0]->toDER();
std::shared_ptr<const CERT_CONTEXT> certificate_chain;
{
PCCERT_CONTEXT certChain;
BOOL ok = CertAddCertificateContextToStore(chainStore, CertCreateCertificateContext(X509_ASN_ENCODING, vecptr(certAsDER), certAsDER.size()), CERT_STORE_ADD_ALWAYS, &certChain);
// maybe free the cert contex we created
if (!ok || !certChain) {
return;
}
certificate_chain.reset(certChain, CertFreeCertificateContext);
}
for (size_t i = 1; i < chain.size(); ++i) {
ByteArray certAsDER = chain[i]->toDER();
CertAddCertificateContextToStore(chainStore, CertCreateCertificateContext(X509_ASN_ENCODING, vecptr(certAsDER), certAsDER.size()), CERT_STORE_ADD_ALWAYS, NULL);
}