~ubuntu-branches/ubuntu/jaunty/psi/jaunty

« back to all changes in this revision

Viewing changes to src/mainwin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2005-01-10 17:41:43 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050110174143-ltocv5zapl6blf5d
Tags: 0.9.3-1
* New upstream release
* Cleaned up debian/rules (some things are done by upstream Makefiles now)
* Fixed some lintian warnings:
  - removed executable bit from some .png files
  - moved psi.desktop to /usr/share/applications
* Updated menu files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
** mainwin.cpp - the main window.  holds contactlist and buttons.
3
 
** Copyright (C) 2001, 2002  Justin Karneges
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 program; if not, write to the Free Software
17
 
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 
**
19
 
****************************************************************************/
 
1
/*
 
2
 * mainwin.cpp - the main window.  holds contactlist and buttons.
 
3
 * Copyright (C) 2001-2003  Justin Karneges, Michail Pishchagin
 
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
20
 
21
21
#include"mainwin.h"
22
 
#include"userlist.h"
23
 
#include"common.h"
24
 
#include"showtextdlg.h"
25
22
 
26
23
#include<qmessagebox.h>
27
24
#include<qiconset.h>
28
25
#include<qtooltip.h>
29
26
#include<qstyle.h>
30
 
 
 
27
#include<qapplication.h>
 
28
#include<qptrlist.h>
 
29
#include<qtimer.h>
 
30
#include<qobjectlist.h>
 
31
#include<qpainter.h>
 
32
#include<qsignalmapper.h>
 
33
#include<qstatusbar.h>
 
34
#include<qmenubar.h>
 
35
#include"im.h"
 
36
#include"common.h"
 
37
#include"showtextdlg.h"
 
38
#include"psicon.h"
 
39
#include"psiaccount.h"
 
40
#include"psitoolbar.h"
 
41
#include"ui_about.h"
 
42
#include"ui_tip.h"
 
43
#include"fancylabel.h"
 
44
#include"psitoolbar.h"
 
45
#include"psipopup.h"
 
46
 
 
47
#include"mainwin_p.h"
 
48
 
 
49
using namespace XMPP;
31
50
 
32
51
// deletes submenus in a popupmenu
33
52
void qpopupmenuclear(QPopupMenu *p)
42
61
        }
43
62
}
44
63
 
45
 
 
46
 
//*******************************************************
47
 
//  MainWin
48
 
//*******************************************************
49
 
MainWin::MainWin(bool _onTop, QWidget *parent, const char *name)
50
 
:QWidget(parent, name, _onTop ? WStyle_StaysOnTop: 0)
51
 
{
52
 
        wmdock[0] = QImage("./image/psiwmdock1.png");
53
 
 
54
 
        setIcon(status2pix(STATUS_OFFLINE));
55
 
 
56
 
        onTop = _onTop;
57
 
        nextAmount = 0;
58
 
        localStatus = STATUS_OFFLINE;
59
 
        userlist = 0;
60
 
        tray = 0;
61
 
        trayMenu = 0;
62
 
        statusTip = "";
63
 
        infoString = "";
64
 
        localJid = "";
65
 
 
66
 
        trayTimer = 0;
67
 
        animStep = 0;
68
 
        v_isActive = FALSE;
69
 
 
70
 
        vb_main = new QVBoxLayout(this, 2);
71
 
        QHBoxLayout *hb_tools = new QHBoxLayout(vb_main);
72
 
 
73
 
        tb_offline = new MToolButton(this);
74
 
        tb_offline->setToggleButton(TRUE);
75
 
        tb_offline->setOn(TRUE);
76
 
        hb_tools->addWidget(tb_offline);
77
 
 
78
 
        tb_away = new MToolButton(this);
79
 
        tb_away->setToggleButton(TRUE);
80
 
        tb_away->setOn(TRUE);
81
 
        hb_tools->addWidget(tb_away);
82
 
 
83
 
        tb_agents = new MToolButton(this);
84
 
        tb_agents->setToggleButton(TRUE);
85
 
        tb_agents->setOn(TRUE);
86
 
        hb_tools->addWidget(tb_agents);
87
 
 
88
 
        setToolBarIcons();
89
 
 
90
 
        hb_tools->addStretch(1);
91
 
 
92
 
        QToolTip::add(tb_offline, tr("Show Offline Contacts"));
93
 
        QToolTip::add(tb_away, tr("Show Away/XA/DnD"));
94
 
        QToolTip::add(tb_agents, tr("Show Agents/Transports"));
95
 
 
96
 
        cvlist = new ContactView(this);
97
 
        //connect(cvlist, SIGNAL(totalAlerts(int)), this, SLOT(totalAlerts(int)));
98
 
        connect(tb_offline, SIGNAL(toggled(bool)), cvlist, SLOT(setShowOffline(bool)));
99
 
        connect(tb_away, SIGNAL(toggled(bool)), cvlist, SLOT(setShowAway(bool)));
100
 
        connect(tb_agents, SIGNAL(toggled(bool)), cvlist, SLOT(setShowAgents(bool)));
101
 
        connect(cvlist, SIGNAL(showOffline(bool)), tb_offline, SLOT(setPressed(bool)));
102
 
        connect(cvlist, SIGNAL(showAway(bool)), tb_away, SLOT(setPressed(bool)));
103
 
        connect(cvlist, SIGNAL(showAgents(bool)), tb_agents, SLOT(setPressed(bool)));
104
 
        vb_main->addWidget(cvlist);
105
 
 
106
 
        QHBoxLayout *hb1 = new QHBoxLayout(vb_main);
107
 
        lb_info = new MLabel(this);
108
 
        connect(lb_info, SIGNAL(clicked(int)), SLOT(statusClicked(int)));
109
 
        connect(lb_info, SIGNAL(doubleClicked()), SLOT(doRecvNextEvent()));
110
 
        lb_info->setMinimumWidth(48);
111
 
        lb_info->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
112
 
        lb_info->setFrameStyle(QFrame::Panel | QFrame::Sunken);
113
 
        hb1->addWidget(lb_info);
114
 
        lb_ssl = new QLabel(this);
115
 
        lb_ssl->setFrameStyle(QFrame::Panel | QFrame::Sunken);
116
 
        setUsingSSL(FALSE);
117
 
        hb1->addWidget(lb_ssl);
118
 
 
119
 
        hb_status = new QHBoxLayout(vb_main);
120
 
        pb_options = new QPushButton(this);
121
 
        pb_options->setPixmap(*pix_main);
122
 
        pb_options->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ) );
123
 
        hb_status->addWidget(pb_options);
124
 
 
125
 
        pb_status = new MPushButton(this);
126
 
        pb_status->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
127
 
        decorateButton(STATUS_OFFLINE);
128
 
        hb_status->addWidget(pb_status);
129
 
 
130
 
        statusMenu = new QPopupMenu(this);
131
 
        optionsMenu = new QPopupMenu(this);
 
64
//----------------------------------------------------------------------------
 
65
// MainWin::Private
 
66
//----------------------------------------------------------------------------
 
67
 
 
68
class MainWin::Private
 
69
{
 
70
public:
 
71
        Private(PsiCon *, MainWin *);
 
72
        ~Private();
 
73
 
 
74
        QVBoxLayout *vb_main;
 
75
        bool onTop, asTool;
 
76
        QPopupMenu *mainMenu, *statusMenu, *optionsMenu, *toolsMenu;
 
77
        int sbState;
 
78
        QString nickname;
 
79
        MTray *tray;
 
80
        QPopupMenu *trayMenu;
 
81
        QString statusTip;
 
82
 
 
83
        PopupAction *optionsButton, *statusButton;
 
84
        IconActionGroup *statusGroup;
 
85
        EventNotifierAction *eventNotifier;
 
86
        PsiCon *psi;
 
87
        MainWin *mainWin;
 
88
 
 
89
        QSignalMapper *statusMapper;
 
90
 
 
91
        Icon *nextAnim;
 
92
        int nextAmount;
 
93
 
 
94
        QMap<QAction *, int> statusActions;
 
95
 
 
96
        int lastStatus;
 
97
#ifdef Q_WS_MAC
 
98
        QMenuBar *gm;
 
99
#endif
 
100
 
 
101
        QString infoString;
 
102
 
 
103
        void registerActions();
 
104
        IconAction *getAction( QString name );
 
105
};
 
106
 
 
107
MainWin::Private::Private(PsiCon *_psi, MainWin *_mainWin)
 
108
{
 
109
        psi = _psi;
 
110
        mainWin = _mainWin;
 
111
 
 
112
        statusGroup   = (IconActionGroup *)getAction("status_all");
 
113
        eventNotifier = (EventNotifierAction *)getAction("event_notifier");
 
114
 
 
115
        optionsButton = (PopupAction *)getAction("button_options");
 
116
        statusButton  = (PopupAction *)getAction("button_status");
 
117
 
 
118
        statusMapper = new QSignalMapper(mainWin, "statusMapper");
 
119
        mainWin->connect(statusMapper, SIGNAL(mapped(int)), mainWin, SLOT(activatedStatusAction(int)));
 
120
}
 
121
 
 
122
MainWin::Private::~Private()
 
123
{
 
124
}
 
125
 
 
126
void MainWin::Private::registerActions()
 
127
{
 
128
        struct {
 
129
                const char *name;
 
130
                int id;
 
131
        } statuslist[] = {
 
132
                { "status_chat",      STATUS_CHAT      },
 
133
                { "status_online",    STATUS_ONLINE    },
 
134
                { "status_away",      STATUS_AWAY      },
 
135
                { "status_xa",        STATUS_XA        },
 
136
                { "status_dnd",       STATUS_DND       },
 
137
                { "status_invisible", STATUS_INVISIBLE },
 
138
                { "status_offline",   STATUS_OFFLINE   },
 
139
                { "", 0 }
 
140
        };
 
141
 
 
142
        int i;
 
143
        QString aName;
 
144
        for ( i = 0; !(aName = QString(statuslist[i].name)).isEmpty(); i++ ) {
 
145
                IconAction *action = getAction( aName );
 
146
                connect (action, SIGNAL(activated()), statusMapper, SLOT(map()));
 
147
 
 
148
                statusMapper->setMapping(action, statuslist[i].id);
 
149
                statusActions[action] = statuslist[i].id;
 
150
        }
 
151
 
 
152
        // register all actions
 
153
        PsiActionList::ActionsType type = PsiActionList::ActionsType( PsiActionList::Actions_MainWin | PsiActionList::Actions_Common );
 
154
        ActionList actions = psi->actionList()->suitableActions( type );
 
155
        QStringList names = actions.actions();
 
156
        QStringList::Iterator it = names.begin();
 
157
        for ( ; it != names.end(); ++it ) {
 
158
                IconAction *action = actions.action( *it );
 
159
                if ( action )
 
160
                        mainWin->registerAction( action );
 
161
        }
 
162
}
 
163
 
 
164
IconAction *MainWin::Private::getAction( QString name )
 
165
{
 
166
        PsiActionList::ActionsType type = PsiActionList::ActionsType( PsiActionList::Actions_MainWin | PsiActionList::Actions_Common );
 
167
        ActionList actions = psi->actionList()->suitableActions( type );
 
168
        IconAction *action = actions.action( name );
 
169
 
 
170
        if ( !action )
 
171
                qWarning("MainWin::Private::getAction(): action %s not found!", name.latin1());
 
172
        //else
 
173
        //      mainWin->registerAction( action );
 
174
 
 
175
        return action;
 
176
}
 
177
 
 
178
//----------------------------------------------------------------------------
 
179
// MainWin
 
180
//----------------------------------------------------------------------------
 
181
 
 
182
//#ifdef Q_WS_X11
 
183
//#define TOOLW_FLAGS WStyle_Customize
 
184
//#else
 
185
#define TOOLW_FLAGS 0
 
186
//#endif
 
187
 
 
188
MainWin::MainWin(bool _onTop, bool _asTool, PsiCon *psi, const char *name)
 
189
:QMainWindow(0, name, 0 | (_onTop ? WStyle_StaysOnTop: 0) | (_asTool ? WStyle_Tool | TOOLW_FLAGS : 0))
 
190
{
 
191
        d = new Private(psi, this);
 
192
 
 
193
        setIcon(is->status(STATUS_OFFLINE));
 
194
 
 
195
        d->onTop = _onTop;
 
196
        d->asTool = _asTool;
 
197
 
 
198
        // sbState:
 
199
        //   -1 : connect
 
200
        // >= 0 : STATUS_*
 
201
        d->sbState = STATUS_OFFLINE;
 
202
        d->lastStatus = -2;
 
203
 
 
204
        d->nextAmount = 0;
 
205
        d->nextAnim = 0;
 
206
        d->tray = 0;
 
207
        d->trayMenu = 0;
 
208
        d->statusTip = "";
 
209
        d->infoString = "";
 
210
        d->nickname = "";
 
211
 
 
212
        QWidget *center = new QWidget (this, "Central widget");
 
213
        setCentralWidget ( center );
 
214
 
 
215
        d->vb_main = new QVBoxLayout(center, 2);
 
216
        cvlist = new ContactView(center);
 
217
        d->vb_main->addWidget(cvlist, 1);
 
218
#ifdef Q_WS_MAC
 
219
        // If the space isn't there, MacOS draws an empty vertical scrollbar :(
 
220
        d->vb_main->addSpacing(1);
 
221
#endif
 
222
 
 
223
        d->statusMenu = new QPopupMenu(this);
 
224
        d->optionsMenu = new QPopupMenu(this);
 
225
 
132
226
        buildStatusMenu();
133
227
        buildOptionsMenu();
134
 
        connect(statusMenu, SIGNAL(aboutToShow()), SLOT(buildStatusMenu()));
135
 
        connect(statusMenu, SIGNAL(activated(int)), SLOT(activatedStatusMenu(int)));
136
 
        connect(optionsMenu, SIGNAL(aboutToShow()), SLOT(buildOptionsMenu()));
137
 
        connect(optionsMenu, SIGNAL(activated(int)), SLOT(activatedOptionsMenu(int)));
138
 
 
139
 
        pb_options->setPopup(optionsMenu);
140
 
        pb_status->setPopup(statusMenu);
141
 
 
 
228
        connect(d->statusMenu, SIGNAL(aboutToShow()), SLOT(buildStatusMenu()));
 
229
        connect(d->optionsMenu, SIGNAL(aboutToShow()), SLOT(buildOptionsMenu()));
 
230
 
 
231
        d->optionsButton->setPopup( d->optionsMenu );
 
232
        d->statusButton->setPopup( d->statusMenu );
 
233
 
 
234
        X11WM_CLASS("main");
 
235
 
 
236
        connect(d->psi, SIGNAL(accountCountChanged()), SLOT(numAccountsChanged()));
 
237
        numAccountsChanged();
 
238
 
 
239
        updateCaption();
 
240
 
 
241
        d->registerActions();
 
242
        buildToolbars();
 
243
 
 
244
        decorateButton(STATUS_OFFLINE);
 
245
 
 
246
        // show tip of the day
 
247
        if ( option.showTips )
 
248
                actTipActivated();
 
249
 
 
250
        // create a menubar on Mac
142
251
#ifdef Q_WS_MAC
143
 
        vb_main->addSpacing(16);
 
252
        d->gm = new QMenuBar(0);
 
253
        QPopupMenu *mainMenu = new QPopupMenu(this);
 
254
        d->gm->insertItem(tr("Menu"), mainMenu);
 
255
        mainMenu->insertItem(tr("Preferences"), this, SIGNAL(doOptions()));
 
256
        mainMenu->insertItem(tr("Quit"), this, SLOT(try2tryCloseProgram()));
 
257
        d->getAction("help_about")->addTo(mainMenu);
 
258
        d->getAction("help_about_qt")->addTo(mainMenu);
 
259
 
 
260
        d->mainMenu = new QPopupMenu(this);
 
261
        d->gm->insertItem(tr("General"), d->mainMenu);
 
262
        connect(d->mainMenu, SIGNAL(aboutToShow()), SLOT(buildMainMenu()));
 
263
 
 
264
        d->gm->insertItem(tr("Status"), d->statusMenu);
 
265
 
 
266
        QPopupMenu *viewMenu = new QPopupMenu(this);
 
267
        d->gm->insertItem(tr("View"), viewMenu);
 
268
        d->getAction("show_offline")->addTo(viewMenu);
 
269
        d->getAction("show_away")->addTo(viewMenu);
 
270
        d->getAction("show_hidden")->addTo(viewMenu);
 
271
        d->getAction("show_agents")->addTo(viewMenu);
 
272
        d->getAction("show_self")->addTo(viewMenu);
 
273
 
 
274
        d->toolsMenu = new QPopupMenu(this);
 
275
        d->gm->insertItem(tr("Tools"), d->toolsMenu);
 
276
        connect(d->toolsMenu, SIGNAL(aboutToShow()), SLOT(buildToolsMenu()));
 
277
 
 
278
        QPopupMenu *helpMenu = new QPopupMenu(this);
 
279
        d->gm->insertItem(tr("Help"), helpMenu);
 
280
        d->getAction("help_readme")->addTo (helpMenu);
 
281
        d->getAction("help_tip")->addTo (helpMenu);
 
282
        helpMenu->insertSeparator();
 
283
        d->getAction("help_online_help")->addTo (helpMenu);
 
284
        d->getAction("help_report_bug")->addTo (helpMenu);
 
285
 
 
286
        d->gm->show();
144
287
#endif
145
288
 
146
 
        updateCaption();
 
289
        connect(qApp, SIGNAL(dockActivated()), SLOT(dockActivated()));
147
290
}
148
291
 
149
292
MainWin::~MainWin()
150
293
{
151
 
        if(tray) {
152
 
                delete tray;
153
 
                tray = 0;
154
 
                delete trayMenu;
155
 
                trayMenu = 0;
156
 
        }
157
 
}
158
 
 
159
 
void MainWin::setAlwaysOnTop(bool _onTop)
160
 
{
161
 
        if(_onTop == onTop)
 
294
        PsiPopup::deleteAll();
 
295
 
 
296
#ifdef Q_WS_MAC
 
297
        delete d->gm;
 
298
#endif
 
299
        if(d->tray) {
 
300
                delete d->tray;
 
301
                d->tray = 0;
 
302
                delete d->trayMenu;
 
303
                d->trayMenu = 0;
 
304
        }
 
305
 
 
306
        //saveToolbarsPositions();
 
307
        // need to find some workaround to case, when you're logging off. in that case
 
308
        // toobars are all disabled, and when you start psi again you need to enable
 
309
        // your toolbars
 
310
 
 
311
        delete d;
 
312
}
 
313
 
 
314
void MainWin::registerAction( IconAction *action )
 
315
{
 
316
        char activated[] = SIGNAL( activated() );
 
317
        char toggled[]   = SIGNAL( toggled(bool) );
 
318
        char setOn[]     = SLOT( setOn(bool) );
 
319
 
 
320
        struct {
 
321
                const char *name;
 
322
                const char *signal;
 
323
                QObject *receiver;
 
324
                const char *slot;
 
325
        } actionlist[] = {
 
326
                { "show_offline", toggled, cvlist, SLOT( setShowOffline(bool) ) },
 
327
                { "show_away",    toggled, cvlist, SLOT( setShowAway(bool) ) },
 
328
                { "show_hidden",  toggled, cvlist, SLOT( setShowHidden(bool) ) },
 
329
                { "show_agents",  toggled, cvlist, SLOT( setShowAgents(bool) ) },
 
330
                { "show_self",    toggled, cvlist, SLOT( setShowSelf(bool) ) },
 
331
 
 
332
                { "button_options", activated, this, SIGNAL( doOptions() ) },
 
333
 
 
334
                { "menu_disco",       SIGNAL( activated(PsiAccount *, int) ), this, SLOT( activatedAccOption(PsiAccount*, int) ) },
 
335
                { "menu_add_contact", SIGNAL( activated(PsiAccount *, int) ), this, SLOT( activatedAccOption(PsiAccount*, int) ) },
 
336
                { "menu_xml_console", SIGNAL( activated(PsiAccount *, int) ), this, SLOT( activatedAccOption(PsiAccount*, int) ) },
 
337
 
 
338
                { "menu_new_message",    activated, this, SIGNAL( blankMessage() ) },
 
339
                { "menu_join_groupchat", activated, this, SIGNAL( doGroupChat() ) },
 
340
                { "menu_account_setup",  activated, this, SIGNAL( doManageAccounts() ) },
 
341
                { "menu_options",        activated, this, SIGNAL( doOptions() ) },
 
342
                { "menu_file_transfer",  activated, this, SIGNAL( doFileTransDlg() ) },
 
343
                { "menu_toolbars",       activated, this, SIGNAL( doToolbars() ) },
 
344
                { "menu_change_profile", activated, this, SIGNAL( changeProfile() ) },
 
345
                { "menu_quit",           activated, this, SLOT( try2tryCloseProgram() ) },
 
346
                { "menu_play_sounds",    toggled,   this, SLOT( actPlaySoundsActivated(bool) ) },
 
347
 
 
348
                { "event_notifier", SIGNAL( clicked(int) ), this, SLOT( statusClicked(int) ) },
 
349
                { "event_notifier", activated, this, SLOT( doRecvNextEvent() ) },
 
350
 
 
351
                { "help_readme",      activated, this, SLOT( actReadmeActivated() ) },
 
352
                { "help_tip",         activated, this, SLOT( actTipActivated() ) },
 
353
                { "help_online_help", activated, this, SLOT( actOnlineHelpActivated() ) },
 
354
                { "help_report_bug",  activated, this, SLOT( actBugReportActivated() ) },
 
355
                { "help_about",       activated, this, SLOT( actAboutActivated() ) },
 
356
                { "help_about_qt",    activated, this, SLOT( actAboutQtActivated() ) },
 
357
 
 
358
                { "", 0, 0, 0 }
 
359
        };
 
360
 
 
361
        int i;
 
362
        QString aName;
 
363
        for ( i = 0; !(aName = QString(actionlist[i].name)).isEmpty(); i++ ) {
 
364
                if ( aName == action->name() ) {
 
365
                        disconnect( action, actionlist[i].signal, actionlist[i].receiver, actionlist[i].slot ); // for safety
 
366
                        connect( action, actionlist[i].signal, actionlist[i].receiver, actionlist[i].slot );
 
367
 
 
368
                        // special cases
 
369
                        if ( aName == "menu_play_sounds" )
 
370
                                action->setOn( useSound );
 
371
                        //else if ( aName == "foobar" )
 
372
                        //      ;
 
373
                }
 
374
        }
 
375
 
 
376
        struct {
 
377
                const char *name;
 
378
                QObject *sender;
 
379
                const char *signal;
 
380
                const char *slot;
 
381
        } reverseactionlist[] = {
 
382
                { "show_away",    cvlist, SIGNAL( showAway(bool) ), setOn },
 
383
                { "show_hidden",  cvlist, SIGNAL( showHidden(bool) ), setOn },
 
384
                { "show_offline", cvlist, SIGNAL( showOffline(bool) ), setOn },
 
385
                { "show_self",    cvlist, SIGNAL( showSelf(bool) ), setOn },
 
386
                { "show_agents",  cvlist, SIGNAL( showAgents(bool) ), setOn },
 
387
                { "", 0, 0, 0 }
 
388
        };
 
389
 
 
390
        for ( i = 0; !(aName = QString(reverseactionlist[i].name)).isEmpty(); i++ ) {
 
391
                if ( aName == action->name() ) {
 
392
                        disconnect( reverseactionlist[i].sender, reverseactionlist[i].signal, action, reverseactionlist[i].slot ); // for safety
 
393
                        connect( reverseactionlist[i].sender, reverseactionlist[i].signal, action, reverseactionlist[i].slot );
 
394
 
 
395
                        action->setOn( true );
 
396
                }
 
397
        }
 
398
}
 
399
 
 
400
PsiCon *MainWin::psiCon() const
 
401
{
 
402
        return d->psi;
 
403
}
 
404
 
 
405
void MainWin::setWindowOpts(bool _onTop, bool _asTool)
 
406
{
 
407
        if(_onTop == d->onTop && _asTool == d->asTool)
162
408
                return;
163
409
 
164
 
        onTop = _onTop;
 
410
        d->onTop = _onTop;
 
411
        d->asTool = _asTool;
 
412
 
 
413
        WFlags flags = 0;
 
414
        if(d->onTop)
 
415
                flags |= WStyle_StaysOnTop;
 
416
        if(d->asTool)
 
417
                flags |= WStyle_Tool | TOOLW_FLAGS;
 
418
 
165
419
        QPoint p = pos();
166
 
        reparent(parentWidget(), onTop ? WStyle_StaysOnTop: 0, p, FALSE);
 
420
        reparent(parentWidget(), flags, p, FALSE);
167
421
        move(p);
168
422
        show();
169
423
}
170
424
 
171
425
void MainWin::setUseDock(bool use)
172
426
{
173
 
        if(use == FALSE) {
174
 
                if(tray) {
175
 
                        traySetAnim(0);
176
 
                        delete tray;
177
 
                        tray = 0;
178
 
                        delete trayMenu;
179
 
                        trayMenu = 0;
 
427
        if(use == false || (d->tray && option.isWMDock != d->tray->isWMDock())) {
 
428
                if(d->tray) {
 
429
                        delete d->tray;
 
430
                        d->tray = 0;
 
431
                        delete d->trayMenu;
 
432
                        d->trayMenu = 0;
180
433
                }
181
 
                return;
 
434
 
 
435
                if (use == false)
 
436
                        return;
182
437
        }
183
438
 
184
 
        if(tray)
 
439
        if(d->tray)
185
440
                return;
186
441
 
187
 
        trayMenu = new QPopupMenu;
188
 
        connect(trayMenu, SIGNAL(aboutToShow()), SLOT(buildTrayMenu()));
189
 
 
190
 
        tray = new TrayIcon(makeTrayIcon(status2qim(localStatus)), "Psi", trayMenu);
191
 
        connect(tray, SIGNAL(clicked(const QPoint &, int)), SLOT(trayClicked(const QPoint &, int)));
192
 
        connect(tray, SIGNAL(doubleClicked(const QPoint &)), SLOT(trayDoubleClicked()));
193
 
        connect(tray, SIGNAL(closed()), SIGNAL(closeProgram()));
194
 
        tray->show();
195
 
 
196
 
        updateReadNext(nextType, nextAmount);
 
442
        d->trayMenu = new QPopupMenu;
 
443
        connect(d->trayMenu, SIGNAL(aboutToShow()), SLOT(buildTrayMenu()));
 
444
 
 
445
        d->tray = new MTray("Psi", d->trayMenu);
 
446
        d->tray->setIcon( is->statusPtr( STATUS_OFFLINE ));
 
447
        d->tray->setToolTip(PROG_NAME);
 
448
        connect(d->tray, SIGNAL(clicked(const QPoint &, int)), SLOT(trayClicked(const QPoint &, int)));
 
449
        connect(d->tray, SIGNAL(doubleClicked(const QPoint &)), SLOT(trayDoubleClicked()));
 
450
        connect(d->tray, SIGNAL(closed()), SLOT(dockActivated()));
 
451
        connect(qApp, SIGNAL(trayOwnerDied()), SLOT(dockActivated()));
 
452
 
 
453
        updateReadNext(d->nextAnim, d->nextAmount);
 
454
 
 
455
        d->tray->show();
197
456
}
198
457
 
199
458
void MainWin::setInfo(const QString &str)
200
459
{
201
 
        infoString = str;
202
 
 
203
 
        if(nextAmount == 0)
204
 
                lb_info->setText(QString("<nobr>") + infoString + "</nobr>");
205
 
}
206
 
 
207
 
void MainWin::setUsingSSL(bool use)
208
 
{
209
 
        usingSSL = use;
210
 
        lb_ssl->setPixmap(usingSSL ? *pix_ssl_yes : *pix_ssl_no);
211
 
        QToolTip::add(lb_ssl, usingSSL ? tr("Connection is encrypted") : tr("Connection is not encrypted"));
 
460
        d->infoString = str;
 
461
 
 
462
        if(d->nextAmount == 0)
 
463
                d->eventNotifier->setText(d->infoString);
212
464
}
213
465
 
214
466
void MainWin::buildStatusMenu()
215
467
{
216
 
        statusMenu->clear();
 
468
        //statusMenu->clear();
 
469
        qpopupmenuclear(d->statusMenu);
217
470
 
218
 
        statusMenu->insertItem(QIconSet(status2pix(STATUS_ONLINE)),  status2txt(STATUS_ONLINE),      STATUS_ONLINE);
219
 
        statusMenu->insertItem(QIconSet(status2pix(STATUS_AWAY)),    status2txt(STATUS_AWAY),        STATUS_AWAY);
220
 
        statusMenu->insertItem(QIconSet(status2pix(STATUS_XA)),      status2txt(STATUS_XA),          STATUS_XA);
221
 
        statusMenu->insertItem(QIconSet(status2pix(STATUS_DND)),     status2txt(STATUS_DND),         STATUS_DND);
222
 
        statusMenu->insertSeparator();
223
 
        statusMenu->insertItem(QIconSet(status2pix(STATUS_OFFLINE)), status2txt(STATUS_OFFLINE),     STATUS_OFFLINE);
 
471
        d->statusGroup->addTo(d->statusMenu);
224
472
}
225
473
 
226
 
void MainWin::activatedStatusMenu(int id)
 
474
void MainWin::activatedStatusAction(int id)
227
475
{
 
476
        QObjectList *l = d->statusGroup->queryList( "IconAction" );
 
477
        QObjectListIt it( *l );
 
478
        QObject *obj;
 
479
        for ( ; (obj = it.current()); ++it) {
 
480
                IconAction *action = (IconAction *)obj;
 
481
                action->setOn ( d->statusActions[action] == id );
 
482
        }
 
483
        delete l;
 
484
 
228
485
        statusChanged(id);
229
486
}
230
487
 
 
488
void MainWin::buildToolbars()
 
489
{
 
490
        bool dockBottom = false;
 
491
 
 
492
        while ( option.toolbars.count() < toolbars.count() && toolbars.count() ) {
 
493
                PsiToolBar *tb = toolbars.last();
 
494
                toolbars.removeLast();
 
495
                delete tb;
 
496
        }
 
497
 
 
498
        uint i;
 
499
        for (i = 0; i < option.toolbars["mainWin"].count(); i++) {
 
500
                PsiToolBar *tb = 0;
 
501
                if ( i < toolbars.count() )
 
502
                        tb = toolbars.at(i);
 
503
 
 
504
                Options::ToolbarPrefs &tbPref = option.toolbars["mainWin"][i];
 
505
                if ( tb && !tbPref.dirty )
 
506
                        continue;
 
507
 
 
508
                if ( tb )
 
509
                        delete tb;
 
510
 
 
511
                tb = new PsiToolBar (tbPref.name, this, this);
 
512
                moveDockWindow ( tb, tbPref.dock, tbPref.nl, tbPref.index, tbPref. extraOffset );
 
513
 
 
514
                tb->setGroup( "mainWin", i );
 
515
                tb->setPsiCon( d->psi );
 
516
                tb->setType( PsiActionList::Actions_MainWin );
 
517
                //connect( tb, SIGNAL( registerAction( IconAction * ) ), SLOT( registerAction( IconAction * ) ) );
 
518
                tb->initialize( tbPref, false );
 
519
 
 
520
                // MacOS stuff
 
521
                dockBottom = dockBottom || (tbPref.dock == Qt::DockBottom && tbPref.on);
 
522
 
 
523
                if ( i < toolbars.count() )
 
524
                        toolbars.remove(i);
 
525
                toolbars.insert(i, tb);
 
526
        }
 
527
 
 
528
#ifdef Q_WS_MAC
 
529
        if (dockBottom) {
 
530
                statusBar()->show();
 
531
        }
 
532
        else {
 
533
                statusBar()->hide();
 
534
        }
 
535
#endif
 
536
}
 
537
 
 
538
void MainWin::saveToolbarsPositions()
 
539
{
 
540
        for (uint i = 0; i < toolbars.count(); i++) {
 
541
                Options::ToolbarPrefs &tbPref = option.toolbars["mainWin"][i];
 
542
                getLocation ( toolbars.at(i), tbPref.dock, tbPref.index, tbPref.nl, tbPref.extraOffset );
 
543
                tbPref.on = toolbars.at(i)->isVisible();
 
544
        }
 
545
}
 
546
 
 
547
bool MainWin::showDockMenu(const QPoint &)
 
548
{
 
549
        return false;
 
550
}
 
551
 
231
552
void MainWin::buildOptionsMenu()
232
553
{
233
 
        // clear the menu and submenus
234
 
        qpopupmenuclear(optionsMenu);
235
 
 
236
 
        QPopupMenu *helpMenu = new QPopupMenu(optionsMenu);
237
 
        helpMenu->insertItem(tr("&ReadMe"), 13);
238
 
        helpMenu->insertItem(tr("&Hints"), 14);
239
 
        helpMenu->insertItem(tr("&License"), 11);
240
 
        helpMenu->insertItem(tr("&Warning"), 12);
241
 
        helpMenu->insertSeparator();
242
 
        helpMenu->insertItem(tr("&About"), 7);
243
 
        helpMenu->insertItem(tr("About &Qt"), 8);
244
 
        helpMenu->setItemEnabled(14, FALSE);
245
 
        connect(helpMenu, SIGNAL(activated(int)), SLOT(activatedOptionsMenu(int)));
246
 
 
247
 
        // options menu
248
 
        optionsMenu->insertItem(QIconSet(*pix_add),   tr("&Add a contact"),     0);
249
 
        optionsMenu->insertItem(QIconSet(*pix_send),  tr("New &blank message"), 1);
250
 
        optionsMenu->insertItem(QIconSet(transport2icon("", STATUS_ONLINE)), tr("Manage &services"), 15);
251
 
        optionsMenu->insertItem(tr("File sharing"), 4);
252
 
        optionsMenu->setItemEnabled(4, FALSE);
253
 
        optionsMenu->insertItem(QIconSet(*pix_account), tr("Account Setup"), 16);
254
 
        optionsMenu->insertItem(QIconSet(*pix_info), tr("Personal &info"), 6);
255
 
        optionsMenu->insertItem(tr("&Options"),             9);
256
 
        optionsMenu->insertItem(tr("&Log window"),          10);
257
 
        optionsMenu->insertItem(QIconSet(*pix_changeacc), tr("&Change profile"),3);
258
 
        optionsMenu->insertItem(tr("Play &sounds"), 2);
259
 
        optionsMenu->setItemChecked(2, useSound);
260
 
        optionsMenu->insertSeparator();
261
 
        optionsMenu->insertItem(tr("&Help"), helpMenu);
262
 
        optionsMenu->insertItem(tr("&Quit"),                 5);
263
 
}
264
 
 
265
 
void MainWin::activatedOptionsMenu(int id)
266
 
{
267
 
        QString dstr; dstr.sprintf("mainwin: id=%d\n", id);
268
 
        pdb(DEBUG_MAINWIN, dstr);
269
 
 
270
 
        if(id == 0)
271
 
                addUser();
272
 
        else if(id == 1)
273
 
                blankMessage();
274
 
        else if(id == 2) {
275
 
                if(useSound)
276
 
                        useSound = FALSE;
277
 
                else
278
 
                        useSound = TRUE;
279
 
        }
280
 
        else if(id == 3)
281
 
                changeProfile();
282
 
        else if(id == 4)
283
 
                doFileSharing();
284
 
        else if(id == 5) {
285
 
                tryCloseProgram();
286
 
        }
287
 
        else if(id == 6)
288
 
                accountInfo();
289
 
        else if(id == 7) {
290
 
                QString content = QString("<h3>%1 v%2</h3>\n").arg(PROG_NAME).arg(PROG_VERSION);
291
 
                content += "<br>\n";
292
 
                content += "Copyright (C) 2001,2002<br>\n";
293
 
                content += "By Justin Karneges<br>\n";
294
 
                content += "infiniti@affinix.com<br>\n";
295
 
                content += "http://psi.affinix.com/<br>\n";
296
 
                content += "<br>\n";
297
 
                content += "Psi is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions.  See Help->License for details.<br>\n";
298
 
                content += "<br>\n";
299
 
                content += "A capable Jabber client written in C++ using the Qt GUI Toolkit.<br>\n";
300
 
                content += "<br>\n";
301
 
//#ifdef Q_WS_MAC
302
 
                content += "Mac port contributed by Bill Myers.<br>\n";
303
 
//#endif
304
 
                content += "Graphics by Jason Kim, Justin Karneges, Hideaki Omuro, and other contributers.<br>\n";
305
 
 
306
 
                AboutDlg *w = new AboutDlg(*pix_icon_48, content, this);
307
 
                w->setCaption(tr("About"));
308
 
                //w->setIcon(*pix_online);
309
 
                w->exec();
310
 
                delete w;
311
 
                //QMessageBox::about(this, CAP("About"), content);
312
 
        }
313
 
        else if(id == 8) {
314
 
                QMessageBox::aboutQt(this);
315
 
        }
316
 
        else if(id == 9) {
317
 
                doOptions();
318
 
        }
319
 
        else if(id == 10)
320
 
                debug_window->show();
321
 
        else if(id == 11) {
322
 
                ShowTextDlg *w = new ShowTextDlg(g.pathBase + "/COPYING");
323
 
                w->setCaption(CAP(tr("License")));
324
 
                w->show();
325
 
        }
326
 
        else if(id == 12) {
327
 
                unfinishedSoftware();
328
 
        }
329
 
        else if(id == 13) {
330
 
                // readme
 
554
        d->optionsMenu->clear();
 
555
 
 
556
        // help menu
 
557
        QPopupMenu *helpMenu = new QPopupMenu(d->optionsMenu);
 
558
 
 
559
        QStringList actionNames;
 
560
        actionNames << "help_readme";
 
561
        actionNames << "help_tip";
 
562
        actionNames << "separator";
 
563
        actionNames << "help_online_help";
 
564
        actionNames << "help_report_bug";
 
565
        actionNames << "separator";
 
566
        actionNames << "help_about";
 
567
        actionNames << "help_about_qt";
 
568
 
 
569
        QStringList::Iterator it;
 
570
        IconAction *action;
 
571
        for ( it = actionNames.begin(); it != actionNames.end(); ++it )
 
572
                if ( (action = d->getAction(*it)) )
 
573
                        action->addTo( helpMenu );
 
574
 
 
575
        buildGeneralMenu( d->optionsMenu );
 
576
 
 
577
        d->optionsMenu->insertSeparator();
 
578
        d->optionsMenu->insertItem(IconsetFactory::icon("psi/help"), tr("&Help"), helpMenu);
 
579
        d->getAction("menu_quit")->addTo( d->optionsMenu );
 
580
 
 
581
}
 
582
 
 
583
void MainWin::buildMainMenu()
 
584
{
 
585
        d->mainMenu->clear();
 
586
 
 
587
        QStringList actionNames;
 
588
 
 
589
        // options menu
 
590
        if(!option.lockdown.roster)
 
591
                actionNames << "menu_add_contact";
 
592
        actionNames << "menu_new_message";
 
593
        if(!option.lockdown.services)
 
594
                actionNames << "menu_disco";
 
595
        actionNames << "menu_join_groupchat";
 
596
        actionNames << "";
 
597
        if(!option.lockdown.accounts)
 
598
                actionNames << "menu_account_setup";
 
599
        if(!option.lockdown.profiles)
 
600
                actionNames << "menu_change_profile";
 
601
        actionNames << "menu_toolbars";
 
602
        actionNames << "menu_play_sounds";
 
603
 
 
604
        QStringList::Iterator it;
 
605
        IconAction *action;
 
606
        for ( it = actionNames.begin(); it != actionNames.end(); ++it ) {
 
607
                if ((*it).isEmpty())
 
608
                        d->mainMenu->insertSeparator();
 
609
                else if ( (action = d->getAction(*it)) )
 
610
                        action->addTo( d->mainMenu );
 
611
        }
 
612
}
 
613
 
 
614
void MainWin::buildToolsMenu()
 
615
{
 
616
        IconAction* action;
 
617
 
 
618
        d->toolsMenu->clear();
 
619
        if ( (action = d->getAction("menu_file_transfer")) )
 
620
                action->addTo(d->toolsMenu);
 
621
        d->toolsMenu->insertSeparator();
 
622
        if ( (action = d->getAction("menu_xml_console")) )
 
623
                action->addTo(d->toolsMenu);
 
624
}
 
625
 
 
626
void MainWin::buildGeneralMenu(QPopupMenu *menu)
 
627
{
 
628
        menu->clear();
 
629
 
 
630
        QStringList actionNames;
 
631
 
 
632
        // options menu
 
633
        if(!option.lockdown.roster)
 
634
                actionNames << "menu_add_contact";
 
635
        actionNames << "menu_new_message";
 
636
        if(!option.lockdown.services)
 
637
                actionNames << "menu_disco";
 
638
        actionNames << "menu_join_groupchat";
 
639
        if(!option.lockdown.accounts)
 
640
                actionNames << "menu_account_setup";
 
641
        if(!option.lockdown.options)
 
642
                actionNames << "menu_options";
 
643
        actionNames << "menu_file_transfer"; // TODO: probably we want to lock down filetransfer, right?
 
644
        if(!option.lockdown.profiles)
 
645
                actionNames << "menu_change_profile";
 
646
        actionNames << "menu_play_sounds";
 
647
 
 
648
        QStringList::Iterator it;
 
649
        IconAction *action;
 
650
        for ( it = actionNames.begin(); it != actionNames.end(); ++it )
 
651
                if ( (action = d->getAction(*it)) )
 
652
                        action->addTo( menu );
 
653
}
 
654
 
 
655
// WTF??
 
656
void MainWin::testme()
 
657
{
 
658
        d->optionsMenu->setItemEnabled(10, false);
 
659
}
 
660
 
 
661
void MainWin::actReadmeActivated ()
 
662
{
331
663
#ifdef Q_WS_WIN
332
 
                ShowTextDlg *w = new ShowTextDlg(g.pathBase + "/readme.txt");
 
664
        ShowTextDlg *w = new ShowTextDlg(g.pathBase + "/readme.txt");
333
665
#else
334
 
                ShowTextDlg *w = new ShowTextDlg(g.pathBase + "/README");
 
666
        ShowTextDlg *w = new ShowTextDlg(g.pathBase + "/README");
335
667
#endif
336
 
                w->setCaption(CAP(tr("ReadMe")));
337
 
                w->show();
338
 
        }
339
 
        else if(id == 14) {
340
 
                // hints
341
 
        }
342
 
        else if(id == 15) {
343
 
                doManageServices();
344
 
 
345
 
                return;
346
 
        }
347
 
        else if(id == 16) {
348
 
                doManageAccounts();
349
 
        }
 
668
        w->setCaption(CAP(tr("ReadMe")));
 
669
        w->show();
 
670
}
 
671
 
 
672
void MainWin::actOnlineHelpActivated ()
 
673
{
 
674
        openURL("http://psi.affinix.com/psi_docs/");
 
675
}
 
676
 
 
677
void MainWin::actBugReportActivated ()
 
678
{
 
679
        openURL("http://psi.affinix.com/forums/index.php?act=SF&f=2");
 
680
}
 
681
 
 
682
void MainWin::actAboutActivated ()
 
683
{
 
684
        AboutDlg *about = new AboutDlg (this, "AboutDlg", false, WDestructiveClose);
 
685
        about->show();
 
686
}
 
687
 
 
688
void MainWin::actTipActivated ()
 
689
{
 
690
        TipUI *tip = new TipUI (this, "TipDlg", false, WDestructiveClose);
 
691
        tip->show();
 
692
}
 
693
 
 
694
void MainWin::actAboutQtActivated ()
 
695
{
 
696
        QMessageBox::aboutQt(this);
 
697
}
 
698
 
 
699
void MainWin::actPlaySoundsActivated (bool state)
 
700
{
 
701
        useSound = state;
 
702
}
 
703
 
 
704
void MainWin::activatedAccOption(PsiAccount *pa, int x)
 
705
{
 
706
        if(x == 0)
 
707
                pa->openAddUserDlg();
 
708
        else if(x == 2)
 
709
                pa->showXmlConsole();
 
710
        else if(x == 3)
 
711
                pa->doDisco();
350
712
}
351
713
 
352
714
void MainWin::buildTrayMenu()
353
715
{
354
 
        if(!trayMenu)
 
716
        if(!d->trayMenu)
355
717
                return;
356
 
        trayMenu->clear();
 
718
        d->trayMenu->clear();
357
719
 
358
 
        if(nextAmount > 0) {
359
 
                trayMenu->insertItem(tr("Receive next event"), this, SLOT(doRecvNextEvent()));
360
 
                trayMenu->insertSeparator();
 
720
        if(d->nextAmount > 0) {
 
721
                d->trayMenu->insertItem(tr("Receive next event"), this, SLOT(doRecvNextEvent()));
 
722
                d->trayMenu->insertSeparator();
361
723
        }
362
724
 
363
725
        if(isHidden())
364
 
                trayMenu->insertItem(tr("Un&hide"), this, SLOT(trayShow()));
 
726
                d->trayMenu->insertItem(tr("Un&hide"), this, SLOT(trayShow()));
365
727
        else
366
 
                trayMenu->insertItem(tr("&Hide"), this, SLOT(trayHide()));
367
 
        trayMenu->insertItem(tr("&Status"), statusMenu);
368
 
        trayMenu->insertSeparator();
369
 
        trayMenu->insertItem(tr("&Quit"), this, SLOT(tryCloseProgram()));
 
728
                d->trayMenu->insertItem(tr("&Hide"), this, SLOT(trayHide()));
 
729
        d->optionsButton->addTo(d->trayMenu);
 
730
        d->statusButton->addTo(d->trayMenu);
 
731
        d->trayMenu->insertSeparator();
 
732
        // TODO!
 
733
        d->getAction("menu_quit")->addTo(d->trayMenu);
 
734
}
 
735
 
 
736
void MainWin::setTrayToolTip(int status)
 
737
{
 
738
        if (!d->tray)
 
739
                return;
 
740
        d->tray->setToolTip(QString("Psi - " + status2txt(status)));
370
741
}
371
742
 
372
743
void MainWin::decorateButton(int status)
373
744
{
374
 
        setIcon(status2pix(status));
375
 
        if(tray && !v_isActive)
376
 
                tray->setIcon(makeTrayIcon(status2qim(status)));
 
745
        // update the 'change status' buttons
 
746
        QObjectList *l = d->statusGroup->queryList( "IconAction" );
 
747
        QObjectListIt it( *l );
 
748
        QObject *obj;
 
749
        for ( ; (obj = it.current()); ++it) {
 
750
                IconAction *action = (IconAction *)obj;
 
751
                action->setOn ( d->statusActions[action] == status );
 
752
        }
 
753
        delete l;
 
754
 
 
755
        if(d->lastStatus == status)
 
756
                return;
 
757
        d->lastStatus = status;
377
758
 
378
759
        QIconSet icon;
379
 
        icon.setPixmap(status2pix(status), QIconSet::Small);
380
 
 
381
 
        pb_status->setIconSet(icon);
382
 
        pb_status->setText(status2txt(status));
 
760
        icon.setPixmap(is->status(status), QIconSet::Small);
 
761
 
 
762
        if(status == -1) {
 
763
                d->statusButton->setText(tr("Connecting"));
 
764
                if (option.alertStyle != 0)
 
765
                        d->statusButton->setAlert(IconsetFactory::iconPtr("psi/connect"));
 
766
                else
 
767
                        d->statusButton->setIcon(is->statusPtr(STATUS_OFFLINE));
 
768
 
 
769
                setIcon(is->status(STATUS_OFFLINE));
 
770
        }
 
771
        else {
 
772
                d->statusButton->setText(status2txt(status));
 
773
                d->statusButton->setIcon(is->statusPtr(status));
 
774
 
 
775
                setIcon(is->status(status));
 
776
        }
 
777
 
 
778
        updateTray();
383
779
}
384
780
 
385
781
bool MainWin::askQuit()
386
782
{
387
 
        if(localStatus != STATUS_OFFLINE) {
388
 
                int n = QMessageBox::information(0, tr("Warning"), tr("You are currently logged in.  Are you sure you want to close Psi?"), tr("&Yes"), tr("&No"));
389
 
                if(n != 0)
390
 
                        return FALSE;
391
 
        }
392
 
 
393
783
        return TRUE;
394
784
}
395
785
 
 
786
void MainWin::try2tryCloseProgram()
 
787
{
 
788
        QTimer::singleShot(0, this, SLOT(tryCloseProgram()));
 
789
}
 
790
 
396
791
void MainWin::tryCloseProgram()
397
792
{
398
793
        if(askQuit())
401
796
 
402
797
void MainWin::closeEvent(QCloseEvent *e)
403
798
{
404
 
        if(tray) {
405
 
                hide();
 
799
#ifdef Q_WS_MAC
 
800
        trayHide();
 
801
        e->accept();
 
802
#else
 
803
        if(d->tray) {
 
804
                trayHide();
 
805
                e->accept();
406
806
                return;
407
807
        }
408
808
 
411
811
 
412
812
        closeProgram();
413
813
        e->accept();
 
814
#endif
 
815
}
 
816
 
 
817
void MainWin::keyPressEvent(QKeyEvent *e)
 
818
{
 
819
#ifdef Q_WS_MAC
 
820
        bool allowed = true;
 
821
#else
 
822
        bool allowed = d->tray ? true: false;
 
823
#endif
 
824
 
 
825
        bool closekey = false;
 
826
        if(e->key() == Key_Escape)
 
827
                closekey = true;
 
828
#ifdef Q_WS_MAC
 
829
        else if(e->key() == Key_W && e->state() & ControlButton)
 
830
                closekey = true;
 
831
#endif
 
832
 
 
833
        if(allowed && closekey) {
 
834
                close();
 
835
                e->accept();
 
836
                return;
 
837
        }
 
838
 
 
839
        QWidget::keyPressEvent(e);
414
840
}
415
841
 
416
842
void MainWin::updateCaption()
417
843
{
418
844
        QString str = "";
419
845
 
420
 
        if(nextAmount > 0)
 
846
        if(d->nextAmount > 0)
421
847
                str += "* ";
422
848
 
423
 
        if(localJid.isEmpty())
 
849
        if(d->nickname.isEmpty())
424
850
                str += PROG_NAME;
425
851
        else
426
 
                str += localJid;
 
852
                str += d->nickname;
427
853
 
428
854
        if(str == caption())
429
855
                return;
431
857
        setCaption(str);
432
858
}
433
859
 
434
 
void MainWin::localUpdate(const JabRosterEntry &e)
435
 
{
436
 
        localJid = e.jid;
437
 
 
438
 
        if(e.isAvailable())
439
 
                localStatus = e.local()->status;
440
 
        else
441
 
                localStatus = STATUS_OFFLINE;
442
 
 
443
 
        if(!localJid.isEmpty()) {
444
 
                statusTip = makeToolTip(e);
445
 
                QToolTip::add(lb_info, statusTip);
446
 
        }
447
 
        else {
448
 
                QToolTip::remove(lb_info);
449
 
        }
450
 
 
451
 
        if(tray)
452
 
                tray->setToolTip(status2txt(localStatus));
453
 
 
454
 
        updateCaption();
455
 
}
456
 
 
457
 
QString MainWin::makeToolTip(const JabRosterEntry &e)
458
 
{
459
 
        QString statusString = "";
460
 
        if(e.isAvailable())
461
 
                statusString = e.local()->statusString;
462
 
 
463
 
        QString jid = e.jid;
464
 
        QString nick = e.nick;
465
 
 
466
 
        QString str = QString("<qt>");
467
 
        str += QString("<nobr>%1: %2</nobr>").arg(jidnick(jid,nick)).arg(status2txt(localStatus));
468
 
        if(!nick.isEmpty())
469
 
                str += QString("<br>[%1]").arg(jid);
470
 
 
471
 
        if(e.isAvailable()) {
472
 
                JabResource *pr = e.res.priority();
473
 
                JabResource *r, *l;
474
 
 
475
 
                // current resource
476
 
                QString curres = "";
477
 
                l = e.res.local();
478
 
                if(l == pr)
479
 
                        curres += "*";
480
 
                curres += l->name;
481
 
                str += QString("<br><nobr>") + QString(tr("Resource: %1")).arg(curres) + "</nobr>";
482
 
 
483
 
                // other resources
484
 
                QString resources;
485
 
                int n = 0;
486
 
                QPtrListIterator<JabResource> it(e.res);
487
 
                for(; (r = it.current()); ++it) {
488
 
                        // skip the local resource
489
 
                        if(l == r)
490
 
                                continue;
491
 
 
492
 
                        if(n > 0)
493
 
                                resources += ", ";
494
 
 
495
 
                        // priority?
496
 
                        if(r == pr)
497
 
                                resources += "*";
498
 
                        resources += r->name;
499
 
                        ++n;
500
 
                }
501
 
                if(!resources.isEmpty())
502
 
                        str += QString("<br><nobr>") + QString(tr("Other(s): %1")).arg(resources) + "</nobr>";
503
 
        }
504
 
 
505
 
        if(!statusString.isEmpty()) {
506
 
                QString head = tr("Status Message");
507
 
                str += QString("<br><u>%1</u><br>%2").arg(head).arg(plain2rich(statusString));
508
 
        }
509
 
        str += "</qt>";
510
 
 
511
 
        return str;
512
 
}
513
 
 
514
 
void MainWin::setToolBarIcons()
515
 
{
516
 
        tb_offline->setIconSet(QIconSet(*pix_offline));
517
 
        tb_away->setIconSet(QIconSet(status2pix(STATUS_AWAY)));
518
 
        tb_agents->setIconSet(QIconSet(transport2icon("", STATUS_ONLINE)));
519
 
}
520
 
 
521
860
void MainWin::optionsUpdate()
522
861
{
523
 
        decorateButton(localStatus);
524
 
        setToolBarIcons();
 
862
        int status = d->lastStatus;
 
863
        d->lastStatus = -2;
 
864
        decorateButton(status);
525
865
 
526
 
        // if the tray animation is active, reset it
527
 
        if(tray && v_isActive) {
528
 
                traySetAnim(messagetype2anim(nextType));
529
 
        }
 
866
        updateTray();
530
867
}
531
868
 
532
 
QPixmap MainWin::makeTrayIcon(const QImage &_in)
 
869
void MainWin::setTrayToolTip(const Status &status)
533
870
{
534
 
#ifdef Q_WS_X11
535
 
        /*if(1) {
536
 
                QImage real = wmdock[0];
537
 
                real.detach();
538
 
                QImage in = _in;
539
 
                in.detach();
540
 
 
541
 
                // make sure it is no bigger than 16x16
542
 
                if(in.width() > 16 || in.height() > 16)
543
 
                        in = in.smoothScale(16,16);
544
 
 
545
 
                int xo = 40;
546
 
                int yo = 40;
547
 
 
548
 
                int n, n2;
549
 
 
550
 
                // draw a border
551
 
                for(n = 0; n < 22; ++n) {
552
 
                        real.setPixel(n + xo, yo, qRgb(0x80,0x80,0x80));
553
 
                        real.setPixel(n + xo, yo + 21, qRgb(0x00,0x00,0x00));
554
 
                        real.setPixel(xo, yo + n, qRgb(0x80,0x80,0x80));
555
 
                        real.setPixel(xo + 21, yo + n, qRgb(0x00,0x00,0x00));
556
 
                }
557
 
 
558
 
                xo += 3;
559
 
                yo += 3;
560
 
 
561
 
                // draw a dropshadow
562
 
                for(n2 = 0; n2 < in.height(); ++n2) {
563
 
                        for(n = 0; n < in.width(); ++n) {
564
 
                                if(qAlpha(_in.pixel(n,n2))) {
565
 
                                        real.setPixel(n + xo + 2, n2 + yo + 2, qRgb(0x80,0x80,0x80));
566
 
                                }
567
 
                        }
568
 
                }
569
 
                for(n2 = 0; n2 < in.height(); ++n2) {
570
 
                        for(n = 0; n < in.width(); ++n) {
571
 
                                if(qAlpha(_in.pixel(n,n2))) {
572
 
                                        real.setPixel(n + xo, n2 + yo, _in.pixel(n,n2));
573
 
                                }
574
 
                        }
575
 
                }
576
 
 
577
 
                QPixmap icon;
578
 
                icon.convertFromImage(real);
579
 
                return icon;
 
871
        if (!d->tray)
 
872
                return;
 
873
        QString s = "Psi";
 
874
 
 
875
        QString show = status.show();
 
876
        if(!show.isEmpty()) {
 
877
                show[0] = show[0].upper();
 
878
                s += " - "+show;
580
879
        }
581
 
        else {*/
