void HistoryDlg::doExport() { UserListItem *u = pa_->findFirstRelevant(jid_); QString them = JIDUtil::nickOrJid(u->name(), u->jid().full()); QString s = JIDUtil::encode(them).toLower(); QString str = QDir::homeDirPath() + "/" + s + ".txt"; int y = QMessageBox::information(this, tr("Export"), tr("Export all history of chats or just from selected day?"), tr("&All"), tr("&Day")); while(1) { str = QFileDialog::getSaveFileName(this, tr("Export message history"), str, tr("Text files (*.txt);;Html files (*.html);;All files (*.*)")); if(str.isEmpty()) break; QFileInfo fi(str); if(fi.exists()) { int x = QMessageBox::information(this, tr("Confirm overwrite"), tr("File already exists, overwrite?"), tr("&Yes"), tr("&No")); if(x != 0) continue; } QDate date; if(y!=0) date = lookDate; HistoryDB::instance()->exportHistory(pa_, jidFull_, str, date); break; } }
//---------------------------------------------------------------------------- // StatusShowDlg // FIXME: Will no longer be needed once it is out of the groupchat contactview //---------------------------------------------------------------------------- StatusShowDlg::StatusShowDlg(const UserListItem &u) : QDialog(0, 0, false) { setAttribute(Qt::WA_DeleteOnClose); // build the dialog QVBoxLayout *vb = new QVBoxLayout(this, 8); PsiTextView *te = new PsiTextView(this); vb->addWidget(te); QHBoxLayout *hb = new QHBoxLayout(vb); QPushButton *pb = new QPushButton(tr("&Close"), this); connect(pb, SIGNAL(clicked()), SLOT(close())); hb->addStretch(1); hb->addWidget(pb); hb->addStretch(1); // set the rest up te->setReadOnly(true); te->setTextFormat(Qt::RichText); te->setText(u.makeDesc()); setWindowTitle(tr("Status for %1").arg(JIDUtil::nickOrJid(u.name(), u.jid().full()))); resize(400,240); pb->setFocus(); }
UserListItem *UserList::find(const XMPP::Jid &j) { UserListIt it(*this); for(UserListItem *i; (i = it.current()); ++it) { if(i->jid().compare(j)) return i; } return 0; }
void IgnoreList::editComments(const QString& n) { QString _c; UserListItem* item = mUserList->findItem(n); if(item) _c = item->comments(); bool res; QString c = QInputDialog::getText(museeq->mainwin(), tr("Comments"), tr("Comments for %1").arg(n), QLineEdit::Normal, _c, &res); if (res) museeq->addIgnored(n, c); }
void YaProfile::updateRosterNick() { QList<UserListItem*> ul = account()->findRelevant(jid()); UserListItem* u = 0; if (!ul.isEmpty()) u = ul.first(); rosterNick_ = QString(); if (u) { rosterNick_ = u->name(); } emit nameChanged(); }
void HistoryDlg::doSave() { UserListItem *u = d->pa->findFirstRelevant(d->jid); QString them = JIDUtil::nickOrJid(u->name(), u->jid().full()); QString s = JIDUtil::encode(them).toLower(); QString str = FileUtil::getSaveFileName(this, tr("Export message history"), s + ".txt", tr("Text files (*.txt);;All files (*.*)")); if (!str.isEmpty()) { exportHistory(str); } }
bool GCUserView::maybeTip(const QPoint &pos) { Q3ListViewItem *qlvi = itemAt(pos); if(!qlvi || !qlvi->parent()) return false; GCUserViewItem *lvi = (GCUserViewItem *) qlvi; QRect r(itemRect(lvi)); const QString &nick = lvi->text(0); const Status &s = lvi->s; UserListItem u; // SICK SICK SICK SICK GCMainDlg* dlg = gcDlg_; if (!dlg) { qDebug("Calling maybetip on an entity without an owning dialog"); return false; } u.setJid(dlg->jid().withResource(nick)); u.setName(nick); // Find out capabilities info Jid caps_jid(s.mucItem().jid().isEmpty() ? dlg->jid().withResource(nick) : s.mucItem().jid()); QString client_name = dlg->account()->capsManager()->clientName(caps_jid); QString client_version = (client_name.isEmpty() ? QString() : dlg->account()->capsManager()->clientVersion(caps_jid)); // make a resource so the contact appears online UserResource ur; ur.setName(nick); ur.setStatus(s); ur.setClient(client_name,client_version,""); u.userResourceList().append(ur); PsiToolTip::showText(mapToGlobal(pos), u.makeTip(), this); return true; }
void paintContact(QPainter* mp, const QStyleOptionViewItem& option, const QModelIndex& index, GCUserViewItem* item) const { mp->save(); QStyleOptionViewItem o = option; QPalette palette = o.palette; MUCItem::Role r = item->s.mucItem().role(); QRect rect = o.rect; if(nickColoring_) { if(r == MUCItem::Moderator) palette.setColor(QPalette::Text, colorModerator_); else if(r == MUCItem::Participant) palette.setColor(QPalette::Text, colorParticipant_); else if(r == MUCItem::Visitor) palette.setColor(QPalette::Text, colorVisitor_); else palette.setColor(QPalette::Text, colorNoRole_); } mp->fillRect(rect, (o.state & QStyle::State_Selected) ? palette.color(QPalette::Highlight) : palette.color(QPalette::Base)); if(showAvatar_) { QPixmap ava = item->avatar(); if(ava.isNull()) { ava = IconsetFactory::iconPixmap("psi/default_avatar"); } ava = AvatarFactory::roundedAvatar(ava, avatarRadius_, avatarSize_); QRect avaRect(rect); avaRect.setWidth(ava.width()); avaRect.setHeight(ava.height()); if(!avatarAtLeft_) { avaRect.moveTopRight(rect.topRight()); avaRect.translate(-1, 1); rect.setRight(avaRect.left() - 1); } else { avaRect.translate(1, 1); rect.setLeft(avaRect.right() + 1); } mp->drawPixmap(avaRect, ava); } QPixmap status = showStatusIcons_ ? item->icon() : QPixmap(); int h = rect.height(); int sh = status.isNull() ? 0 : status.height(); rect.setHeight(qMax(sh, fontHeight_)); rect.moveTop(rect.top() + (h - rect.height())/2); if(!status.isNull()) { QRect statusRect(rect); statusRect.setWidth(status.width()); statusRect.setHeight(status.height()); statusRect.translate(1, 1); mp->drawPixmap(statusRect, status); rect.setLeft(statusRect.right() + 2); } else rect.setLeft(rect.left() + 2); mp->setPen(QPen((o.state & QStyle::State_Selected) ? palette.color(QPalette::HighlightedText) : palette.color(QPalette::Text))); mp->setFont(o.font); mp->setClipRect(rect); QTextOption to; to.setWrapMode(QTextOption::NoWrap); mp->drawText(rect, index.data(Qt::DisplayRole).toString(), to); QList<QPixmap> rightPixs; if(showAffiliations_) { MUCItem::Affiliation a = item->s.mucItem().affiliation(); QPixmap pix; if(a == MUCItem::Owner) pix = IconsetFactory::iconPixmap("affiliation/owner"); else if(a == MUCItem::Admin) pix = IconsetFactory::iconPixmap("affiliation/admin"); else if(a == MUCItem::Member) pix = IconsetFactory::iconPixmap("affiliation/member"); else if(a == MUCItem::Outcast) pix = IconsetFactory::iconPixmap("affiliation/outcast"); else pix = IconsetFactory::iconPixmap("affiliation/noaffiliation"); if(!pix.isNull()) rightPixs.push_back(pix); } if(showClients_) { GCUserView *gcuv = (GCUserView*)item->treeWidget(); GCMainDlg* dlg = gcuv->mainDlg(); QPixmap clientPix; if(dlg) { UserListItem u; const QString &nick = item->text(0); Jid caps_jid(/*s.mucItem().jid().isEmpty() ? */ dlg->jid().withResource(nick) /* : s.mucItem().jid()*/); CapsManager *cm = dlg->account()->client()->capsManager(); QString client_name = cm->clientName(caps_jid); QString client_version = (client_name.isEmpty() ? QString() : cm->clientVersion(caps_jid)); UserResource ur; ur.setStatus(item->s); ur.setClient(client_name,client_version,""); u.userResourceList().append(ur); QStringList clients = u.clients(); if(!clients.isEmpty()) clientPix = IconsetFactory::iconPixmap("clients/" + clients.takeFirst()); } if(!clientPix.isNull()) rightPixs.push_back(clientPix); } mp->restore(); if(rightPixs.isEmpty()) return; int sumWidth = 0; foreach (const QPixmap& pix, rightPixs) { sumWidth += pix.width(); } sumWidth += rightPixs.count(); QColor bgc = (option.state & QStyle::State_Selected) ? palette.color(QPalette::Highlight) : palette.color(QPalette::Base); QColor tbgc = bgc; tbgc.setAlpha(0); QLinearGradient grad(rect.right() - sumWidth - 20, 0, rect.right() - sumWidth, 0); grad.setColorAt(0, tbgc); grad.setColorAt(1, bgc); QBrush tbakBr(grad); QRect gradRect(rect); gradRect.setLeft(gradRect.right() - sumWidth - 20); mp->fillRect(gradRect, tbakBr); QRect iconRect(rect); for (int i=0; i<rightPixs.size(); i++) { const QPixmap pix = rightPixs[i]; iconRect.setRight(iconRect.right() - pix.width() -1); mp->drawPixmap(iconRect.topRight(), pix); } }
void ChatDlg::setChatState(ChatState state) { if (PsiOptions::instance()->getOption("options.messages.send-composing-events").toBool() && (sendComposingEvents_ || (contactChatState_ != XMPP::StateNone))) { // Don't send to offline resource QList<UserListItem*> ul = account()->findRelevant(jid()); if (ul.isEmpty()) { sendComposingEvents_ = false; lastChatState_ = XMPP::StateNone; return; } UserListItem *u = ul.first(); if (!u->isAvailable()) { sendComposingEvents_ = false; lastChatState_ = XMPP::StateNone; return; } // Transform to more privacy-enabled chat states if necessary if (!PsiOptions::instance()->getOption("options.messages.send-inactivity-events").toBool() && (state == XMPP::StateGone || state == XMPP::StateInactive)) { state = XMPP::StatePaused; } if (lastChatState_ == XMPP::StateNone && (state != XMPP::StateActive && state != XMPP::StateComposing && state != XMPP::StateGone)) { //this isn't a valid transition, so don't send it, and don't update laststate return; } // Check if we should send a message if (state == lastChatState_ || state == XMPP::StateActive || (lastChatState_ == XMPP::StateActive && state == XMPP::StatePaused)) { lastChatState_ = state; return; } // Build event message Message m(jid()); if (sendComposingEvents_) { m.setEventId(eventId_); if (state == XMPP::StateComposing) { m.addEvent(ComposingEvent); } else if (lastChatState_ == XMPP::StateComposing) { m.addEvent(CancelEvent); } } if (contactChatState_ != XMPP::StateNone) { if (lastChatState_ != XMPP::StateGone) { if ((state == XMPP::StateInactive && lastChatState_ == XMPP::StateComposing) || (state == XMPP::StateComposing && lastChatState_ == XMPP::StateInactive)) { // First go to the paused state Message tm(jid()); m.setType("chat"); m.setChatState(XMPP::StatePaused); if (account()->isAvailable()) { account()->dj_sendMessage(m, false); } } m.setChatState(state); } } // Send event message if (m.containsEvents() || m.chatState() != XMPP::StateNone) { m.setType("chat"); if (account()->isAvailable()) { account()->dj_sendMessage(m, false); } } // Save last state if (lastChatState_ != XMPP::StateGone || state == XMPP::StateActive) lastChatState_ = state; } }
QVariant UserListModel::data(const QModelIndex & index, int role) const { if (!index.isValid()) return QVariant(); UserListItem * item = static_cast<UserListItem*>(index.internalPointer()); if (!item) return QVariant(); switch (role) { case Qt::DisplayRole: { switch (index.column()) { case COLUMN_NICK: return item->getNick(); case COLUMN_COMMENT: return item->getComment(); case COLUMN_TAG: return item->getTag(); case COLUMN_CONN: return item->getConnection(); case COLUMN_EMAIL: return item->getEmail(); case COLUMN_SHARE: return WulforUtil::formatBytes(item->getShare()); case COLUMN_IP: return item->getIP(); } break; } case Qt::DecorationRole: { if (index.column() != COLUMN_NICK) break; return (*WU->getUserIcon(item->ptr, item->isAway(), item->isOP(), item->getConnection())); break; } case Qt::ToolTipRole: { if (index.column() == COLUMN_SHARE) return QString::number(item->getShare()); else { QString ttip = ""; ttip = "<b>" + headerData(COLUMN_NICK, Qt::Horizontal, Qt::DisplayRole).toString() + "</b>: " + item->getNick() + "<br/>"; ttip += "<b>" + headerData(COLUMN_COMMENT, Qt::Horizontal, Qt::DisplayRole).toString() + "</b>: " + item->getComment() + "<br/>"; ttip += "<b>" + headerData(COLUMN_EMAIL, Qt::Horizontal, Qt::DisplayRole).toString() + "</b>: " + item->getEmail() + "<br/>"; ttip += "<b>" + headerData(COLUMN_IP, Qt::Horizontal, Qt::DisplayRole).toString() + "</b>: " + item->getIP() + "<br/>"; ttip += "<b>" + headerData(COLUMN_SHARE, Qt::Horizontal, Qt::DisplayRole).toString() + "</b>: " + WulforUtil::formatBytes(item->getShare()) + "<br/>"; QString tag = item->getTag(); WulforUtil::getInstance()->textToHtml(tag, true); ttip += "<b>" + headerData(COLUMN_TAG, Qt::Horizontal, Qt::DisplayRole).toString() + "</b>: " + tag + "<br/>"; ttip += "<b>" + headerData(COLUMN_CONN, Qt::Horizontal, Qt::DisplayRole).toString() + "</b>: " + item->getConnection() + "<br/>"; if (item->isOP()) ttip += tr("<b>Hub role</b>: Operator"); else ttip += tr("<b>Hub role</b>: User"); if (item->isFav()) ttip += tr("<br/><b>Favorite user</b>"); return ttip; } break; } case Qt::TextAlignmentRole: { if (index.column() == COLUMN_SHARE) return static_cast<int>(Qt::AlignRight | Qt::AlignVCenter); break; } case Qt::FontRole: { QFont font; font.setBold(true); if (item->isFav() && WBGET(WB_CHAT_HIGHLIGHT_FAVS)) return font; break; } } return QVariant(); }
void HistoryDlg::exportHistory(const QString &fname) { QFile f(fname); if(!f.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { QMessageBox::information(this, tr("Error"), tr("Error writing to file.")); return; } QTextStream stream(&f); QString us = d->pa->nick(); UserListItem *u = d->pa->findFirstRelevant(d->jid); QString them = JIDUtil::nickOrJid(u->name(), u->jid().full()); d->exp = new EDBHandle(d->pa->edb()); QString id; while(1) { if(id.isEmpty()) { d->exp->getOldest(d->jid, 1000); } else { d->exp->get(d->jid, id, EDB::Forward, 1000); } while(d->exp->busy()) { qApp->processEvents(); } const EDBResult *r = d->exp->result(); if(!r) { break; } if(r->count() <= 0) { break; } // events are in forward order for(int i = 0; i < r->count(); ++i) { EDBItem* item = r->value(i); id = item->nextId(); PsiEvent *e = item->event(); QString txt; QDateTime dt = e->timeStamp(); QString ts; //ts.sprintf("%04d/%02d/%02d %02d:%02d:%02d", dt.date().year(), dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second()); ts = dt.toString(Qt::LocalDate); QString nick; if(e->originLocal()) { nick = us; } else { nick = them; } QString heading = QString("(%1) ").arg(ts) + nick + ": "; if(e->type() == PsiEvent::Message) { MessageEvent *me = (MessageEvent *)e; stream << heading << endl; QStringList lines = me->message().body().split('\n', QString::KeepEmptyParts); foreach(const QString& str, lines) { QStringList sub = wrapString(str, 72); foreach(const QString& str2, sub) { txt += QString(" ") + str2 + '\n'; } } }