~ubuntu-branches/ubuntu/vivid/psi/vivid

« back to all changes in this revision

Viewing changes to src/tabs/tabbablewidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * tabbable.cpp
 
3
 * Copyright (C) 2007 Kevin Smith
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License
 
7
 * as published by the Free Software Foundation; either version 2
 
8
 * of the License, or (at your option) any later version.
 
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 library; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *
 
19
 */
 
20
 
 
21
#include "tabbablewidget.h"
 
22
#include "tabmanager.h"
 
23
#include "tabdlg.h"
 
24
#include "jidutil.h"
 
25
#include "groupchatdlg.h"
 
26
#include "psioptions.h"
 
27
#include <QTimer>
 
28
 
 
29
 
 
30
#ifdef Q_WS_WIN
 
31
#include <windows.h>
 
32
#endif
 
33
 
 
34
//----------------------------------------------------------------------------
 
35
// TabbableWidget
 
36
//----------------------------------------------------------------------------
 
37
 
 
38
TabbableWidget::TabbableWidget(const Jid &jid, PsiAccount *pa, TabManager *tabManager)
 
39
        : AdvancedWidget<QWidget>(0)
 
40
        , jid_(jid)
 
41
        , pa_(pa)
 
42
        , tabManager_(tabManager)
 
43
{
 
44
        QTimer::singleShot(0, this, SLOT(ensureTabbedCorrectly()));
 
45
}
 
46
 
 
47
void TabbableWidget::ensureTabbedCorrectly()
 
48
{
 
49
        if (tabManager_->shouldBeTabbed(this)) {
 
50
                if (!isTabbed()) {
 
51
                        tabManager_->getTabs(this)->addTab(this);
 
52
                }
 
53
        }
 
54
        else {
 
55
                if (PsiOptions::instance()->getOption("options.ui.tabs.tab-singles").toString().contains(tabManager_->tabKind(this))) {
 
56
                        if (isTabbed()) {
 
57
                                if (getManagingTabDlg()->tabCount() > 1) {
 
58
                                        getManagingTabDlg()->closeTab(this, false);
 
59
                                        tabManager_->newTabs(this)->addTab(this);
 
60
                                }
 
61
                        }
 
62
                        else {
 
63
                                tabManager_->newTabs(this)->addTab(this);
 
64
                        }
 
65
                }
 
66
                else {
 
67
                        if (isTabbed()) {
 
68
                                getManagingTabDlg()->closeTab(this, false);
 
69
                        }
 
70
 
 
71
                        // FIXME: showWithoutActivation() works on all
 
72
                        //   platforms, but bringToFront() (which might be
 
73
                        //   called immediately after) does not work on all
 
74
                        //   platforms if it follows a call to
 
75
                        //   showWithoutActivation().  As a temporary fix, we
 
76
                        //   will only call showWithoutActivation() on
 
77
                        //   platforms where both calls can be made in
 
78
                        //   succession.
 
79
#ifdef Q_WS_WIN
 
80
                        showWithoutActivation();
 
81
#else
 
82
                        show();
 
83
#endif
 
84
                }
 
85
        }
 
86
}
 
87
 
 
88
void TabbableWidget::bringToFront()
 
89
{
 
90
        if (isTabbed()) {
 
91
                getManagingTabDlg()->selectTab(this);
 
92
        }
 
93
        ::bringToFront(this);
 
94
}
 
95
 
 
96
TabbableWidget::~TabbableWidget()
 
97
{
 
98
        if (isTabbed()) {
 
99
                getManagingTabDlg()->removeTabWithNoChecks(this);
 
100
        }
 
101
}
 
102
 
 
103
/**
 
104
 * Checks if the dialog is in a tabset
 
105
 */
 
106
bool TabbableWidget::isTabbed()
 
107
{
 
108
        return tabManager_->isChatTabbed(this);
 
109
}
 
110
 
 
111
TabDlg* TabbableWidget::getManagingTabDlg()
 
112
{
 
113
        return tabManager_->getManagingTabs(this);
 
114
}
 
115
 
 
116
/**
 
117
 * Runs any gumph necessary before hiding a tab.
 
118
 * (checking new messages, setting the autodelete, cancelling composing etc)
 
119
 * \return TabbableWidget is ready to be hidden.
 
120
 */
 
121
bool TabbableWidget::readyToHide()
 
122
{
 
123
        return true;
 
124
}
 
125
 
 
126
Jid TabbableWidget::jid() const
 
127
{
 
128
        return jid_;
 
129
}
 
130
 
 
131
void TabbableWidget::setJid(const Jid& j)
 
132
{
 
133
        jid_ = j;
 
134
}
 
135
 
 
136
const QString& TabbableWidget::getDisplayName()
 
137
{
 
138
        return jid_.user();
 
139
}
 
140
 
 
141
void TabbableWidget::deactivated()
 
142
{
 
143
}
 
144
 
 
145
void TabbableWidget::activated()
 
146
{
 
147
}
 
148
 
 
149
/**
 
150
 * Returns true if this tab is active in the active window.
 
151
 */
 
152
bool TabbableWidget::isActiveTab()
 
153
{
 
154
        if (isHidden()) {
 
155
                return false;
 
156
        }
 
157
        if (!isTabbed()) {
 
158
                return isActiveWindow() && !isMinimized();
 
159
        }
 
160
        return getManagingTabDlg()->isActiveWindow() &&
 
161
               getManagingTabDlg()->tabOnTop(this) &&
 
162
              !getManagingTabDlg()->isMinimized();
 
163
}
 
164
 
 
165
void TabbableWidget::doFlash(bool on)
 
166
{
 
167
        AdvancedWidget<QWidget>::doFlash(on);
 
168
        emit updateFlashState();
 
169
}
 
170
 
 
171
TabbableWidget::State TabbableWidget::state() const
 
172
{
 
173
        return TabbableWidget::StateNone;
 
174
}
 
175
 
 
176
int TabbableWidget::unreadMessageCount() const
 
177
{
 
178
        return 0;
 
179
}
 
180
 
 
181
/**
 
182
 * Use this to invalidate tab state.
 
183
 */
 
184
void TabbableWidget::invalidateTab()
 
185
{
 
186
        setWindowTitle(desiredCaption());
 
187
        emit invalidateTabInfo();
 
188
}
 
189
 
 
190
PsiAccount* TabbableWidget::account() const
 
191
{
 
192
        return pa_;
 
193
}
 
194
 
 
195
void TabbableWidget::changeEvent(QEvent* event)
 
196
{
 
197
        AdvancedWidget<QWidget>::changeEvent(event);
 
198
 
 
199
        if (event->type() == QEvent::ActivationChange ||
 
200
            event->type() == QEvent::WindowStateChange)
 
201
        {
 
202
                if (isActiveTab()) {
 
203
                        activated();
 
204
                }
 
205
                else {
 
206
                        deactivated();
 
207
                }
 
208
        }
 
209
}