582
 
                // on X11, the KDE dock is 22x22.  let's make our icon "seem" bigger.
583
 
                QImage real(22,22,32);
584
 
                //QImage in = _in.convertToImage();
585
 
                QImage in = _in;
586
 
                in.detach();
587
 
                real.fill(0);
588
 
                real.setAlphaBuffer(TRUE);
589
 
 
590
 
                // make sure it is no bigger than 16x16
591
 
                if(in.width() > 16 || in.height() > 16)
592
 
                        in = in.smoothScale(16,16);
593
 
 
594
 
                int xo = (real.width() - in.width()) / 2;
595
 
                int yo = (real.height() - in.height()) / 2;
596
 
 
597
 
                int n, n2;
598
 
 
599
 
                // draw a border
600
 
                for(n = 0; n < 22; ++n) {
601
 
                        real.setPixel(n,  0, qRgb(0x80,0x80,0x80));
602
 
                        real.setPixel(n, 21, qRgb(0x00,0x00,0x00));
603
 
                        real.setPixel( 0, n, qRgb(0x80,0x80,0x80));
604
 
                        real.setPixel(21, n, qRgb(0x00,0x00,0x00));
605
 
                }
606
 
 
607
 
                // draw a dropshadow
608
 
                for(n2 = 0; n2 < in.height(); ++n2) {
609
 
                        for(n = 0; n < in.width(); ++n) {
610
 
                                if(qAlpha(in.pixel(n,n2))) {
611
 
                                        int x = n + xo + 2;
612
 
                                        int y = n2 + yo + 2;
613
 
                                        real.setPixel(x, y, qRgba(0x80,0x80,0x80,0xff));
614
 
                                }
615
 
                        }
616
 
                }
