File indexing completed on 2024-05-12 05:40:39
0001 /*************************************************************************** 0002 * Copyright (C) 2015 by Renaud Guezennec * 0003 * https://rolisteam.org/contact * 0004 * * 0005 * rolisteam is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 0021 #include "sharednotecontainer.h" 0022 #include "controller/view_controller/sharednotecontroller.h" 0023 0024 SharedNoteContainer::SharedNoteContainer(SharedNoteController* ctrl, QWidget* parent) 0025 : MediaContainer(ctrl, MediaContainer::ContainerType::SharedNoteContainer, parent) 0026 , m_sharedCtrl(ctrl) 0027 , m_edit(new SharedNote(ctrl)) 0028 { 0029 if(!m_sharedCtrl) 0030 return; 0031 0032 m_edit->setId(m_sharedCtrl->uuid()); 0033 #ifdef Q_OS_MAC 0034 m_edit->menuBar()->setNativeMenuBar(false); 0035 #endif 0036 // setCleverUriType(Core::ContentType::SHAREDNOTE); 0037 setWidget(m_edit.get()); 0038 setWindowIcon(QIcon::fromTheme("sharedEditor")); 0039 // m_edit->setFileName(getUriName()); 0040 0041 connect(m_sharedCtrl, &SharedNoteController::ownerIdChanged, m_edit.get(), &SharedNote::setOwnerId); 0042 0043 m_edit->setOwnerId(m_sharedCtrl->ownerId()); 0044 } 0045 0046 /*void SharedNoteContainer::updateNoteToAll() 0047 { 0048 NetworkMessageWriter msg(NetMsg::SharedNoteCategory, NetMsg::updateTextAndPermission); 0049 msg.string8(m_mediaId); 0050 m_edit->updateDocumentToAll(&msg); 0051 msg.sendToServer(); 0052 }*/ 0053 0054 bool SharedNoteContainer::readFileFromUri() 0055 { 0056 return false; 0057 /*if((nullptr == m_uri) || (nullptr == m_edit)) 0058 0059 bool val= false; 0060 if(!m_uri->exists()) 0061 { 0062 QByteArray array= m_uri->getData(); 0063 QDataStream in(&array, QIODevice::ReadOnly); 0064 in.setVersion(QDataStream::Qt_5_7); 0065 readFromFile(in); 0066 val= true; 0067 } 0068 else 0069 { 0070 QString uri= m_uri->getUri(); 0071 QFile file(uri); 0072 if(file.open(QIODevice::ReadOnly)) 0073 { 0074 QTextStream in(&file); 0075 val= m_edit->loadFileAsText(in, uri.endsWith(".md")); 0076 } 0077 } 0078 updateTitle(); 0079 return val;*/ 0080 } 0081 0082 void SharedNoteContainer::saveMedia(const QString&) 0083 { 0084 if(nullptr != m_edit) 0085 { 0086 /*if(nullptr != m_uri) 0087 { 0088 QString filter= CleverURI::getFilterForType(m_uri->getType()); 0089 filter= filter.remove(0, filter.indexOf("(") + 1); 0090 filter= filter.remove(filter.indexOf(")"), 1); 0091 filter= filter.replace('*', ' '); 0092 QStringList list= filter.split(' ', QString::SkipEmptyParts); 0093 0094 bool hasEnd= false; 0095 for(auto& end : list) 0096 { 0097 if(m_uri->getUri().endsWith(end)) 0098 { 0099 hasEnd= true; 0100 } 0101 } 0102 if(!hasEnd) 0103 { 0104 QString str= m_uri->getUri() + ".rsn"; 0105 m_uri->setUri(str); 0106 } 0107 updateTitle(); 0108 0109 QFile file(m_uri->getUri()); 0110 if(!file.open(QIODevice::WriteOnly)) 0111 { 0112 return; 0113 } 0114 QTextStream out(&file); 0115 m_edit->saveFileAsText(out); 0116 file.close(); 0117 }*/ 0118 } 0119 } 0120 0121 void SharedNoteContainer::updateTitle() 0122 { 0123 // m_edit->setFileName(getUriName()); // update the title too 0124 } 0125 0126 /*void SharedNoteContainer::putDataIntoCleverUri() 0127 { 0128 if(nullptr != m_edit) 0129 { 0130 QByteArray data; 0131 QDataStream out(&data, QIODevice::WriteOnly); 0132 out.setVersion(QDataStream::Qt_5_7); 0133 m_edit->saveFile(out); 0134 // if(nullptr != m_uri) 0135 // { 0136 // m_uri->setData(data); 0137 // } 0138 } 0139 }*/ 0140 void SharedNoteContainer::readFromFile(QDataStream& data) 0141 { 0142 if(nullptr != m_edit) 0143 { 0144 m_edit->loadFile(data); 0145 } 0146 } 0147 0148 void SharedNoteContainer::saveInto(QDataStream& out) 0149 { 0150 if(nullptr != m_edit) 0151 { 0152 m_edit->saveFile(out); 0153 } 0154 }