Line 0
Link Here
|
|
|
1 |
/* |
2 |
kopetechatwindow.cpp - Chat Window |
3 |
|
4 |
Copyright (c) 2002-2005 by Olivier Goffart <ogoffart@ kde.org> |
5 |
Copyright (c) 2003-2004 by Richard Smith <kde@metafoo.co.uk> |
6 |
Copyright (C) 2002 by James Grant |
7 |
Copyright (c) 2002 by Stefan Gehn <metz AT gehn.net> |
8 |
Copyright (c) 2002-2004 by Martijn Klingens <klingens@kde.org> |
9 |
|
10 |
Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org> |
11 |
|
12 |
************************************************************************* |
13 |
* * |
14 |
* This program is free software; you can redistribute it and/or modify * |
15 |
* it under the terms of the GNU General Public License as published by * |
16 |
* the Free Software Foundation; either version 2 of the License, or * |
17 |
* (at your option) any later version. * |
18 |
* * |
19 |
************************************************************************* |
20 |
*/ |
21 |
|
22 |
#include <qtimer.h> |
23 |
#include <qhbox.h> |
24 |
#include <qvbox.h> |
25 |
#include <qlayout.h> |
26 |
#include <qtooltip.h> |
27 |
#include <qfileinfo.h> |
28 |
|
29 |
#include <kapplication.h> |
30 |
#include <kcursor.h> |
31 |
#include <klocale.h> |
32 |
#include <kmenubar.h> |
33 |
#include <kconfig.h> |
34 |
#include <kpopupmenu.h> |
35 |
#include <kiconloader.h> |
36 |
#include <kdebug.h> |
37 |
#include <kwin.h> |
38 |
#include <ktempfile.h> |
39 |
#include <kkeydialog.h> |
40 |
#include <kedittoolbar.h> |
41 |
#include <kstatusbar.h> |
42 |
#include <kpushbutton.h> |
43 |
#include <ktabwidget.h> |
44 |
#include <kstandarddirs.h> |
45 |
#include <kdialog.h> |
46 |
#include <kstringhandler.h> |
47 |
#include <ksqueezedtextlabel.h> |
48 |
#include <kstdaccel.h> |
49 |
|
50 |
#include "chatmessagepart.h" |
51 |
#include "chattexteditpart.h" |
52 |
#include "chatview.h" |
53 |
#include "../kopeteapplication.h" |
54 |
#include "kopetechatwindow.h" |
55 |
#include "kopeteemoticonaction.h" |
56 |
#include "kopetegroup.h" |
57 |
#include "kopetemessagemanager.h" |
58 |
#include "kopetemetacontact.h" |
59 |
#include "kopetepluginmanager.h" |
60 |
#include "kopeteprefs.h" |
61 |
#include "kopeteprotocol.h" |
62 |
#include "kopetestdaction.h" |
63 |
#include "kopeteviewmanager.h" |
64 |
|
65 |
#include <qtoolbutton.h> |
66 |
#include <kactionclasses.h> |
67 |
|
68 |
typedef QMap<Kopete::Account*,KopeteChatWindow*> AccountMap; |
69 |
typedef QMap<Kopete::Group*,KopeteChatWindow*> GroupMap; |
70 |
typedef QMap<Kopete::MetaContact*,KopeteChatWindow*> MetaContactMap; |
71 |
typedef QPtrList<KopeteChatWindow> WindowList; |
72 |
|
73 |
namespace |
74 |
{ |
75 |
AccountMap accountMap; |
76 |
GroupMap groupMap; |
77 |
MetaContactMap mcMap; |
78 |
WindowList windows; |
79 |
} |
80 |
|
81 |
KopeteChatWindow *KopeteChatWindow::window( Kopete::ChatSession *manager ) |
82 |
{ |
83 |
bool windowCreated = false; |
84 |
KopeteChatWindow *myWindow; |
85 |
|
86 |
//Take the first and the first? What else? |
87 |
Kopete::Group *group = 0L; |
88 |
Kopete::ContactPtrList members = manager->members(); |
89 |
Kopete::MetaContact *metaContact = members.first()->metaContact(); |
90 |
|
91 |
if ( metaContact ) |
92 |
{ |
93 |
Kopete::GroupList gList = metaContact->groups(); |
94 |
group = gList.first(); |
95 |
} |
96 |
|
97 |
switch( KopetePrefs::prefs()->chatWindowPolicy() ) |
98 |
{ |
99 |
case GROUP_BY_ACCOUNT: //Open chats from the same protocol in the same window |
100 |
if( accountMap.contains( manager->account() ) ) |
101 |
myWindow = accountMap[ manager->account() ]; |
102 |
else |
103 |
windowCreated = true; |
104 |
break; |
105 |
|
106 |
case GROUP_BY_GROUP: //Open chats from the same group in the same window |
107 |
if( group && groupMap.contains( group ) ) |
108 |
myWindow = groupMap[ group ]; |
109 |
else |
110 |
windowCreated = true; |
111 |
break; |
112 |
|
113 |
case GROUP_BY_METACONTACT: //Open chats from the same metacontact in the same window |
114 |
if( mcMap.contains( metaContact ) ) |
115 |
myWindow = mcMap[ metaContact ]; |
116 |
else |
117 |
windowCreated = true; |
118 |
break; |
119 |
|
120 |
case GROUP_ALL: //Open all chats in the same window |
121 |
if( windows.isEmpty() ) |
122 |
windowCreated = true; |
123 |
else |
124 |
{ |
125 |
//Here we are finding the window with the most tabs and |
126 |
//putting it there. Need this for the cases where config changes |
127 |
//midstream |
128 |
|
129 |
int viewCount = -1; |
130 |
for ( KopeteChatWindow *thisWindow = windows.first(); thisWindow; thisWindow = windows.next() ) |
131 |
{ |
132 |
if( thisWindow->chatViewCount() > viewCount ) |
133 |
{ |
134 |
myWindow = thisWindow; |
135 |
viewCount = thisWindow->chatViewCount(); |
136 |
} |
137 |
} |
138 |
} |
139 |
break; |
140 |
|
141 |
case NEW_WINDOW: //Open every chat in a new window |
142 |
default: |
143 |
windowCreated = true; |
144 |
break; |
145 |
} |
146 |
|
147 |
if ( windowCreated ) |
148 |
{ |
149 |
myWindow = new KopeteChatWindow(); |
150 |
|
151 |
if ( !accountMap.contains( manager->account() ) ) |
152 |
accountMap.insert( manager->account(), myWindow ); |
153 |
|
154 |
if ( !mcMap.contains( metaContact ) ) |
155 |
mcMap.insert( metaContact, myWindow ); |
156 |
|
157 |
if ( group && !groupMap.contains( group ) ) |
158 |
groupMap.insert( group, myWindow ); |
159 |
} |
160 |
|
161 |
// kdDebug( 14010 ) << k_funcinfo << "Open Windows: " << windows.count() << endl; |
162 |
|
163 |
return myWindow; |
164 |
} |
165 |
|
166 |
KopeteChatWindow::KopeteChatWindow( QWidget *parent, const char* name ) |
167 |
: KParts::MainWindow( parent, name ) |
168 |
{ |
169 |
m_activeView = 0L; |
170 |
m_popupView = 0L; |
171 |
backgroundFile = 0L; |
172 |
updateBg = true; |
173 |
m_tabBar = 0L; |
174 |
|
175 |
initActions(); |
176 |
|
177 |
QVBox *vBox = new QVBox( this ); |
178 |
vBox->setLineWidth( 0 ); |
179 |
vBox->setSpacing( 0 ); |
180 |
vBox->setFrameStyle( QFrame::NoFrame ); |
181 |
// set default window size. This could be removed by fixing the size hints of the contents |
182 |
resize( 500, 500 ); |
183 |
setCentralWidget( vBox ); |
184 |
|
185 |
mainArea = new QFrame( vBox ); |
186 |
mainArea->setLineWidth( 0 ); |
187 |
mainArea->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); |
188 |
mainLayout = new QVBoxLayout( mainArea ); |
189 |
|
190 |
if ( KopetePrefs::prefs()->chatWShowSend() ) |
191 |
{ |
192 |
//Send Button |
193 |
m_button_send = new KPushButton( i18n("Send"), statusBar() ); |
194 |
m_button_send->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); |
195 |
m_button_send->setEnabled( false ); |
196 |
m_button_send->setFont( statusBar()->font() ); |
197 |
m_button_send->setFixedHeight( statusBar()->sizeHint().height() ); |
198 |
connect( m_button_send, SIGNAL( clicked() ), this, SLOT( slotSendMessage() ) ); |
199 |
statusBar()->addWidget( m_button_send, 0, true ); |
200 |
} |
201 |
else |
202 |
m_button_send = 0L; |
203 |
|
204 |
m_status_text = new KSqueezedTextLabel( i18n("Ready."), statusBar(), "m_status_text" ); |
205 |
m_status_text->setAlignment( AlignLeft | AlignVCenter ); |
206 |
m_status_text->setFont( statusBar()->font() ); |
207 |
m_status_text->setFixedHeight( statusBar()->sizeHint().height() ); |
208 |
statusBar()->addWidget( m_status_text, 1 ); |
209 |
|
210 |
readOptions(); |
211 |
setWFlags( Qt::WDestructiveClose ); |
212 |
|
213 |
windows.append( this ); |
214 |
windowListChanged(); |
215 |
|
216 |
KGlobal::config()->setGroup( QString::fromLatin1("ChatWindowSettings") ); |
217 |
m_alwaysShowTabs = KGlobal::config()->readBoolEntry( QString::fromLatin1("AlwaysShowTabs"), false ); |
218 |
// kdDebug( 14010 ) << k_funcinfo << "Open Windows: " << windows.count() << endl; |
219 |
kapp->ref(); |
220 |
} |
221 |
|
222 |
KopeteChatWindow::~KopeteChatWindow() |
223 |
{ |
224 |
// kdDebug( 14010 ) << k_funcinfo << endl; |
225 |
|
226 |
emit( closing( this ) ); |
227 |
|
228 |
for( AccountMap::Iterator it = accountMap.begin(); it != accountMap.end(); ) |
229 |
{ |
230 |
AccountMap::Iterator mayDeleteIt = it; |
231 |
++it; |
232 |
if( mayDeleteIt.data() == this ) |
233 |
accountMap.remove( mayDeleteIt.key() ); |
234 |
} |
235 |
|
236 |
for( GroupMap::Iterator it = groupMap.begin(); it != groupMap.end(); ) |
237 |
{ |
238 |
GroupMap::Iterator mayDeleteIt = it; |
239 |
++it; |
240 |
if( mayDeleteIt.data() == this ) |
241 |
groupMap.remove( mayDeleteIt.key() ); |
242 |
} |
243 |
|
244 |
for( MetaContactMap::Iterator it = mcMap.begin(); it != mcMap.end(); ) |
245 |
{ |
246 |
MetaContactMap::Iterator mayDeleteIt = it; |
247 |
++it; |
248 |
if( mayDeleteIt.data() == this ) |
249 |
mcMap.remove( mayDeleteIt.key() ); |
250 |
} |
251 |
|
252 |
windows.remove( this ); |
253 |
windowListChanged(); |
254 |
|
255 |
// kdDebug( 14010 ) << "Open Windows: " << windows.count() << endl; |
256 |
|
257 |
saveOptions(); |
258 |
|
259 |
if( backgroundFile ) |
260 |
{ |
261 |
backgroundFile->close(); |
262 |
backgroundFile->unlink(); |
263 |
delete backgroundFile; |
264 |
} |
265 |
|
266 |
delete anim; |
267 |
kapp->deref(); |
268 |
} |
269 |
|
270 |
void KopeteChatWindow::windowListChanged() |
271 |
{ |
272 |
// update all windows' Move Tab to Window action |
273 |
for ( QPtrListIterator<KopeteChatWindow> it( windows ); *it; ++it ) |
274 |
(*it)->checkDetachEnable(); |
275 |
} |
276 |
|
277 |
void KopeteChatWindow::slotNickComplete() |
278 |
{ |
279 |
if( m_activeView ) |
280 |
m_activeView->nickComplete(); |
281 |
} |
282 |
|
283 |
void KopeteChatWindow::slotTabContextMenu( QWidget *tab, const QPoint &pos ) |
284 |
{ |
285 |
m_popupView = static_cast<ChatView*>( tab ); |
286 |
|
287 |
KPopupMenu *popup = new KPopupMenu; |
288 |
popup->insertTitle( KStringHandler::rsqueeze( m_popupView->caption() ) ); |
289 |
|
290 |
actionContactMenu->plug( popup ); |
291 |
popup->insertSeparator(); |
292 |
actionTabPlacementMenu->plug( popup ); |
293 |
tabDetach->plug( popup ); |
294 |
actionDetachMenu->plug( popup ); |
295 |
tabClose->plug( popup ); |
296 |
popup->exec( pos ); |
297 |
|
298 |
delete popup; |
299 |
m_popupView = 0; |
300 |
} |
301 |
|
302 |
ChatView *KopeteChatWindow::activeView() |
303 |
{ |
304 |
return m_activeView; |
305 |
} |
306 |
|
307 |
void KopeteChatWindow::initActions(void) |
308 |
{ |
309 |
KActionCollection *coll = actionCollection(); |
310 |
|
311 |
createStandardStatusBarAction(); |
312 |
|
313 |
chatSend = new KAction( i18n( "&Send Message" ), QString::fromLatin1( "mail_send" ), 0, |
314 |
this, SLOT( slotSendMessage() ), coll, "chat_send" ); |
315 |
//Default to 'Return' for sending messages |
316 |
chatSend->setShortcut( QKeySequence(Key_Return) ); |
317 |
chatSend->setEnabled( false ); |
318 |
|
319 |
KStdAction::save ( this, SLOT(slotChatSave()), coll ); |
320 |
KStdAction::print ( this, SLOT(slotChatPrint()), coll ); |
321 |
KStdAction::quit ( this, SLOT(close()), coll ); |
322 |
|
323 |
tabClose = KStdAction::close ( this, SLOT(slotChatClosed()), coll, "tabs_close" ); |
324 |
|
325 |
tabRight=new KAction( i18n( "&Activate Next Tab" ), 0, KStdAccel::tabNext(), |
326 |
this, SLOT( slotNextTab() ), coll, "tabs_right" ); |
327 |
tabLeft=new KAction( i18n( "&Activate Previous Tab" ), 0, KStdAccel::tabPrev(), |
328 |
this, SLOT( slotPreviousTab() ), coll, "tabs_left" ); |
329 |
tabLeft->setEnabled( false ); |
330 |
tabRight->setEnabled( false ); |
331 |
|
332 |
nickComplete = new KAction( i18n( "Nic&k Completion" ), QString::null, 0, this, SLOT( slotNickComplete() ), coll , "nick_compete"); |
333 |
nickComplete->setShortcut( QKeySequence( Key_Tab ) ); |
334 |
|
335 |
tabDetach = new KAction( i18n( "&Detach Chat" ), QString::fromLatin1( "tab_breakoff" ), 0, |
336 |
this, SLOT( slotDetachChat() ), coll, "tabs_detach" ); |
337 |
tabDetach->setEnabled( false ); |
338 |
|
339 |
actionDetachMenu = new KActionMenu( i18n( "&Move Tab to Window" ), QString::fromLatin1( "tab_breakoff" ), coll, "tabs_detachmove" ); |
340 |
actionDetachMenu->setDelayed( false ); |
341 |
|
342 |
connect ( actionDetachMenu->popupMenu(), SIGNAL(aboutToShow()), this, SLOT(slotPrepareDetachMenu()) ); |
343 |
connect ( actionDetachMenu->popupMenu(), SIGNAL(activated(int)), this, SLOT(slotDetachChat(int)) ); |
344 |
|
345 |
actionTabPlacementMenu = new KActionMenu( i18n( "&Tab Placement" ), coll, "tabs_placement" ); |
346 |
connect ( actionTabPlacementMenu->popupMenu(), SIGNAL(aboutToShow()), this, SLOT(slotPreparePlacementMenu()) ); |
347 |
connect ( actionTabPlacementMenu->popupMenu(), SIGNAL(activated(int)), this, SLOT(slotPlaceTabs(int)) ); |
348 |
|
349 |
tabDetach->setShortcut( QKeySequence(CTRL + SHIFT + Key_B) ); |
350 |
|
351 |
KStdAction::cut( this, SLOT(slotCut()), coll); |
352 |
KStdAction::copy( this, SLOT(slotCopy()), coll); |
353 |
KStdAction::paste( this, SLOT(slotPaste()), coll); |
354 |
|
355 |
new KAction( i18n( "Set Default &Font..." ), QString::fromLatin1( "charset" ), 0, this, SLOT( slotSetFont() ), coll, "format_font" ); |
356 |
new KAction( i18n( "Set Default Text &Color..." ), QString::fromLatin1( "pencil" ), 0, this, SLOT( slotSetFgColor() ), coll, "format_fgcolor" ); |
357 |
new KAction( i18n( "Set &Background Color..." ), QString::fromLatin1( "fill" ), 0, this, SLOT( slotSetBgColor() ), coll, "format_bgcolor" ); |
358 |
|
359 |
historyUp = new KAction( i18n( "Previous History" ), QString::null, 0, |
360 |
this, SLOT( slotHistoryUp() ), coll, "history_up" ); |
361 |
historyUp->setShortcut( QKeySequence(CTRL + Key_Up) ); |
362 |
|
363 |
historyDown = new KAction( i18n( "Next History" ), QString::null, 0, |
364 |
this, SLOT( slotHistoryDown() ), coll, "history_down" ); |
365 |
historyDown->setShortcut( QKeySequence(CTRL + Key_Down) ); |
366 |
|
367 |
KStdAction::prior( this, SLOT( slotPageUp() ), coll, "scroll_up" ); |
368 |
KStdAction::next( this, SLOT( slotPageDown() ), coll, "scroll_down" ); |
369 |
|
370 |
KStdAction::showMenubar( this, SLOT(slotViewMenuBar()), coll ); |
371 |
|
372 |
membersLeft = new KToggleAction( i18n( "Place to Left of Chat Area" ), QString::null, 0, |
373 |
this, SLOT( slotViewMembersLeft() ), coll, "options_membersleft" ); |
374 |
membersRight = new KToggleAction( i18n( "Place to Right of Chat Area" ), QString::null, 0, |
375 |
this, SLOT( slotViewMembersRight() ), coll, "options_membersright" ); |
376 |
toggleMembers = new KToggleAction( i18n( "Show" ), QString::null, 0, |
377 |
this, SLOT( slotToggleViewMembers() ), coll, "options_togglemembers" ); |
378 |
#if KDE_IS_VERSION(3,2,90) |
379 |
toggleMembers->setCheckedState(i18n("Hide")); |
380 |
#endif |
381 |
|
382 |
actionSmileyMenu = new KopeteEmoticonAction( coll, "format_smiley" ); |
383 |
actionSmileyMenu->setDelayed( false ); |
384 |
connect(actionSmileyMenu, SIGNAL(activated(const QString &)), this, SLOT(slotSmileyActivated(const QString &))); |
385 |
|
386 |
actionContactMenu = new KActionMenu(i18n("Co&ntacts"), coll, "contacts_menu" ); |
387 |
actionContactMenu->setDelayed( false ); |
388 |
connect ( actionContactMenu->popupMenu(), SIGNAL(aboutToShow()), this, SLOT(slotPrepareContactMenu()) ); |
389 |
|
390 |
// add configure key bindings menu item |
391 |
#if KDE_IS_VERSION(3, 2, 90) |
392 |
KStdAction::keyBindings( guiFactory(), SLOT( configureShortcuts() ), coll ); |
393 |
#else // when we will drop the KDE 3.2 compatibility, do not forget to remove slotConfKeys |
394 |
KStdAction::keyBindings( this, SLOT( slotConfKeys() ), coll ); |
395 |
#endif |
396 |
|
397 |
|
398 |
KStdAction::configureToolbars(this, SLOT(slotConfToolbar()), coll); |
399 |
KopeteStdAction::preferences( coll , "settings_prefs" ); |
400 |
|
401 |
//The Sending movie |
402 |
normalIcon = QPixmap( BarIcon( QString::fromLatin1( "kopete" ) ) ); |
403 |
animIcon = KGlobal::iconLoader()->loadMovie( QString::fromLatin1( "newmessage" ), KIcon::Toolbar); |
404 |
|
405 |
// Pause the animation because otherwise it's running even when we're not |
406 |
// showing it. This eats resources, and also triggers a pixmap leak in |
407 |
// QMovie in at least Qt 3.1, Qt 3.2 and the current Qt 3.3 beta |
408 |
if( !animIcon.isNull() ) //and another QT bug: it crash if we pause a null movie |
409 |
animIcon.pause(); |
410 |
|
411 |
// we can't set the tool bar as parent, if we do, it will be deleted when we configure toolbars |
412 |
anim = new QLabel( QString::null, 0L ,"kde toolbar widget" ); |
413 |
anim->setMargin(5); |
414 |
anim->setPixmap( normalIcon ); |
415 |
|
416 |
|
417 |
new KWidgetAction( anim , i18n("Toolbar Animation") , 0, 0 , 0 , coll , "toolbar_animation"); |
418 |
|
419 |
//toolBar()->insertWidget( 99, anim->width(), anim ); |
420 |
//toolBar()->alignItemRight( 99 ); |
421 |
setStandardToolBarMenuEnabled( true ); |
422 |
|
423 |
setXMLFile( QString::fromLatin1( "kopetechatwindow.rc" ) ); |
424 |
createGUI( 0L ); |
425 |
|
426 |
#if !KDE_IS_VERSION( 3, 1, 90 ) |
427 |
mStatusbarAction->setChecked(!statusBar()->isHidden()); |
428 |
#endif |
429 |
} |
430 |
|
431 |
const QString KopeteChatWindow::fileContents( const QString &path ) const |
432 |
{ |
433 |
QString contents; |
434 |
QFile file( path ); |
435 |
if ( file.open( IO_ReadOnly ) ) |
436 |
{ |
437 |
QTextStream stream( &file ); |
438 |
contents = stream.read(); |
439 |
file.close(); |
440 |
} |
441 |
|
442 |
return contents; |
443 |
} |
444 |
|
445 |
void KopeteChatWindow::slotStopAnimation( ChatView* view ) |
446 |
{ |
447 |
if( view == m_activeView ) |
448 |
anim->setPixmap( normalIcon ); |
449 |
} |
450 |
|
451 |
void KopeteChatWindow::slotUpdateSendEnabled() |
452 |
{ |
453 |
if ( !m_activeView ) return; |
454 |
|
455 |
bool enabled = m_activeView->canSend(); |
456 |
chatSend->setEnabled( enabled ); |
457 |
if(m_button_send) |
458 |
m_button_send->setEnabled( enabled ); |
459 |
} |
460 |
|
461 |
void KopeteChatWindow::updateMembersActions() |
462 |
{ |
463 |
if( m_activeView ) |
464 |
{ |
465 |
const KDockWidget::DockPosition pos = m_activeView->membersListPosition(); |
466 |
bool visibleMembers = m_activeView->visibleMembersList(); |
467 |
membersLeft->setChecked( pos == KDockWidget::DockLeft ); |
468 |
membersLeft->setEnabled( visibleMembers ); |
469 |
membersRight->setChecked( pos == KDockWidget::DockRight ); |
470 |
membersRight->setEnabled( visibleMembers ); |
471 |
toggleMembers->setChecked( visibleMembers ); |
472 |
} |
473 |
} |
474 |
|
475 |
void KopeteChatWindow::slotViewMembersLeft() |
476 |
{ |
477 |
m_activeView->placeMembersList( KDockWidget::DockLeft ); |
478 |
updateMembersActions(); |
479 |
} |
480 |
|
481 |
void KopeteChatWindow::slotViewMembersRight() |
482 |
{ |
483 |
m_activeView->placeMembersList( KDockWidget::DockRight ); |
484 |
updateMembersActions(); |
485 |
} |
486 |
|
487 |
void KopeteChatWindow::slotToggleViewMembers() |
488 |
{ |
489 |
m_activeView->toggleMembersVisibility(); |
490 |
updateMembersActions(); |
491 |
} |
492 |
|
493 |
void KopeteChatWindow::slotHistoryUp() |
494 |
{ |
495 |
if( m_activeView ) |
496 |
m_activeView->editPart()->historyUp(); |
497 |
} |
498 |
|
499 |
void KopeteChatWindow::slotHistoryDown() |
500 |
{ |
501 |
if( m_activeView ) |
502 |
m_activeView->editPart()->historyDown(); |
503 |
} |
504 |
|
505 |
void KopeteChatWindow::slotPageUp() |
506 |
{ |
507 |
if( m_activeView ) |
508 |
m_activeView->messagePart()->pageUp(); |
509 |
} |
510 |
|
511 |
void KopeteChatWindow::slotPageDown() |
512 |
{ |
513 |
if( m_activeView ) |
514 |
m_activeView->messagePart()->pageDown(); |
515 |
} |
516 |
|
517 |
void KopeteChatWindow::slotCut() |
518 |
{ |
519 |
m_activeView->cut(); |
520 |
} |
521 |
|
522 |
void KopeteChatWindow::slotCopy() |
523 |
{ |
524 |
m_activeView->copy(); |
525 |
} |
526 |
|
527 |
void KopeteChatWindow::slotPaste() |
528 |
{ |
529 |
m_activeView->paste(); |
530 |
} |
531 |
|
532 |
|
533 |
void KopeteChatWindow::slotSetFont() |
534 |
{ |
535 |
m_activeView->setFont(); |
536 |
} |
537 |
|
538 |
void KopeteChatWindow::slotSetFgColor() |
539 |
{ |
540 |
m_activeView->setFgColor(); |
541 |
} |
542 |
|
543 |
void KopeteChatWindow::slotSetBgColor() |
544 |
{ |
545 |
m_activeView->setBgColor(); |
546 |
} |
547 |
|
548 |
void KopeteChatWindow::setStatus(const QString &text) |
549 |
{ |
550 |
m_status_text->setText(text); |
551 |
} |
552 |
|
553 |
void KopeteChatWindow::createTabBar() |
554 |
{ |
555 |
if( !m_tabBar ) |
556 |
{ |
557 |
KGlobal::config()->setGroup( QString::fromLatin1("ChatWindowSettings") ); |
558 |
|
559 |
m_tabBar = new KTabWidget( mainArea ); |
560 |
m_tabBar->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); |
561 |
m_tabBar->setHoverCloseButton(KGlobal::config()->readBoolEntry( QString::fromLatin1("HoverClose"), false )); |
562 |
m_tabBar->setTabReorderingEnabled(true); |
563 |
m_tabBar->setAutomaticResizeTabs(true); |
564 |
connect( m_tabBar, SIGNAL( closeRequest( QWidget* )), this, SLOT( slotCloseChat( QWidget* ) ) ); |
565 |
|
566 |
QToolButton* m_rightWidget = new QToolButton( m_tabBar ); |
567 |
connect( m_rightWidget, SIGNAL( clicked() ), this, SLOT( slotChatClosed() ) ); |
568 |
m_rightWidget->setIconSet( SmallIcon( "tab_remove" ) ); |
569 |
m_rightWidget->adjustSize(); |
570 |
QToolTip::add( m_rightWidget, i18n("Close the current tab")); |
571 |
m_tabBar->setCornerWidget( m_rightWidget, QWidget::TopRight ); |
572 |
|
573 |
mainLayout->addWidget( m_tabBar ); |
574 |
m_tabBar->show(); |
575 |
connect ( m_tabBar, SIGNAL(currentChanged(QWidget *)), this, SLOT(setActiveView(QWidget *)) ); |
576 |
connect ( m_tabBar, SIGNAL(contextMenu(QWidget *, const QPoint & )), this, SLOT(slotTabContextMenu( QWidget *, const QPoint & )) ); |
577 |
|
578 |
for( ChatView *view = chatViewList.first(); view; view = chatViewList.next() ) |
579 |
addTab( view ); |
580 |
|
581 |
if( m_activeView ) |
582 |
m_tabBar->showPage( m_activeView ); |
583 |
else |
584 |
setActiveView( chatViewList.first() ); |
585 |
|
586 |
int tabPosition = KGlobal::config()->readNumEntry( QString::fromLatin1("Tab Placement") , 0 ); |
587 |
slotPlaceTabs( tabPosition ); |
588 |
} |
589 |
} |
590 |
|
591 |
void KopeteChatWindow::slotCloseChat( QWidget *chatView ) |
592 |
{ |
593 |
static_cast<ChatView*>( chatView )->closeView(); |
594 |
} |
595 |
|
596 |
void KopeteChatWindow::addTab( ChatView *view ) |
597 |
{ |
598 |
QPtrList<Kopete::Contact> chatMembers=view->msgManager()->members(); |
599 |
Kopete::Contact *c=0L; |
600 |
for ( Kopete::Contact *contact = chatMembers.first(); contact; contact = chatMembers.next() ) |
601 |
{ |
602 |
if(!c || c->onlineStatus() < contact->onlineStatus()) |
603 |
c=contact; |
604 |
} |
605 |
QPixmap pluginIcon = c ? view->msgManager()->contactOnlineStatus( c ).iconFor( c) : SmallIcon( view->msgManager()->protocol()->pluginIcon() ); |
606 |
|
607 |
view->reparent( m_tabBar, 0, QPoint(), true ); |
608 |
m_tabBar->addTab( view, pluginIcon, QString::null ); |
609 |
view->setTabBar( m_tabBar ); |
610 |
if( view == m_activeView ) |
611 |
view->show(); |
612 |
else |
613 |
view->hide(); |
614 |
view->setCaption( view->caption(), false ); |
615 |
} |
616 |
|
617 |
void KopeteChatWindow::setPrimaryChatView( ChatView *view ) |
618 |
{ |
619 |
//TODO figure out what else we have to save here besides the font |
620 |
//reparent clears a lot of stuff out |
621 |
QFont savedFont = view->font(); |
622 |
view->reparent( mainArea, 0, QPoint(), true ); |
623 |
view->setTabBar( 0L ); |
624 |
view->setFont( savedFont ); |
625 |
view->show(); |
626 |
|
627 |
mainLayout->addWidget( view ); |
628 |
setActiveView( view ); |
629 |
} |
630 |
|
631 |
void KopeteChatWindow::deleteTabBar() |
632 |
{ |
633 |
if( m_tabBar ) |
634 |
{ |
635 |
disconnect ( m_tabBar, SIGNAL(currentChanged(QWidget *)), this, SLOT(setActiveView(QWidget *)) ); |
636 |
disconnect ( m_tabBar, SIGNAL(contextMenu(QWidget *, const QPoint & )), this, SLOT(slotTabContextMenu( QWidget *, const QPoint & )) ); |
637 |
|
638 |
if( !chatViewList.isEmpty() ) |
639 |
setPrimaryChatView( chatViewList.first() ); |
640 |
|
641 |
m_tabBar->deleteLater(); |
642 |
m_tabBar = 0L; |
643 |
} |
644 |
} |
645 |
|
646 |
void KopeteChatWindow::attachChatView( ChatView* newView ) |
647 |
{ |
648 |
chatViewList.append( newView ); |
649 |
|
650 |
if ( !m_alwaysShowTabs && chatViewList.count() == 1 ) |
651 |
setPrimaryChatView( newView ); |
652 |
else |
653 |
{ |
654 |
if ( !m_tabBar ) |
655 |
createTabBar(); |
656 |
else |
657 |
addTab( newView ); |
658 |
newView->setActive( false ); |
659 |
} |
660 |
|
661 |
newView->setMainWindow( this ); |
662 |
newView->editWidget()->installEventFilter( this ); |
663 |
|
664 |
KCursor::setAutoHideCursor( newView->editWidget(), true, true ); |
665 |
connect( newView, SIGNAL(captionChanged( bool)), this, SLOT(slotSetCaption(bool)) ); |
666 |
connect( newView, SIGNAL(messageSuccess( ChatView* )), this, SLOT(slotStopAnimation( ChatView* )) ); |
667 |
connect( newView, SIGNAL(updateStatusIcon( const ChatView* )), this, SLOT(slotUpdateCaptionIcons( const ChatView* )) ); |
668 |
|
669 |
checkDetachEnable(); |
670 |
} |
671 |
|
672 |
void KopeteChatWindow::checkDetachEnable() |
673 |
{ |
674 |
bool haveTabs = (chatViewList.count() > 1); |
675 |
tabDetach->setEnabled( haveTabs ); |
676 |
tabLeft->setEnabled( haveTabs ); |
677 |
tabRight->setEnabled( haveTabs ); |
678 |
actionTabPlacementMenu->setEnabled( m_tabBar != 0 ); |
679 |
|
680 |
bool otherWindows = (windows.count() > 1); |
681 |
actionDetachMenu->setEnabled( otherWindows ); |
682 |
} |
683 |
|
684 |
void KopeteChatWindow::detachChatView( ChatView *view ) |
685 |
{ |
686 |
if( !chatViewList.removeRef( view ) ) |
687 |
return; |
688 |
|
689 |
disconnect( view, SIGNAL(captionChanged( bool)), this, SLOT(slotSetCaption(bool)) ); |
690 |
disconnect( view, SIGNAL(updateStatusIcon( const ChatView *)), this, SLOT(slotUpdateCaptionIcons( const ChatView * )) ); |
691 |
view->editWidget()->removeEventFilter( this ); |
692 |
|
693 |
if( m_tabBar ) |
694 |
{ |
695 |
int curPage = m_tabBar->currentPageIndex(); |
696 |
QWidget *page = m_tabBar->page( curPage ); |
697 |
|
698 |
// if the current view is to be detached, switch to a different one |
699 |
if( page == view ) |
700 |
{ |
701 |
if( curPage > 0 ) |
702 |
m_tabBar->setCurrentPage( curPage - 1 ); |
703 |
else |
704 |
m_tabBar->setCurrentPage( curPage + 1 ); |
705 |
} |
706 |
|
707 |
view->setTabBar( 0L ); |
708 |
m_tabBar->removePage( view ); |
709 |
|
710 |
if( m_tabBar->currentPage() ) |
711 |
setActiveView( static_cast<ChatView*>(m_tabBar->currentPage()) ); |
712 |
} |
713 |
|
714 |
if( chatViewList.isEmpty() ) |
715 |
close(); |
716 |
else if( !m_alwaysShowTabs && chatViewList.count() == 1) |
717 |
deleteTabBar(); |
718 |
|
719 |
checkDetachEnable(); |
720 |
} |
721 |
|
722 |
void KopeteChatWindow::slotDetachChat( int newWindowIndex ) |
723 |
{ |
724 |
KopeteChatWindow *newWindow = 0L; |
725 |
ChatView *detachedView; |
726 |
|
727 |
if( m_popupView ) |
728 |
detachedView = m_popupView; |
729 |
else |
730 |
detachedView = m_activeView; |
731 |
|
732 |
if( !detachedView ) |
733 |
return; |
734 |
|
735 |
//if we don't do this, we might crash |
736 |
createGUI(0L); |
737 |
guiFactory()->removeClient(detachedView->msgManager()); |
738 |
|
739 |
if( newWindowIndex == -1 ) |
740 |
newWindow = new KopeteChatWindow(); |
741 |
else |
742 |
newWindow = windows.at( newWindowIndex ); |
743 |
|
744 |
newWindow->show(); |
745 |
newWindow->raise(); |
746 |
|
747 |
detachChatView( detachedView ); |
748 |
newWindow->attachChatView( detachedView ); |
749 |
} |
750 |
|
751 |
void KopeteChatWindow::slotPreviousTab() |
752 |
{ |
753 |
int curPage = m_tabBar->currentPageIndex(); |
754 |
if( curPage > 0 ) |
755 |
m_tabBar->setCurrentPage( curPage - 1 ); |
756 |
else |
757 |
m_tabBar->setCurrentPage( m_tabBar->count() - 1 ); |
758 |
} |
759 |
|
760 |
void KopeteChatWindow::slotNextTab() |
761 |
{ |
762 |
int curPage = m_tabBar->currentPageIndex(); |
763 |
if( curPage == ( m_tabBar->count() - 1 ) ) |
764 |
m_tabBar->setCurrentPage( 0 ); |
765 |
else |
766 |
m_tabBar->setCurrentPage( curPage + 1 ); |
767 |
} |
768 |
|
769 |
void KopeteChatWindow::slotSetCaption( bool active ) |
770 |
{ |
771 |
if( active && m_activeView ) |
772 |
{ |
773 |
setCaption( m_activeView->caption(), false ); |
774 |
} |
775 |
} |
776 |
|
777 |
void KopeteChatWindow::updateBackground( const QPixmap &pm ) |
778 |
{ |
779 |
if( updateBg ) |
780 |
{ |
781 |
updateBg = false; |
782 |
if( backgroundFile != 0L ) |
783 |
{ |
784 |
backgroundFile->close(); |
785 |
backgroundFile->unlink(); |
786 |
} |
787 |
|
788 |
backgroundFile = new KTempFile( QString::null, QString::fromLatin1( ".bmp" ) ); |
789 |
pm.save( backgroundFile->name(), "BMP" ); |
790 |
QTimer::singleShot( 100, this, SLOT( slotEnableUpdateBg() ) ); |
791 |
} |
792 |
} |
793 |
|
794 |
void KopeteChatWindow::setActiveView( QWidget *widget ) |
795 |
{ |
796 |
ChatView *view = static_cast<ChatView*>(widget); |
797 |
|
798 |
if( m_activeView == view ) |
799 |
return; |
800 |
|
801 |
if(m_activeView) |
802 |
{ |
803 |
disconnect( m_activeView, SIGNAL( canSendChanged(bool) ), this, SLOT( slotUpdateSendEnabled() ) ); |
804 |
guiFactory()->removeClient(m_activeView->msgManager()); |
805 |
} |
806 |
|
807 |
guiFactory()->addClient(view->msgManager()); |
808 |
createGUI( view->part() ); |
809 |
|
810 |
if( m_activeView ) |
811 |
m_activeView->setActive( false ); |
812 |
|
813 |
m_activeView = view; |
814 |
|
815 |
if( !chatViewList.contains( view ) ) |
816 |
attachChatView( view ); |
817 |
|
818 |
connect( m_activeView, SIGNAL( canSendChanged(bool) ), this, SLOT( slotUpdateSendEnabled() ) ); |
819 |
|
820 |
//Tell it it is active |
821 |
m_activeView->setActive( true ); |
822 |
|
823 |
//Update icons to match |
824 |
slotUpdateCaptionIcons( m_activeView ); |
825 |
|
826 |
//Update chat members actions |
827 |
updateMembersActions(); |
828 |
|
829 |
if ( m_activeView->sendInProgress() && !animIcon.isNull() ) |
830 |
{ |
831 |
anim->setMovie( animIcon ); |
832 |
animIcon.unpause(); |
833 |
} |
834 |
else |
835 |
{ |
836 |
anim->setPixmap( normalIcon ); |
837 |
if( !animIcon.isNull() ) |
838 |
animIcon.pause(); |
839 |
} |
840 |
|
841 |
if ( m_alwaysShowTabs || chatViewList.count() > 1 ) |
842 |
{ |
843 |
if( !m_tabBar ) |
844 |
createTabBar(); |
845 |
|
846 |
m_tabBar->showPage( m_activeView ); |
847 |
} |
848 |
|
849 |
setCaption( m_activeView->caption() ); |
850 |
setStatus( m_activeView->statusText() ); |
851 |
m_activeView->setFocus(); |
852 |
|
853 |
slotUpdateSendEnabled(); |
854 |
} |
855 |
|
856 |
void KopeteChatWindow::slotUpdateCaptionIcons( const ChatView *view ) |
857 |
{ |
858 |
if(!view||!m_activeView||view!=m_activeView ) |
859 |
return; //(pas de charité) |
860 |
QPtrList<Kopete::Contact> chatMembers=view->msgManager()->members(); |
861 |
Kopete::Contact *c=0L; |
862 |
for ( Kopete::Contact *contact = chatMembers.first(); contact; contact = chatMembers.next() ) |
863 |
{ |
864 |
if(!c || c->onlineStatus() < contact->onlineStatus()) |
865 |
c=contact; |
866 |
} |
867 |
QPixmap icon16 = c ? view->msgManager()->contactOnlineStatus( c ).iconFor( c , 16) : SmallIcon( view->msgManager()->protocol()->pluginIcon() ); |
868 |
QPixmap icon32 = c ? view->msgManager()->contactOnlineStatus( c ).iconFor( c , 32) : SmallIcon( view->msgManager()->protocol()->pluginIcon() ); |
869 |
|
870 |
KWin::setIcons( winId(), icon32, icon16 ); |
871 |
} |
872 |
|
873 |
void KopeteChatWindow::slotChatClosed() |
874 |
{ |
875 |
if( m_popupView ) |
876 |
m_popupView->closeView(); |
877 |
else |
878 |
m_activeView->closeView(); |
879 |
} |
880 |
|
881 |
void KopeteChatWindow::slotPrepareDetachMenu(void) |
882 |
{ |
883 |
QPopupMenu *detachMenu = actionDetachMenu->popupMenu(); |
884 |
detachMenu->clear(); |
885 |
|
886 |
for ( unsigned id=0; id < windows.count(); id++ ) |
887 |
{ |
888 |
KopeteChatWindow *win = windows.at( id ); |
889 |
if( win != this ) |
890 |
detachMenu->insertItem( win->caption(), id ); |
891 |
} |
892 |
} |
893 |
|
894 |
void KopeteChatWindow::slotSendMessage() |
895 |
{ |
896 |
if ( m_activeView && m_activeView->canSend() ) |
897 |
{ |
898 |
if( !animIcon.isNull() ) |
899 |
{ |
900 |
anim->setMovie( animIcon ); |
901 |
animIcon.unpause(); |
902 |
} |
903 |
m_activeView->sendMessage(); |
904 |
} |
905 |
} |
906 |
|
907 |
void KopeteChatWindow::slotPrepareContactMenu(void) |
908 |
{ |
909 |
QPopupMenu *contactsMenu = actionContactMenu->popupMenu(); |
910 |
contactsMenu->clear(); |
911 |
|
912 |
Kopete::Contact *contact; |
913 |
Kopete::ContactPtrList m_them; |
914 |
|
915 |
if( m_popupView ) |
916 |
m_them = m_popupView->msgManager()->members(); |
917 |
else |
918 |
m_them = m_activeView->msgManager()->members(); |
919 |
|
920 |
//TODO: don't display a menu with one contact in it, display that |
921 |
// contact's menu instead. Will require changing text and icon of |
922 |
// 'Contacts' action, or something cleverer. |
923 |
uint contactCount = 0; |
924 |
|
925 |
for ( contact = m_them.first(); contact; contact = m_them.next() ) |
926 |
{ |
927 |
KPopupMenu *p = contact->popupMenu(); |
928 |
connect ( actionContactMenu->popupMenu(), SIGNAL(aboutToHide()), |
929 |
p, SLOT(deleteLater() ) ); |
930 |
|
931 |
if( contact->metaContact() ) |
932 |
contactsMenu->insertItem( contact->onlineStatus().iconFor( contact ) , contact->metaContact()->displayName(), p ); |
933 |
else |
934 |
contactsMenu->insertItem( contact->onlineStatus().iconFor( contact ) , contact->contactId(), p ); |
935 |
|
936 |
//FIXME: This number should be a config option |
937 |
if( ++contactCount == 15 && contact != m_them.getLast() ) |
938 |
{ |
939 |
KActionMenu *moreMenu = new KActionMenu( i18n("More..."), |
940 |
QString::fromLatin1("folder_open"), contactsMenu ); |
941 |
connect ( actionContactMenu->popupMenu(), SIGNAL(aboutToHide()), |
942 |
moreMenu, SLOT(deleteLater() ) ); |
943 |
moreMenu->plug( contactsMenu ); |
944 |
contactsMenu = moreMenu->popupMenu(); |
945 |
contactCount = 0; |
946 |
} |
947 |
} |
948 |
} |
949 |
|
950 |
void KopeteChatWindow::slotPreparePlacementMenu() |
951 |
{ |
952 |
QPopupMenu *placementMenu = actionTabPlacementMenu->popupMenu(); |
953 |
placementMenu->clear(); |
954 |
|
955 |
placementMenu->insertItem( i18n("Top"), 0 ); |
956 |
placementMenu->insertItem( i18n("Bottom"), 1 ); |
957 |
} |
958 |
|
959 |
void KopeteChatWindow::slotPlaceTabs( int placement ) |
960 |
{ |
961 |
if( m_tabBar ) |
962 |
{ |
963 |
|
964 |
if( placement == 0 ) |
965 |
m_tabBar->setTabPosition( QTabWidget::Top ); |
966 |
else |
967 |
m_tabBar->setTabPosition( QTabWidget::Bottom ); |
968 |
|
969 |
saveOptions(); |
970 |
} |
971 |
} |
972 |
|
973 |
void KopeteChatWindow::readOptions() |
974 |
{ |
975 |
// load and apply config file settings affecting the appearance of the UI |
976 |
// kdDebug(14010) << k_funcinfo << endl; |
977 |
KConfig *config = KGlobal::config(); |
978 |
applyMainWindowSettings( config, QString::fromLatin1( "KopeteChatWindow" ) ); |
979 |
config->setGroup( QString::fromLatin1("ChatWindowSettings") ); |
980 |
} |
981 |
|
982 |
void KopeteChatWindow::saveOptions() |
983 |
{ |
984 |
// kdDebug(14010) << k_funcinfo << endl; |
985 |
|
986 |
KConfig *config = KGlobal::config(); |
987 |
|
988 |
// saves menubar,toolbar and statusbar setting |
989 |
saveMainWindowSettings( config, QString::fromLatin1( "KopeteChatWindow" ) ); |
990 |
config->setGroup( QString::fromLatin1("ChatWindowSettings") ); |
991 |
if( m_tabBar ) |
992 |
config->writeEntry ( QString::fromLatin1("Tab Placement"), m_tabBar->tabPosition() ); |
993 |
|
994 |
config->sync(); |
995 |
} |
996 |
|
997 |
void KopeteChatWindow::slotChatSave() |
998 |
{ |
999 |
// kdDebug(14010) << "KopeteChatWindow::slotChatSave()" << endl; |
1000 |
if( isActiveWindow() && m_activeView ) |
1001 |
m_activeView->messagePart()->save(); |
1002 |
} |
1003 |
|
1004 |
void KopeteChatWindow::windowActivationChange( bool ) |
1005 |
{ |
1006 |
if( isActiveWindow() && m_activeView ) |
1007 |
m_activeView->setActive( true ); |
1008 |
} |
1009 |
|
1010 |
void KopeteChatWindow::slotChatPrint() |
1011 |
{ |
1012 |
m_activeView->messagePart()->print(); |
1013 |
} |
1014 |
|
1015 |
void KopeteChatWindow::slotToggleStatusBar() |
1016 |
{ |
1017 |
if (statusBar()->isVisible()) |
1018 |
statusBar()->hide(); |
1019 |
else |
1020 |
statusBar()->show(); |
1021 |
} |
1022 |
|
1023 |
void KopeteChatWindow::slotViewMenuBar() |
1024 |
{ |
1025 |
if( !menuBar()->isHidden() ) |
1026 |
menuBar()->hide(); |
1027 |
else |
1028 |
menuBar()->show(); |
1029 |
} |
1030 |
|
1031 |
void KopeteChatWindow::slotSmileyActivated(const QString &sm) |
1032 |
{ |
1033 |
if ( !sm.isNull() ) |
1034 |
m_activeView->addText( sm ); |
1035 |
} |
1036 |
|
1037 |
bool KopeteChatWindow::queryClose() |
1038 |
{ |
1039 |
bool canClose = true; |
1040 |
|
1041 |
// kdDebug( 14010 ) << " Windows left open:" << endl; |
1042 |
// for( QPtrListIterator<ChatView> it( chatViewList ); it; ++it) |
1043 |
// kdDebug( 14010 ) << " " << *it << " (" << (*it)->caption() << ")" << endl; |
1044 |
|
1045 |
for( QPtrListIterator<ChatView> it( chatViewList ); it; ) |
1046 |
{ |
1047 |
ChatView *view = *it; |
1048 |
// move out of the way before view is removed |
1049 |
++it; |
1050 |
|
1051 |
// FIXME: This should only check if it *can* close |
1052 |
// and not start closing if the close can be aborted halfway, it would |
1053 |
// leave us with half the chats open and half of them closed. - Martijn |
1054 |
|
1055 |
// if the view is closed, it is removed from chatViewList for us |
1056 |
if ( !view->closeView() ) |
1057 |
{ |
1058 |
kdDebug() << k_funcinfo << "Closing view failed!" << endl; |
1059 |
canClose = false; |
1060 |
} |
1061 |
} |
1062 |
return canClose; |
1063 |
} |
1064 |
|
1065 |
bool KopeteChatWindow::queryExit() |
1066 |
{ |
1067 |
KopeteApplication *app = static_cast<KopeteApplication *>( kapp ); |
1068 |
if ( app->sessionSaving() |
1069 |
|| app->isShuttingDown() /* only set if KopeteApplication::quitKopete() or |
1070 |
KopeteApplication::commitData() called */ |
1071 |
|| !KopetePrefs::prefs()->showTray() /* also close if our tray icon is hidden! */ |
1072 |
|| !isShown() ) |
1073 |
{ |
1074 |
Kopete::PluginManager::self()->shutdown(); |
1075 |
return true; |
1076 |
} |
1077 |
else |
1078 |
return false; |
1079 |
} |
1080 |
|
1081 |
void KopeteChatWindow::closeEvent( QCloseEvent * e ) |
1082 |
{ |
1083 |
// if there's a system tray applet and we are not shutting down then just do what needs to be done if a |
1084 |
// window is closed. |
1085 |
KopeteApplication *app = static_cast<KopeteApplication *>( kapp ); |
1086 |
if ( KopetePrefs::prefs()->showTray() && !app->isShuttingDown() && !app->sessionSaving() ) { |
1087 |
// BEGIN of code borrowed from KMainWindow::closeEvent |
1088 |
// Save settings if auto-save is enabled, and settings have changed |
1089 |
if ( settingsDirty() && autoSaveSettings() ) |
1090 |
saveAutoSaveSettings(); |
1091 |
|
1092 |
if ( queryClose() ) { |
1093 |
e->accept(); |
1094 |
} |
1095 |
// END of code borrowed from KMainWindow::closeEvent |
1096 |
} |
1097 |
else |
1098 |
KMainWindow::closeEvent( e ); |
1099 |
} |
1100 |
|
1101 |
void KopeteChatWindow::slotConfKeys() |
1102 |
{ |
1103 |
KKeyDialog dlg( false, this ); |
1104 |
dlg.insert( actionCollection() ); |
1105 |
if( m_activeView ) |
1106 |
{ |
1107 |
dlg.insert(m_activeView->msgManager()->actionCollection() , i18n("Plugin Actions") ); |
1108 |
QPtrListIterator<KXMLGUIClient> it( *m_activeView->msgManager()->childClients() ); |
1109 |
KXMLGUIClient *c = 0; |
1110 |
while( (c = it.current()) != 0 ) |
1111 |
{ |
1112 |
dlg.insert( c->actionCollection() /*, i18n("Plugin Actions")*/ ); |
1113 |
++it; |
1114 |
} |
1115 |
|
1116 |
if( m_activeView->part() ) |
1117 |
dlg.insert( m_activeView->part()->actionCollection(), m_activeView->part()->name() ); |
1118 |
} |
1119 |
|
1120 |
dlg.configure(); |
1121 |
} |
1122 |
|
1123 |
void KopeteChatWindow::slotConfToolbar() |
1124 |
{ |
1125 |
saveMainWindowSettings(KGlobal::config(), QString::fromLatin1( "KopeteChatWindow" )); |
1126 |
KEditToolbar *dlg = new KEditToolbar(factory(), this ); |
1127 |
if (dlg->exec()) |
1128 |
{ |
1129 |
if( m_activeView ) |
1130 |
{ |
1131 |
createGUI( m_activeView->part() ); |
1132 |
//guiFactory()->addClient(m_activeView->msgManager()); |
1133 |
} |
1134 |
else |
1135 |
createGUI( 0L ); |
1136 |
applyMainWindowSettings(KGlobal::config(), QString::fromLatin1( "KopeteChatWindow" )); |
1137 |
} |
1138 |
delete dlg; |
1139 |
} |
1140 |
|
1141 |
#include "kopetechatwindow.moc" |
1142 |
|
1143 |
// vim: set noet ts=4 sts=4 sw=4: |
1144 |
|