617
 
                // draw the image
618
 
                for(n2 = 0; n2 < in.height(); ++n2) {
619
 
                        for(n = 0; n < in.width(); ++n) {
620
 
                                if(qAlpha(in.pixel(n,n2))) {
621
 
                                        QRgb c = in.pixel(n, n2);
622
 
                                        real.setPixel(n + xo, n2 + yo, qRgba(qRed(c), qGreen(c), qBlue(c), 0xff));
623
 
                                }
624
 
                        }
625
 
                }
626
 
                // create the alpha layer
627
 
                /*for(n2 = real.height()-2; n2 >= 0; --n2) {
628
 
                        for(n = 0; n < real.width(); ++n) {
629
 
                                uint c = real.pixel(n, n2);
630
 
                                if(c > 0) {
631
 
                                        QRgb old = real.pixel(n, n2);
632
 
                                        real.setPixel(n, n2, qRgba(qRed(old), qGreen(old), qBlue(old), 0xff));
633
 
                                }
634
 
                        }
635
 
                }*/
636
 
 
637
 
                QPixmap icon;
638
 
                icon.convertFromImage(real);
639
 
                return icon;
640
 
        //}
641
 
#else
642
 
        QPixmap icon;
643
 
        icon.convertFromImage(_in);
644
 
        return icon;
