*************** *** 21,26 **** #include"eventdlg.h" #include #include #include #include --- 21,27 ---- #include"eventdlg.h" #include + #include #include #include #include *************** *** 289,294 **** class AttachViewItem : public QListViewItem { public: static const int RTTI = 9200; AttachViewItem(AttachView *par, const char *icon) --- 290,296 ---- class AttachViewItem : public QListViewItem { public: + typedef enum { UrlAttach, RosterItemAttach } AttachType; static const int RTTI = 9200; AttachViewItem(AttachView *par, const char *icon) *************** *** 297,302 **** if(icon) setPixmap(0, IconsetFactory::icon(icon)); setMultiLinesEnabled(true); } --- 299,305 ---- if(icon) setPixmap(0, IconsetFactory::icon(icon)); + type = UrlAttach; setMultiLinesEnabled(true); } *************** *** 307,312 **** virtual void contextMenuRequested(const QPoint &pos) = 0; virtual void doubleClicked() = 0; }; class AttachViewUrl: public AttachViewItem --- 310,318 ---- virtual void contextMenuRequested(const QPoint &pos) = 0; virtual void doubleClicked() = 0; + + AttachType type; + RosterItem ri; }; class AttachViewUrl: public AttachViewItem *************** *** 317,326 **** AttachViewUrl(const QString &_url, const QString &_desc, AttachView *par) : AttachViewItem(par, "psi/www") { url = _url; desc = _desc; - setText(0, url + " (" + desc + ')'); } int rtti() const --- 323,350 ---- AttachViewUrl(const QString &_url, const QString &_desc, AttachView *par) : AttachViewItem(par, "psi/www") { + type = UrlAttach; url = _url; desc = _desc; + if (!desc.isEmpty()) { + setText(0, url + " (" + desc + ')'); + } + else { + setText(0, url); + } + } + + AttachViewUrl(const RosterItem &rosterItem, AttachView *par) + : AttachViewItem(par, "psi/rosteritem") + { + type = RosterItemAttach; + ri = rosterItem; + + QString text = ri.jid().full(); + if (!ri.name().isEmpty()) + text += " (" + ri.name() + ")"; + setText(0, text); } int rtti() const *************** *** 330,348 **** void contextMenuRequested(const QPoint &pos) { QPopupMenu pm(listView()); - pm.insertItem(AttachView::tr("Go to &URL..."), 0); - pm.insertItem(AttachView::tr("Copy location"), 1); - pm.insertSeparator(); - pm.insertItem(AttachView::tr("Remove"), 2); - AttachView *lv = (AttachView *)listView(); - if(lv->readOnly()) - pm.setItemEnabled(2, false); switch(pm.exec(pos)) { case 0: - lv->goURL(url); break; case 1: QApplication::clipboard()->setText(url, QClipboard::Clipboard); --- 354,382 ---- void contextMenuRequested(const QPoint &pos) { + AttachView *lv = (AttachView *)listView(); QPopupMenu pm(listView()); + if(type == AttachViewItem::RosterItemAttach) { + pm.insertItem(AttachView::tr("&Add Contact..."), 0); + if (!lv->readOnly ()) + pm.setItemEnabled(0, false); + } + else { + pm.insertItem(AttachView::tr("Go to &URL..."), 0); + pm.insertItem(AttachView::tr("Copy location"), 1); + pm.insertSeparator(); + pm.insertItem(AttachView::tr("Remove"), 2); + if(lv->readOnly()) + pm.setItemEnabled(2, false); + } switch(pm.exec(pos)) { case 0: + if(type == AttachViewItem::RosterItemAttach) + lv->actionAddContact(ri); + else + lv->goURL(url); break; case 1: QApplication::clipboard()->setText(url, QClipboard::Clipboard); *************** *** 359,365 **** void doubleClicked() { AttachView *lv = (AttachView *)listView(); - lv->goURL(url); } QString url, desc; --- 393,402 ---- void doubleClicked() { AttachView *lv = (AttachView *)listView(); + if(type != AttachViewItem::RosterItemAttach) + lv->goURL(url); + else + lv->actionAddContact(ri); } QString url, desc; *************** *** 374,388 **** connect(this, SIGNAL(contextMenuRequested(QListViewItem *, const QPoint &, int)), SLOT(qlv_context(QListViewItem *, const QPoint &, int))); connect(this, SIGNAL(doubleClicked(QListViewItem *)), SLOT(qlv_doubleClicked(QListViewItem *))); }; AttachView::~AttachView() { } void AttachView::setReadOnly(bool b) { v_readOnly = b; } void AttachView::urlAdd(const QString &url, const QString &desc) --- 411,460 ---- connect(this, SIGNAL(contextMenuRequested(QListViewItem *, const QPoint &, int)), SLOT(qlv_context(QListViewItem *, const QPoint &, int))); connect(this, SIGNAL(doubleClicked(QListViewItem *)), SLOT(qlv_doubleClicked(QListViewItem *))); + setAcceptDrops(TRUE); }; AttachView::~AttachView() { } + void AttachView::dragEnterEvent(QDragEnterEvent *e) + { + e->accept(QTextDrag::canDecode(e)); + } + + void AttachView::dropEvent(QDropEvent *e) + { + QString str; + + if(QTextDrag::decode(e, str)) { + Jid jid(str); + if (jid.isValid() && !jid.node().isEmpty()) { + /* Try to find roster item */ + EventDlg *e = (EventDlg *)parent(); + QPtrList ul = e->psiAccount()->findRelavent(jid); + + if(!ul.isEmpty()) { + /* Add roster item */ + UserListItem *u = ul.first(); + rosterItemAdd(*u); + } + else { + /* Add new roster item */ + rosterItemAdd(RosterItem(jid)); + } + } + else { + /* Add as URL */ + urlAdd(str,""); + } + } + } + void AttachView::setReadOnly(bool b) { v_readOnly = b; + setAcceptDrops(!b); } void AttachView::urlAdd(const QString &url, const QString &desc) *************** *** 416,421 **** openURL(url); } UrlList AttachView::urlList() const { UrlList list; --- 488,498 ---- openURL(url); } + void AttachView::actionAddContact(const RosterItem& ri) + { + ((EventDlg*)parent())->psiAccount()->openAddUserDlg(ri.jid(),ri.name(),ri.groups()); + } + UrlList AttachView::urlList() const { UrlList list; *************** *** 423,429 **** for(AttachViewItem *i = (AttachViewItem *)firstChild(); i; i = (AttachViewItem *)i->nextSibling()) { if(i->rtti() == AttachViewUrl::RTTI) { AttachViewUrl *i_url = (AttachViewUrl *)i; - list += Url(i_url->url, i_url->desc); } } --- 500,507 ---- for(AttachViewItem *i = (AttachViewItem *)firstChild(); i; i = (AttachViewItem *)i->nextSibling()) { if(i->rtti() == AttachViewUrl::RTTI) { AttachViewUrl *i_url = (AttachViewUrl *)i; + if (i_url->type == AttachViewItem::UrlAttach) + list += Url(i_url->url, i_url->desc); } } *************** *** 449,454 **** childCountChanged(); } void AttachView::takeItem(QListViewItem *i) { QListView::takeItem(i); --- 527,538 ---- childCountChanged(); } + void AttachView::rosterItemAdd(const RosterItem& ri) + { + new AttachViewUrl(ri, this); + childCountChanged(); + } + void AttachView::takeItem(QListViewItem *i) { QListView::takeItem(i); *************** *** 460,465 **** emit childCountChanged(); } //---------------------------------------------------------------------------- // AddUrlDlg //---------------------------------------------------------------------------- --- 544,568 ---- emit childCountChanged(); } + + RosterItemList AttachView::rosterItemList() const + { + RosterItemList list; + + for(AttachViewItem *i = (AttachViewItem *)firstChild(); i; i = (AttachViewItem *)i->nextSibling()) + if (i->type == AttachViewItem::RosterItemAttach) + list += i->ri; + + return list; + } + + void AttachView::addRosterItemList(const RosterItemList &list) + { + for(QValueList::ConstIterator it = list.begin(); it != list.end(); ++it) { + rosterItemAdd(*it); + } + } + //---------------------------------------------------------------------------- // AddUrlDlg //---------------------------------------------------------------------------- *************** *** 514,519 **** IconButton *pb_join, *pb_decline; // invitation buttons ChatView *mle; AttachView *attachView; QTimer *whois; QString lastWhois; Jid jid, realJid; --- 617,623 ---- IconButton *pb_join, *pb_decline; // invitation buttons ChatView *mle; AttachView *attachView; + QTimer *attachHide; QTimer *whois; QString lastWhois; Jid jid, realJid; *************** *** 585,590 **** d->mayShowReplyingBtns = false; d->psi = psi; d->pa = 0; d->psi->dialogRegister(this); d->anim = 0; --- 689,695 ---- d->mayShowReplyingBtns = false; d->psi = psi; d->pa = 0; + d->attachView = 0; d->psi->dialogRegister(this); d->anim = 0; *************** *** 597,602 **** d->whois = new QTimer; connect(d->whois, SIGNAL(timeout()), SLOT(doWhois())); init(); d->cb_ident->setAccount(pa); --- 702,710 ---- d->whois = new QTimer; connect(d->whois, SIGNAL(timeout()), SLOT(doWhois())); + d->attachHide = new QTimer; + connect(d->attachHide, SIGNAL(timeout()), SLOT(showHideAttachView())); + init(); d->cb_ident->setAccount(pa); *************** *** 642,647 **** if(u && u->isSecure(d->jid.resource())) d->tb_pgp->setOn(true); } } EventDlg::EventDlg(const Jid &j, PsiAccount *pa, bool unique) --- 750,757 ---- if(u && u->isSecure(d->jid.resource())) d->tb_pgp->setOn(true); } + + setAcceptDrops(TRUE); } EventDlg::EventDlg(const Jid &j, PsiAccount *pa, bool unique) *************** *** 685,690 **** { if(d->composing) { delete d->whois; d->psi->dialogUnregister(this); } else { --- 795,801 ---- { if(d->composing) { delete d->whois; + delete d->attachHide; d->psi->dialogUnregister(this); } else { *************** *** 1332,1337 **** return QSize(420, 280); } void EventDlg::showEvent(QShowEvent *e) { QWidget::showEvent(e); --- 1443,1460 ---- return QSize(420, 280); } + void EventDlg::dragEnterEvent(QDragEnterEvent *) + { + d->attachHide->stop(); + if(d->attachView->isHidden()) + d->attachView->show(); + } + + void EventDlg::dragLeaveEvent(QDragLeaveEvent *) + { + d->attachHide->start(3000,true); + } + void EventDlg::showEvent(QShowEvent *e) { QWidget::showEvent(e); *************** *** 1416,1421 **** m.setBody(d->mle->text()); m.setSubject(d->le_subj->text()); m.setUrlList(d->attachView->urlList()); m.setTimeStamp(QDateTime::currentDateTime()); m.setThread(d->thread); --- 1539,1545 ---- m.setBody(d->mle->text()); m.setSubject(d->le_subj->text()); + m.setRosterItemList(d->attachView->rosterItemList()); m.setUrlList(d->attachView->urlList()); m.setTimeStamp(QDateTime::currentDateTime()); m.setThread(d->thread); *************** *** 1769,1774 **** d->attachView->clear(); d->attachView->addUrlList(m.urlList()); showHideAttachView(); } --- 1893,1899 ---- d->attachView->clear(); d->attachView->addUrlList(m.urlList()); + d->attachView->addRosterItemList(m.rosterItemList()); showHideAttachView(); }