Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Right-click on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: <erijo@us...> - 2006-08-30 12:45:17
|
Author: erijo Date: Wed Aug 30 14:39:13 2006 New Revision: 4589 URL: http://svn.licq.org/viewvc/licq?rev=3D4589&view=3Drev Log: Refactored CUserView::viewportDropEvent by moving common code introduced in= r4587 to a new function. Also rewrote the drag&drop behaviour for contacts= to work with all protocols. Modified: trunk/qt-gui/src/userbox.cpp Modified: trunk/qt-gui/src/userbox.cpp URL: http://svn.licq.org/viewvc/licq/trunk/qt-gui/src/userbox.cpp?rev=3D458= 9&r1=3D4588&r2=3D4589&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- trunk/qt-gui/src/userbox.cpp (original) +++ trunk/qt-gui/src/userbox.cpp Wed Aug 30 14:39:13 2006 @@ -42,6 +42,7 @@ #include "usereventdlg.h" #include "usercodec.h" =20 +#include "licq_icqd.h" #include "licq_user.h" #include "licq_socket.h" =20 @@ -1182,6 +1183,68 @@ e->accept(QTextDrag::canDecode(e) || QUriDrag::canDecode(e)); } =20 +/** + * Get a pointer to a dialog for sending events with the given @a type, to= the contact + * @a szId over the protocol @a nPPID. If the dialog is already open, the = dialog is + * converted to the correct type before being returned. + * + * @returns a pointer to a send event dialog of type @a T, or NULL on erro= r=2E + */ +template<typename T> +static T* getSendEventDialog(UserEventCommon::type type, const char *szId,= unsigned long nPPID) +{ + int function; + if (type =3D=3D UserEventCommon::UC_CONTACT) + function =3D mnuUserSendContact; + else if (type =3D=3D UserEventCommon::UC_FILE) + function =3D mnuUserSendFile; + else if (type =3D=3D UserEventCommon::UC_MESSAGE) + function =3D mnuUserSendMsg; + else if (type =3D=3D UserEventCommon::UC_URL) + function =3D mnuUserSendUrl; + else + return NULL; + + UserEventCommon *common =3D gMainWindow->callFunction(function, szId, nP= PID); + if (!common) + return NULL; + + T *dialog =3D dynamic_cast<T *>(common); + if (!dialog) + { + UserSendCommon *base =3D dynamic_cast<UserSendCommon *>(common); + if (!base) + return NULL; + + base->changeEventType(type); + dialog =3D dynamic_cast<T *>(gMainWindow->callFunction(function, szId,= nPPID)); + if (!dialog) + return NULL; + } + + return dialog; +} + +/// Convenient, wrapper functions for getSendEventDialog. +static inline UserSendContactEvent* getSendContactEventDialog(const char *= szId, unsigned long nPPID) +{ + return getSendEventDialog<UserSendContactEvent>(UserEventCommon::UC_CONT= ACT, szId, nPPID); +} + +static inline UserSendFileEvent* getSendFileEventDialog(const char *szId, = unsigned long nPPID) +{ + return getSendEventDialog<UserSendFileEvent>(UserEventCommon::UC_FILE, s= zId, nPPID); +} + +static inline UserSendMsgEvent* getSendMsgEventDialog(const char *szId, un= signed long nPPID) +{ + return getSendEventDialog<UserSendMsgEvent>(UserEventCommon::UC_MESSAGE,= szId, nPPID); +} + +static inline UserSendUrlEvent* getSendUrlEventDialog(const char *szId, un= signed long nPPID) +{ + return getSendEventDialog<UserSendUrlEvent>(UserEventCommon::UC_URL, szI= d, nPPID); +} =20 void CUserView::viewportDropEvent(QDropEvent* e) { @@ -1190,153 +1253,126 @@ e->ignore(); =20 CUserViewItem* it =3D static_cast<CUserViewItem*>(itemAt(e->pos())); - - if (it) - { - if (it->ItemId()) - { - QString text; - QStrList lst; - if (QUriDrag::decode(e, lst)) - { - QStrListIterator strIter(lst); - if (!(text =3D QUriDrag::uriToLocalFile(strIter)).isEmpty()) + if (!it) + return; + + if (it->ItemId()) + { + QString text; + QStrList lst; + if (QUriDrag::decode(e, lst)) + { + QStrListIterator strIter(lst); + if (!(text =3D QUriDrag::uriToLocalFile(strIter)).isEmpty()) + { + UserSendFileEvent *sendFile =3D getSendFileEventDialog(it->ItemId(= ), it->ItemPPID()); + if (!sendFile) + return; + + sendFile->setFile(text, QString::null); + + // Add all the files + while (strIter !=3D lst.getLast()) { - UserSendCommon *basePtr =3D dynamic_cast<UserSendCommon *> - (gMainWindow->callFunction(mnuUserSendFile, it->ItemId(), it= ->ItemPPID())); - if (!basePtr) - return; - - UserSendFileEvent *sendFile; - if (!(sendFile =3D dynamic_cast<UserSendFileEvent *>(basePtr))) - { - basePtr->changeEventType(UserEventCommon::UC_FILE); - sendFile =3D dynamic_cast<UserSendFileEvent *> - (gMainWindow->callFunction(mnuUserSendFile, it->ItemId(), = it->ItemPPID())); - if (!sendFile) - return; - } - - sendFile->setFile(text, QString::null); - - // Add all the files - while (strIter !=3D lst.getLast()) - { - ++strIter; - if (!(text =3D QUriDrag::uriToLocalFile(strIter)).isEmpty()) - sendFile->addFile(text); - } - - sendFile->show(); + ++strIter; + if (!(text =3D QUriDrag::uriToLocalFile(strIter)).isEmpty()) + sendFile->addFile(text); } - else + + sendFile->show(); + } + else + { + UserSendUrlEvent *sendUrl =3D getSendUrlEventDialog(it->ItemId(), = it->ItemPPID()); + if (!sendUrl) + return; + + sendUrl->setUrl(QString(strIter), QString::null); + sendUrl->show(); + } + } + + else if (QTextDrag::decode(e, text)) + { + unsigned long nPPID =3D 0; + FOR_EACH_PROTO_PLUGIN_START(gMainWindow->licqDaemon) + { + if (text.startsWith(PPIDSTRING((*_ppit)->PPID()))) { - UserSendCommon *basePtr =3D dynamic_cast<UserSendCommon *> - (gMainWindow->callFunction(mnuUserSendUrl, it->ItemId(),it->= ItemPPID())); - if (!basePtr) - return; - - UserSendUrlEvent *sendUrl; - if (!(sendUrl =3D dynamic_cast<UserSendUrlEvent *>(basePtr))) - { - basePtr->changeEventType(UserSendCommon::UC_URL); - sendUrl =3D dynamic_cast<UserSendUrlEvent *> - (gMainWindow->callFunction(mnuUserSendUrl, it->ItemId(),it= ->ItemPPID())); - if (!sendUrl) - return; - } - - sendUrl->setUrl(QString(strIter), QString::null); - sendUrl->show(); + nPPID =3D (*_ppit)->PPID(); + break; } } - - //TODO change this - else if (QTextDrag::decode(e, text)) - { -// const char *p =3D (text.left(4).latin1()); - char *szId =3D strdup((text.mid(4, text.length() - 4).latin1())); - unsigned long nPPID =3D LICQ_PPID; //TODO fix this - - if (szId) + FOR_EACH_PROTO_PLUGIN_END; + + if (nPPID && text.length() > 4) + { + char *szId =3D strdup(text.mid(4).latin1()); + if (strcmp(szId, it->ItemId()) =3D=3D 0 && nPPID =3D=3D it->ItemPP= ID()) { - if (strcmp(szId, it->ItemId()) =3D=3D 0 && nPPID =3D=3D it->Item= PPID()) - { - free(szId); - return; - } - - UserSendCommon *basePtr =3D dynamic_cast<UserSendCommon *> - (gMainWindow->callFunction(mnuUserSendContact, it->ItemId(),= it->ItemPPID())); - if (!basePtr) - { - free(szId); - return; - } - - UserSendContactEvent* sendContact; - if (!(sendContact =3D dynamic_cast<UserSendContactEvent *>(baseP= tr))) - { - basePtr->changeEventType(UserSendCommon::UC_CONTACT); - sendContact =3D dynamic_cast<UserSendContactEvent *> - (gMainWindow->callFunction(mnuUserSendContact, it->ItemId(= ), it->ItemPPID())); - if (!sendContact) - { - free(szId); - return; - } - } - - ICQUser* u =3D gUserManager.FetchUser(szId, nPPID, LOCK_R); - QString alias =3D u ? u->GetAlias() : ""; - gUserManager.DropUser(u); - - sendContact->setContact(szId, nPPID, alias); - sendContact->show(); + free(szId); + return; } - else // if (szId) + + UserSendContactEvent* sendContact =3D getSendContactEventDialog(it= ->ItemId(), it->ItemPPID()); + if (!sendContact) { - UserSendCommon *basePtr =3D dynamic_cast<UserSendCommon *> - (gMainWindow->callFunction(mnuUserSendMsg, it->ItemId(), it-= >ItemPPID())); - if (!basePtr) - return; - - UserSendMsgEvent* sendMsg; - if (!(sendMsg =3D dynamic_cast<UserSendMsgEvent *>(basePtr))) - { - basePtr->changeEventType(UserSendCommon::UC_MESSAGE); - sendMsg =3D dynamic_cast<UserSendMsgEvent *> - (gMainWindow->callFunction(mnuUserSendMsg, it->ItemId(), i= t->ItemPPID())); - if (!sendMsg) - return; - } - - sendMsg->setText(text); - sendMsg->show(); + free(szId); + return; } =20 - free (szId); - } - } - //TODO Change this - else if (it->isGroupItem()) - { - QString text; - if (QTextDrag::decode(e, text)) - { -// const char *p =3D (text.left(4).latin1()); - char *szId =3D strdup(text.mid(4, text.length() - 4).latin1()); - unsigned long nPPID =3D LICQ_PPID; //TODO Fix this - - if (szId) + ICQUser* u =3D gUserManager.FetchUser(szId, nPPID, LOCK_R); + QString alias =3D u ? u->GetAlias() : ""; + gUserManager.DropUser(u); + + sendContact->setContact(szId, nPPID, alias); + sendContact->show(); + + free(szId); + } + else + { + UserSendMsgEvent* sendMsg =3D getSendMsgEventDialog(it->ItemId(), = it->ItemPPID()); + if (!sendMsg) + return; + + sendMsg->setText(text); + sendMsg->show(); + } + } + } + + else if (it->isGroupItem()) + { + QString text; + if (QTextDrag::decode(e, text) && text.length() > 4) + { + unsigned long nPPID =3D 0; + FOR_EACH_PROTO_PLUGIN_START(gMainWindow->licqDaemon) + { + if (text.startsWith(PPIDSTRING((*_ppit)->PPID()))) { - gUserManager.AddUserToGroup(szId, nPPID, it->GroupId()); - gMainWindow->updateUserWin(); + nPPID =3D (*_ppit)->PPID(); + break; } - - free(szId); - } - } + } + FOR_EACH_PROTO_PLUGIN_END; + + if (nPPID =3D=3D 0) + return; + + char *szId =3D strdup(text.mid(4).latin1()); + + if (szId) + { + gUserManager.AddUserToGroup(szId, nPPID, it->GroupId()); + gMainWindow->updateUserWin(); + } + + free(szId); + } + else + return; // Not accepted } =20 e->accept(); @@ -1361,7 +1397,8 @@ CUserViewItem* item =3D static_cast<CUserViewItem*>(currentItem()); if(item =3D=3D NULL) return; =20 - if(item->isGroupItem()) { + if(item->isGroupItem()) + { setOpen(item, !item->isOpen()); return; } @@ -1392,7 +1429,8 @@ =20 QListViewItemIterator it(this); QListViewItem* lastitem =3D 0; - while(it.current() !=3D NULL) { + while(it.current() !=3D NULL) + { lastitem =3D it.current(); ++it; } @@ -1410,18 +1448,18 @@ if (m_typePos > 0) { m_typeAhead.truncate(m_typeAhead.length()-1); - m_typePos--; + m_typePos--; } /* fall through */ - =20 + default: { int ascii =3D tolower(e->ascii()); if (!isalnum(ascii) && e->key() !=3D Key_Backspace) { QListView::keyPressEvent(e); - m_typeAhead =3D ""; - m_typePos =3D 0 ; + m_typeAhead =3D ""; + m_typePos =3D 0 ; return; } =20 @@ -1429,20 +1467,18 @@ m_typePos++; =20 QListViewItemIterator it(firstChild()); - =20 + while (it.current() !=3D NULL) { CUserViewItem* item =3D static_cast<CUserViewItem*>(it.current()); + if (item->text(1).lower().startsWith(m_typeAhead)) { - if (item->text(1).lower().startsWith(m_typeAhead)) - { - setSelected(item, true); - ensureItemVisible(item); - item->repaint(); - return; - } - ++it; + setSelected(item, true); + ensureItemVisible(item); + item->repaint(); + return; } + ++it; } =20 // If we are here we didn't find any names |