void MetaEntry::handleRealVariantsChanged (QStringList variants, QObject *passedObj) { QObject *obj = passedObj ? passedObj : sender (); Q_FOREACH (const QString& var, Variant2RealVariant_.keys ()) { const QPair<QObject*, QString>& pair = Variant2RealVariant_ [var]; if (pair.first == obj) Variant2RealVariant_.remove (var); } ICLEntry *entry = qobject_cast<ICLEntry*> (obj); if (!variants.contains (QString ())) variants.prepend (QString ()); Q_FOREACH (const QString& var, variants) Variant2RealVariant_ [entry->GetEntryName () + '/' + var] = qMakePair (obj, var); emit availableVariantsChanged (Variants ()); Q_FOREACH (const QString& var, variants) { const QString& str = entry->GetEntryName () + '/' + var; emit statusChanged (GetStatus (str), str); } }
bool SortFilterProxyModel::lessThan (const QModelIndex& right, const QModelIndex& left) const // sort in reverse order ok { if (GetType (left) != Core::CLETContact || GetType (right) != Core::CLETContact) return QSortFilterProxyModel::lessThan (left, right); ICLEntry *lE = GetEntry (left); ICLEntry *rE = GetEntry (right); if (lE->GetEntryType () == ICLEntry::ETPrivateChat && rE->GetEntryType () == ICLEntry::ETPrivateChat && lE->GetParentCLEntry () == rE->GetParentCLEntry ()) { IMUCPerms *lp = qobject_cast<IMUCPerms*> (lE->GetParentCLEntry ()); if (lp) { bool less = lp->IsLessByPerm (lE->GetObject (), rE->GetObject ()); bool more = lp->IsLessByPerm (rE->GetObject (), lE->GetObject ()); if (less || more) return more; } } State lState = lE->GetStatus ().State_; State rState = rE->GetStatus ().State_; if (lState == rState || !OrderByStatus_) return lE->GetEntryName ().localeAwareCompare (rE->GetEntryName ()) < 0; else return IsLess (lState, rState); }
void Core::Process (QObject *msgObj) { IMessage *msg = qobject_cast<IMessage*> (msgObj); if (msg->GetMessageType () != IMessage::Type::ChatMessage && msg->GetMessageType () != IMessage::Type::MUCMessage) return; if (msg->GetBody ().isEmpty ()) return; if (msg->GetDirection () == IMessage::Direction::Out && msg->GetMessageType () == IMessage::Type::MUCMessage) return; const double secsDiff = msg->GetDateTime ().secsTo (QDateTime::currentDateTime ()); if (msg->GetMessageType () == IMessage::Type::MUCMessage && std::abs (secsDiff) >= 2) return; ICLEntry *entry = qobject_cast<ICLEntry*> (msg->ParentCLEntry ()); if (!entry) { qWarning () << Q_FUNC_INFO << "message's other part doesn't implement ICLEntry" << msg->GetQObject () << msg->OtherPart (); return; } if (DisabledIDs_.contains (entry->GetEntryID ())) return; const auto acc = entry->GetParentAccount (); QVariantMap data; data ["EntryID"] = entry->GetEntryID (); data ["AccountID"] = acc->GetAccountID (); data ["DateTime"] = msg->GetDateTime (); data ["Direction"] = msg->GetDirection () == IMessage::Direction::In ? "IN" : "OUT"; data ["Body"] = msg->GetBody (); data ["OtherVariant"] = msg->GetOtherVariant (); data ["Type"] = static_cast<int> (msg->GetMessageType ()); data ["EscapePolicy"] = msg->GetEscapePolicy () == IMessage::EscapePolicy::Escape ? "Esc" : "NEs"; if (const auto irtm = qobject_cast<IRichTextMessage*> (msgObj)) data ["RichBody"] = irtm->GetRichBody (); if (entry->GetEntryType () == ICLEntry::EntryType::PrivateChat) { const auto parent = entry->GetParentCLEntry (); data ["VisibleName"] = parent->GetEntryName () + "/" + entry->GetEntryName (); } else data ["VisibleName"] = entry->GetEntryName (); QMetaObject::invokeMethod (StorageThread_->GetStorage (), "addMessage", Qt::QueuedConnection, Q_ARG (QVariantMap, data)); }
AcceptRIEXDialog::AcceptRIEXDialog (const QList<RIEXItem>& items, QObject *entryObj, QString message, QWidget *parent) : QDialog (parent) , Model_ (new QStandardItemModel (this)) { Ui_.setupUi (this); Model_->setHorizontalHeaderLabels ({ tr ("Action"), tr ("ID"), tr ("Name"), tr ("Groups") }); for (const RIEXItem& item : items) { QList<QStandardItem*> row; QStandardItem *action = new QStandardItem; action->setCheckState (Qt::Checked); action->setCheckable (true); switch (item.Action_) { case RIEXItem::AAdd: action->setText (tr ("add")); break; case RIEXItem::ADelete: action->setText (tr ("delete")); break; case RIEXItem::AModify: action->setText (tr ("modify")); break; default: action->setText (tr ("(unknown)")); break; } action->setData (QVariant::fromValue<RIEXItem> (item)); row << action; row << new QStandardItem (item.ID_); row << new QStandardItem (item.Nick_); row << new QStandardItem (item.Groups_.join ("; ")); Model_->appendRow (row); } Ui_.ItemsTree_->setModel (Model_); ICLEntry *entry = qobject_cast<ICLEntry*> (entryObj); const QString& id = entry->GetEntryName ().isEmpty () ? entry->GetHumanReadableID () : entry->GetEntryName () + " (" + entry->GetHumanReadableID () + ")"; const QString& text = message.isEmpty () ? tr ("%1 has suggested to modify your contact list:") .arg (id) : tr ("%1 has suggested to modify your contact list:\n%2") .arg (id) .arg (message); Ui_.MessageLabel_->setText (text); }
bool CLModel::TryDropFile (const QMimeData* mime, const QModelIndex& parent) { if (parent.data (Core::CLREntryType).value<Core::CLEntryType> () != Core::CLETContact) return false; QObject *entryObj = parent.data (Core::CLREntryObject).value<QObject*> (); ICLEntry *entry = qobject_cast<ICLEntry*> (entryObj); if (entry->Variants ().isEmpty ()) return false; IAccount *acc = qobject_cast<IAccount*> (entry->GetParentAccount ()); ITransferManager *mgr = qobject_cast<ITransferManager*> (acc->GetTransferManager ()); if (!mgr) return false; const QList<QUrl>& urls = mime->urls (); if (urls.isEmpty ()) return false; QString text; if (urls.size () > 2) text = tr ("Are you sure you want to send %n files to %1?", 0, urls.size ()) .arg (entry->GetEntryName ()); else { QStringList list; Q_FOREACH (const QUrl& url, urls) list << QFileInfo (url.path ()).fileName (); text = tr ("Are you sure you want to send %1 to %2?") .arg ("<em>" + list.join (", ") + "</em>") .arg (entry->GetEntryName ()); } if (QMessageBox::question (0, "LeechCraft", text, QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return false; Q_FOREACH (const QUrl& url, urls) { const QString& path = url.toLocalFile (); if (!QFileInfo (path).exists ()) continue; QObject *job = mgr->SendFile (entry->GetEntryID (), entry->Variants ().first (), path); Core::Instance ().GetTransferJobManager()->HandleJob (job); } return true; }
bool SortFilterProxyModel::lessThan (const QModelIndex& right, const QModelIndex& left) const // sort in reverse order ok { const auto leftType = GetType (left); if (leftType == Core::CLETAccount) return QSortFilterProxyModel::lessThan (left, right); else if (leftType == Core::CLETCategory) { const bool leftIsMuc = left.data (Core::CLRIsMUCCategory).toBool (); const bool rightIsMuc = right.data (Core::CLRIsMUCCategory).toBool (); if ((leftIsMuc && rightIsMuc) || (!leftIsMuc && !rightIsMuc)) return QSortFilterProxyModel::lessThan (left, right); else return rightIsMuc; } ICLEntry *lE = GetEntry (left); ICLEntry *rE = GetEntry (right); if (lE->GetEntryType () == ICLEntry::ETPrivateChat && rE->GetEntryType () == ICLEntry::ETPrivateChat && lE->GetParentCLEntry () == rE->GetParentCLEntry ()) if (IMUCPerms *lp = qobject_cast<IMUCPerms*> (lE->GetParentCLEntry ())) { bool less = lp->IsLessByPerm (lE->GetObject (), rE->GetObject ()); bool more = lp->IsLessByPerm (rE->GetObject (), lE->GetObject ()); if (less || more) return more; } State lState = lE->GetStatus ().State_; State rState = rE->GetStatus ().State_; if (lState == rState || !OrderByStatus_) return lE->GetEntryName ().localeAwareCompare (rE->GetEntryName ()) < 0; else return IsLess (lState, rState); }
void Core::Process (QObject *msgObj) { IMessage *msg = qobject_cast<IMessage*> (msgObj); if (msg->GetMessageType () != IMessage::MTChatMessage && msg->GetMessageType () != IMessage::MTMUCMessage) return; if (msg->GetBody ().isEmpty ()) return; if (msg->GetDirection () == IMessage::DOut && msg->GetMessageType () == IMessage::MTMUCMessage) return; ICLEntry *entry = qobject_cast<ICLEntry*> (msg->ParentCLEntry ()); if (!entry) { qWarning () << Q_FUNC_INFO << "message's other part doesn't implement ICLEntry" << msg->GetObject () << msg->OtherPart (); return; } if (DisabledIDs_.contains (entry->GetEntryID ())) return; IAccount *acc = qobject_cast<IAccount*> (entry->GetParentAccount ()); if (!acc) { qWarning () << Q_FUNC_INFO << "message's account doesn't implement IAccount" << entry->GetParentAccount (); return; } QVariantMap data; data ["EntryID"] = entry->GetEntryID (); data ["VisibleName"] = entry->GetEntryName (); data ["AccountID"] = acc->GetAccountID (); data ["DateTime"] = msg->GetDateTime (); data ["Direction"] = msg->GetDirection () == IMessage::DIn ? "IN" : "OUT"; data ["Body"] = msg->GetBody (); data ["OtherVariant"] = msg->GetOtherVariant (); data ["MessageType"] = static_cast<int> (msg->GetMessageType ()); QMetaObject::invokeMethod (StorageThread_->GetStorage (), "addMessage", Qt::QueuedConnection, Q_ARG (QVariantMap, data)); }
void ChatHistoryWidget::handleGotUsersForAccount (const QStringList& users, const QString& id, const QStringList& nameCache) { if (id != Ui_.AccountBox_->itemData (Ui_.AccountBox_->currentIndex ()).toString ()) return; IProxyObject *proxy = Core::Instance ()->GetPluginProxy (); ContactsModel_->clear (); Ui_.HistView_->clear (); QStandardItem *ourFocus = 0; const QString& focusId = EntryToFocus_ ? EntryToFocus_->GetEntryID () : CurrentEntry_; EntryToFocus_ = 0; for (int i = 0; i < users.size (); ++i) { const QString& user = users.at (i); ICLEntry *entry = qobject_cast<ICLEntry*> (proxy->GetEntry (user, id)); const QString& name = entry ? entry->GetEntryName () : (nameCache.value (i).isEmpty () ? user : nameCache.value (i)); EntryID2NameCache_ [user] = name; QStandardItem *item = new QStandardItem (name); item->setData (user, MRIDRole); item->setToolTip (name); item->setEditable (false); ContactsModel_->appendRow (item); if (!ourFocus && user == focusId) ourFocus = item; } if (ourFocus) { ShowLoading (); QModelIndex idx = ContactsModel_->indexFromItem (ourFocus); idx = SortFilter_->mapFromSource (idx); Ui_.Contacts_->selectionModel ()-> setCurrentIndex (idx, QItemSelectionModel::SelectCurrent); } }
void ChatHistoryWidget::handleGotChatLogs (const QString& accountId, const QString& entryId, int, int, const QVariant& logsVar) { const QString& selectedEntry = Ui_.Contacts_->selectionModel ()-> currentIndex ().data (MRIDRole).toString (); if (accountId != Ui_.AccountBox_-> itemData (Ui_.AccountBox_->currentIndex ()).toString () || entryId != selectedEntry) return; Amount_ = 0; Ui_.HistView_->clear (); const auto& defFormat = Ui_.HistView_->currentCharFormat (); ICLEntry *entry = qobject_cast<ICLEntry*> (Core::Instance ()-> GetPluginProxy ()->GetEntry (entryId, accountId)); const QString& name = entry ? entry->GetEntryName () : EntryID2NameCache_.value (entryId, entryId); const QString& ourName = entry ? qobject_cast<IAccount*> (entry->GetParentAccount ())->GetOurNick () : QString (); QString preNick = Core::Instance ()->GetPluginProxy ()-> GetSettingsManager ()->property ("PreNickText").toString (); QString postNick = Core::Instance ()->GetPluginProxy ()-> GetSettingsManager ()->property ("PostNickText").toString (); preNick.replace ('<', "<"); postNick.replace ('<', "<"); const auto& bgColor = palette ().color (QPalette::Base); const auto& colors = Core::Instance ()-> GetPluginProxy ()->GenerateColors ("hash", bgColor); int scrollPos = -1; for (const auto& logVar : logsVar.toList ()) { const QVariantMap& map = logVar.toMap (); const bool isChat = map ["Type"] == "CHAT"; QString html = "[" + map ["Date"].toDateTime ().toString () + "] " + preNick; const QString& var = map ["Variant"].toString (); if (isChat) { QString remoteName; if (!entry && !var.isEmpty ()) remoteName += var; else if (entry && var.isEmpty ()) remoteName += name; else remoteName += name + '/' + var; if (!ourName.isEmpty ()) html += map ["Direction"] == "IN" ? remoteName : ourName; else { html += map ["Direction"] == "IN" ? QString::fromUtf8 ("← ") : QString::fromUtf8 ("→ "); html += remoteName; } } else { const QString& color = Core::Instance ()-> GetPluginProxy ()->GetNickColor (var, colors); html += "<font color=\"" + color + "\">" + var + "</font>"; } auto msgText = map ["Message"].toString (); msgText.replace ('<', "<"); Core::Instance ()->GetPluginProxy ()->FormatLinks (msgText); msgText.replace ('\n', "<br/>"); html += postNick + ' ' + msgText; const bool isSearchRes = SearchResultPosition_ == PerPageAmount_ - Amount_; if (isChat && !isSearchRes) { html.prepend (QString ("<font color=\"#") + (map ["Direction"] == "IN" ? "0000dd" : "dd0000") + "\">"); html += "</font>"; } else if (isSearchRes) { QTextCharFormat fmt = defFormat; scrollPos = Ui_.HistView_->document ()->characterCount (); html.prepend ("<font color='#FF7E00'>"); html += "</font>"; } ++Amount_; Ui_.HistView_->append (html); if (isSearchRes) Ui_.HistView_->setCurrentCharFormat (defFormat); } if (scrollPos >= 0) { QTextCursor cur (Ui_.HistView_->document ()); cur.setPosition (scrollPos); Ui_.HistView_->setTextCursor (cur); Ui_.HistView_->ensureCursorVisible (); } }
void MetaEntry::handleRealAttentionDrawn (const QString& text, const QString& var) { ICLEntry *entry = qobject_cast<ICLEntry*> (sender ()); emit attentionDrawn (text, entry->GetEntryName () + '/' + var); }
void MetaEntry::handleRealCPSChanged (const ChatPartState& cps, const QString& var) { ICLEntry *entry = qobject_cast<ICLEntry*> (sender ()); emit chatPartStateChanged (cps, entry->GetEntryName () + '/' + var); }
void MetaEntry::handleRealStatusChanged (const EntryStatus& status, const QString& var) { ICLEntry *entry = qobject_cast<ICLEntry*> (sender ()); emit statusChanged (status, entry->GetEntryName () + '/' + var); }