File indexing completed on 2024-05-12 05:40:38
0001 /* 0002 Cahoots is a crossplatform real-time collaborative text editor. 0003 0004 Copyright (C) 2010 Chris Dimpfl, Anandi Hira, David Vega 0005 0006 This program is free software: you can redistribute it and/or modify 0007 it under the terms of the GNU General Public License as published by 0008 the Free Software Foundation, either version 3 of the License, or 0009 (at your option) any later version. 0010 0011 This program is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 GNU General Public License for more details. 0015 0016 You should have received a copy of the GNU General Public License 0017 along with this program. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 #include <QHostAddress> 0020 #include <QItemSelectionModel> 0021 #include <QJsonArray> 0022 #include <QJsonDocument> 0023 #include <QJsonObject> 0024 #include <QSettings> 0025 #include <QTime> 0026 #include <QTreeWidgetItem> 0027 0028 #include "controller/view_controller/sharednotecontroller.h" 0029 #include "participantspane.h" 0030 #include "ui_participantspane.h" 0031 0032 #include "data/player.h" 0033 #include "enu.h" 0034 #include "model/playerproxymodel.h" 0035 #include "utilities.h" 0036 0037 //////////////////////////////////////////////// 0038 /// \brief ParticipantsPane::ParticipantsPane 0039 /// \param parent 0040 //////////////////////////////////////////////// 0041 0042 ParticipantsPane::ParticipantsPane(SharedNoteController* ctrl, QWidget* parent) 0043 : QWidget(parent), ui(new Ui::ParticipantsPane), m_sharedCtrl(ctrl) 0044 { 0045 ui->setupUi(this); 0046 0047 if(!m_sharedCtrl) 0048 return; 0049 0050 ui->m_downToolBtn->setDefaultAction(ui->m_demoteAction); 0051 ui->m_upToolBtn->setDefaultAction(ui->m_promoteAction); 0052 0053 connect(ui->m_promoteAction, &QAction::triggered, this, &ParticipantsPane::promoteCurrentItem); 0054 connect(ui->m_demoteAction, &QAction::triggered, this, &ParticipantsPane::demoteCurrentItem); 0055 0056 ui->m_treeview->setModel(m_sharedCtrl->participantModel()); 0057 0058 auto selectionModel= ui->m_treeview->selectionModel(); 0059 connect(selectionModel, &QItemSelectionModel::currentChanged, this, 0060 [this](const QModelIndex& idx, const QModelIndex&) { 0061 auto item= static_cast<ParticipantItem*>(idx.internalPointer()); 0062 0063 auto canMove= (item->uuid() != m_sharedCtrl->ownerId() & item->isLeaf()); 0064 ui->m_demoteAction->setEnabled(canMove); 0065 ui->m_promoteAction->setEnabled(canMove); 0066 }); 0067 0068 ui->connectInfoLabel->hide(); 0069 ui->m_treeview->resizeColumnToContents(0); 0070 ui->m_treeview->resizeColumnToContents(1); 0071 ui->m_treeview->expandAll(); 0072 0073 ui->connectInfoLabel->setFont(QFont(Utilities::s_labelFont, Utilities::s_labelFontSize)); 0074 ui->participantsLabel->setFont(QFont(Utilities::s_labelFont, Utilities::s_labelFontSize)); 0075 0076 ui->m_demoteAction->setEnabled(false); 0077 ui->m_promoteAction->setEnabled(false); 0078 } 0079 0080 ParticipantsPane::~ParticipantsPane() 0081 { 0082 delete ui; 0083 } 0084 void ParticipantsPane::promoteCurrentItem() 0085 { 0086 QModelIndex current= ui->m_treeview->currentIndex(); 0087 0088 if(!current.isValid() || !current.parent().isValid()) 0089 return; 0090 0091 m_sharedCtrl->promoteCurrentItem(current); 0092 } 0093 0094 void ParticipantsPane::demoteCurrentItem() 0095 { 0096 QModelIndex current= ui->m_treeview->currentIndex(); 0097 0098 if(!current.isValid() || !current.parent().isValid()) 0099 return; 0100 0101 m_sharedCtrl->demoteCurrentItem(current); 0102 } 0103 0104 /*void ParticipantsPane::fill(NetworkMessageWriter* msg) 0105 { 0106 QJsonDocument doc; 0107 QJsonObject root; 0108 m_model->saveModel(root); 0109 doc.setObject(root); 0110 msg->byteArray32(doc.toJson()); 0111 } 0112 void ParticipantsPane::readFromMsg(NetworkMessageReader* msg) 0113 { 0114 if(nullptr != msg) 0115 { 0116 QByteArray data= msg->byteArray32(); 0117 QJsonDocument doc= QJsonDocument::fromJson(data); 0118 0119 QJsonObject root= doc.object(); 0120 m_model->loadModel(root); 0121 } 0122 } 0123 void ParticipantsPane::readPermissionChanged(NetworkMessageReader* msg) 0124 { 0125 QString playerId= msg->string8(); 0126 int perm= msg->int8(); 0127 / * m_model->setPlayerPermission(playerId, static_cast<ParticipantModel::Permission>(perm)); 0128 if(playerId == m_model->getOwner()) 0129 { 0130 emit localPlayerPermissionChanged(m_model->getPermissionFor(playerId)); 0131 }* / 0132 }*/