30 #include <QCloseEvent>
31 #include <QMouseEvent>
36 #include <QSignalMapper>
42 #include <kactionmenu.h>
43 #include <kactioncollection.h>
44 #include <ktoggleaction.h>
47 #include <kglobalaccel.h>
50 #include <kiconloader.h>
51 #include <kmessagebox.h>
52 #include <knotifyconfigwidget.h>
54 #include <kshortcutsdialog.h>
55 #include <kedittoolbar.h>
57 #include <kstatusbar.h>
58 #include <kwindowsystem.h>
59 #include <kdeversion.h>
60 #include <kinputdialog.h>
61 #include <kplugininfo.h>
62 #include <ksqueezedtextlabel.h>
63 #include <kstringhandler.h>
65 #include <kxmlguifactory.h>
68 #include <kstandardaction.h>
69 #include <solid/networking.h>
70 #include <kstatusbarofflineindicator.h>
71 #include <kfilterproxysearchline.h>
73 #include "addcontactpage.h"
74 #include "addressbooklinkwidget.h"
75 #include "ui_groupkabcselectorwidget.h"
77 #include "kopeteappearancesettings.h"
79 #include "kopeteaccount.h"
80 #include "kopeteaccountmanager.h"
83 #include "kopetebehaviorsettings.h"
84 #include "kopetecontact.h"
85 #include "kopetecontactlist.h"
86 #include "kopetegroup.h"
87 #include "kopeteidentity.h"
88 #include "kopeteidentitymanager.h"
89 #include "kopetelistviewsearchline.h"
90 #include "kopetechatsessionmanager.h"
91 #include "kopetepluginmanager.h"
92 #include "kopeteprotocol.h"
93 #include "kopetestdaction.h"
94 #include "kopeteuiglobal.h"
96 #include "kopeteonlinestatusmanager.h"
98 #include "kopetestatusmanager.h"
101 #include "kopeteemoticons.h"
102 #include "kopeteinfoeventmanager.h"
108 #include "kopetemetacontact.h"
110 #include "kopetestatusitems.h"
119 setPixmap ( SmallIcon (
"im-status-message-edit" ) );
120 setToolTip ( i18n (
"Global status message" ) );
125 if ( event->
button() == Qt::LeftButton ||
event->button() == Qt::RightButton )
142 connect( Kopete::InfoEventManager::self(), SIGNAL(changed()),
this, SLOT(updateIcon()) );
147 if ( event->
button() == Qt::LeftButton ||
event->button() == Qt::RightButton )
154 void InfoEventIconLabel::updateIcon()
156 if ( Kopete::InfoEventManager::self()->eventCount() > 0 )
165 class KopeteWindow::Private
169 : contactlist ( 0 ), model(0), proxyModel(0), identitywidget ( 0 ), infoEventWidget ( 0 ), actionAddContact ( 0 ), actionDisconnect ( 0 ),
170 actionExportContacts ( 0 ), actionStatusMenu ( 0 ), actionDockMenu ( 0 ), actionSetAway ( 0 ),
171 actionSetBusy ( 0 ), actionSetAvailable ( 0 ), actionSetInvisible ( 0 ), actionPrefs ( 0 ),
172 actionQuit ( 0 ), actionSave ( 0 ), menubarAction ( 0 ), statusbarAction ( 0 ),
173 actionShowOfflineUsers ( 0 ), actionShowEmptyGroups ( 0 ), docked ( 0 ), deskRight ( 0 ),
174 statusBarWidget ( 0 ), tray ( 0 ), hidden ( false ), autoHide ( false ),
175 autoHideTimeout ( 0 ), autoHideTimer ( 0 ), addContactMapper ( 0 ),
176 showIdentityIcons( Kopete::AppearanceSettings::self()->showIdentityIcons() ),
177 globalStatusMessage ( 0 )
207 KToggleAction *menubarAction;
208 KToggleAction *statusbarAction;
209 KToggleAction *actionShowAllOfflineEmpty;
210 KToggleAction *actionShowOfflineUsers;
211 KToggleAction *actionShowEmptyGroups;
216 KHBox *statusBarWidget;
221 unsigned int autoHideTimeout;
226 bool showIdentityIcons;
229 KSqueezedTextLabel *globalStatusMessage;
259 d->appDestroyed =
false;
260 connect ( kapp, SIGNAL (destroyed()),
this, SLOT (slotAppDestroyed()) );
261 setAttribute ( Qt::WA_DeleteOnClose,
false );
262 setAttribute ( Qt::WA_QuitOnClose,
false );
268 d->statusBarWidget =
new KHBox ( statusBar() );
269 d->statusBarWidget->setMargin ( 2 );
270 d->statusBarWidget->setSpacing ( 1 );
271 window()->setAttribute( Qt::WA_AlwaysShowToolTips );
272 statusBar()->addPermanentWidget ( d->statusBarWidget, 0 );
277 KStatusBarOfflineIndicator * indicator =
new KStatusBarOfflineIndicator (
this );
278 statusBar()->addPermanentWidget ( indicator, 0 );
281 connect ( label, SIGNAL (iconClicked(
QPoint)),
282 this, SLOT (slotGlobalStatusMessageIconClicked(
QPoint)) );
283 statusBarMessageLayout->
addWidget ( label );
287 connect ( infoLabel, SIGNAL(clicked()),
this, SLOT(slotInfoIconClicked()) );
288 statusBarMessageLayout->
addWidget ( infoLabel );
290 connect( Kopete::InfoEventManager::self(), SIGNAL(eventAdded(Kopete::InfoEvent*)),
this, SLOT(slotNewInfoEvent()) );
292 d->globalStatusMessage =
new KSqueezedTextLabel ( statusBarMessage );
293 connect ( Kopete::StatusManager::self(), SIGNAL (globalStatusChanged()),
294 this, SLOT (globalStatusChanged()) );
295 statusBarMessageLayout->
addWidget ( d->globalStatusMessage );
296 statusBar()->addWidget ( statusBarMessage, 1 );
298 d->autoHideTimer =
new QTimer (
this );
299 d->autoResizeTimer =
new QTimer (
this );
300 d->autoResizeTimer->setSingleShot (
true );
305 d->contactlist->initActions ( actionCollection() );
310 connect ( Kopete::PluginManager::self(), SIGNAL (pluginLoaded(Kopete::Plugin*)),
311 this, SLOT (slotPluginLoaded(Kopete::Plugin*)) );
312 connect ( Kopete::PluginManager::self(), SIGNAL (allPluginsLoaded()),
313 this, SLOT (slotAllPluginsLoaded()) );
316 connect ( Kopete::IdentityManager::self(), SIGNAL (identityRegistered(Kopete::Identity*)),
317 this, SLOT (slotIdentityRegistered(Kopete::Identity*)) );
318 connect ( Kopete::IdentityManager::self(), SIGNAL (identityUnregistered(
const Kopete::Identity*)),
319 this, SLOT (slotIdentityUnregistered(
const Kopete::Identity*)) );
321 connect ( d->autoHideTimer, SIGNAL (timeout()),
this, SLOT (slotAutoHide()) );
322 connect ( d->contactlist, SIGNAL(visibleContentHeightChanged()),
this, SLOT (slotStartAutoResizeTimer()) );
323 connect ( d->autoResizeTimer, SIGNAL (timeout()),
this, SLOT (slotUpdateSize()) );
324 connect ( Kopete::AppearanceSettings::self(), SIGNAL (contactListAppearanceChanged()),
325 this, SLOT (slotContactListAppearanceChanged()) );
332 Kopete::PluginList plugins = Kopete::PluginManager::self()->loadedPlugins();
333 foreach ( Kopete::Plugin *plug, plugins )
334 slotPluginLoaded ( plug );
337 Kopete::Identity::List identityList = Kopete::IdentityManager::self()->identities();
338 foreach ( Kopete::Identity *i, identityList )
339 slotIdentityRegistered ( i );
343 toolBar (
"quickSearchBar" )->installEventFilter (
this );
346 void KopeteWindow::slotAppDestroyed()
348 d->appDestroyed =
true;
351 void KopeteWindow::initView()
357 if ( Kopete::AppearanceSettings::self()->groupContactByGroup() )
364 d->proxyModel->setSourceModel( d->model );
365 d->contactlist->setModel( d->proxyModel );
370 d->identitywidget->setSizePolicy (
QSizePolicy ( QSizePolicy::Preferred, QSizePolicy::Minimum ) );
371 d->identitywidget->setVisible (
false );
374 d->infoEventWidget->setSizePolicy (
QSizePolicy ( QSizePolicy::Preferred, QSizePolicy::Minimum ) );
375 d->infoEventWidget->setVisible (
false );
376 connect ( d->infoEventWidget, SIGNAL(showRequest()),
this, SLOT(slotShowInfoEventWidget()) );
379 setCentralWidget ( w );
380 d->contactlist->setFocus();
383 void KopeteWindow::initActions()
386 d->actionAddContact =
new KActionMenu ( KIcon (
"list-add-user" ), i18n (
"&Add Contact" ),
this );
387 d->actionAddContact->setIconText ( i18n (
"Add" ) );
388 actionCollection()->addAction (
"AddContact", d->actionAddContact );
389 d->actionAddContact->setDelayed (
false );
393 this, SLOT (slotAddContactDialogInternal(
QString)) );
395 d->actionDisconnect =
new KAction ( KIcon (
"user-offline" ), i18n (
"Offline" ),
this );
396 actionCollection()->addAction (
"DisconnectAll", d->actionDisconnect );
397 connect ( d->actionDisconnect, SIGNAL (triggered(
bool)),
this, SLOT (slotDisconnectAll()) );
398 d->actionDisconnect->setEnabled (
false );
400 d->actionExportContacts =
new KAction ( i18n (
"&Export Contacts..." ),
this );
401 d->actionExportContacts->setIcon ( KIcon (
"document-export" ) );
402 actionCollection()->addAction (
"ExportContacts", d->actionExportContacts );
403 connect ( d->actionExportContacts, SIGNAL (triggered(
bool)),
this, SLOT (showExportDialog()) );
405 d->actionSetAway =
new KAction ( KIcon (
"user-identity", 0,
QStringList() <<
QString() <<
"user-away" ), i18n (
"&Away" ),
this );
406 actionCollection()->addAction (
"SetAwayAll", d->actionSetAway );
407 connect ( d->actionSetAway, SIGNAL (triggered(
bool)),
this, SLOT (slotGlobalAway()) );
409 d->actionSetBusy =
new KAction ( KIcon (
"user-identity", 0,
QStringList() <<
QString() <<
"user-busy" ), i18n (
"&Busy" ),
this );
410 actionCollection()->addAction (
"SetBusyAll", d->actionSetBusy );
411 connect ( d->actionSetBusy, SIGNAL (triggered(
bool)),
this, SLOT (slotGlobalBusy()) );
414 d->actionSetInvisible =
new KAction ( KIcon (
"user-identity", 0,
QStringList() <<
QString() <<
"user-invisible" ), i18n (
"&Invisible" ),
this );
415 actionCollection()->addAction (
"SetInvisibleAll", d->actionSetInvisible );
416 connect ( d->actionSetInvisible, SIGNAL (triggered(
bool)),
this, SLOT (slotSetInvisibleAll()) );
418 d->actionSetAvailable =
new KAction ( KIcon (
"user-identity", 0,
QStringList() <<
QString() <<
"user-online" ), i18n (
"&Online" ),
this );
419 actionCollection()->addAction (
"SetAvailableAll", d->actionSetAvailable );
420 connect ( d->actionSetAvailable, SIGNAL (triggered(
bool)),
this, SLOT (slotGlobalAvailable()) );
422 d->actionStatusMenu =
new KActionMenu ( KIcon (
"user-identity", 0,
QStringList() <<
QString() <<
"user-online" ), i18n (
"&Set Status" ),
this );
423 d->actionStatusMenu->setIconText ( i18n (
"Status" ) );
424 actionCollection()->addAction (
"Status", d->actionStatusMenu );
425 d->actionStatusMenu->setDelayed (
false );
430 connect ( statusAction, SIGNAL (changeStatus(uint,Kopete::StatusMessage)),
431 this, SLOT (setOnlineStatus(uint,Kopete::StatusMessage)) );
434 connect ( statusAction, SIGNAL (changeMessage(Kopete::StatusMessage)),
435 this, SLOT (setStatusMessage(Kopete::StatusMessage)) );
437 d->actionPrefs = KopeteStdAction::preferences ( actionCollection(),
"settings_prefs" );
439 KStandardAction::quit (
this, SLOT (slotQuit()), actionCollection() );
441 setStandardToolBarMenuEnabled (
true );
442 d->menubarAction = KStandardAction::showMenubar ( menuBar(), SLOT (setVisible(
bool)), actionCollection() );
443 actionCollection()->addAction (
"settings_showmenubar", d->menubarAction );
444 d->statusbarAction = KStandardAction::showStatusbar ( statusBar(), SLOT (setVisible(
bool)), actionCollection() );
445 actionCollection()->addAction (
"settings_showstatusbar", d->statusbarAction );
447 KAction* act = KStandardAction::keyBindings ( guiFactory(), SLOT (configureShortcuts()), actionCollection() );
448 actionCollection()->addAction (
"settings_keys", act );
450 KAction *configureGlobalShortcutsAction =
new KAction ( KIcon (
"configure-shortcuts" ), i18n (
"Configure &Global Shortcuts..." ),
this );
451 configureGlobalShortcutsAction->setMenuRole( QAction::NoRole );
452 actionCollection()->addAction (
"settings_global", configureGlobalShortcutsAction );
453 connect ( configureGlobalShortcutsAction, SIGNAL (triggered(
bool)),
this, SLOT (slotConfGlobalKeys()) );
455 KStandardAction::configureToolbars (
this, SLOT (slotConfToolbar()), actionCollection() );
456 act = KStandardAction::configureNotifications (
this, SLOT (slotConfNotifications()), actionCollection() );
457 actionCollection()->addAction (
"settings_notifications", act );
459 d->actionShowAllOfflineEmpty =
new KToggleAction ( KIcon (
"view-user-offline-kopete" ), i18n (
"Show &All" ),
this );
460 actionCollection()->addAction (
"settings_show_all_offline_empty", d->actionShowAllOfflineEmpty );
461 d->actionShowAllOfflineEmpty->setShortcut ( KShortcut ( Qt::CTRL + Qt::Key_U ) );
462 connect ( d->actionShowAllOfflineEmpty, SIGNAL (triggered(
bool)),
this, SLOT (slotToggleShowAllOfflineEmpty(
bool)) );
464 d->actionShowOfflineUsers =
new KToggleAction ( KIcon (
"view-user-offline-kopete" ), i18n (
"Show Offline &Users" ),
this );
465 actionCollection()->addAction (
"settings_show_offliners", d->actionShowOfflineUsers );
466 connect ( d->actionShowOfflineUsers, SIGNAL (triggered(
bool)),
this, SLOT (slotToggleShowOfflineUsers()) );
468 d->actionShowEmptyGroups =
new KToggleAction ( KIcon (
"folder-grey" ), i18n (
"Show Empty &Groups" ),
this );
469 actionCollection()->addAction (
"settings_show_empty_groups", d->actionShowEmptyGroups );
470 d->actionShowEmptyGroups->setShortcut ( KShortcut ( Qt::CTRL + Qt::Key_G ) );
471 connect ( d->actionShowEmptyGroups, SIGNAL (triggered(
bool)),
this, SLOT (slotToggleShowEmptyGroups()) );
479 KFilterProxySearchLine* searchLine =
new KFilterProxySearchLine (
this );
480 searchLine->setProxy( d->proxyModel );
481 KAction *quickSearch =
new KAction ( i18n (
"Quick Search Bar" ),
this );
482 actionCollection()->addAction (
"quicksearch_bar", quickSearch );
483 quickSearch->setDefaultWidget ( searchLine );
486 connect ( Kopete::AppearanceSettings::self(), SIGNAL (configChanged()),
this, SLOT (slotConfigChanged()) );
490 KAction *globalReadMessage =
new KAction ( i18n (
"Read Message" ),
this );
491 actionCollection()->addAction (
"ReadMessage", globalReadMessage );
492 connect ( globalReadMessage, SIGNAL (triggered(
bool)), Kopete::ChatSessionManager::self(), SLOT (slotReadMessage()) );
493 globalReadMessage->setGlobalShortcut ( KShortcut ( Qt::CTRL + Qt::SHIFT + Qt::Key_I ) );
494 globalReadMessage->setWhatsThis ( i18n (
"Read the next pending message" ) );
496 KAction *globalShowContactList =
new KAction ( i18n (
"Show/Hide Contact List" ),
this );
497 actionCollection()->addAction (
"ShowContactList", globalShowContactList );
498 connect ( globalShowContactList, SIGNAL (triggered(
bool)),
this, SLOT (slotShowHide()) );
499 globalShowContactList->setGlobalShortcut ( KShortcut ( Qt::CTRL + Qt::ALT + Qt::Key_T ) );
500 globalShowContactList->setWhatsThis ( i18n (
"Show or hide the contact list" ) );
502 KAction *globalSetAway =
new KAction ( i18n (
"Set Away/Back" ),
this );
503 actionCollection()->addAction (
"Set_Away_Back", globalSetAway );
504 connect ( globalSetAway, SIGNAL (triggered(
bool)),
this, SLOT (slotToggleAway()) );
505 globalSetAway->setGlobalShortcut ( KShortcut ( Qt::CTRL + Qt::SHIFT + Qt::Key_W ) );
508 void KopeteWindow::slotShowHide()
510 if ( isActiveWindow() )
512 d->autoHideTimer->stop();
519 if ( !KWindowSystem::windowInfo ( winId(),NET::WMDesktop ).onAllDesktops() )
520 KWindowSystem::setOnDesktop ( winId(), KWindowSystem::currentDesktop() );
523 KWindowSystem::forceActiveWindow( winId() );
527 void KopeteWindow::slotToggleAway()
530 Kopete::StatusManager * statusManager = Kopete::StatusManager::self();
531 const Kopete::Status::StatusItem * item = 0;
532 bool away = Kopete::StatusManager::self()->globalAway();
534 foreach (
const Kopete::Status::StatusItem *i, statusManager->getRootGroup()->childList()) {
544 const Kopete::Status::Status * status = qobject_cast<
const Kopete::Status::Status*>(item);
546 statusManager->setGlobalStatusMessage(Kopete::StatusMessage(status->title(), status->message()));
550 slotGlobalAvailable();
555 void KopeteWindow::initSystray()
557 if ( Kopete::BehaviorSettings::self()->showSystemTray() ) {
561 this, SLOT (slotTrayAboutToShowMenu(KMenu*)) );
574 KToolBar *toolBar =
dynamic_cast<KToolBar*
> ( target );
575 QAction *resetAction = actionCollection()->action (
"quicksearch_reset" );
580 if ( event->
type() == QEvent::Hide )
585 return KXmlGuiWindow::eventFilter ( target, event );
588 return KXmlGuiWindow::eventFilter ( target, event );
591 void KopeteWindow::loadOptions()
593 KSharedConfig::Ptr config = KGlobal::config();
595 toolBar (
"mainToolBar" )->applySettings ( config->group (
"ToolBar Settings" ) );
596 toolBar (
"quickSearchBar" )->applySettings ( config->group (
"QuickSearchBar Settings" ) );
598 applyMainWindowSettings ( config->group (
"General Options" ) );
599 KConfigGroup cg ( config,
"General Options" );
600 QPoint pos = cg.readEntry (
"Position",
QPoint(-1, -1) );
601 if ( pos.
x() != -1 || pos.
y() != -1 )
604 QSize size = cg.readEntry (
"Geometry",
QSize() );
606 resize (
QSize ( 272, 400 ) );
610 d->autoHide = Kopete::AppearanceSettings::self()->contactListAutoHide();
611 d->autoHideTimeout = Kopete::AppearanceSettings::self()->contactListAutoHideTimeout();
614 QString tmp = cg.readEntry (
"WindowState",
"Shown" );
615 if ( tmp ==
"Minimized" && Kopete::BehaviorSettings::self()->showSystemTray() )
619 else if ( tmp ==
"Hidden" && Kopete::BehaviorSettings::self()->showSystemTray() )
623 else if ( !Kopete::BehaviorSettings::self()->startDocked() || !Kopete::BehaviorSettings::self()->showSystemTray() )
626 d->menubarAction->setChecked ( !menuBar()->isHidden() );
627 d->statusbarAction->setChecked ( !statusBar()->isHidden() );
630 void KopeteWindow::saveOptions()
632 KConfigGroup mainToolbarGroup ( KGlobal::config(),
"ToolBar Settings" );
633 toolBar (
"mainToolBar" )->saveSettings ( mainToolbarGroup );
634 KConfigGroup qsbGroup ( KGlobal::config(),
"QuickSearchBar Settings" );
635 toolBar (
"quickSearchBar" )->saveSettings ( qsbGroup );
637 KConfigGroup cg ( KGlobal::config(),
"General Options" );
638 saveMainWindowSettings ( cg );
640 cg.writeEntry (
"Position", pos() );
641 cg.writeEntry (
"Geometry", size() );
645 cg.writeEntry (
"WindowState",
"Minimized" );
647 else if ( isHidden() )
649 cg.writeEntry (
"WindowState",
"Hidden" );
653 cg.writeEntry (
"WindowState",
"Shown" );
656 Kopete::Identity *identity = d->identitywidget->identity();
658 cg.writeEntry (
"ShownIdentityId", identity->id() );
660 cg.writeEntry (
"ShownIdentityId",
QString() );
665 void KopeteWindow::slotToggleShowAllOfflineEmpty (
bool toggled )
667 d->actionShowOfflineUsers->setChecked ( toggled );
668 d->actionShowEmptyGroups->setChecked ( toggled );
669 Kopete::AppearanceSettings::self()->setShowOfflineUsers ( toggled );
670 Kopete::AppearanceSettings::self()->setShowEmptyGroups ( toggled );
671 Kopete::AppearanceSettings::self()->writeConfig();
674 void KopeteWindow::slotToggleShowOfflineUsers()
676 Kopete::AppearanceSettings::self()->setShowOfflineUsers ( d->actionShowOfflineUsers->isChecked() );
677 Kopete::AppearanceSettings::self()->writeConfig();
680 void KopeteWindow::slotToggleShowEmptyGroups()
682 Kopete::AppearanceSettings::self()->setShowEmptyGroups ( d->actionShowEmptyGroups->isChecked() );
683 Kopete::AppearanceSettings::self()->writeConfig();
689 void KopeteWindow::slotConfigChanged()
692 if ( groupContactByGroupModel != Kopete::AppearanceSettings::self()->groupContactByGroup() )
695 if ( Kopete::AppearanceSettings::self()->groupContactByGroup() )
701 d->proxyModel->setSourceModel( d->model );
705 if ( isHidden() && !Kopete::BehaviorSettings::self()->showSystemTray() )
708 d->actionShowAllOfflineEmpty->setChecked ( Kopete::AppearanceSettings::self()->showOfflineUsers() && Kopete::AppearanceSettings::self()->showEmptyGroups() );
709 d->actionShowOfflineUsers->setChecked ( Kopete::AppearanceSettings::self()->showOfflineUsers() );
710 d->actionShowEmptyGroups->setChecked ( Kopete::AppearanceSettings::self()->showEmptyGroups() );
712 if ( d->showIdentityIcons != Kopete::AppearanceSettings::self()->showIdentityIcons() )
715 if ( d->showIdentityIcons )
717 if ( d->identitywidget->isVisible() )
719 d->identitywidget->setIdentity( 0 );
720 d->identitywidget->setVisible(
false );
723 qDeleteAll( d->identityStatusBarIcons );
724 d->identityStatusBarIcons.clear();
728 qDeleteAll( d->accountStatusBarIcons );
729 d->accountStatusBarIcons.clear();
733 d->showIdentityIcons = Kopete::AppearanceSettings::self()->showIdentityIcons();
734 if ( d->showIdentityIcons )
736 Kopete::Identity::List identityList = Kopete::IdentityManager::self()->identities();
737 foreach ( Kopete::Identity *identity, identityList )
740 connect ( sbIcon, SIGNAL(leftClicked(Kopete::Identity*,
QPoint)),
this,
741 SLOT(slotIdentityStatusIconLeftClicked(Kopete::Identity*,
QPoint)) );
743 d->identityStatusBarIcons.insert ( identity, sbIcon );
744 slotIdentityStatusIconChanged ( identity );
745 slotIdentityToolTipChanged ( identity );
752 foreach ( Kopete::Account *account, accountList )
755 d->accountStatusBarIcons.insert ( account, sbIcon );
761 void KopeteWindow::slotContactListAppearanceChanged()
763 d->autoHide = Kopete::AppearanceSettings::self()->contactListAutoHide();
764 d->autoHideTimeout = Kopete::AppearanceSettings::self()->contactListAutoHideTimeout();
766 startAutoHideTimer();
769 void KopeteWindow::slotConfNotifications()
771 KNotifyConfigWidget::configure (
this );
774 void KopeteWindow::slotConfGlobalKeys()
776 KShortcutsDialog::configure ( actionCollection() );
779 void KopeteWindow::slotConfToolbar()
781 KConfigGroup cg ( KGlobal::config(),
"General Options" );
782 saveMainWindowSettings ( cg );
783 KEditToolBar *dlg =
new KEditToolBar ( factory() );
784 connect ( dlg, SIGNAL (newToolBarConfig()),
this, SLOT (slotUpdateToolbar()) );
785 connect ( dlg, SIGNAL (finished()) , dlg, SLOT (deleteLater()) );
789 void KopeteWindow::slotUpdateToolbar()
791 applyMainWindowSettings ( KGlobal::config()->group (
"General Options" ) );
794 void KopeteWindow::slotGlobalAway()
796 Kopete::AccountManager::self()->setOnlineStatus ( Kopete::OnlineStatusManager::Away,
797 Kopete::StatusManager::self()->globalStatusMessage() );
800 void KopeteWindow::slotGlobalBusy()
802 Kopete::AccountManager::self()->setOnlineStatus ( Kopete::OnlineStatusManager::Busy,
803 Kopete::StatusManager::self()->globalStatusMessage() );
806 void KopeteWindow::slotGlobalAvailable()
808 Kopete::AccountManager::self()->setOnlineStatus ( Kopete::OnlineStatusManager::Online,
809 Kopete::StatusManager::self()->globalStatusMessage() );
812 void KopeteWindow::slotSetInvisibleAll()
814 Kopete::AccountManager::self()->setOnlineStatus ( Kopete::OnlineStatusManager::Invisible,
815 Kopete::StatusManager::self()->globalStatusMessage() );
818 void KopeteWindow::slotDisconnectAll()
820 Kopete::AccountManager::self()->setOnlineStatus ( Kopete::OnlineStatusManager::Offline,
821 Kopete::StatusManager::self()->globalStatusMessage() );
824 bool KopeteWindow::queryClose()
832 Kopete::PluginList list = Kopete::PluginManager::self()->loadedPlugins();
833 foreach ( Kopete::Plugin *plugin, list ) {
843 if ( Kopete::BehaviorSettings::self()->showSystemTray()
846 KMessageBox::information (
this,
847 i18n (
"<qt>Closing the main window will keep Kopete running in the "
848 "system tray. Use 'Quit' from the 'File' menu to quit the application.</qt>" ),
849 i18n (
"Docking in System Tray" ),
"hideOnCloseInfo" );
856 bool KopeteWindow::shouldExitOnClose()
const
858 Kopete::PluginList list = Kopete::PluginManager::self()->loadedPlugins();
859 foreach ( Kopete::Plugin *plugin, list ) {
863 kDebug ( 14000 ) <<
"plugin" << plugin->displayName() <<
"does not want to exit";
868 return !Kopete::BehaviorSettings::self()->showSystemTray();
871 bool KopeteWindow::queryExit()
874 if ( app->sessionSaving()
877 || shouldExitOnClose()
881 kDebug ( 14000 ) <<
" shutting down plugin manager";
882 Kopete::PluginList list = Kopete::PluginManager::self()->loadedPlugins();
883 foreach ( Kopete::Plugin *plugin, list ) {
884 guiFactory()->removeClient(plugin);
886 Kopete::PluginManager::self()->shutdown();
898 if ( !shouldExitOnClose() && !app->
isShuttingDown() && !app->sessionSaving() ) {
901 if ( settingsDirty() && autoSaveSettings() )
902 saveAutoSaveSettings();
904 if ( queryClose() ) {
908 kDebug ( 14000 ) <<
"just closing because we have a system tray icon";
912 kDebug ( 14000 ) <<
"delegating to KXmlGuiWindow::closeEvent()";
913 KXmlGuiWindow::closeEvent ( e );
917 void KopeteWindow::slotQuit()
924 d->tray->deleteLater();
929 void KopeteWindow::slotPluginLoaded ( Kopete::Plugin * p )
931 guiFactory()->addClient ( p );
934 void KopeteWindow::slotAllPluginsLoaded()
937 d->actionDisconnect->setEnabled (
true );
939 KConfigGroup cg( KGlobal::config(),
"General Options" );
944 foreach ( Kopete::Account *a, accountList )
945 slotAccountRegistered ( a );
950 connect ( Kopete::AccountManager::self(), SIGNAL (accountRegistered(Kopete::Account*)),
951 this, SLOT (slotAccountRegistered(Kopete::Account*)) );
952 connect ( Kopete::AccountManager::self(), SIGNAL (accountUnregistered(
const Kopete::Account*)),
953 this, SLOT (slotAccountUnregistered(
const Kopete::Account*)) );
955 if ( d->showIdentityIcons )
957 QString identityId = cg.readEntry(
"ShownIdentityId", Kopete::IdentityManager::self()->defaultIdentity()->
id() );
960 Kopete::Identity* identity = Kopete::IdentityManager::self()->findIdentity( identityId );
962 slotIdentityStatusIconLeftClicked( identity,
QPoint() );
967 void KopeteWindow::slotIdentityRegistered ( Kopete::Identity *identity )
972 connect ( identity, SIGNAL(onlineStatusChanged(Kopete::Identity*)),
973 this, SLOT(slotIdentityStatusIconChanged(Kopete::Identity*)) );
974 connect ( identity, SIGNAL(identityChanged(Kopete::Identity*)),
975 this, SLOT(slotIdentityStatusIconChanged(Kopete::Identity*)) );
976 connect ( identity, SIGNAL(toolTipChanged(Kopete::Identity*)),
977 this, SLOT(slotIdentityToolTipChanged(Kopete::Identity*)) );
979 if ( d->showIdentityIcons )
982 connect ( sbIcon, SIGNAL (leftClicked(Kopete::Identity*,
QPoint)),
983 SLOT (slotIdentityStatusIconLeftClicked(Kopete::Identity*,
QPoint)) );
985 d->identityStatusBarIcons.insert ( identity, sbIcon );
988 slotIdentityStatusIconChanged ( identity );
989 slotIdentityToolTipChanged( identity );
992 void KopeteWindow::slotIdentityUnregistered (
const Kopete::Identity *identity )
996 if ( d->showIdentityIcons )
1001 d->identityStatusBarIcons.remove ( identity );
1010 void KopeteWindow::slotIdentityToolTipChanged ( Kopete::Identity *identity )
1012 if ( d->appDestroyed )
1028 void KopeteWindow::slotIdentityStatusIconChanged ( Kopete::Identity *identity )
1030 kDebug ( 14000 ) << identity->property ( Kopete::Global::Properties::self()->statusMessage() ).value();
1042 if ( d->appDestroyed )
1049 if ( identity->onlineStatus() != Kopete::OnlineStatus::Connecting )
1060 switch ( identity->onlineStatus() ) {
1061 case Kopete::OnlineStatus::Offline:
1062 case Kopete::OnlineStatus::Connecting:
1063 pm = SmallIcon (
"user-identity", 0, KIconLoader::DefaultState,
1066 case Kopete::OnlineStatus::Invisible:
1067 pm = SmallIcon (
"user-identity", 0, KIconLoader::DefaultState,
1070 case Kopete::OnlineStatus::Away:
1071 pm = SmallIcon (
"user-identity", 0, KIconLoader::DefaultState,
1074 case Kopete::OnlineStatus::Busy:
1075 pm = SmallIcon (
"user-identity", 0, KIconLoader::DefaultState,
1078 case Kopete::OnlineStatus::Online:
1079 pm = SmallIcon (
"user-identity", 0, KIconLoader::DefaultState,
1082 case Kopete::OnlineStatus::Unknown:
1083 pm = SmallIcon (
"user-identity" );
1089 i->
setPixmap ( SmallIcon (
"user-identity" ) );
1098 if (a->identity() && b->identity()) {
1103 c = a->myself()->onlineStatus().status() - b->myself()->onlineStatus().status();
1118 void KopeteWindow::makeTrayToolTip()
1127 foreach ( Kopete::Account *a, accountList )
1129 Kopete::Contact *
self = a->myself();
1134 tt += i18nc (
"Account tooltip information: <nobr>ICON <b>PROTOCOL:</b> NAME (<i>STATUS</i>)</nobr><br />",
1135 "<nobr><img src=\"%3\" width=\"16\" height=\"16\" /> <b>%1:</b> %2 (<i>%4</i>)</nobr><br />",
1136 a->protocol()->displayName(), a->accountLabel(),
1137 a->accountIconPath(KIconLoader::Small),
self->onlineStatus().description() );
1140 d->tray->setToolTip (
"kopete", i18n(
"Kopete"), tt );
1144 void KopeteWindow::slotIdentityStatusIconLeftClicked ( Kopete::Identity *identity,
const QPoint &p )
1147 if ( d->identitywidget->isVisible() && d->identitywidget->identity() == identity )
1149 d->identitywidget->setIdentity ( 0 );
1150 d->identitywidget->setVisible (
false );
1154 if ( d->infoEventWidget->isVisible() )
1155 d->infoEventWidget->setVisible (
false );
1157 d->identitywidget->setIdentity ( identity );
1158 d->identitywidget->setVisible (
true );
1161 void KopeteWindow::slotShowInfoEventWidget()
1163 if ( d->identitywidget->isVisible() )
1165 d->identitywidget->setIdentity( 0 );
1166 d->identitywidget->setVisible(
false );
1169 if ( !d->infoEventWidget->isVisible() )
1170 d->infoEventWidget->setVisible(
true );
1172 if ( !isActiveWindow() )
1176 void KopeteWindow::slotInfoIconClicked()
1178 if ( d->infoEventWidget->isVisible() )
1180 d->infoEventWidget->setVisible(
false );
1184 if ( d->identitywidget->isVisible() )
1186 d->identitywidget->setIdentity( 0 );
1187 d->identitywidget->setVisible(
false );
1189 d->infoEventWidget->setVisible(
true );
1193 void KopeteWindow::slotAccountRegistered ( Kopete::Account *account )
1198 d->actionDisconnect->setEnabled (
true );
1202 KAction *action =
new KAction ( KIcon ( account->accountIcon() ), account->accountLabel(), this );
1203 actionCollection()->addAction ( s, action );
1204 connect ( action, SIGNAL (triggered(
bool)), d->addContactMapper, SLOT (
map()) );
1205 connect ( account, SIGNAL(colorChanged(
QColor)),
this, SLOT(slotAccountColorChanged()) );
1207 d->addContactMapper->setMapping ( action, account->protocol()->pluginId() +
QChar ( 0xE000 ) + account->accountId() );
1208 d->actionAddContact->addAction ( action );
1210 if ( !d->showIdentityIcons )
1213 d->accountStatusBarIcons.insert ( account, sbIcon );
1217 void KopeteWindow::slotAccountColorChanged()
1219 Kopete::Account* account = qobject_cast<Kopete::Account*>(sender());
1224 QAction *action = actionCollection()->action ( s );
1226 action->
setIcon( KIcon( account->accountIcon() ) );
1229 void KopeteWindow::slotAccountUnregistered (
const Kopete::Account *account )
1235 d->actionDisconnect->setEnabled (
false );
1238 disconnect ( account, SIGNAL(colorChanged(
QColor)),
this, SLOT(slotAccountColorChanged()) );
1242 QAction *action = actionCollection()->action ( s );
1245 kDebug ( 14000 ) <<
" found KAction " << action <<
" with name: " << action->
objectName();
1246 d->addContactMapper->removeMappings ( action );
1247 d->actionAddContact->removeAction ( action );
1250 if ( !d->showIdentityIcons )
1255 d->accountStatusBarIcons.remove ( account );
1261 void KopeteWindow::slotTrayAboutToShowMenu ( KMenu * popup )
1263 KActionCollection *actionCollection = d->tray->actionCollection();
1266 popup->addTitle ( qApp->windowIcon(), KGlobal::caption() );
1270 foreach ( Kopete::Account *account, accountList )
1273 menu->setIcon( account->myself()->onlineStatus().iconFor( account ) );
1275 if ( !account->hasCustomStatusMenu() )
1278 account->fillActionMenu ( menu );
1279 popup->addAction ( menu );
1281 connect ( popup , SIGNAL (aboutToHide()) , menu , SLOT (deleteLater()) );
1284 popup->addSeparator();
1285 popup->addAction ( d->actionStatusMenu );
1286 popup->addSeparator();
1287 popup->addAction ( d->actionPrefs );
1288 popup->addAction ( d->actionAddContact );
1289 popup->addSeparator();
1290 popup->addAction ( actionCollection->action (
"minimizeRestore" ) );
1291 popup->addAction ( actionCollection->action ( KStandardAction::name ( KStandardAction::Quit ) ) );
1294 void KopeteWindow::showExportDialog()
1297 wizard->setObjectName (
QLatin1String (
"export_contact_dialog" ) );
1303 startAutoHideTimer();
1308 startAutoHideTimer();
1309 slotStartAutoResizeTimer();
1314 d->autoResizeTimer->stop();
1317 void KopeteWindow::slotAutoHide()
1319 if ( this->geometry().contains (
QCursor::pos() ) ==
false )
1323 d->autoHideTimer->stop();
1328 void KopeteWindow::startAutoHideTimer()
1330 if ( d->autoHideTimeout > 0 && d->autoHide ==
true && isVisible() && Kopete::BehaviorSettings::self()->showSystemTray() )
1331 d->autoHideTimer->start ( d->autoHideTimeout * 1000 );
1334 void KopeteWindow::slotStartAutoResizeTimer()
1336 if ( Kopete::AppearanceSettings::contactListAutoResize() ==
true )
1337 if ( ! d->autoResizeTimer->isActive() )
1338 d->autoResizeTimer->start ( 1000 );
1341 void KopeteWindow::setOnlineStatus( uint category,
const Kopete::StatusMessage& statusMessage )
1343 Kopete::AccountManager::self()->setOnlineStatus( category, statusMessage, 0,
true );
1346 void KopeteWindow::setStatusMessage (
const Kopete::StatusMessage& statusMessage )
1348 Kopete::StatusManager::self()->setGlobalStatusMessage ( statusMessage );
1351 void KopeteWindow::globalStatusChanged()
1353 QString statusTitle = Kopete::StatusManager::self()->globalStatusMessage().title();
1354 QString statusMessage = Kopete::StatusManager::self()->globalStatusMessage().message();
1355 d->globalStatusMessage->setText( statusTitle );
1358 toolTip += i18nc(
"@label:textbox formatted status title",
"<b>Status Title:</b> %1",
1359 Kopete::Emoticons::parseEmoticons( Kopete::Message::escape(statusTitle) ) );
1361 toolTip += i18nc(
"@label:textbox formatted status message",
"<br /><b>Status Message:</b> %1",
1362 Kopete::Emoticons::parseEmoticons( Kopete::Message::escape(statusMessage) ) );
1364 d->globalStatusMessage->setToolTip( toolTip );
1367 void KopeteWindow::slotGlobalStatusMessageIconClicked (
const QPoint &position )
1369 KMenu *menu =
new KMenu (
this );
1371 menu->addTitle ( i18n (
"Status Message" ) );
1374 statusEditAction->
setStatusMessage ( Kopete::StatusManager::self()->globalStatusMessage() );
1375 connect ( statusEditAction, SIGNAL (statusChanged(Kopete::StatusMessage)),
1376 this, SLOT (setStatusMessage(Kopete::StatusMessage)) );
1378 menu->addAction ( statusEditAction );
1379 menu->exec ( position );
1385 void KopeteWindow::slotAddContactDialogInternal (
const QString & accountIdentifier )
1389 Kopete::Account *account = Kopete::AccountManager::self()->findAccount ( protocolId, accountId );
1390 showAddContactDialog ( account );
1395 statusRootAction->
setCurrentMessage ( Kopete::StatusManager::self()->globalStatusMessage() );
1398 void KopeteWindow::showAddContactDialog ( Kopete::Account * account )
1401 kDebug ( 14000 ) <<
"no account given";
1406 addDialog->setCaption ( i18n (
"Add Contact" ) );
1407 addDialog->setButtons ( KDialog::Ok | KDialog::Cancel );
1408 addDialog->setDefaultButton ( KDialog::Ok );
1409 addDialog->showButtonSeparator (
true );
1413 AddContactPage *addContactPage =
1414 account->protocol()->createAddContactWidget ( mainWid, account );
1418 Ui::GroupKABCSelectorWidget ui_groupKABC;
1419 ui_groupKABC.setupUi ( groupKABC );
1422 Kopete::GroupList groups=Kopete::ContactList::self()->groups();
1426 groupItems.
insert ( Kopete::Group::topLevel()->displayName(), Kopete::Group::topLevel() );
1427 ui_groupKABC.groupCombo->addItem ( Kopete::Group::topLevel()->displayName() );
1431 if ( group->type() != Kopete::Group::Normal )
1433 QString groupname = group->displayName();
1436 groupItems.
insert ( groupname, group );
1437 ui_groupKABC.groupCombo->addItem ( groupname );
1441 if ( !addContactPage )
1444 "Error while creating addcontactpage" << endl;
1448 addDialog->setMainWidget ( mainWid );
1449 if ( addDialog->exec() == QDialog::Accepted )
1451 if ( addContactPage->validateData() )
1454 metacontact->addToGroup ( groupItems[ ui_groupKABC.groupCombo->currentText() ] );
1455 metacontact->setKabcId ( ui_groupKABC.widAddresseeLink->uid() );
1456 if ( addContactPage->apply ( account, metacontact ) )
1458 Kopete::ContactList::self()->addMetaContact ( metacontact );
1467 addDialog->deleteLater();
1470 void KopeteWindow::slotUpdateSize()
1479 if ( this->geometry().contains (
QCursor::pos() ) ==
true )
1483 const int amountWindowBiggerThanContactList = 200;
1484 const QRect workArea = KWindowSystem::workArea();
1485 const int minHeight = 400;
1486 QRect newGeometry = geometry();
1487 const QRect oldGeometry = geometry();
1488 const int topFrameWidth = - ( frameGeometry().top() - oldGeometry.
top() );
1489 const int bottomFrameWidth = frameGeometry().bottom() - oldGeometry.
bottom();
1493 int height = d->contactlist->visibleContentHeight();
1494 newGeometry.
setHeight ( height + amountWindowBiggerThanContactList );
1499 newGeometry.
setHeight ( workArea.
height() - topFrameWidth - bottomFrameWidth );
1500 else if ( newGeometry.
height() < minHeight )
1504 if ( Kopete::AppearanceSettings::contactListResizeAnchor() ==
1505 Kopete::AppearanceSettings::EnumContactListResizeAnchor::Top )
1511 if ( ( newGeometry.
top() - topFrameWidth ) < workArea.
top() )
1512 newGeometry.
moveTop ( workArea.
top() + topFrameWidth );
1514 else if ( ( newGeometry.
bottom() + bottomFrameWidth ) > workArea.
bottom() )
1518 setGeometry ( newGeometry );
1523 void KopeteWindow::slotNewInfoEvent()
1525 if ( !d->infoEventWidget->isVisible() )
1527 if ( d->identitywidget->isVisible() )
1529 d->identitywidget->setIdentity( 0 );
1530 d->identitywidget->setVisible(
false );
1532 d->infoEventWidget->setVisible(
true );
1536 #include "kopetewindow.moc"
virtual void closeEvent(QCloseEvent *ev)
virtual void showEvent(QShowEvent *ev)
void setContentsMargins(int left, int top, int right, int bottom)
iterator insert(const Key &key, const T &value)
int localeAwareCompare(const QString &other) const
void setPixmap(const QPixmap &)
void setIcon(const QIcon &icon)
void addSpacing(int size)
KopeteWindow(QWidget *parent=0)
void mouseReleaseEvent(QMouseEvent *event)
void setCurrentMessage(const Kopete::StatusMessage &statusMessage)
Set current status message.
virtual void leaveEvent(QEvent *ev)
const QPoint & globalPos() const
static bool invertedCompareOnlineStatus(const Kopete::Account *a, const Kopete::Account *b)
void setStatusMessage(const Kopete::StatusMessage &statusMessage)
Set status message to statusMessage.
static void createAccountStatusActions(Account *account, KActionMenu *parent, QAction *before=0)
insert "setStatus" actions from the given account to the specified actionMenu.
QFuture< void > map(Sequence &sequence, MapFunction function)
virtual void hideEvent(QHideEvent *ev)
void setMargin(int margin)
bool isShuttingDown() const
Method to return whether or not we're shutting down or not at this point.
static bool compareOnlineStatus(const Kopete::Account *a, const Kopete::Account *b)
bool contains(const T &value) const
InfoEventIconLabel(QWidget *parent=0)
static KopeteSystemTray * systemTray(QWidget *parent=0)
Retrieve the system tray instance.
void setHeight(int height)
QString section(QChar sep, int start, int end, QFlags< QString::SectionFlag > flags) const
virtual bool eventFilter(QObject *o, QEvent *e)
void quitKopete()
Quit Kopete, closing all the windows, which causes application shutdown This method marks Kopete as '...
GlobalStatusMessageIconLabel(QWidget *parent=0)
void iconClicked(const QPoint &position)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void mouseReleaseEvent(QMouseEvent *event)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QFuture< T > mapped(const Sequence &sequence, MapFunction function)
void setSpacing(int spacing)