645
 
#endif
 
880
 
 
881
        QString text = status.status();
 
882
        if(!text.isEmpty())
 
883
                s += ": "+text;
 
884
 
 
885
        d->tray->setToolTip(s);
646
886
}
647
887
 
648
888
void MainWin::trayClicked(const QPoint &, int button)
655
895
                return;
656
896
        }
657
897
 
658
 
        if(isHidden())
 
898
        if(!isHidden())
 
899
                trayHide();
 
900
        else
659
901
                trayShow();
660
 
        else
661
 
                trayHide();
662
902
}
663
903
 
664
904
void MainWin::trayDoubleClicked()
666
906
        if(!option.dockDCstyle)
667
907
                return;
668
908
 
669
 
        if(nextAmount > 0) {
 
909
        if(d->nextAmount > 0) {
670
910
                doRecvNextEvent();
671
911
                return;
672
912
        }
673
913
 
674
 
        trayShow();
 
914
 
 
915
        if(!isHidden())
 
916
                trayHide();
 
917
        else
 
918
                trayShow();
675
919
}
676
920
 
677
921
void MainWin::trayShow()
678
922
{
679
 
        show();
680
923
        bringToFront(this);
681
924
}
682
925
 
683
926
void MainWin::trayHide()
684
927
{
 
928
        emit geomChanged(x(), y(), width(), height());
685
929
        hide();
686
930
}
687
931
 
