Allow the TabCompleter to complete channel names as well.
[quassel.git] / src / uisupport / graphicalui.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-09 by the Quassel Project                          *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #include "graphicalui.h"
22
23 #include "actioncollection.h"
24 #include "contextmenuactionprovider.h"
25
26 #ifdef Q_WS_X11
27 #  include <QX11Info>
28 #endif
29 #ifdef HAVE_KDE
30 #  include <KWindowInfo>
31 #  include <KWindowSystem>
32 #endif
33
34 QWidget *GraphicalUi::_mainWidget = 0;
35 QHash<QString, ActionCollection *> GraphicalUi::_actionCollections;
36 ContextMenuActionProvider *GraphicalUi::_contextMenuActionProvider = 0;
37 ToolBarActionProvider *GraphicalUi::_toolBarActionProvider = 0;
38 UiStyle *GraphicalUi::_uiStyle = 0;
39 bool GraphicalUi::_onAllDesktops = false;
40
41 GraphicalUi::GraphicalUi(QObject *parent) : AbstractUi(parent)
42 {
43
44 }
45
46 ActionCollection *GraphicalUi::actionCollection(const QString &category) {
47   if(_actionCollections.contains(category))
48     return _actionCollections.value(category);
49   ActionCollection *coll = new ActionCollection(_mainWidget);
50   if(_mainWidget)
51     coll->addAssociatedWidget(_mainWidget);
52   _actionCollections.insert(category, coll);
53   return coll;
54 }
55
56 void GraphicalUi::setMainWidget(QWidget *widget) {
57   _mainWidget = widget;
58 }
59
60 void GraphicalUi::setContextMenuActionProvider(ContextMenuActionProvider *provider) {
61   _contextMenuActionProvider = provider;
62 }
63
64 void GraphicalUi::setToolBarActionProvider(ToolBarActionProvider *provider) {
65   _toolBarActionProvider = provider;
66 }
67
68 void GraphicalUi::setUiStyle(UiStyle *style) {
69   _uiStyle = style;
70 }
71
72 void GraphicalUi::activateMainWidget() {
73 #ifdef HAVE_KDE
74 #  ifdef Q_WS_X11
75     KWindowInfo info = KWindowSystem::windowInfo(mainWidget()->winId(), NET::WMDesktop | NET::WMFrameExtents);
76     if(_onAllDesktops) {
77       KWindowSystem::setOnAllDesktops(mainWidget()->winId(), true);
78     } else {
79       KWindowSystem::setCurrentDesktop(info.desktop());
80     }
81
82     mainWidget()->move(info.frameGeometry().topLeft()); // avoid placement policies
83     mainWidget()->show();
84     mainWidget()->raise();
85     KWindowSystem::raiseWindow(mainWidget()->winId());
86     KWindowSystem::activateWindow(mainWidget()->winId());
87 #  else
88     mainWidget()->show();
89     KWindowSystem::raiseWindow(mainWidget()->winId());
90     KWindowSystem::forceActiveWindow(mainWidget()->winId());
91 #  endif
92
93 #else /* HAVE_KDE */
94
95 #ifdef Q_WS_X11
96   // Bypass focus stealing prevention
97   QX11Info::setAppUserTime(QX11Info::appTime());
98 #endif
99
100   if(mainWidget()->windowState() & Qt::WindowMinimized) {
101     // restore
102     mainWidget()->setWindowState((mainWidget()->windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
103   }
104
105   // this does not actually work on all platforms... and causes more evil than good
106   // mainWidget()->move(mainWidget()->frameGeometry().topLeft()); // avoid placement policies
107   mainWidget()->show();
108   mainWidget()->raise();
109   mainWidget()->activateWindow();
110
111 #endif /* HAVE_KDE */
112 }
113
114 void GraphicalUi::hideMainWidget() {
115
116 #if defined(HAVE_KDE) && defined(Q_WS_X11)
117   KWindowInfo info = KWindowSystem::windowInfo(mainWidget()->winId(), NET::WMDesktop | NET::WMFrameExtents);
118   _onAllDesktops = info.onAllDesktops();
119 #endif
120
121   mainWidget()->hide();
122 }