void GlooxAccount::SetBookmarkedMUCs (const QVariantList& datas) { QSet<QString> jids; QList<QXmppBookmarkConference> mucs; Q_FOREACH (const QVariant& var, datas) { const QVariantMap& map = var.toMap (); QXmppBookmarkConference conf; conf.setAutoJoin (map.value ("Autojoin").toBool ()); const auto& room = map.value ("Room").toString (); const auto& server = map.value ("Server").toString (); if (room.isEmpty () || server.isEmpty ()) continue; const auto& jid = room + '@' + server; if (jids.contains (jid)) continue; jids << jid; conf.setJid (jid); conf.setNickName (map.value ("Nick").toString ()); conf.setName (map.value ("StoredName").toString ()); mucs << conf; } QXmppBookmarkSet set; set.setConferences (mucs); set.setUrls (GetBookmarks ().urls ()); SetBookmarks (set); }
QVariantList GlooxAccount::GetBookmarkedMUCs () const { QVariantList result; const QXmppBookmarkSet& set = GetBookmarks (); Q_FOREACH (const QXmppBookmarkConference& conf, set.conferences ()) { const QStringList& split = conf.jid ().split ('@', QString::SkipEmptyParts); if (split.size () != 2) { qWarning () << Q_FUNC_INFO << "incorrectly split jid for conf" << conf.jid () << split; continue; } QVariantMap cm; cm ["HumanReadableName"] = QString ("%1 (%2)") .arg (conf.jid ()) .arg (conf.nickName ()); cm ["AccountID"] = GetAccountID (); cm ["Nick"] = conf.nickName (); cm ["Room"] = split.at (0); cm ["Server"] = split.at (1); cm ["Autojoin"] = conf.autoJoin (); cm ["StoredName"] = conf.name (); result << cm; } return result; }
QVariantList IrcAccount::GetBookmarkedMUCs () const { QVariantList result; const QList<IrcBookmark>& bookmarks = GetBookmarks (); Q_FOREACH (const IrcBookmark& channel, bookmarks) { QVariantMap cm; cm ["HumanReadableName"] = QString ("%1@%2 (%3)") .arg (channel.ChannelName_ ) .arg (channel.ServerName_) .arg (channel.NickName_); cm ["AccountID"] = GetAccountID (); cm ["Server"] = channel.ServerName_; cm ["Port"] = channel.ServerPort_; cm ["ServerPassword"] = channel.ServerPassword_; cm ["Encoding"] = channel.ServerEncoding_; cm ["Channel"] = channel.ChannelName_; cm ["Password"] = channel.ChannelPassword_; cm ["Nickname"] = channel.NickName_; cm ["SSL"] = channel.SSL_; cm ["Autojoin"] = channel.AutoJoin_; cm ["StoredName"] = channel.Name_; result << cm; }
/*! * \brief TSSettings::GetBookmarkByServerUID Find a bookmark by server uid * \param sUID the server uid * \param result a QMap * \return true on success, false when an error has occurred; note that not found is a non-error -> success; just check if the QMap is empty for that */ bool TSSettings::GetBookmarkByServerUID(QString sUID, QMap<QString, QString> &result) { QStringList bookmarks; if (!GetBookmarks(bookmarks)) return false; sUID.prepend("ServerUID="); for (int i = 0;i<bookmarks.count();++i) { QString bookmark = bookmarks.at(i); if (bookmark.contains(sUID)) { result = GetMapFromValue(bookmark); break; } } return true; }
//Sweep history from specified contact void SweepHistoryFromContact(MCONTACT hContact, CriteriaStruct Criteria, BOOL keepUnread) { int lPolicy; if (hContact == NULL) // for system history lPolicy = db_get_b(NULL, ModuleName, "SweepSHistory", 0); else // for contact history (or "SweepHistory" - default action) lPolicy = db_get_b(hContact, ModuleName, "SweepHistory", db_get_b(NULL, ModuleName, "SweepHistory", 0)); if (lPolicy == 0) return; // nothing to do int eventsCnt = db_event_count(hContact); if (eventsCnt == 0) return; BOOL doDelete, unsafe = db_get_b(NULL, ModuleName, "UnsafeMode", 0); BEventData *books, *item, ev = { 0 }; size_t bookcnt, btshift; SetCursor(LoadCursor(0, IDC_WAIT)); // switch off SAFETYMODE if necessary if (unsafe) CallService(MS_DB_SETSAFETYMODE, 0, 0); GetBookmarks(hContact, &books, &bookcnt); // Get first event for (MEVENT hDBEvent = db_event_first(hContact); hDBEvent != NULL; ) { DBEVENTINFO dbei = { sizeof(dbei) }; db_event_get(hDBEvent, &dbei); // should we stop processing? // lPolicy == 1 - for time criterion, lPolicy == 2 - keep N last events, lPolicy == 3 - delete all events if ((lPolicy == 1 && (unsigned)Criteria.time < dbei.timestamp) || (lPolicy == 2 && Criteria.keep > --eventsCnt)) break; doDelete = TRUE; if (!(dbei.flags & (DBEF_SENT | DBEF_READ)) && keepUnread) doDelete = FALSE; // keep unread events if (bookcnt != 0) { // keep bookmarks ev.hDBEvent = hDBEvent; item = (BEventData*)bsearch(&ev, books, bookcnt, sizeof(BEventData), CompareBookmarks); if (item != NULL && item->Timestamp == dbei.timestamp) { doDelete = FALSE; btshift = (--bookcnt - (item - books))*sizeof(BEventData); if (btshift) memmove(item, item + 1, btshift); } } // find next event MEVENT hDBEventNext = db_event_next(hContact, hDBEvent); if (doDelete) db_event_delete(hContact, hDBEvent); hDBEvent = hDBEventNext; } mir_free(books); // switch ON safety mode as fast as we can to avoid DB corruption if (unsafe) CallService(MS_DB_SETSAFETYMODE, 1, 0); SetCursor(LoadCursor(0, IDC_ARROW)); }