688
 
void MainWin::updateReadNext(int type, int amount)
 
932
void MainWin::updateReadNext(Icon *anim, int amount)
689
933
{
690
 
        nextType = type;
691
 
        nextAmount = amount;
692
 
 
693
 
        if(nextAmount == 0)
694
 
                lb_info->setText(QString("<nobr>") + infoString + "</nobr>");
 
934
#ifdef Q_WS_MAC
 
935
        if(amount > 0)
 
936
                bounceDockTile();
695
937
        else
696
 
                lb_info->setText(QString("<nobr><b>") + tr("%1 event(s) received").arg(nextAmount) + "</b></nobr>");
697
 
 
698
 
        if(tray) {
699
 
                if(nextAmount == 0)
700
 
                        traySetAnim(0);
701
 
                else
702
 
                        traySetAnim(messagetype2anim(nextType));
703
 
        }
704
 
 
705
 
#ifdef Q_WS_MAC
706
 
        if(nextAmount == 0)
707
938
                stopDockTileBounce();
708
 
        else
709
 
                bounceDockTile();
710
939
#endif
711
940
 
 
941
        d->nextAnim = anim;
 
942
        if(anim == 0)
 
943
                d->nextAmount = 0;
 
944
        else
 
945
                d->nextAmount = amount;
 
946
 
 
947
        if(d->nextAmount <= 0) {
 
948
                d->eventNotifier->hide();
 
949
                d->eventNotifier->setText("");
 
950
        }
 
951
        else {
 
952
                d->eventNotifier->setText(QString("<b>") + numEventsString(d->nextAmount) + "</b>");
 
953
                d->eventNotifier->show();
 
954
                // make sure it shows
 
955
                //qApp->processEvents();
 
956
        }
 
957
 
 
958
        updateTray();
712
959
        updateCaption();
713
960
}
714
961
 
