/** * @author Rafal 'Vogel' Malinowski * @short Stored chat data to storage. * * Stores all chat data to storage. If details class is loaded it is stored too. */ void ChatShared::store() { ensureLoaded(); if (!isValidStorage()) return; Shared::store(); ConfigurationApi *configurationStorage = storage()->storage(); QDomElement parent = storage()->point(); storeValue("Account", ChatAccount->uuid().toString()); storeValue("Display", Display); // import from alias to new name of chat type ChatType *chatType = m_chatTypeManager->chatType(Type); if (chatType) Type = chatType->name(); storeValue("Type", Type); if (!Groups.isEmpty()) { QDomElement groupsNode = configurationStorage->getNode(parent, "ChatGroups", ConfigurationApi::ModeCreate); foreach (const Group &group, Groups) configurationStorage->appendTextNode(groupsNode, "Group", group.uuid().toString()); }
void EditTalkableAction::updateChatActionState(Action *action) { setChatActionTitleAndIcon(action); const Chat &chat = actionChat(action->context()); ChatType *chatType = ChatTypeManager::instance()->chatType(chat.type()); action->setEnabled(chat && (!chatType || (chatType->name() != "Contact" && !chat.display().isEmpty()))); }
bool HistoryChatsModelProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const { // chats? Chat *leftChat = left.data(ChatRole).value<Chat *>(); Chat *rightChat = right.data(ChatRole).value<Chat *>(); if (leftChat && rightChat) return compareNames(leftChat->name(), rightChat->name()) < 0; ChatType leftType = left.data(ChatTypeRole).value<ChatType>(); ChatType rightType = right.data(ChatTypeRole).value<ChatType>(); return compareNames(leftType.displayName(), rightType.displayName()) < 0; }
/** * @author Rafal 'Vogel' Malinowski * @short Loads chat data from storage. * * This method is called when object is used at first time. It loads data from object's * storage point. After loading data chat type is known ('Type') so this method check * if the type is any of known chat types. If so, details class is created, assigned and * loaded - chat has full data available. If no, loading details class is deffered to * moment after good chat type is loaded. This mechanism is provided by * @link ChatTypeAvareObject @endlink class. */ void ChatShared::load() { if (!isValidStorage()) return; Shared::load(); ConfigurationApi *configurationStorage = storage()->storage(); QDomElement parent = storage()->point(); Groups.clear(); QDomElement groupsNode = configurationStorage->getNode(parent, "ChatGroups", ConfigurationApi::ModeFind); if (!groupsNode.isNull()) { QDomNodeList groupsList = groupsNode.elementsByTagName("Group"); int count = groupsList.count(); for (int i = 0; i < count; i++) { QDomElement groupElement = groupsList.at(i).toElement(); if (groupElement.isNull()) continue; doAddToGroup(m_groupManager->byUuid(groupElement.text())); } } *ChatAccount = m_accountManager->byUuid(QUuid(loadValue<QString>("Account"))); Display = loadValue<QString>("Display"); auto type = loadValue<QString>("Type"); // import from alias to new name of chat type ChatType *chatType = m_chatTypeManager->chatType(type); if (chatType) type = chatType->name(); // we should not have display names for Contact chats if (type == "Contact") Display.clear(); setType(type); }
void ChatDataWindow::createGui() { QVBoxLayout *layout = new QVBoxLayout(this); TabWidget = new QTabWidget(this); GeneralTab = new QWidget(TabWidget); QVBoxLayout *generalLayout = new QVBoxLayout(GeneralTab); QWidget *nameWidget = new QWidget(this); QHBoxLayout *nameLayout = new QHBoxLayout(nameWidget); QLabel *numberLabel = new QLabel(tr("Visible Name") + ':', nameWidget); DisplayEdit = new QLineEdit(nameWidget); DisplayEdit->setText(MyChat.display()); nameLayout->addWidget(numberLabel); nameLayout->addWidget(DisplayEdit); generalLayout->addWidget(nameWidget); TabWidget->addTab(GeneralTab, tr("General")); ChatType *chatType = ChatTypeManager::instance()->chatType(MyChat.type()); if (chatType) { EditWidget = chatType->createEditWidget(MyChat, TabWidget); if (EditWidget) { auto groupBox = new QGroupBox{GeneralTab}; groupBox->setFlat(true); groupBox->setTitle(tr("Chat")); auto groupBoxLayout = new QVBoxLayout{groupBox}; groupBoxLayout->setMargin(0); groupBoxLayout->setSpacing(4); groupBoxLayout->addWidget(EditWidget); generalLayout->addWidget(groupBox); if (EditWidget->stateNotifier()) ValueStateNotifier->addConfigurationValueStateNotifier(EditWidget->stateNotifier()); } } generalLayout->addStretch(100); GroupsTab = new ChatGroupsConfigurationWidget(MyChat, this); TabWidget->addTab(GroupsTab, tr("Groups")); auto optionsTab = new QWidget{this}; (new QVBoxLayout{optionsTab})->addStretch(100); new ChatConfigurationWidgetGroupBoxesAdapter(this, optionsTab); TabWidget->addTab(optionsTab, tr("Options")); layout->addWidget(TabWidget); createButtons(layout); connect(DisplayEdit, SIGNAL(textChanged(QString)), this, SLOT(displayEditChanged())); }