46
//*******************************************************
48
//*******************************************************
49
MainWin::MainWin(bool _onTop, QWidget *parent, const char *name)
50
:QWidget(parent, name, _onTop ? WStyle_StaysOnTop: 0)
52
wmdock[0] = QImage("./image/psiwmdock1.png");
54
setIcon(status2pix(STATUS_OFFLINE));
58
localStatus = STATUS_OFFLINE;
70
vb_main = new QVBoxLayout(this, 2);
71
QHBoxLayout *hb_tools = new QHBoxLayout(vb_main);
73
tb_offline = new MToolButton(this);
74
tb_offline->setToggleButton(TRUE);
75
tb_offline->setOn(TRUE);
76
hb_tools->addWidget(tb_offline);
78
tb_away = new MToolButton(this);
79
tb_away->setToggleButton(TRUE);
81
hb_tools->addWidget(tb_away);
83
tb_agents = new MToolButton(this);
84
tb_agents->setToggleButton(TRUE);
85
tb_agents->setOn(TRUE);
86
hb_tools->addWidget(tb_agents);
90
hb_tools->addStretch(1);
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"));
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);
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);
117
hb1->addWidget(lb_ssl);
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);
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);
130
statusMenu = new QPopupMenu(this);
131
optionsMenu = new QPopupMenu(this);
64
//----------------------------------------------------------------------------
66
//----------------------------------------------------------------------------
68
class MainWin::Private
71
Private(PsiCon *, MainWin *);
76
QPopupMenu *mainMenu, *statusMenu, *optionsMenu, *toolsMenu;
83
PopupAction *optionsButton, *statusButton;
84
IconActionGroup *statusGroup;
85
EventNotifierAction *eventNotifier;
89
QSignalMapper *statusMapper;
94
QMap<QAction *, int> statusActions;
103
void registerActions();
104
IconAction *getAction( QString name );
107
MainWin::Private::Private(PsiCon *_psi, MainWin *_mainWin)
112
statusGroup = (IconActionGroup *)getAction("status_all");
113
eventNotifier = (EventNotifierAction *)getAction("event_notifier");
115
optionsButton = (PopupAction *)getAction("button_options");
116
statusButton = (PopupAction *)getAction("button_status");
118
statusMapper = new QSignalMapper(mainWin, "statusMapper");
119
mainWin->connect(statusMapper, SIGNAL(mapped(int)), mainWin, SLOT(activatedStatusAction(int)));
122
MainWin::Private::~Private()
126
void MainWin::Private::registerActions()
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 },
144
for ( i = 0; !(aName = QString(statuslist[i].name)).isEmpty(); i++ ) {
145
IconAction *action = getAction( aName );
146
connect (action, SIGNAL(activated()), statusMapper, SLOT(map()));
148
statusMapper->setMapping(action, statuslist[i].id);
149
statusActions[action] = statuslist[i].id;
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 );
160
mainWin->registerAction( action );
164
IconAction *MainWin::Private::getAction( QString name )
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 );
171
qWarning("MainWin::Private::getAction(): action %s not found!", name.latin1());
173
// mainWin->registerAction( action );
178
//----------------------------------------------------------------------------
180
//----------------------------------------------------------------------------
183
//#define TOOLW_FLAGS WStyle_Customize
185
#define TOOLW_FLAGS 0
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))
191
d = new Private(psi, this);
193
setIcon(is->status(STATUS_OFFLINE));
201
d->sbState = STATUS_OFFLINE;
212
QWidget *center = new QWidget (this, "Central widget");
213
setCentralWidget ( center );
215
d->vb_main = new QVBoxLayout(center, 2);
216
cvlist = new ContactView(center);
217
d->vb_main->addWidget(cvlist, 1);
219
// If the space isn't there, MacOS draws an empty vertical scrollbar :(
220
d->vb_main->addSpacing(1);
223
d->statusMenu = new QPopupMenu(this);
224
d->optionsMenu = new QPopupMenu(this);
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)));
139
pb_options->setPopup(optionsMenu);
140
pb_status->setPopup(statusMenu);
228
connect(d->statusMenu, SIGNAL(aboutToShow()), SLOT(buildStatusMenu()));
229
connect(d->optionsMenu, SIGNAL(aboutToShow()), SLOT(buildOptionsMenu()));
231
d->optionsButton->setPopup( d->optionsMenu );
232
d->statusButton->setPopup( d->statusMenu );
236
connect(d->psi, SIGNAL(accountCountChanged()), SLOT(numAccountsChanged()));
237
numAccountsChanged();
241
d->registerActions();
244
decorateButton(STATUS_OFFLINE);
246
// show tip of the day
247
if ( option.showTips )
250
// create a menubar on 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);
260
d->mainMenu = new QPopupMenu(this);
261
d->gm->insertItem(tr("General"), d->mainMenu);
262
connect(d->mainMenu, SIGNAL(aboutToShow()), SLOT(buildMainMenu()));
264
d->gm->insertItem(tr("Status"), d->statusMenu);
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);
274
d->toolsMenu = new QPopupMenu(this);
275
d->gm->insertItem(tr("Tools"), d->toolsMenu);
276
connect(d->toolsMenu, SIGNAL(aboutToShow()), SLOT(buildToolsMenu()));
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);
289
connect(qApp, SIGNAL(dockActivated()), SLOT(dockActivated()));
149
292
MainWin::~MainWin()
159
void MainWin::setAlwaysOnTop(bool _onTop)
294
PsiPopup::deleteAll();
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
314
void MainWin::registerAction( IconAction *action )
316
char activated[] = SIGNAL( activated() );
317
char toggled[] = SIGNAL( toggled(bool) );
318
char setOn[] = SLOT( setOn(bool) );
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) ) },
332
{ "button_options", activated, this, SIGNAL( doOptions() ) },
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) ) },
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) ) },
348
{ "event_notifier", SIGNAL( clicked(int) ), this, SLOT( statusClicked(int) ) },
349
{ "event_notifier", activated, this, SLOT( doRecvNextEvent() ) },
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() ) },
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 );
369
if ( aName == "menu_play_sounds" )
370
action->setOn( useSound );
371
//else if ( aName == "foobar" )
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 },
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 );
395
action->setOn( true );
400
PsiCon *MainWin::psiCon() const
405
void MainWin::setWindowOpts(bool _onTop, bool _asTool)
407
if(_onTop == d->onTop && _asTool == d->asTool)
415
flags |= WStyle_StaysOnTop;
417
flags |= WStyle_Tool | TOOLW_FLAGS;
165
419
QPoint p = pos();
166
reparent(parentWidget(), onTop ? WStyle_StaysOnTop: 0, p, FALSE);
420
reparent(parentWidget(), flags, p, FALSE);
171
425
void MainWin::setUseDock(bool use)
427
if(use == false || (d->tray && option.isWMDock != d->tray->isWMDock())) {
187
trayMenu = new QPopupMenu;
188
connect(trayMenu, SIGNAL(aboutToShow()), SLOT(buildTrayMenu()));
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()));
196
updateReadNext(nextType, nextAmount);
442
d->trayMenu = new QPopupMenu;
443
connect(d->trayMenu, SIGNAL(aboutToShow()), SLOT(buildTrayMenu()));
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()));
453
updateReadNext(d->nextAnim, d->nextAmount);
199
458
void MainWin::setInfo(const QString &str)
204
lb_info->setText(QString("<nobr>") + infoString + "</nobr>");
207
void MainWin::setUsingSSL(bool 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"));
462
if(d->nextAmount == 0)
463
d->eventNotifier->setText(d->infoString);
214
466
void MainWin::buildStatusMenu()
468
//statusMenu->clear();
469
qpopupmenuclear(d->statusMenu);
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);
226
void MainWin::activatedStatusMenu(int id)
474
void MainWin::activatedStatusAction(int id)
476
QObjectList *l = d->statusGroup->queryList( "IconAction" );
477
QObjectListIt it( *l );
479
for ( ; (obj = it.current()); ++it) {
480
IconAction *action = (IconAction *)obj;
481
action->setOn ( d->statusActions[action] == id );
228
485
statusChanged(id);
488
void MainWin::buildToolbars()
490
bool dockBottom = false;
492
while ( option.toolbars.count() < toolbars.count() && toolbars.count() ) {
493
PsiToolBar *tb = toolbars.last();
494
toolbars.removeLast();
499
for (i = 0; i < option.toolbars["mainWin"].count(); i++) {
501
if ( i < toolbars.count() )
504
Options::ToolbarPrefs &tbPref = option.toolbars["mainWin"][i];
505
if ( tb && !tbPref.dirty )
511
tb = new PsiToolBar (tbPref.name, this, this);
512
moveDockWindow ( tb, tbPref.dock, tbPref.nl, tbPref.index, tbPref. extraOffset );
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 );
521
dockBottom = dockBottom || (tbPref.dock == Qt::DockBottom && tbPref.on);
523
if ( i < toolbars.count() )
525
toolbars.insert(i, tb);
538
void MainWin::saveToolbarsPositions()
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();
547
bool MainWin::showDockMenu(const QPoint &)
231
552
void MainWin::buildOptionsMenu()
233
// clear the menu and submenus
234
qpopupmenuclear(optionsMenu);
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)));
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);
265
void MainWin::activatedOptionsMenu(int id)
267
QString dstr; dstr.sprintf("mainwin: id=%d\n", id);
268
pdb(DEBUG_MAINWIN, dstr);
290
QString content = QString("<h3>%1 v%2</h3>\n").arg(PROG_NAME).arg(PROG_VERSION);
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";
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";
299
content += "A capable Jabber client written in C++ using the Qt GUI Toolkit.<br>\n";
302
content += "Mac port contributed by Bill Myers.<br>\n";
304
content += "Graphics by Jason Kim, Justin Karneges, Hideaki Omuro, and other contributers.<br>\n";
306
AboutDlg *w = new AboutDlg(*pix_icon_48, content, this);
307
w->setCaption(tr("About"));
308
//w->setIcon(*pix_online);
311
//QMessageBox::about(this, CAP("About"), content);
314
QMessageBox::aboutQt(this);
320
debug_window->show();
322
ShowTextDlg *w = new ShowTextDlg(g.pathBase + "/COPYING");
323
w->setCaption(CAP(tr("License")));
327
unfinishedSoftware();
554
d->optionsMenu->clear();
557
QPopupMenu *helpMenu = new QPopupMenu(d->optionsMenu);
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";
569
QStringList::Iterator it;
571
for ( it = actionNames.begin(); it != actionNames.end(); ++it )
572
if ( (action = d->getAction(*it)) )
573
action->addTo( helpMenu );
575
buildGeneralMenu( d->optionsMenu );
577
d->optionsMenu->insertSeparator();
578
d->optionsMenu->insertItem(IconsetFactory::icon("psi/help"), tr("&Help"), helpMenu);
579
d->getAction("menu_quit")->addTo( d->optionsMenu );
583
void MainWin::buildMainMenu()
585
d->mainMenu->clear();
587
QStringList actionNames;
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";
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";
604
QStringList::Iterator it;
606
for ( it = actionNames.begin(); it != actionNames.end(); ++it ) {
608
d->mainMenu->insertSeparator();
609
else if ( (action = d->getAction(*it)) )
610
action->addTo( d->mainMenu );
614
void MainWin::buildToolsMenu()
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);
626
void MainWin::buildGeneralMenu(QPopupMenu *menu)
630
QStringList actionNames;
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";
648
QStringList::Iterator it;
650
for ( it = actionNames.begin(); it != actionNames.end(); ++it )
651
if ( (action = d->getAction(*it)) )
652
action->addTo( menu );
656
void MainWin::testme()
658
d->optionsMenu->setItemEnabled(10, false);
661
void MainWin::actReadmeActivated ()
332
ShowTextDlg *w = new ShowTextDlg(g.pathBase + "/readme.txt");
664
ShowTextDlg *w = new ShowTextDlg(g.pathBase + "/readme.txt");
334
ShowTextDlg *w = new ShowTextDlg(g.pathBase + "/README");
666
ShowTextDlg *w = new ShowTextDlg(g.pathBase + "/README");
336
w->setCaption(CAP(tr("ReadMe")));
668
w->setCaption(CAP(tr("ReadMe")));
672
void MainWin::actOnlineHelpActivated ()
674
openURL("http://psi.affinix.com/psi_docs/");
677
void MainWin::actBugReportActivated ()
679
openURL("http://psi.affinix.com/forums/index.php?act=SF&f=2");
682
void MainWin::actAboutActivated ()
684
AboutDlg *about = new AboutDlg (this, "AboutDlg", false, WDestructiveClose);
688
void MainWin::actTipActivated ()
690
TipUI *tip = new TipUI (this, "TipDlg", false, WDestructiveClose);
694
void MainWin::actAboutQtActivated ()
696
QMessageBox::aboutQt(this);
699
void MainWin::actPlaySoundsActivated (bool state)
704
void MainWin::activatedAccOption(PsiAccount *pa, int x)
707
pa->openAddUserDlg();
709
pa->showXmlConsole();
352
714
void MainWin::buildTrayMenu()
718
d->trayMenu->clear();
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();
364
trayMenu->insertItem(tr("Un&hide"), this, SLOT(trayShow()));
726
d->trayMenu->insertItem(tr("Un&hide"), this, SLOT(trayShow()));
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();
733
d->getAction("menu_quit")->addTo(d->trayMenu);
736
void MainWin::setTrayToolTip(int status)
740
d->tray->setToolTip(QString("Psi - " + status2txt(status)));
372
743
void MainWin::decorateButton(int status)
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 );
749
for ( ; (obj = it.current()); ++it) {
750
IconAction *action = (IconAction *)obj;
751
action->setOn ( d->statusActions[action] == status );
755
if(d->lastStatus == status)
757
d->lastStatus = status;
379
icon.setPixmap(status2pix(status), QIconSet::Small);
381
pb_status->setIconSet(icon);
382
pb_status->setText(status2txt(status));
760
icon.setPixmap(is->status(status), QIconSet::Small);
763
d->statusButton->setText(tr("Connecting"));
764
if (option.alertStyle != 0)
765
d->statusButton->setAlert(IconsetFactory::iconPtr("psi/connect"));
767
d->statusButton->setIcon(is->statusPtr(STATUS_OFFLINE));
769
setIcon(is->status(STATUS_OFFLINE));
772
d->statusButton->setText(status2txt(status));
773
d->statusButton->setIcon(is->statusPtr(status));
775
setIcon(is->status(status));
385
781
bool MainWin::askQuit()
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"));
786
void MainWin::try2tryCloseProgram()
788
QTimer::singleShot(0, this, SLOT(tryCloseProgram()));
396
791
void MainWin::tryCloseProgram()
779
//*******************************************************
781
//*******************************************************
782
MPushButton::MPushButton(QWidget *parent, const char *name)
783
:QPushButton(parent, name)
786
setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
791
void MPushButton::setText(const QString &_text)
794
QToolTip::remove(this);
999
void MainWin::numAccountsChanged()
1001
bool enabled = d->psi->accountList(TRUE).isEmpty() ? false : true;
1002
d->statusButton->setEnabled (enabled);
1005
void MainWin::dockActivated()
1013
void MainWin::setIcon(const QPixmap&)
1017
void MainWin::setIcon(const QPixmap& p)
1019
QMainWindow::setIcon(p);
1023
#if defined(Q_WS_WIN)
1025
void MainWin::showNoFocus()
1027
clearWState( WState_ForceHide );
1029
if ( testWState(WState_Visible) ) {
1030
SetWindowPos(winId(),HWND_TOPMOST,0,0,0,0, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE);
1032
SetWindowPos(winId(),HWND_NOTOPMOST,0,0,0,0, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE);
1033
return; // nothing to do
798
QPushButton::setText(_text);
801
void MPushButton::drawButtonLabel(QPainter *p)
803
// crazy code ahead! watch out for potholes and deer.
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);
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));
814
QFontMetrics fm(font());
816
// w1 = width of button text, w2 = width of text area
817
int w1 = fm.width(text());
820
// backup original text
821
QString oldtext = text();
823
// button text larger than what will fit?
826
QToolTip::add(this, text());
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
1040
QSize s = sizeHint();
1041
QSizePolicy::ExpandData exp;
1042
#ifndef QT_NO_LAYOUT
1044
if ( layout()->hasHeightForWidth() )
1045
s.setHeight( layout()->totalHeightForWidth( s.width() ) );
1046
exp = layout()->expanding();
1050
if ( sizePolicy().hasHeightForWidth() )
1051
s.setHeight( heightForWidth( s.width() ) );
1052
exp = sizePolicy().expanding();
830
// make a string that fits
834
for(n = oldtext.length(); n > 0; --n) {
835
if(fm.width(oldtext, n) < w2) {
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 ) );
1065
QApplication::sendPostedEvents( this, QEvent::Move );
1066
QApplication::sendPostedEvents( this, QEvent::Resize );
1068
setWState( WState_Visible );
1070
if ( testWFlags(WStyle_Tool) || isPopup() ) {
1072
} else if ( testWFlags(WType_TopLevel) ) {
1073
while ( QApplication::activePopupWidget() )
1074
QApplication::activePopupWidget()->close();
1077
if ( !testWState(WState_Polished) )
1081
QObjectListIt it(*children());
1082
register QObject *object;
1084
while ( it ) { // show all widget children
1085
object = it.current(); // (except popups and other toplevels)
1087
if ( object->isWidgetType() ) {
1088
widget = (QWidget*)object;
1089
if ( !widget->isHidden() && !widget->isTopLevel() )
841
newtext = oldtext.mid(0, n);
845
// set the new text that fits. updates must be off, or we recurse.
846
setUpdatesEnabled(FALSE);
847
QButton::setText(newtext);
848
setUpdatesEnabled(TRUE);
852
QToolTip::remove(this);
858
QPushButton::drawButtonLabel(p);
860
// restore original button text now that we are done drawing.
861
setUpdatesEnabled(FALSE);
862
QButton::setText(oldtext);
863
setUpdatesEnabled(TRUE);
867
//*******************************************************
869
//*******************************************************
870
MToolButton::MToolButton(QWidget *parent, const char *name)
871
:QToolButton(parent, name)
875
void MToolButton::setPressed(bool x)
881
//*******************************************************
883
//*******************************************************
884
MLabel::MLabel(QWidget *parent, const char *name)
885
:QLabel(parent, name)
889
void MLabel::mouseReleaseEvent(QMouseEvent *e)
891
clicked(e->button());
895
void MLabel::mouseDoubleClickEvent(QMouseEvent *e)
897
if(e->button() == LeftButton)
904
//*******************************************************
906
//*******************************************************
907
AboutDlg::AboutDlg(const QPixmap &icon, const QString &content, QWidget *par)
908
:QDialog(par, 0, TRUE)
911
QVBoxLayout *vb = new QVBoxLayout(this, 8);
912
QHBoxLayout *hb = new QHBoxLayout(vb);
915
col = new QVBoxLayout(hb);
916
l = new QLabel(this);
921
col = new QVBoxLayout(hb);
922
l = new QLabel(this);
927
hb = new QHBoxLayout(vb);
929
QPushButton *pb_ok = new QPushButton("&OK", this);
930
connect(pb_ok, SIGNAL(clicked()), SLOT(close()));
931
hb->addWidget(pb_ok);
1095
#if defined(QT_ACCESSIBILITY_SUPPORT)
1096
QAccessible::updateAccessibility( this, 0, QAccessible::ObjectShow );
1099
SetWindowPos(winId(),HWND_TOP,0,0,0,0, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
1100
UpdateWindow(winId());
1105
void MainWin::showNoFocus()