715
 
void MainWin::traySetAnim(Anim *_anim)
 
962
QString MainWin::numEventsString(int x) const
716
963
{
717
 
        if(_anim) {
718
 
                anim = _anim;
719
 
                animStep = 0;
720
 
                if(option.alertStyle == 0)
721
 
                        tray->setIcon(makeTrayIcon(anim->qim_base()));
722
 
                if(!v_isActive) {
723
 
                        v_isActive = TRUE;
724
 
 
725
 
                        trayTimer = new QTimer(this);
726
 
                        connect(trayTimer, SIGNAL(timeout()), SLOT(trayAnimate()));
727
 
                        trayTimer->start(120);
728
 
                }
729
 
        }
730
 
        else {
731
 
                anim = 0;
732
 
                if(v_isActive) {
733
 
                        v_isActive = FALSE;
734
 
                        delete trayTimer;
735
 
 
736
 
                        // change back to normal icon
737
 
                        tray->setIcon(makeTrayIcon(status2qim(localStatus)));
738
 
                }
739
 
        }
 
964
        QString s;
 
965
        if(x <= 0)
 
966
                s = "";
 
967
        else if(x == 1)
 
968
                s = tr("1 event received");
 
969
        else
 
970
                s = tr("%1 events received").arg(x);
 
971
 
 
972
        return s;
740
973
}
741
974
 
