27 #include <QHeaderView>
33 #include <KStandardAction>
34 #include <KActionMenu>
35 #include <KActionCollection>
36 #include <KXmlGuiWindow>
37 #include <KLocalizedString>
38 #include <KInputDialog>
39 #include <KMessageBox>
40 #include <KToolInvocation>
41 #include <kxmlguifactory.h>
42 #include <kabc/stdaddressbook.h>
44 #include "kopeteuiglobal.h"
45 #include "kopetecontactlistelement.h"
46 #include "kopetemetacontact.h"
47 #include "kopeteaccountmanager.h"
48 #include "kopetecontact.h"
49 #include "kopetegroup.h"
50 #include "kopetecontactlist.h"
51 #include "kopetestdaction.h"
55 #include "kopeteaccount.h"
56 #include "addcontactpage.h"
57 #include "kopeteappearancesettings.h"
58 #include "kopetebehaviorsettings.h"
64 class KopeteContactListViewPrivate
67 KopeteContactListViewPrivate()
68 : controlPressed( false ),
69 scrollAutoHideTimer(0),
70 scrollAutoHideCounter(10),
71 scrollAutoHideTimeout(10),
72 scrollAutoHide(false),
78 QMap<KMenu*, QAction*> menuTitleMap;
90 KAction *actionAddTemporaryContact;
96 QMap<KAction*, Kopete::Account*> addContactAccountMap;
97 QPointer<Kopete::MetaContact> selectedMetaContact;
99 QPointer<Kopete::Contact> pressedContact;
103 int scrollAutoHideTimer;
105 int scrollAutoHideCounter;
107 int scrollAutoHideTimeout;
115 :
QTreeView( parent ), d( new KopeteContactListViewPrivate() )
119 setSelectionMode( QAbstractItemView::ExtendedSelection );
120 setDragEnabled(
true );
121 setDragDropMode( QAbstractItemView::DragDrop );
122 setAcceptDrops(
true );
123 setAlternatingRowColors(
true );
125 setDropIndicatorShown(
true );
127 setExpandsOnDoubleClick(
true );
128 setEditTriggers(QAbstractItemView::EditKeyPressed);
130 connect(
this, SIGNAL(activated(QModelIndex)),
132 connect(
this, SIGNAL(expanded(QModelIndex)),
133 this, SLOT(itemExpanded(QModelIndex)));
134 connect(
this, SIGNAL(collapsed(QModelIndex)),
135 this, SLOT(itemCollapsed(QModelIndex)));
137 this, SLOT(
reset()) );
138 connect( Kopete::BehaviorSettings::self(), SIGNAL(configChanged()), SLOT(slotSettingsChanged()) );
139 connect( Kopete::AppearanceSettings::self(), SIGNAL(configChanged()), SLOT(slotSettingsChanged()) );
141 setEditTriggers( NoEditTriggers );
143 slotSettingsChanged();
159 KAction *actionCreateNewGroup =
new KAction( i18n(
"Create New Group..." ), ac );
160 actionCreateNewGroup->setIcon( KIcon(
"user-group-new" ) );
161 connect( actionCreateNewGroup, SIGNAL(triggered(
bool)),
this, SLOT(
addGroup()) );
162 ac->addAction(
"AddGroup", actionCreateNewGroup );
164 d->actionSendMessage = KopeteStdAction::sendMessage(
this, SLOT(
sendMessage()), ac );
165 ac->addAction(
"contactSendMessage", d->actionSendMessage );
166 d->actionStartChat = KopeteStdAction::chat(
this, SLOT(
startChat()), ac );
167 ac->addAction(
"contactStartChat", d->actionStartChat );
171 ac->addAction(
"contactMove", d->actionMove );
174 ac->addAction(
"contactCopy", d->actionCopy );
176 d->actionMakeMetaContact =
new KAction(KIcon(
"list-add-user"), i18n(
"Merge Meta Contacts"), ac);
177 ac->addAction(
"makeMetaContact", d->actionMakeMetaContact );
178 connect (d->actionMakeMetaContact, SIGNAL(triggered(
bool)),
this, SLOT(
mergeMetaContact()));
181 ac->addAction(
"contactRemove", d->actionRemove );
183 d->actionSendEmail =
new KAction( KIcon(
"mail-send"), i18n(
"Send Email..." ), ac );
184 ac->addAction(
"contactSendEmail", d->actionSendEmail );
185 connect( d->actionSendEmail, SIGNAL(triggered(
bool)),
this, SLOT(
sendEmail()) );
187 d->actionRename =
new KAction( KIcon(
"edit-rename"), i18nc(
"verb, rename a contact",
"Rename" ), ac );
188 d->actionRename->setShortcut( KShortcut(Qt::Key_F2) );
189 ac->addAction(
"contactRename", d->actionRename );
190 connect( d->actionRename, SIGNAL(triggered(
bool)),
this, SLOT(
rename()) );
192 d->actionSendFile = KopeteStdAction::sendFile(
this, SLOT(
sendFile()), ac );
193 ac->addAction(
"contactSendFile", d->actionSendFile );
195 d->actionAddContact =
new KActionMenu( KIcon( QLatin1String(
"list-add-user") ), i18n(
"&Add Contact" ), ac );
196 ac->addAction(
"contactAddContact", d->actionAddContact );
197 d->actionAddContact->menu()->addTitle( i18n(
"Select Account") );
199 d->actionAddTemporaryContact =
new KAction( KIcon(
"list-add-user"), i18n(
"Add to Your Contact List" ), ac );
200 ac->addAction(
"contactAddTemporaryContact", d->actionAddTemporaryContact );
201 connect( d->actionAddTemporaryContact, SIGNAL(triggered(
bool)),
this, SLOT(
addTemporaryContact()) );
205 connect( Kopete::AccountManager::self(), SIGNAL(accountRegistered(Kopete::Account*)),
206 this, SLOT(addToAddContactMenu(Kopete::Account*)) );
207 connect( Kopete::AccountManager::self(), SIGNAL(accountUnregistered(
const Kopete::Account*)),
208 this, SLOT(removeToAddContactMenu(
const Kopete::Account*)) );
210 d->actionProperties =
new KAction( KIcon(
"user-properties"), i18n(
"&Properties" ), ac );
211 ac->addAction(
"contactProperties", d->actionProperties );
212 d->actionProperties->setShortcut( KShortcut(Qt::Key_Alt + Qt::Key_Return) );
213 connect( d->actionProperties, SIGNAL(triggered(
bool)),
this, SLOT(
showItemProperties()) );
219 Kopete::MetaContact* KopeteContactListView::metaContactFromIndex(
const QModelIndex& index )
const
225 Kopete::Group* KopeteContactListView::groupFromIndex(
const QModelIndex& index )
const
236 if ( !d->controlPressed )
238 if ( d->pressedContact )
240 d->pressedContact->execute();
258 disconnect( model(), SIGNAL(layoutChanged()),
this, SLOT(reexpandGroups()) );
262 QTreeView::setModel( newModel );
265 connect( newModel, SIGNAL(layoutChanged()),
this, SLOT(reexpandGroups()) );
271 QModelIndex parent = rootIndex();
274 int rows = model()->rowCount( parent );
275 for (
int i = 0; i < rows; ++i )
284 setSelectionMode( QAbstractItemView::SingleSelection );
285 QTreeView::keyboardSearch( search );
286 setSelectionMode( QAbstractItemView::ExtendedSelection );
293 if ( Kopete::AppearanceSettings::self()->groupContactByGroup() )
294 setRootIndex( model()->index( 0, 0 ) );
302 QModelIndex index = currentIndex();
303 if ( !index.isValid() )
308 QPointer <KopeteMetaLVIProps> propsDialog =
new KopeteMetaLVIProps( metaContactFromIndex( index ), 0L );
314 QPointer <KopeteGVIProps> propsDialog =
new KopeteGVIProps( groupFromIndex( index ), 0L );
323 if ( !destMetaContact )
327 QList<Kopete::MetaContact *> metaContactList;
328 foreach ( QModelIndex index, selectedIndexes() )
331 if ( mc && mc != destMetaContact )
332 metaContactList.append( mc );
335 if ( metaContactList.isEmpty() )
338 Kopete::ContactList::self()->mergeMetaContacts( metaContactList, destMetaContact );
343 QString groupName = KInputDialog::getText( i18n(
"New Group" ),
344 i18n(
"Please enter the name for the new group:" ) );
346 if ( !groupName.isEmpty() )
347 Kopete::ContactList::self()->findGroup( groupName );
352 QList<Kopete::MetaContact *> metaContactList;
353 QList<Kopete::Group *> groupList;
354 QStringList displayNameList;
356 foreach (
const QModelIndex& index, selectedIndexes() )
360 metaContactList.append( metaContact );
362 if( !metaContact->displayName().isEmpty() )
363 displayNameList.append( metaContact->displayName() );
368 if ( group == Kopete::Group::topLevel() )
372 if ( group == Kopete::Group::offline() )
375 groupList.append( group );
377 if( !group->displayName().isEmpty() )
378 displayNameList.append( group->displayName() );
382 if ( groupList.isEmpty() && metaContactList.isEmpty() )
385 if( (groupList.count() + metaContactList.count()) == 1 )
388 if( !metaContactList.isEmpty() )
390 msg = i18n(
"<qt>Are you sure you want to remove the contact <b>%1</b>" \
391 " from your contact list?</qt>" ,
392 metaContactList.first()->displayName() ) ;
394 else if( !groupList.isEmpty() )
396 msg = i18n(
"<qt>Are you sure you want to remove the group <b>%1</b> " \
397 "and all contacts that are contained within it?</qt>" ,
398 groupList.first()->displayName() );
401 if( KMessageBox::warningContinueCancel(
this, msg, i18n(
"Remove" ), KGuiItem( i18n(
"Remove" ),
"edit-delete" ),
402 KStandardGuiItem::cancel(),
"askRemovingContactOrGroup" ,
403 KMessageBox::Notify | KMessageBox::Dangerous ) != KMessageBox::Continue )
410 QString msg = groupList.isEmpty() ?
411 i18n(
"Are you sure you want to remove these contacts " \
412 "from your contact list?" ) :
413 i18n(
"Are you sure you want to remove these groups and " \
414 "contacts from your contact list?" );
416 if( KMessageBox::warningContinueCancelList(
this, msg, displayNameList, i18n(
"Remove"), KGuiItem( i18n(
"Remove" ),
"edit-delete" ),
417 KStandardGuiItem::cancel(),
"askRemovingContactOrGroup",
418 KMessageBox::Notify | KMessageBox::Dangerous ) != KMessageBox::Continue )
425 Kopete::ContactList::self()->removeMetaContact( metaContact );
428 Kopete::ContactList::self()->removeGroup( group );
434 QModelIndexList indexList = selectedIndexes();
435 if ( indexList.count() != 1 )
438 QModelIndex index = indexList.first();
442 foreach( Kopete::Contact *c, metaContact->contacts() )
444 if ( !c->account()->isConnected() )
446 const QString msg = i18n(
"Account %1 is offline. Do you really want to move this metacontact?", c->account()->accountLabel() );
447 if ( KMessageBox::warningYesNo(
this, msg, i18n(
"Move contact" ), KStandardGuiItem::yes(), KStandardGuiItem::no(),
448 "askMoveMetaContactToGroup", KMessageBox::Notify | KMessageBox::Dangerous ) == KMessageBox::No )
454 uint groupId = d->actionMove->currentAction()->data().toUInt( &ok );
458 Kopete::Group *toGroup = Kopete::ContactList::self()->group( groupId );
466 if ( toGroup == Kopete::Group::offline() )
469 metaContact->moveToGroup( fromGroup, toGroup );
476 QModelIndexList indexList = selectedIndexes();
477 if ( indexList.count() != 1 )
480 QModelIndex index = indexList.first();
484 foreach( Kopete::Contact *c, metaContact->contacts() )
486 if ( !c->account()->isConnected() )
491 uint groupId = d->actionCopy->currentAction()->data().toUInt( &ok );
495 Kopete::Group *toGroup = Kopete::ContactList::self()->group( groupId );
500 if ( toGroup == Kopete::Group::offline() )
503 metaContact->addToGroup( toGroup );
511 metaContact->startChat();
518 metaContact->sendFile( KUrl() );
524 metaContact->sendMessage();
525 else if (
Kopete::Group* group = groupFromIndex( currentIndex() ) )
526 group->sendMessage();
534 KABC::Addressee addressee = KABC::StdAddressBook::self()->findByUid( metaContact->kabcId() );
535 if ( !addressee.isEmpty() )
537 QString emailAddr = addressee.fullEmail();
539 kDebug( 14000 ) <<
"Email: " << emailAddr <<
"!";
540 if ( !emailAddr.isEmpty() )
541 KToolInvocation::invokeMailer( emailAddr, QString::null );
543 KMessageBox::queuedMessageBox(
this, KMessageBox::Sorry, i18n(
"There is no email address set for this contact in the KDE address book." ), i18n(
"No Email Address in Address Book" ) );
547 KMessageBox::queuedMessageBox(
this, KMessageBox::Sorry, i18n(
"This contact was not found in the KDE address book. Check that a contact is selected in the properties dialog." ), i18n(
"Not Found in Address Book" ) );
557 edit(currentIndex());
564 if ( metaContact && metaContact->isTemporary() )
565 metaContact->setTemporary(
false );
571 QModelIndexList indexList = selectedIndexes();
572 if ( indexList.isEmpty() )
575 if ( indexList.count() > 1 )
577 miscPopup( indexList, event->globalPos() );
581 QModelIndex index = indexList.first();
584 Kopete::Contact* contact = contactAt( event->pos() );
587 KMenu *menu = contact->popupMenu();
588 connect( menu, SIGNAL(aboutToHide()), menu, SLOT(deleteLater()) );
589 menu->popup( event->globalPos() );
593 metaContactPopup( metaContactFromIndex( index ), event->globalPos() );
597 groupPopup( groupFromIndex( index ),
event->globalPos() );
604 if ( (event->modifiers() & Qt::ControlModifier) == Qt::ControlModifier )
605 d->controlPressed =
true;
607 d->pressedContact = contactAt( event->pos() );
609 QTreeView::mouseReleaseEvent( event );
610 d->pressedContact = 0;
611 d->controlPressed =
false;
616 QModelIndexList indexes = selectedIndexes();
617 for (
int i = indexes.count() - 1 ; i >= 0; --i )
619 if ( !(model()->flags( indexes.at(i) ) & Qt::ItemIsDragEnabled) )
623 if (indexes.count() > 0)
625 QMimeData *data = model()->mimeData( indexes );
629 QDrag *drag =
new QDrag(
this );
630 drag->setMimeData( data );
632 Qt::DropAction defaultDropAction = Qt::MoveAction;
633 drag->exec( supportedActions, defaultDropAction );
639 const QMimeData *data =
event->mimeData();
641 QTreeView::dragMoveEvent ( event );
642 if ( !event->isAccepted() )
646 switch ( dropIndicatorPosition() )
648 case QAbstractItemView::AboveItem:
649 case QAbstractItemView::BelowItem:
650 index = indexAt( event->pos() ).parent();
652 case QAbstractItemView::OnItem:
653 index = indexAt( event->pos() );
655 case QAbstractItemView::OnViewport:
663 Kopete::AppearanceSettings* as = Kopete::AppearanceSettings::self();
664 bool groupContactByGroup = as->groupContactByGroup();
667 if ( data->hasFormat(
"application/kopete.metacontacts.list" ) )
670 accept = (event->proposedAction() & Qt::MoveAction);
672 accept = (event->proposedAction() & (Qt::MoveAction | Qt::CopyAction));
673 else if ( !groupContactByGroup && !index.isValid() )
674 accept = (event->proposedAction() & Qt::MoveAction);
678 else if ( data->hasFormat(
"application/kopete.group" ) )
680 if ( !groupContactByGroup )
682 else if ( !index.parent().isValid() )
683 accept = (event->proposedAction() & Qt::MoveAction);
696 event->acceptProposedAction();
701 QTreeView::timerEvent( event );
703 if ( event->timerId() == d->scrollAutoHideTimer )
705 if ( !d->scrollAutoHideCounter-- )
706 setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
712 if ( d->scrollAutoHide &&
object == verticalScrollBar() )
714 if ( event->type() == QEvent::MouseMove )
715 d->scrollAutoHideCounter = 9999;
716 else if ( event->type() == QEvent::Enter )
717 d->scrollAutoHideCounter = 9999;
718 else if ( event->type() == QEvent::Leave )
719 d->scrollAutoHideCounter = d->scrollAutoHideTimeout;
721 else if ( d->scrollAutoHide &&
object == viewport() )
723 if ( event->type() == QEvent::MouseMove )
725 setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded );
726 d->scrollAutoHideCounter = 9999;
728 else if ( event->type() == QEvent::Leave )
730 d->scrollAutoHideCounter = d->scrollAutoHideTimeout;
734 return QTreeView::eventFilter(
object, event );
743 executeDelayedItemsLayout();
744 return QTreeView::viewportEvent( event );
749 QTreeView::rowsInserted( parent, start, end );
751 const int delta = end - start + 1;
752 for (
int i = 0; i < delta; ++i)
754 QModelIndex index = model()->index( i + start, 0, parent );
762 QTreeView::selectionChanged( selected, deselected );
764 QSet<Kopete::MetaContact*> contacts;
765 QSet<Kopete::Group*> groups;
767 foreach (
const QModelIndex& index, selected.indexes() )
770 contacts.insert( metaContactFromIndex( index ) );
772 groups.insert( groupFromIndex( index ) );
775 Kopete::ContactList::self()->setSelectedItems( contacts.toList(), groups.toList() );
779 if ( d->selectedMetaContact )
781 disconnect( d->selectedMetaContact, SIGNAL(onlineStatusChanged(
Kopete::MetaContact*,Kopete::OnlineStatus::StatusType)),
782 this, SLOT(updateMetaContactActions()) );
783 d->selectedMetaContact = 0;
786 if ( contacts.count() == 1 && groups.empty() )
788 d->selectedMetaContact = contacts.values().first();
789 connect( d->selectedMetaContact, SIGNAL(onlineStatusChanged(
Kopete::MetaContact*,Kopete::OnlineStatus::StatusType)),
790 this, SLOT(updateMetaContactActions()) );
793 updateMetaContactActions();
796 void KopeteContactListView::reexpandGroups()
799 QModelIndex parent = rootIndex();
800 for (
int i = 0; i < model()->rowCount( parent ); ++i)
802 QModelIndex index = model()->index( i, 0, parent );
808 void KopeteContactListView::itemExpanded(
const QModelIndex& index )
815 void KopeteContactListView::itemCollapsed(
const QModelIndex& index )
822 void KopeteContactListView::updateActions()
824 QModelIndexList selected = selectedIndexes();
828 Kopete::MetaContact* metaContact = ( singleContactSelected ) ? metaContactFromIndex( selected.first() ) : 0;
829 Kopete::Group* group = ( singleGroupSelected ) ? groupFromIndex( selected.first() ) : 0;
832 if ( singleContactSelected )
834 QString kabcid = metaContact->kabcId();
835 inkabc = !kabcid.isEmpty() && !kabcid.contains(
":");
837 d->actionSendEmail->setEnabled( inkabc );
839 if ( singleContactSelected )
841 d->actionRename->setText( i18n(
"Rename Contact") );
842 d->actionRemove->setText( i18n(
"Remove Contact") );
843 d->actionSendMessage->setText( i18n(
"Send Single Message...") );
844 d->actionRename->setEnabled(
true );
845 d->actionRemove->setEnabled(
true );
846 d->actionAddContact->setText( i18n(
"&Add Subcontact") );
847 d->actionAddContact->setEnabled( !metaContact->isTemporary() );
849 else if ( singleGroupSelected )
851 d->actionRename->setText( i18n(
"Rename Group") );
852 d->actionRemove->setText( i18n(
"Remove Group") );
853 d->actionSendMessage->setText( i18n(
"Send Message to Group") );
854 d->actionRename->setEnabled(
true );
855 d->actionRemove->setEnabled(
true );
856 d->actionSendMessage->setEnabled(
true );
857 d->actionAddContact->setText( i18n(
"&Add Contact to Group") );
858 d->actionAddContact->setEnabled( group->type() == Kopete::Group::Normal );
862 d->actionRename->setText( i18n(
"Rename") );
863 d->actionRemove->setText( i18n(
"Remove") );
864 d->actionRename->setEnabled(
false );
865 d->actionRemove->setEnabled( !selected.isEmpty() );
866 d->actionAddContact->setEnabled(
false );
867 d->actionMakeMetaContact->setText( i18n(
"Make Meta Contact") );
869 bool hasContactInSelection =
false;
870 foreach (
const QModelIndex& index, selected )
874 hasContactInSelection =
true;
878 d->actionMakeMetaContact->setEnabled( hasContactInSelection );
881 d->actionProperties->setEnabled( selected.count() == 1 );
884 void KopeteContactListView::updateMetaContactActions()
886 bool reachable =
false;
888 if( d->selectedMetaContact )
890 reachable = d->selectedMetaContact->isReachable();
891 d->actionAddTemporaryContact->setEnabled( d->selectedMetaContact->isTemporary() );
892 d->actionSendFile->setEnabled( reachable && d->selectedMetaContact->canAcceptFiles() );
893 d->actionSendMessage->setEnabled( reachable );
894 d->actionStartChat->setEnabled( reachable );
898 QModelIndexList selected = selectedIndexes();
901 d->actionAddTemporaryContact->setEnabled(
false );
902 d->actionSendFile->setEnabled(
false );
903 d->actionSendMessage->setEnabled( singleGroupSelected );
904 d->actionStartChat->setEnabled(
false );
909 void KopeteContactListView::slotSettingsChanged()
911 if ( Kopete::AppearanceSettings::self()->contactListTreeView() )
913 setRootIsDecorated(
true );
914 setIndentation( 20 );
918 setRootIsDecorated(
false );
919 setIndentation( Kopete::AppearanceSettings::self()->contactListIndentContact() ? 20 : 0 );
922 if( Kopete::AppearanceSettings::self()->contactListHideVerticalScrollBar() )
924 setScrollAutoHide(
false );
925 setScrollHide(
true );
929 setScrollHide(
false );
930 setScrollAutoHide( Kopete::AppearanceSettings::self()->contactListAutoHideVScroll() );
933 d->scrollAutoHideTimeout = Kopete::AppearanceSettings::self()->contactListAutoHideTimeout();
938 setAnimated( Kopete::AppearanceSettings::self()->contactListAnimateChange() );
945 void KopeteContactListView::addToAddContactMenu( Kopete::Account* account )
947 KAction *action =
new KAction( KIcon( QIcon( account->accountIcon() ) ), account->accountLabel(), this );
948 connect( action, SIGNAL(triggered(
bool)),
this, SLOT(addContact()) );
949 d->addContactAccountMap.insert( action, account );
950 d->actionAddContact->addAction( action );
953 void KopeteContactListView::removeToAddContactMenu(
const Kopete::Account *account )
955 QMapIterator<KAction *, Kopete::Account *> it( d->addContactAccountMap );
956 while ( it.hasNext() )
959 if ( it.value() == account )
962 d->addContactAccountMap.remove( action );
963 d->actionAddContact->removeAction( action );
968 void KopeteContactListView::addContact()
975 Kopete::Account *account = d->addContactAccountMap.value( dynamic_cast<KAction*>( sender() ) );
977 if ( (metaContact && metaContact->isTemporary() ) ||
978 (group && group->type() == Kopete::Group::Temporary) )
981 if( !account || !(metaContact || group) )
984 QPointer <KDialog> addDialog =
new KDialog(
this );
985 addDialog->setCaption( i18n(
"Add Contact" ) );
986 addDialog->setButtons( KDialog::Ok | KDialog::Cancel );
988 AddContactPage *addContactPage = account->protocol()->createAddContactWidget( addDialog, account );
990 if ( !addContactPage )
992 kDebug(14000) <<
"Error while creating addcontactpage";
996 addDialog->setMainWidget( addContactPage );
997 if( addDialog->exec() == QDialog::Accepted )
999 if( addContactPage->validateData() )
1004 metaContact->addToGroup( group );
1005 if ( addContactPage->apply( account, metaContact ) )
1006 Kopete::ContactList::self()->addMetaContact( metaContact );
1012 addContactPage->apply( account, metaContact );
1017 addDialog->deleteLater();
1020 void KopeteContactListView::groupPopup(
Kopete::Group *group,
const QPoint& pos )
1026 kError( 14000 ) <<
"Main window not found, unable to display context-menu; "
1027 <<
"Kopete::UI::Global::mainWidget() = " << Kopete::UI::Global::mainWidget() << endl;
1031 if ( group == Kopete::Group::offline() )
1034 KMenu *popup =
dynamic_cast<KMenu *
>( window->factory()->container(
"group_popup", window ) );
1037 QString title = group->displayName();
1038 if ( title.length() > 32 )
1039 title = title.left( 30 ) + QLatin1String(
"..." );
1042 if( d->menuTitleMap.contains(popup) )
1044 QAction *action = d->menuTitleMap[popup];
1045 popup->removeAction( action );
1048 d->menuTitleMap.insert( popup, popup->addTitle(title, popup->actions().first()) );
1049 popup->popup( pos );
1053 void KopeteContactListView::metaContactPopup(
Kopete::MetaContact *metaContact,
const QPoint& pos )
1055 Q_ASSERT(metaContact);
1059 kError( 14000 ) <<
"Main window not found, unable to display context-menu; "
1060 <<
"Kopete::UI::Global::mainWidget() = " << Kopete::UI::Global::mainWidget() << endl;
1064 KMenu *popup =
dynamic_cast<KMenu *
>( window->factory()->container(
"contact_popup", window ) );
1067 QString title = i18nc(
"Translators: format: '<nickname> (<online status>)'",
"%1 (%2)",
1068 metaContact->displayName(), metaContact->statusString() );
1070 if ( title.length() > 43 )
1071 title = title.left( 40 ) + QLatin1String(
"..." );
1074 if( d->menuTitleMap.contains(popup) )
1076 QAction *action = d->menuTitleMap[popup];
1077 popup->removeAction( action );
1080 d->menuTitleMap.insert( popup, popup->addTitle(title, popup->actions().first()) );
1084 foreach( Kopete::Contact* c , metaContact->contacts() )
1088 popup->addSeparator();
1092 KMenu *contactMenu = c->popupMenu();
1093 connect( popup, SIGNAL(aboutToHide()), contactMenu, SLOT(deleteLater()) );
1094 QString text = i18nc(
"Translators: format: '<displayName> (<id>)'",
"%2 <%1>", c->contactId(), c->nickName() );
1095 text=text.replace(
'&',
"&&");
1097 if ( text.length() > 41 )
1098 text = text.left( 38 ) + QLatin1String(
"..." );
1100 contactMenu->setTitle(text);
1101 contactMenu->setIcon(c->onlineStatus().iconFor( c ));
1102 popup->addMenu( contactMenu );
1104 popup->popup( pos );
1108 void KopeteContactListView::miscPopup( QModelIndexList indexes,
const QPoint& pos )
1110 Q_ASSERT(indexes.count() > 1);
1114 kError( 14000 ) <<
"Main window not found, unable to display context-menu; "
1115 <<
"Kopete::UI::Global::mainWidget() = " << Kopete::UI::Global::mainWidget() << endl;
1119 bool onlyMetaContacts =
true;
1120 foreach ( QModelIndex index, indexes )
1124 onlyMetaContacts =
false;
1130 if ( onlyMetaContacts )
1131 popup =
dynamic_cast<KMenu *
>( window->factory()->container(
"contactlistitems_popup", window ) );
1134 popup->popup( pos );
1137 Kopete::Contact* KopeteContactListView::contactAt(
const QPoint& point )
const
1139 QModelIndex index = indexAt( point );
1140 if ( !index.isValid() )
1143 QRect rect = visualRect( index );
1144 if ( rect.width() <= 0 || rect.height() <= 0 )
1151 QStyleOptionViewItem option = viewOptions();
1153 return delegate->
contactAt( option, index, point );
1157 void KopeteContactListView::setScrollAutoHide(
bool autoHide )
1159 if ( d->scrollAutoHide == autoHide )
1164 viewport()->installEventFilter(
this );
1165 viewport()->setMouseTracking(
true );
1166 verticalScrollBar()->installEventFilter(
this );
1167 verticalScrollBar()->setMouseTracking(
true );
1170 d->scrollAutoHide =
true;
1172 setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
1174 killTimer( d->scrollAutoHideTimer );
1175 d->scrollAutoHideTimer = startTimer( 1000 );
1179 viewport()->removeEventFilter(
this );
1180 viewport()->setMouseTracking(
false );
1181 verticalScrollBar()->removeEventFilter(
this );
1182 verticalScrollBar()->setMouseTracking(
false );
1184 d->scrollAutoHide =
false;
1185 setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded );
1186 killTimer( d->scrollAutoHideTimer );
1190 void KopeteContactListView::setScrollHide(
bool hide )
1192 if ( d->scrollHide == hide )
1195 d->scrollHide = hide;
1197 setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
1199 setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded );
1204 if ( !parent.isValid() )
1207 int height = rowHeight( parent );
1211 int rows = model()->rowCount( parent );
1212 for (
int i = 0; i < rows; ++i )
1218 #include "kopetecontactlistview.moc"
Contains definitions common between model items.
const int MetaContactGroupRole
Action used for Copy To and Move To.
const int TypeRole
Qt Model Role Definitions.
Kopete::Contact * contactAt(const QStyleOptionViewItem &option, const QModelIndex &index, const QPoint &point) const
const int ExpandStateRole