26 #include <QtCore/QTextStream>
27 #include <QtCore/QTimer>
28 #include <QtGui/QDockWidget>
29 #include <QtGui/QFrame>
30 #include <QtGui/QLabel>
31 #include <QtGui/QLayout>
32 #include <QtGui/QMenu>
33 #include <QtGui/QPixmap>
34 #include <QtGui/QCloseEvent>
35 #include <QtGui/QVBoxLayout>
41 #include <kactioncollection.h>
48 #include <kiconloader.h>
50 #include <kwindowsystem.h>
51 #include <ktemporaryfile.h>
52 #include <kedittoolbar.h>
53 #include <kstatusbar.h>
54 #include <kpushbutton.h>
55 #include <ktabwidget.h>
57 #include <kstringhandler.h>
58 #include <ksqueezedtextlabel.h>
59 #include <kstandardshortcut.h>
60 #include <kglobalsettings.h>
61 #include <kcolorscheme.h>
65 #include <kstandardaction.h>
66 #include <ktoggleaction.h>
67 #include <kactionmenu.h>
68 #include <ktoolbarspaceraction.h>
74 #include "kopetebehaviorsettings.h"
76 #include "kopetegroup.h"
77 #include "kopetechatsession.h"
78 #include "kopetemetacontact.h"
79 #include "kopetepluginmanager.h"
80 #include "kopeteprotocol.h"
81 #include "kopetestdaction.h"
82 #include "kopeteviewmanager.h"
84 #include "chatsessionmemberslistmodel.h"
86 #include <qtoolbutton.h>
87 #include <kxmlguifactory.h>
95 using Kopete::ChatSessionMembersListModel;
107 bool windowCreated =
false;
117 Kopete::GroupList gList = metaContact->groups();
118 group = gList.first();
121 switch( Kopete::BehaviorSettings::self()->chatWindowGroupPolicy() )
124 case Kopete::BehaviorSettings::EnumChatWindowGroupPolicy::GroupByAccount:
125 if( accountMap.contains( manager->account() ) )
126 myWindow = accountMap[ manager->account() ];
128 windowCreated =
true;
132 case Kopete::BehaviorSettings::EnumChatWindowGroupPolicy::GroupByGroup:
133 if( group && groupMap.contains( group ) )
134 myWindow = groupMap[ group ];
136 windowCreated =
true;
140 case Kopete::BehaviorSettings::EnumChatWindowGroupPolicy::GroupByMetaContact:
141 if( mcMap.contains( metaContact ) )
142 myWindow = mcMap[ metaContact ];
144 windowCreated =
true;
148 case Kopete::BehaviorSettings::EnumChatWindowGroupPolicy::GroupAll:
149 if( windows.isEmpty() )
150 windowCreated =
true;
159 for ( it = windows.begin(); it != windows.end(); ++it )
161 if( (*it)->chatViewCount() > viewCount )
171 case Kopete::BehaviorSettings::EnumChatWindowGroupPolicy::OpenNewWindow:
173 windowCreated =
true;
181 if ( !accountMap.contains( manager->account() ) )
182 accountMap.insert( manager->account(), myWindow );
184 if ( !mcMap.contains( metaContact ) )
185 mcMap.insert( metaContact, myWindow );
187 if ( group && !groupMap.contains( group ) )
188 groupMap.insert( group, myWindow );
196 KopeteChatWindow::KopeteChatWindow( Kopete::ChatSession::Form form,
QWidget *parent )
208 m_participantsWidget =
new QDockWidget(i18n(
"Participants"),
this);
209 m_participantsWidget->
setAllowedAreas(Qt::RightDockWidgetArea | Qt::LeftDockWidgetArea);
210 m_participantsWidget->
setFeatures(QDockWidget::DockWidgetClosable);
214 ChatSessionMembersListModel *members_model =
new ChatSessionMembersListModel(
this);
216 connect(
this, SIGNAL(
chatSessionChanged(Kopete::ChatSession*)), members_model, SLOT(setChatSession(Kopete::ChatSession*)));
219 chatmembers->
setModel(members_model);
221 m_participantsWidget->
setWidget(chatmembers);
224 addDockWidget(Qt::RightDockWidgetArea, m_participantsWidget);
227 vBox->setLineWidth( 0 );
228 vBox->setSpacing( 0 );
229 vBox->setFrameStyle( QFrame::NoFrame );
231 if ( initialForm == Kopete::ChatSession::Chatroom ) {
234 m_participantsWidget->
hide();
237 setCentralWidget( vBox );
239 mainArea =
new QFrame( vBox );
245 if ( Kopete::BehaviorSettings::self()->chatWindowShowSendButton() )
248 m_button_send =
new KPushButton( i18nc(
"@action:button",
"Send"), statusBar() );
249 m_button_send->setSizePolicy(
QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) );
250 m_button_send->setEnabled(
false );
251 m_button_send->setFont( statusBar()->font() );
252 m_button_send->setFixedHeight( statusBar()->sizeHint().height() );
253 connect( m_button_send, SIGNAL(clicked()),
this, SLOT(slotSendMessage()) );
254 statusBar()->addPermanentWidget( m_button_send, 0 );
259 m_status_text =
new KSqueezedTextLabel( i18nc(
"@info:status",
"Ready."), statusBar() );
260 m_status_text->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
261 m_status_text->setFont( statusBar()->font() );
262 m_status_text->setFixedHeight( statusBar()->sizeHint().height() );
263 statusBar()->addWidget( m_status_text, 1 );
265 windows.append(
this );
268 m_alwaysShowTabs = KGlobal::config()->group(
"ChatWindowSettings" ).
272 setupGUI( static_cast<StandardWindowOptions>(ToolBar | Keys | StatusBar | Save | Create) ,
"kopetechatwindow.rc" );
277 kDebug()<<
"TIME: "<<chrono.
elapsed();
289 if( it.value() == this )
290 it=accountMap.erase( it );
297 if( it.value() == this )
298 it=groupMap.erase( it );
305 if( it.value() == this )
306 it=mcMap.erase( it );
311 windows.removeAt( windows.indexOf(
this ) );
323 void KopeteChatWindow::windowListChanged()
327 (*it)->checkDetachEnable();
330 void KopeteChatWindow::slotTabContextMenu(
QWidget *tab,
const QPoint &pos )
332 m_popupView =
static_cast<ChatView*
>( tab );
335 popup.addTitle( KStringHandler::rsqueeze( m_popupView->
caption() ) );
336 popup.addAction( actionContactMenu );
337 popup.addSeparator();
338 popup.addAction( actionTabPlacementMenu );
339 popup.addAction( tabDetach );
340 popup.addAction( actionDetachMenu );
341 popup.addAction( tabCloseAllOthers );
342 popup.addAction( tabClose );
353 void KopeteChatWindow::updateSendKeySequence()
355 if ( !sendMessage || !m_activeView )
358 m_activeView->editPart()->textEdit()->setSendKeySequenceList( sendMessage->
shortcuts() );
361 void KopeteChatWindow::initActions(
void)
363 KActionCollection *coll = actionCollection();
365 createStandardStatusBarAction();
367 chatSend =
new KAction( KIcon(
"mail-send"), i18n(
"&Send Message" ), coll );
369 sendMessage = coll->addAction(
"chat_send", chatSend );
371 connect( sendMessage, SIGNAL(changed()), SLOT(updateSendKeySequence()) );
373 connect( chatSend, SIGNAL(triggered(
bool)), SLOT(slotSendMessage()) );
378 chatSend->setShortcut( chatSendShortcut );
379 chatSend->setEnabled(
false );
381 chatSendFile =
new KAction( KIcon(
"mail-attachment"), i18n(
"Send File..." ), coll );
382 coll->addAction(
"chat_send_file", chatSendFile );
383 connect( chatSendFile, SIGNAL(triggered(
bool)), SLOT(slotSendFile()) );
384 chatSendFile->setEnabled(
false );
386 KStandardAction::save (
this, SLOT(slotChatSave()), coll );
387 KStandardAction::print (
this, SLOT(slotChatPrint()), coll );
388 KAction* quitAction = KStandardAction::quit (
this, SLOT(close()), coll );
389 quitAction->setText( i18n(
"Close All Chats") );
391 tabClose = KStandardAction::close (
this, SLOT(slotChatClosed()), coll );
392 coll->addAction(
"tabs_close", tabClose );
394 tabActive=
new KAction( i18n(
"&Activate Next Active Tab" ), coll );
395 coll->addAction(
"tabs_active", tabActive );
397 tabActive->setEnabled(
false );
398 connect( tabActive, SIGNAL(triggered(
bool)),
this, SLOT(slotNextActiveTab()) );
400 tabRight=
new KAction( i18n(
"&Activate Next Tab" ), coll );
401 coll->addAction(
"tabs_right", tabRight );
402 tabRight->setShortcut( KStandardShortcut::tabNext() );
403 tabRight->setEnabled(
false );
404 connect( tabRight, SIGNAL(triggered(
bool)),
this, SLOT(slotNextTab()) );
406 tabLeft=
new KAction( i18n(
"&Activate Previous Tab" ), coll );
407 coll->addAction(
"tabs_left", tabLeft );
408 tabLeft->setShortcut( KStandardShortcut::tabPrev() );
409 tabLeft->setEnabled(
false );
410 connect( tabLeft, SIGNAL(triggered(
bool)),
this, SLOT(slotPreviousTab()) );
414 nickComplete =
new KAction( i18n(
"Nic&k Completion" ), coll );
415 coll->addAction(
"nick_complete", nickComplete );
416 nickComplete->setShortcut(
QKeySequence( Qt::Key_Tab ) );
418 tabDetach =
new KAction( KIcon(
"tab-detach"), i18n(
"&Detach Chat" ), coll );
419 coll->addAction(
"tabs_detach", tabDetach );
420 tabDetach->setEnabled(
false );
421 connect( tabDetach, SIGNAL(triggered(
bool)),
this, SLOT(slotDetachChat()));
423 tabCloseAllOthers =
new KAction( KIcon(
"tab-close"), i18n(
"Close &All But This Tab" ), coll );
424 coll->addAction(
"tabs_close_others", tabCloseAllOthers );
425 tabCloseAllOthers->setEnabled(
true );
426 connect( tabCloseAllOthers, SIGNAL(triggered(
bool)),
this, SLOT(slotCloseAllOtherTabs()));
428 actionDetachMenu =
new KActionMenu( KIcon(
"tab-detach"), i18n(
"&Move Tab to Window" ), coll );
429 coll->addAction(
"tabs_detachmove", actionDetachMenu );
430 actionDetachMenu->setDelayed(
false );
432 connect ( actionDetachMenu->menu(), SIGNAL(aboutToShow()),
this, SLOT(slotPrepareDetachMenu()) );
433 connect ( actionDetachMenu->menu(), SIGNAL(triggered(
QAction*)),
this, SLOT(slotDetachChat(
QAction*)) );
435 actionTabPlacementMenu =
new KActionMenu( i18n(
"&Tab Placement" ), coll );
436 coll->addAction(
"tabs_placement", actionTabPlacementMenu );
437 connect ( actionTabPlacementMenu->menu(), SIGNAL(aboutToShow()),
this, SLOT(slotPreparePlacementMenu()) );
438 connect ( actionTabPlacementMenu->menu(), SIGNAL(triggered(
QAction*)),
this, SLOT(slotPlaceTabs(
QAction*)) );
440 tabDetach->setShortcut(
QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B) );
442 KStandardAction::cut(
this, SLOT(slotCut()), coll);
443 KStandardAction::copy(
this, SLOT(slotCopy()), coll);
444 KStandardAction::paste(
this, SLOT(slotPaste()), coll);
448 historyUp =
new KAction( i18n(
"Previous History" ), coll );
449 coll->addAction(
"history_up", historyUp );
450 historyUp->setShortcut(
QKeySequence(Qt::CTRL + Qt::Key_Up) );
451 connect( historyUp, SIGNAL(triggered(
bool)),
this, SLOT(slotHistoryUp()) );
453 historyDown =
new KAction( i18n(
"Next History" ), coll );
454 coll->addAction(
"history_down", historyDown );
455 historyDown->setShortcut(
QKeySequence(Qt::CTRL + Qt::Key_Down) );
456 connect( historyDown, SIGNAL(triggered(
bool)),
this, SLOT(slotHistoryDown()) );
458 action = KStandardAction::prior(
this, SLOT(slotPageUp()), coll );
459 coll->addAction(
"scroll_up", action );
460 action = KStandardAction::next(
this, SLOT(slotPageDown()), coll );
461 coll->addAction(
"scroll_down", action );
463 KStandardAction::showMenubar( menuBar(), SLOT(setVisible(
bool)), coll );
465 toggleAutoSpellCheck =
new KToggleAction( i18n(
"Automatic Spell Checking" ), coll );
466 coll->addAction(
"enable_auto_spell_check", toggleAutoSpellCheck );
467 toggleAutoSpellCheck->setChecked(
true );
468 connect( toggleAutoSpellCheck, SIGNAL(triggered(
bool)),
this, SLOT(toggleAutoSpellChecking()) );
471 toggleParticipantsAction->
setText( i18n(
"Show Participants" ) );
472 toggleParticipantsAction->
setIconText(i18n(
"Participants" ));
473 toggleParticipantsAction->
setIcon(KIcon(
"system-users" ) );
474 coll->addAction (
"show_participants_widget", toggleParticipantsAction );
477 coll->addAction(
"format_smiley", actionSmileyMenu );
478 actionSmileyMenu->setDelayed(
false );
481 actionContactMenu =
new KActionMenu(i18n(
"Co&ntacts"), coll );
482 coll->addAction(
"contacts_menu", actionContactMenu );
483 actionContactMenu->setDelayed(
false );
484 connect ( actionContactMenu->menu(), SIGNAL(aboutToShow()),
this, SLOT(slotPrepareContactMenu()) );
486 KopeteStdAction::preferences( coll ,
"settings_prefs" );
488 KToolBarSpacerAction * spacer =
new KToolBarSpacerAction( coll );
489 coll->addAction(
"spacer", spacer );
495 anim =
new QLabel( QString::null, 0L );
500 animIcon = KIconLoader::global()->loadMovie(
QLatin1String(
"newmessage" ), KIconLoader::Toolbar);
504 KAction *animAction =
new KAction( i18n(
"Toolbar Animation"), coll );
505 coll->addAction(
"toolbar_animation", animAction );
506 animAction->setDefaultWidget( anim );
527 void KopeteChatWindow::slotStopAnimation(
ChatView* view )
529 if( view == m_activeView )
532 if( animIcon && animIcon->
state() == QMovie::Running )
537 void KopeteChatWindow::slotUpdateSendEnabled()
539 if ( !m_activeView )
return;
541 bool enabled = m_activeView->canSend();
542 chatSend->setEnabled( enabled );
544 m_button_send->setEnabled( enabled );
547 void KopeteChatWindow::updateChatSendFileAction()
552 chatSendFile->setEnabled( m_activeView->canSendFile() );
555 void KopeteChatWindow::toggleAutoSpellChecking()
560 bool currentSetting = m_activeView->editPart()->checkSpellingEnabled();
561 m_activeView->editPart()->setCheckSpellingEnabled( !currentSetting );
562 updateSpellCheckAction();
565 void KopeteChatWindow::updateSpellCheckAction()
570 bool currentSetting = m_activeView->editPart()->checkSpellingEnabled();
571 toggleAutoSpellCheck->setChecked( currentSetting );
574 void KopeteChatWindow::enableSpellCheckAction(
bool enable)
576 toggleAutoSpellCheck->setChecked( enable );
579 void KopeteChatWindow::updateActions()
581 updateSpellCheckAction();
582 updateChatSendFileAction();
585 void KopeteChatWindow::slotHistoryUp()
588 m_activeView->editPart()->historyUp();
591 void KopeteChatWindow::slotHistoryDown()
594 m_activeView->editPart()->historyDown();
597 void KopeteChatWindow::slotPageUp()
600 m_activeView->messagePart()->pageUp();
603 void KopeteChatWindow::slotPageDown()
606 m_activeView->messagePart()->pageDown();
609 void KopeteChatWindow::slotCut()
614 void KopeteChatWindow::slotCopy()
616 m_activeView->copy();
619 void KopeteChatWindow::slotPaste()
621 m_activeView->paste();
624 void KopeteChatWindow::slotResetFontAndColor()
626 m_activeView->resetFontAndColor();
631 m_status_text->setText(text);
634 void KopeteChatWindow::testCanDecode(
const QDragMoveEvent *event,
bool &accept)
636 if ( m_tabBar && qobject_cast<KTabBar*>(m_tabBar->childAt( event->
pos() )) &&
chatViewList[
static_cast<KTabBar*
>(m_tabBar->childAt( event->
pos()))->selectTab( event->
pos() )]->isDragEventAccepted( event )) {
645 m_tabBar->setCurrentWidget( w );
649 void KopeteChatWindow::createTabBar()
653 KConfigGroup cg( KGlobal::config(),
QLatin1String(
"ChatWindowSettings") );
655 m_tabBar =
new KTabWidget( mainArea );
656 m_tabBar->setSizePolicy(
QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
657 m_tabBar->setTabsClosable(cg.readEntry(
QLatin1String(
"HoverClose"),
true ));
658 m_tabBar->setMovable(
true);
659 m_tabBar->setAutomaticResizeTabs(
true);
660 connect( m_tabBar, SIGNAL(closeRequest(
QWidget*)),
this, SLOT(slotCloseChat(
QWidget*)) );
662 m_UpdateChatLabel = cg.readEntry(
QLatin1String(
"ShowContactName"),
true );
665 connect( m_rightWidget, SIGNAL(clicked()),
this, SLOT(slotChatClosed()) );
666 m_rightWidget->
setIcon( SmallIcon(
"tab-close" ) );
668 m_rightWidget->
setToolTip( i18nc(
"@info:tooltip",
"Close the current tab") );
669 m_tabBar->setCornerWidget( m_rightWidget, Qt::TopRightCorner );
683 m_tabBar->setCurrentWidget( m_activeView );
687 int tabPosition = cg.readEntry(
QLatin1String(
"Tab Placement") , 0 );
690 action.setData(tabPosition);
691 slotPlaceTabs( &action );
695 void KopeteChatWindow::slotCloseChat(
QWidget *chatView )
697 static_cast<ChatView*
>( chatView )->closeView();
701 void KopeteChatWindow::addTab(
ChatView *view )
704 Kopete::Contact *c=0L;
705 foreach( Kopete::Contact *contact , chatMembers )
707 if(!c || c->onlineStatus() < contact->onlineStatus())
710 QIcon pluginIcon = c ? view->msgManager()->contactOnlineStatus( c ).iconFor( c) :
711 KIcon( view->msgManager()->protocol()->pluginIcon() );
713 view->setParent( m_tabBar );
714 view->setWindowFlags( 0 );
718 m_tabBar->addTab( view, pluginIcon,
"");
719 view->setVisible(view == m_activeView);
720 connect( view, SIGNAL(updateStatusIcon(
ChatView*)),
this, SLOT(slotUpdateCaptionIcons(
ChatView*)) );
722 if (m_UpdateChatLabel) {
723 connect( view, SIGNAL(captionChanged(
bool)),
this, SLOT(updateChatLabel()) );
729 void KopeteChatWindow::setPrimaryChatView(
ChatView *view )
733 view->setParent( mainArea );
734 view->setWindowFlags( 0 );
742 void KopeteChatWindow::deleteTabBar()
752 m_tabBar->deleteLater();
762 setPrimaryChatView( newView );
773 newView->
editWidget()->installEventFilter(
this );
775 KCursor::setAutoHideCursor( newView->
editWidget(),
true, true );
776 connect( newView, SIGNAL(captionChanged(
bool)),
this, SLOT(slotSetCaption(
bool)) );
777 connect( newView, SIGNAL(messageSuccess(
ChatView*)),
this, SLOT(slotStopAnimation(
ChatView*)) );
778 connect( newView, SIGNAL(updateStatusIcon(
ChatView*)),
this, SLOT(slotUpdateCaptionIcons(
ChatView*)) );
780 if (m_UpdateChatLabel) {
781 connect( newView, SIGNAL(updateChatState(
ChatView*,
int)),
this, SLOT(updateChatState(
ChatView*,
int)) );
786 connect( newView, SIGNAL(autoSpellCheckEnabled(
ChatView*,
bool)),
787 this, SLOT(slotAutoSpellCheckEnabled(
ChatView*,
bool)) );
790 void KopeteChatWindow::checkDetachEnable()
793 tabCloseAllOthers->setEnabled( haveTabs );
794 tabDetach->setEnabled( haveTabs );
795 tabLeft->setEnabled( haveTabs );
796 tabRight->setEnabled( haveTabs );
797 tabActive->setEnabled( haveTabs );
798 actionTabPlacementMenu->setEnabled( m_tabBar != 0 );
800 bool otherWindows = (windows.count() > 1);
801 actionDetachMenu->setEnabled( otherWindows );
808 disconnect( view, SIGNAL(captionChanged(
bool)),
this, SLOT(slotSetCaption(
bool)) );
809 disconnect( view, SIGNAL(updateStatusIcon(
ChatView*)),
this, SLOT(slotUpdateCaptionIcons(
ChatView*)) );
810 disconnect( view, SIGNAL(updateChatState(
ChatView*,
int)),
this, SLOT(updateChatState(
ChatView*,
int)) );
811 view->
editWidget()->removeEventFilter(
this );
815 int curPage = m_tabBar->currentIndex();
816 QWidget *page = m_tabBar->currentWidget();
822 m_tabBar->setCurrentIndex( curPage - 1 );
824 m_tabBar->setCurrentIndex( curPage + 1 );
827 m_tabBar->removePage( view );
829 if( m_tabBar->currentWidget() )
830 setActiveView( static_cast<ChatView*>(m_tabBar->currentWidget()) );
833 if( m_activeView == view )
844 void KopeteChatWindow::slotDetachChat(
QAction *action )
850 detachedView = m_popupView;
852 detachedView = m_activeView;
859 guiFactory()->removeClient(detachedView->msgManager());
864 newWindow->setObjectName(
QLatin1String(
"KopeteChatWindow") );
867 newWindow = windows.at( action->
data().
toInt() );
876 void KopeteChatWindow::slotCloseAllOtherTabs()
881 detachedView = m_popupView;
883 detachedView = m_activeView;
886 if (view != detachedView)
891 void KopeteChatWindow::slotPreviousTab()
893 int curPage = m_tabBar->currentIndex();
895 m_tabBar->setCurrentIndex( curPage - 1 );
897 m_tabBar->setCurrentIndex( m_tabBar->count() - 1 );
900 void KopeteChatWindow::slotNextTab()
902 int curPage = m_tabBar->currentIndex();
903 if( curPage == ( m_tabBar->count() - 1 ) )
904 m_tabBar->setCurrentIndex( 0 );
906 m_tabBar->setCurrentIndex( curPage + 1 );
909 void KopeteChatWindow::slotNextActiveTab()
911 int curPage = m_tabBar->currentIndex();
912 for(
int i=(curPage+1) % m_tabBar->count(); i!=curPage; i = (i+1) % m_tabBar->count())
917 m_tabBar->setCurrentIndex( i );
923 void KopeteChatWindow::slotSetCaption(
bool active )
925 if( active && m_activeView )
927 setCaption( m_activeView->caption(), false );
950 if( m_activeView == view )
955 disconnect( m_activeView->editWidget(), SIGNAL(checkSpellingChanged(
bool)),
this, SLOT(enableSpellCheckAction(
bool)) );
956 disconnect( m_activeView, SIGNAL(canSendChanged(
bool)),
this, SLOT(slotUpdateSendEnabled()) );
957 disconnect( m_activeView, SIGNAL(canAcceptFilesChanged()),
this, SLOT(updateChatSendFileAction()) );
958 guiFactory()->removeClient(m_activeView->msgManager());
959 m_activeView->saveChatSettings();
963 guiFactory()->addClient(view->msgManager());
967 m_activeView->setActive(
false );
977 connect( m_activeView->editWidget(), SIGNAL(checkSpellingChanged(
bool)),
this, SLOT(enableSpellCheckAction(
bool)) );
978 connect( m_activeView, SIGNAL(canSendChanged(
bool)),
this, SLOT(slotUpdateSendEnabled()) );
979 connect( m_activeView, SIGNAL(canAcceptFilesChanged()),
this, SLOT(updateChatSendFileAction()) );
982 m_activeView->setActive(
true );
985 slotUpdateCaptionIcons( m_activeView );
987 if ( m_activeView->sendInProgress() && animIcon )
1004 m_tabBar->setCurrentWidget( m_activeView );
1007 setCaption( m_activeView->caption() );
1008 setStatus( m_activeView->statusText() );
1009 m_activeView->setFocus();
1011 slotUpdateSendEnabled();
1012 m_activeView->loadChatSettings();
1013 updateSendKeySequence();
1018 void KopeteChatWindow::slotUpdateCaptionIcons(
ChatView *view )
1024 Kopete::Contact *c=0L;
1025 foreach ( Kopete::Contact *contact , chatMembers )
1027 if(!c || c->onlineStatus() < contact->onlineStatus())
1031 if ( view == m_activeView )
1033 setWindowIcon( c ? view->msgManager()->contactOnlineStatus( c ).iconFor( c ) :
1034 KIcon(view->msgManager()->protocol()->pluginIcon()));
1038 m_tabBar->setTabIcon(m_tabBar->indexOf( view ), c ? view->msgManager()->contactOnlineStatus( c ).iconFor( c ) :
1039 KIcon( view->msgManager()->protocol()->pluginIcon() ) );
1042 void KopeteChatWindow::slotChatClosed()
1047 m_activeView->closeView();
1050 void KopeteChatWindow::slotPrepareDetachMenu(
void)
1052 QMenu *detachMenu = actionDetachMenu->menu();
1053 detachMenu->
clear();
1056 for (
int id = 0;
id < windows.count();
id++ )
1061 action = detachMenu->
addAction( win->windowIcon(), win->windowTitle() );
1067 void KopeteChatWindow::slotSendMessage()
1069 if ( m_activeView && m_activeView->canSend() )
1076 m_activeView->sendMessage();
1080 void KopeteChatWindow::slotSendFile()
1083 m_activeView->sendFile();
1086 void KopeteChatWindow::slotPrepareContactMenu(
void)
1088 KMenu *contactsMenu = actionContactMenu->menu();
1089 contactsMenu->clear();
1094 m_them = m_popupView->msgManager()->members();
1096 m_them = m_activeView->msgManager()->members();
1101 uint contactCount = 0;
1103 foreach(Kopete::Contact *contact, m_them)
1105 KMenu *p = contact->popupMenu();
1106 connect ( actionContactMenu->menu(), SIGNAL(aboutToHide()),
1107 p, SLOT(deleteLater()) );
1109 p->setIcon( contact->onlineStatus().iconFor( contact ) );
1110 if( contact->metaContact() )
1111 p->setTitle( contact->metaContact()->displayName() );
1113 p->setTitle( contact->contactId() );
1115 contactsMenu->addMenu( p );
1118 if( ++contactCount == 15 && contact != m_them.
last() )
1121 connect ( actionContactMenu->menu(), SIGNAL(aboutToHide()),
1122 moreMenu, SLOT(deleteLater()) );
1123 contactsMenu->addAction( moreMenu );
1124 contactsMenu = moreMenu->menu();
1130 void KopeteChatWindow::slotPreparePlacementMenu()
1132 QMenu *placementMenu = actionTabPlacementMenu->menu();
1133 placementMenu->
clear();
1136 action = placementMenu->
addAction( i18n(
"Top") );
1139 action = placementMenu->
addAction( i18n(
"Bottom") );
1142 action = placementMenu->
addAction( i18n(
"Left") );
1145 action = placementMenu->
addAction( i18n(
"Right") );
1149 void KopeteChatWindow::slotPlaceTabs(
QAction *action )
1157 case 1 : m_tabBar->setTabPosition( QTabWidget::South );
break;
1158 case 2 : m_tabBar->setTabPosition( QTabWidget::West );
break;
1159 case 3 : m_tabBar->setTabPosition( QTabWidget::East );
break;
1160 default: m_tabBar->setTabPosition( QTabWidget::North );
1166 void KopeteChatWindow::readOptions()
1170 applyMainWindowSettings( KGlobal::config()->group( ( initialForm == Kopete::ChatSession::Chatroom ?
QLatin1String(
"KopeteChatWindowGroupMode" ) :
QLatin1String(
"KopeteChatWindowIndividualMode" ) ) ) );
1174 void KopeteChatWindow::saveOptions()
1178 KConfigGroup kopeteChatWindowMainWinSettings( KGlobal::config(), ( initialForm == Kopete::ChatSession::Chatroom ?
QLatin1String(
"KopeteChatWindowGroupMode" ) :
QLatin1String(
"KopeteChatWindowIndividualMode" ) ) );
1181 saveMainWindowSettings( kopeteChatWindowMainWinSettings );
1183 KConfigGroup chatWindowSettings( KGlobal::config(),
QLatin1String(
"ChatWindowSettings") );
1184 chatWindowSettings.writeEntry (
QLatin1String(
"Tab Placement"), (
int)m_tabBar->tabPosition() );
1185 chatWindowSettings.sync();
1187 kopeteChatWindowMainWinSettings.sync();
1190 void KopeteChatWindow::slotChatSave()
1193 if( isActiveWindow() && m_activeView )
1194 m_activeView->messagePart()->save();
1199 if( e->
type() == QEvent::ActivationChange && isActiveWindow() && m_activeView )
1200 m_activeView->setActive(
true );
1203 void KopeteChatWindow::slotChatPrint()
1205 m_activeView->messagePart()->print();
1212 m_activeView->addText(
' ' + sm +
' ' );
1216 void KopeteChatWindow::slotAutoSpellCheckEnabled(
ChatView* view,
bool isEnabled )
1218 if ( view != m_activeView )
1221 toggleAutoSpellCheck->setChecked( isEnabled );
1222 m_activeView->editPart()->setCheckSpellingEnabled( isEnabled );
1230 bool canClose =
true;
1235 setUpdatesEnabled(
false);
1248 kDebug() <<
"Closing view failed!";
1252 setUpdatesEnabled(
true);
1254 kDebug()<<
"TIME: "<<chrono.
elapsed();
1262 if ( app->sessionSaving()
1265 || !Kopete::BehaviorSettings::self()->showSystemTray()
1268 Kopete::PluginManager::self()->shutdown();
1280 if ( Kopete::BehaviorSettings::self()->showSystemTray() && !app->
isShuttingDown() && !app->sessionSaving() ) {
1284 if ( settingsDirty() && autoSaveSettings() )
1285 saveAutoSaveSettings();
1296 KXmlGuiWindow::closeEvent( e );
1300 void KopeteChatWindow::updateChatState(
ChatView* cv,
int newState )
1306 KColorScheme scheme(QPalette::Active, KColorScheme::Window);
1310 m_tabBar->setTabTextColor( m_tabBar->indexOf(cv), scheme.foreground(KColorScheme::LinkText).color());
1313 m_tabBar->setTabTextColor( m_tabBar->indexOf(cv), scheme.foreground(KColorScheme::ActiveText).color());
1316 m_tabBar->setTabTextColor( m_tabBar->indexOf(cv), scheme.foreground(KColorScheme::NeutralText).color());
1319 m_tabBar->setTabTextColor( m_tabBar->indexOf(cv), scheme.foreground(KColorScheme::PositiveText).color());
1323 m_tabBar->setTabTextColor( m_tabBar->indexOf(cv), scheme.foreground(KColorScheme::NormalText).color() );
1329 void KopeteChatWindow::updateChatTooltip(
ChatView* cv )
1335 void KopeteChatWindow::updateChatLabel()
1338 if ( !chat || !m_tabBar )
1343 m_tabBar->setTabText( m_tabBar->indexOf( chat ), chat->
caption() );
1344 if ( m_tabBar->count() < 2 || m_tabBar->currentWidget() == chat )
1345 setCaption( chat->
caption() );
1351 KXmlGuiWindow::resizeEvent( e );
1352 if ( m_activeView && m_activeView->messagePart() )
1353 m_activeView->messagePart()->keepScrolledDown();
1358 if ( m_activeView && obj == m_activeView->editWidget() &&
event->type() == QEvent::KeyPress ) {
1360 if (nickComplete->shortcut().primary() ==
QKeySequence(keyEvent->
key())) {
1361 m_activeView->nickComplete();
1365 return KXmlGuiWindow::eventFilter(obj, event);
1368 #include "kopetechatwindow.moc"
void setText(const QString &text)
virtual bool eventFilter(QObject *obj, QEvent *event)
void chatSessionChanged(Kopete::ChatSession *newSession)
void setCaption(const QString &text, bool modified)
Sets the text to be displayed on tab label and window caption.
void setContentsMargins(int left, int top, int right, int bottom)
QString & caption() const
ChatViewList chatViewList
virtual bool closeView(bool force=false)
void closing(KopeteChatWindow *)
int chatViewCount()
Returns the number of chat views attached to this window.
QMap< Kopete::MetaContact *, KopeteChatWindow * > MetaContactMap
KTemporaryFile * backgroundFile
virtual void resizeEvent(QResizeEvent *e)
KopeteTabState tabState() const
Retrieves the tab state.
virtual void dropEvent(QDropEvent *)
void setIconText(const QString &text)
virtual void setModel(QAbstractItemModel *model)
void setPixmap(const QPixmap &)
void detachChatView(ChatView *chat)
Detach a chat view from this window.
QMap< Kopete::Account *, KopeteChatWindow * > AccountMap
void setIcon(const QIcon &icon)
virtual Kopete::ChatSession * manager(Kopete::Contact::CanCreateFlags)
const QPoint & pos() const
QList< QKeySequence > shortcuts() const
void slotSmileyActivated(const QString &)
void updateBackground(const QPixmap &pm)
void setWordWrap(bool on)
void setActive(bool value)
Tells this view it is the active view.
virtual bool queryClose()
Reimplemented from KXmlGuiWindow - asks each ChatView in the window if it is ok to close the window...
virtual void changeEvent(QEvent *e)
int indexOf(const T &value, int from) const
void setPaused(bool paused)
int count(const T &value) const
void append(const T &value)
bool save(const QString &fileName, const char *format, int quality) const
int toInt(bool *ok) const
void setMovie(QMovie *movie)
void setObjectName(const QString &name)
static KopeteChatWindow * window(Kopete::ChatSession *manager)
Find the appropriate window for a ChatView of the given protocol to dock into.
virtual void closeEvent(QCloseEvent *e)
QList< KopeteChatWindow * > WindowList
bool isShuttingDown() const
Method to return whether or not we're shutting down or not at this point.
void setData(const QVariant &userData)
QMap< Kopete::Group *, KopeteChatWindow * > GroupMap
void setMainWindow(KopeteChatWindow *parent)
Changes the pointer to the chat window.
ChatView * activeView()
Returns the chatview in the currently active tab, or the only chat view if chatViewCount() == 1...
void attachChatView(ChatView *chat)
Attach an unattached chatview to this window.
void setActiveView(QWidget *active)
void setStatus(const QString &)
QString fromLatin1(const char *str, int size)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const