742
 
void MainWin::trayAnimate()
 
975
void MainWin::updateTray()
743
976
{
744
 
        if(anim->isAnim() && option.alertStyle == 2) {
745
 
                tray->setIcon(makeTrayIcon(anim->qim_frame(animStep)));
746
 
 
747
 
                ++animStep;
748
 
                if(animStep >= anim->numFrames()-1)
749
 
                        animStep = 0;
750
 
        }
751
 
        else if(option.alertStyle != 0) {
752
 
                if(animStep == 0)
753
 
                        tray->setIcon(makeTrayIcon(anim->qim_base()));
754
 
                else if(animStep == 4) {
755
 
                        QImage blank(16,16,32);
756
 
                        blank.fill(0);
757
 
                        blank.setAlphaBuffer(TRUE);
758
 
                        tray->setIcon(makeTrayIcon(blank));
759
 
                }
760
 
 
761
 
                ++animStep;
762
 
                if(animStep == 8)
763
 
                        animStep = 0;
764
 
        }
 
977
        if(!d->tray)
 
978
                return;
 
979
 
 
980
        if ( d->nextAmount > 0 )
 
981
                d->tray->setAlert(d->nextAnim);
 
982
        else if ( d->lastStatus == -1 )
 
983
                d->tray->setAlert(IconsetFactory::iconPtr("psi/connect"));
 
984
        else
 
985
                d->tray->setIcon(is->statusPtr(d->lastStatus));
765
986
}
766
987
 
767
988
void MainWin::doRecvNextEvent()
775
996
                recvNextEvent();
776
997
}
777
998
 
778
 
 
779
 
//*******************************************************
780
 
//  MPushButton
781
 
//*******************************************************
782
 
MPushButton::MPushButton(QWidget *parent, const char *name)
783
 
:QPushButton(parent, name)
784
 
{
785
 
        setMinimumWidth(48);
786
 
        setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
787
 
 
788
 
        hasTip = FALSE;
789
 
}
790
 
 
791
 
void MPushButton::setText(const QString &_text)
792
 
{
793
 
        if(hasTip) {
794
 
                QToolTip::remove(this);
795
 
                hasTip = FALSE;
 
999
void MainWin::numAccountsChanged()
 
1000
{
 
1001
        bool enabled = d->psi->accountList(TRUE).isEmpty() ? false : true;
 
1002
        d->statusButton->setEnabled (enabled);
 
1003
}
 
1004
 
 
1005
void MainWin::dockActivated()
 
1006
{
 
1007
        if(isHidden())
 
1008
                show();
 
1009
}
 
1010
 
 
1011
 
 
1012
#ifdef Q_WS_MAC
 
1013
void MainWin::setIcon(const QPixmap&)
 
1014
{
 
1015
}
 
1016
#else
 
1017
void MainWin::setIcon(const QPixmap& p)
 
1018
{
 
1019
        QMainWindow::setIcon(p);
 
1020
}
 
1021
#endif
 
1022
 
 
1023
#if defined(Q_WS_WIN)
 
1024
#include<windows.h>
 
1025
void MainWin::showNoFocus()
 
1026
{
 
1027
        clearWState( WState_ForceHide );
 
1028
 
 
1029
        if ( testWState(WState_Visible) ) {
 
1030
                SetWindowPos(winId(),HWND_TOPMOST,0,0,0,0, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE);
 
1031
                if(!d->onTop)
 
1032
                        SetWindowPos(winId(),HWND_NOTOPMOST,0,0,0,0, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE);
 
1033
                return; // nothing to do
796
1034
        }
797
1035
 
798
 
        QPushButton::setText(_text);
799
 
}
800
 
 
801
 
void MPushButton::drawButtonLabel(QPainter *p)
802
 
{
803
 
        // crazy code ahead!  watch out for potholes and deer.
804
 
 
805
 
        // this gets us the width of the "text area" on the button.
806
 
        // adapted from qt/src/styles/qcommonstyle.cpp and qt/src/widgets/qpushbutton.cpp
807
 
        QRect r = style().subRect(QStyle::SR_PushButtonContents, this);
808
 
        if(isMenuButton())
809
 
                r.setWidth(r.width() - style().pixelMetric(QStyle::PM_MenuButtonIndicator, this));
810
 
        if(iconSet() && !iconSet()->isNull())
811
 
                r.setWidth(r.width() - (iconSet()->pixmap(QIconSet::Small, QIconSet::Normal, QIconSet::Off).width() + 4));
812
 
 
813
 
        // font metrics
814
 
        QFontMetrics fm(font());
815
 
 
816
 
        // w1 = width of button text, w2 = width of text area
817
 
        int w1 = fm.width(text());
818
 
        int w2 = r.width();
819
 
 
820
 
        // backup original text
821
 
        QString oldtext = text();
822
 
 
823
 
        // button text larger than what will fit?
824
 
        if(w1 > w2) {
825
 
                if(!hasTip) {
826
 
                        QToolTip::add(this, text());
827
 
                        hasTip = TRUE;
 
1036
        if ( isTopLevel() && !testWState( WState_Resized ) )  {
 
1037
                // do this before sending the posted resize events. Otherwise
 
1038
                // the layout would catch the resize event and may expand the
 
1039
                // minimum size.
 
1040
                QSize s = sizeHint();
 
1041
                QSizePolicy::ExpandData exp;
 
1042
#ifndef QT_NO_LAYOUT
 
1043
                if ( layout() ) {
 
1044
                        if ( layout()->hasHeightForWidth() )
 
1045
                                s.setHeight( layout()->totalHeightForWidth( s.width() ) );
 
1046
                        exp =  layout()->expanding();
 
1047
                } else
 
1048
#endif
 
1049
                {
 
1050
                        if ( sizePolicy().hasHeightForWidth() )
 
1051
                                s.setHeight( heightForWidth( s.width() ) );
 
1052
                        exp = sizePolicy().expanding();
828
1053
                }
829
 
 
830
 
                // make a string that fits
831
 
                bool found = FALSE;
832
 
                QString newtext;
833
 
                int n;
834
 
                for(n = oldtext.length(); n > 0; --n) {
835
 
                        if(fm.width(oldtext, n) < w2) {
836
 
                                found = TRUE;
837
 
                                break;
 
1054
                if ( exp & QSizePolicy::Horizontally )
 
1055
                        s.setWidth( QMAX( s.width(), 200 ) );
 
1056
                if ( exp & QSizePolicy::Vertically )
 
1057
                        s.setHeight( QMAX( s.height(), 150 ) );
 
1058
                QRect screen = QApplication::desktop()->screenGeometry( QApplication::desktop()->screenNumber( pos() ) );
 
1059
                s.setWidth( QMIN( s.width(), screen.width()*2/3 ) );
 
1060
                s.setHeight( QMIN( s.height(), screen.height()*2/3 ) );
 
1061
                if ( !s.isEmpty() )
 
1062
                        resize( s );
 
1063
        }
 
1064
 
 
1065
        QApplication::sendPostedEvents( this, QEvent::Move );
 
1066
        QApplication::sendPostedEvents( this, QEvent::Resize );
 
1067
 
 
1068
        setWState( WState_Visible );
 
1069
 
 
1070
        if ( testWFlags(WStyle_Tool) || isPopup() ) {
 
1071
                raise();
 
1072
        } else if ( testWFlags(WType_TopLevel) ) {
 
1073
                while ( QApplication::activePopupWidget() )
 
1074
                QApplication::activePopupWidget()->close();
 
1075
        }
 
1076
 
 
1077
        if ( !testWState(WState_Polished) )
 
1078
                polish();
 
1079
 
 
1080
        if ( children() ) {
 
1081
                QObjectListIt it(*children());
 
1082
                register QObject *object;
 
1083
                QWidget *widget;
 
1084
                while ( it ) {                          // show all widget children
 
1085
                        object = it.current();          //   (except popups and other toplevels)
 
1086
                        ++it;
 
1087
                        if ( object->isWidgetType() ) {
 
1088
                                widget = (QWidget*)object;
 
1089
                                if ( !widget->isHidden() && !widget->isTopLevel() )
 
1090
                                widget->show();
838
1091
                        }
839
1092
                }
840
 
                if(found)
841
 
                        newtext = oldtext.mid(0, n);
842
 
                else
843
 
                        newtext = "";
844
 
 
845
 
                // set the new text that fits.  updates must be off, or we recurse.
846
 
                setUpdatesEnabled(FALSE);
847
 
                QButton::setText(newtext);
848
 
                setUpdatesEnabled(TRUE);
849
 
        }
850
 
        else {
851
 
                if(hasTip) {
852
 
                        QToolTip::remove(this);
853
 
                        hasTip = FALSE;
854
 
                }
855
 
        }
856
 
 
857
 
        // draw!
858
 
        QPushButton::drawButtonLabel(p);
859
 
 
860
 
        // restore original button text now that we are done drawing.
861
 
        setUpdatesEnabled(FALSE);
862
 
        QButton::setText(oldtext);
863
 
        setUpdatesEnabled(TRUE);
864
 
}
865
 
 
866
 
 
867
 
//*******************************************************
868
 
//  MToolButton
869
 
//*******************************************************
870
 
MToolButton::MToolButton(QWidget *parent, const char *name)
871
 
:QToolButton(parent, name)
872
 
{
873
 
}
874
 
 
875
 
void MToolButton::setPressed(bool x)
876
 
{
877
 
        setOn(x);
878
 
}
879
 
 
880
 
 
881
 
//*******************************************************
882
 
//  MLabel
883
 
//*******************************************************
884
 
MLabel::MLabel(QWidget *parent, const char *name)
885
 
:QLabel(parent, name)
886
 
{
887
 
}
888
 
 
889
 
void MLabel::mouseReleaseEvent(QMouseEvent *e)
890
 
{
891
 
        clicked(e->button());
892
 
        e->ignore();
893
 
}
894
 
 
895
 
void MLabel::mouseDoubleClickEvent(QMouseEvent *e)
896
 
{
897
 
        if(e->button() == LeftButton)
898
 
                doubleClicked();
899
 
 
900
 
        e->ignore();
901
 
}
902
 
 
903
 
 
904
 
//*******************************************************
905
 
//  AboutDlg
906
 
//*******************************************************
907
 
AboutDlg::AboutDlg(const QPixmap &icon, const QString &content, QWidget *par)
908
 
:QDialog(par, 0, TRUE)
909
 
{
910
 
        QLabel *l;
911
 
        QVBoxLayout *vb = new QVBoxLayout(this, 8);
912
 
        QHBoxLayout *hb = new QHBoxLayout(vb);
913
 
        QVBoxLayout *col;
914
 
 
915
 
        col = new QVBoxLayout(hb);
916
 
        l = new QLabel(this);
917
 
        l->setPixmap(icon);
918
 
        col->addWidget(l);
919
 
        col->addStretch(1);
920
 
 
921
 
        col = new QVBoxLayout(hb);
922
 
        l = new QLabel(this);
923
 
        l->setText(content);
924
 
        col->addWidget(l);
925
 
        col->addStretch(1);
926
 
 
927
 
        hb = new QHBoxLayout(vb);
928
 
        hb->addStretch(1);
929
 
        QPushButton *pb_ok = new QPushButton("&OK", this);
930
 
        connect(pb_ok, SIGNAL(clicked()), SLOT(close()));
931
 
        hb->addWidget(pb_ok);
932
 
        hb->addStretch(1);
933
 
}
934
 
 
 
1093
        }
 
1094
 
 
1095
#if defined(QT_ACCESSIBILITY_SUPPORT)
 
1096
        QAccessible::updateAccessibility( this, 0, QAccessible::ObjectShow );
 
1097
#endif
 
1098
 
 
1099
        SetWindowPos(winId(),HWND_TOP,0,0,0,0, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
 
1100
        UpdateWindow(winId());
 
1101
}
 
1102
 
 
1103
#else
 
1104
 
 
1105
void MainWin::showNoFocus()
 
1106
{
 
1107
        bringToFront(this);
 
1108
}
 
1109
 
 
1110
#endif