~ubuntu-branches/ubuntu/oneiric/psi/oneiric

« back to all changes in this revision

Viewing changes to src/psicon.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2006-01-20 00:20:36 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060120002036-7nw6yo6totip0ee5
Tags: 0.10-2
* Added upstream changelog (Closes: Bug#327748)
* Mention --no-gpg and --no-gpg-agent in manpage (Closes: Bug#204416)

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
#include"filetransfer.h"
59
59
#include"filetransdlg.h"
60
60
#include"psiactionlist.h"
 
61
#include"systemwatch.h"
 
62
#include"globalaccelman.h"
 
63
#include "tabdlg.h"
 
64
#include "chatdlg.h"
 
65
 
 
66
#ifdef Q_WS_MAC
 
67
#include "mac_dock.h"
 
68
#endif
61
69
 
62
70
//----------------------------------------------------------------------------
63
71
// PsiIconFactory
291
299
public:
292
300
        Private() {
293
301
                iconSelect = 0;
 
302
                //the list 'owns' the tabs
 
303
                tabs.setAutoDelete( true );
 
304
                tabControlledChats.setAutoDelete( false );
294
305
        }
295
306
        ~Private() {
296
307
                if ( iconSelect )
327
338
                iconSelect->setIconset(iss);
328
339
        }
329
340
 
 
341
        PsiAccount *queueLowestEventId(bool includeDND)
 
342
        {
 
343
                PsiAccount *low = 0;
 
344
                int low_id = 0;
 
345
                int low_prior = option.EventPriorityDontCare;
 
346
 
 
347
                PsiAccountListIt it(listEnabled);
 
348
                for ( PsiAccount *pa; (pa = it.current()); ++it ) {
 
349
                        int n = pa->eventQueue()->nextId();
 
350
                        if ( n == -1 )
 
351
                                continue;
 
352
 
 
353
                        if ( !includeDND && pa->status().show() == "dnd" )
 
354
                                continue;
 
355
 
 
356
                        int p = pa->eventQueue()->peekNext()->priority();
 
357
                        if ( !low || (n < low_id && p == low_prior) || p > low_prior ) {
 
358
                                low = pa;
 
359
                                low_id = n;
 
360
                                low_prior = p;
 
361
                        }
 
362
                }
 
363
 
 
364
                return low;
 
365
        }
 
366
 
 
367
 
330
368
        PsiAccountList list;
331
369
        PsiAccountList listEnabled;
332
370
        UserProfile pro;
334
372
        MainWin *mainwin;
335
373
        Idle idle;
336
374
        QPtrList<item_dialog> dialogList;
 
375
        QPtrList<TabDlg> tabs;
 
376
        QPtrList<ChatDlg> tabControlledChats;
337
377
        int eventId;
338
378
        QStringList recentGCList, recentBrowseList, recentNodeList;
339
379
        EDB *edb;
345
385
        QRect mwgeom;
346
386
        FileTransDlg *ftwin;
347
387
        PsiActionList *actionList;
 
388
        GlobalAccelManager *globalAccelManager;
348
389
};
349
390
 
350
391
//----------------------------------------------------------------------------
359
400
        d = new Private;
360
401
 
361
402
        d->lastStatusString = "";
362
 
        useSound = true;
 
403
        useSound = false;
363
404
        d->mainwin = 0;
364
405
        d->ftwin = 0;
365
406
 
488
529
        // load accounts
489
530
        loadAccounts(d->pro.acc);
490
531
 
 
532
        // Connect to the system monitor
 
533
        SystemWatch* sw = SystemWatch::instance();
 
534
        connect(sw, SIGNAL(sleep()), this, SLOT(doSleep()));
 
535
        connect(sw, SIGNAL(idleSleep()), this, SLOT(doSleep()));
 
536
        connect(sw, SIGNAL(wakeup()), this, SLOT(doWakeup()));
 
537
 
 
538
        // global accelerator manager
 
539
        d->globalAccelManager = new GlobalAccelManager;
 
540
        d->globalAccelManager->setAccel(option.globalAccels[0]);
 
541
        d->globalAccelManager->setAccel(option.globalAccels[1]);
 
542
        connect(d->globalAccelManager, SIGNAL(activated(int)), SLOT(accel_activated(int)));
 
543
 
491
544
        return true;
492
545
}
493
546
 
538
591
        connect(pa, SIGNAL(updatedActivity()), SLOT(pa_updatedActivity()));
539
592
        connect(pa, SIGNAL(updatedAccount()), SLOT(pa_updatedAccount()));
540
593
        connect(pa, SIGNAL(queueChanged()), SLOT(queueChanged()));
 
594
        connect(pa, SIGNAL(enabledChanged()), SIGNAL(accountCountChanged()));
541
595
        accountAdded(pa);
542
596
        if(d->s5bServer)
543
597
                pa->client()->s5bManager()->setServer(d->s5bServer);
712
766
        return 0;
713
767
}
714
768
 
 
769
TabDlg* PsiCon::newTabs()
 
770
{
 
771
        TabDlg *tab;
 
772
        tab=new TabDlg(this);
 
773
        d->tabs.append(tab);
 
774
        connect (tab, SIGNAL ( isDying(TabDlg*) ), SLOT ( tabDying(TabDlg*) ) );
 
775
        return tab;
 
776
}
 
777
 
 
778
TabDlg* PsiCon::getTabs()
 
779
{
 
780
        if (!d->tabs.isEmpty())
 
781
        {
 
782
                return d->tabs.getFirst();
 
783
        }
 
784
        else
 
785
        {
 
786
                return newTabs();
 
787
        }
 
788
}
 
789
 
 
790
void PsiCon::tabDying(TabDlg* tab)
 
791
{
 
792
        d->tabs.remove(tab);
 
793
}
 
794
 
 
795
bool PsiCon::isChatTabbed(ChatDlg* chat)
 
796
{
 
797
        for (uint i = 0; i < d->tabs.count(); ++i)
 
798
        {
 
799
                if ( d->tabs.at(i)->managesChat(chat) )
 
800
                                return true;
 
801
        }
 
802
        return false;
 
803
}
 
804
 
 
805
ChatDlg* PsiCon::getChatInTabs(QString jid){
 
806
        for (uint i = 0; i < d->tabs.count(); ++i)
 
807
        {
 
808
                if ( d->tabs.at(i)->getChatPointer(jid) )
 
809
                                return d->tabs.at(i)->getChatPointer(jid);
 
810
        }
 
811
        return NULL;
 
812
 
 
813
}
 
814
 
 
815
TabDlg* PsiCon::getManagingTabs(ChatDlg* chat)
 
816
{
 
817
        for (uint i = 0; i < d->tabs.count(); ++i)
 
818
        {
 
819
                if ( d->tabs.at(i)->managesChat(chat) )
 
820
                                return d->tabs.at(i);
 
821
        }
 
822
        return NULL;
 
823
 
 
824
}
 
825
 
 
826
QPtrList<TabDlg>* PsiCon::getTabSets()
 
827
{
 
828
        return &d->tabs;
 
829
}
 
830
 
 
831
bool PsiCon::isChatActiveWindow(ChatDlg* chat)
 
832
{
 
833
        //returns true if chat is on top of a tab pile
 
834
        if ( chat->isHidden() )
 
835
        {
 
836
                return false;
 
837
        }
 
838
        if (!option.useTabs)
 
839
        {
 
840
                return chat->isActiveWindow();
 
841
        }
 
842
        for (uint i = 0; i < d->tabs.count(); ++i)
 
843
        {
 
844
                if ( d->tabs.at(i)->isActiveWindow() )
 
845
                {
 
846
                        if ( d->tabs.at(i)->chatOnTop( chat ) )
 
847
                        {
 
848
                                return true;
 
849
                        }
 
850
                }
 
851
        }
 
852
        return false;
 
853
}
 
854
 
715
855
void PsiCon::dialogRegister(QWidget *w)
716
856
{
717
857
        item_dialog *i = new item_dialog;
759
899
        acc.name = name;
760
900
 
761
901
        acc.jid = j.full();
762
 
        if(!pass.isEmpty()) {
 
902
        if(!pass.isEmpty()) { 
763
903
                acc.opt_pass = true;
764
904
                acc.pass = pass;
765
905
        }
969
1109
{
970
1110
        QString oldpgp = option.pgp;
971
1111
        Options oldOpt = option;
 
1112
        bool notifyRestart = true;
972
1113
 
973
1114
        option = opt;
974
1115
 
 
1116
        if ( option.useTabs != oldOpt.useTabs || opt.chatLineEdit != oldOpt.chatLineEdit ) {
 
1117
                QMessageBox::information(0, tr("Information"), tr("Some of the options you changed will only have full effect upon restart."));
 
1118
                notifyRestart = false;
 
1119
        }
 
1120
 
975
1121
        // change icon set
976
1122
        if ( option.systemIconset               != oldOpt.systemIconset         ||
977
1123
             option.emoticons                   != oldOpt.emoticons             ||
979
1125
             option.serviceRosterIconset        != oldOpt.serviceRosterIconset  ||
980
1126
             option.customRosterIconset         != oldOpt.customRosterIconset )
981
1127
        {
982
 
                if ( is->optionsChanged(&oldOpt) )
 
1128
                if ( notifyRestart && is->optionsChanged(&oldOpt) )
983
1129
                        QMessageBox::information(0, tr("Information"), tr("The complete iconset update will happen on next Psi start."));
984
1130
 
985
1131
                // update icon selector
1039
1185
PsiAccount *PsiCon::queueLowestEventId()
1040
1186
{
1041
1187
        PsiAccount *low = 0;
1042
 
        int low_id = 0;
1043
 
        int low_prior = option.EventPriorityDontCare;
1044
 
 
1045
 
        PsiAccountListIt it(d->listEnabled);
1046
 
        for(PsiAccount *pa; (pa = it.current()); ++it) {
1047
 
                int n = pa->eventQueue()->nextId();
1048
 
                if(n == -1)
1049
 
                        continue;
1050
 
 
1051
 
                int p = pa->eventQueue()->peekNext()->priority();
1052
 
                if(!low || (n < low_id && p == low_prior)|| p > low_prior ) {
1053
 
                        low = pa;
1054
 
                        low_id = n;
1055
 
                        low_prior = p;
1056
 
                }
1057
 
        }
 
1188
 
 
1189
        low = d->queueLowestEventId( false ); // first try to get event from non-dnd account
 
1190
 
 
1191
        // if failed, then get the event from dnd account instead
 
1192
        if ( !low )
 
1193
                low = d->queueLowestEventId( true );
1058
1194
 
1059
1195
        return low;
1060
1196
}
1067
1203
        if(pa)
1068
1204
                nextAnim = is->event2icon(pa->eventQueue()->peekNext());
1069
1205
 
 
1206
#ifdef Q_WS_MAC
 
1207
        {
 
1208
                // The Mac Dock icon
 
1209
 
 
1210
                // Update the event count
 
1211
                if (nextAmount) 
 
1212
                        MacDock::overlay(QString::number(nextAmount));
 
1213
                else 
 
1214
                        MacDock::overlay(QString::null);
 
1215
 
 
1216
                // Check if bouncing is necessary
 
1217
                bool doBounce = false;
 
1218
                PsiAccountListIt it(d->listEnabled);
 
1219
                for(PsiAccount *pa; (pa = it.current()); ++it) {
 
1220
                        if ( pa->eventQueue()->count() && pa->status().show() != "dnd" ) {
 
1221
                                doBounce = true;
 
1222
                                break;
 
1223
                        }
 
1224
                }
 
1225
 
 
1226
                // Bouncy bouncy
 
1227
                if (doBounce) {
 
1228
                        if (option.bounceDock != Options::NoBounce) {
 
1229
                                MacDock::startBounce();
 
1230
                                if (option.bounceDock == Options::BounceOnce) 
 
1231
                                        MacDock::stopBounce();
 
1232
                        }
 
1233
                }
 
1234
                else 
 
1235
                        MacDock::stopBounce();
 
1236
        }
 
1237
#endif
 
1238
 
1070
1239
        d->mainwin->updateReadNext(nextAnim, nextAmount);
1071
1240
}
1072
1241
 
1216
1385
        saveAccounts();
1217
1386
}
1218
1387
 
 
1388
void PsiCon::accel_activated(int x)
 
1389
{
 
1390
        switch (x) {
 
1391
        case 1:
 
1392
                recvNextEvent();
 
1393
                break;
 
1394
        case 2:
 
1395
                d->mainwin->toggleVisible();
 
1396
                break;
 
1397
        }
 
1398
}
 
1399
 
1219
1400
MainWin *PsiCon::mainWin() const
1220
1401
{
1221
1402
        return d->mainwin;
1281
1462
                                return; // should never happen
1282
1463
 
1283
1464
                        e->account()->processChats(e->from()); // this will delete all events, corresponding to that chat dialog
 
1465
                        //KIS: I changed the following line with the one following that to attempt to get tabs to behave correctly. Lots of this stuff isn't great.
1284
1466
                        bringToFront((QWidget *)c);
 
1467
                        if ( option.useTabs)
 
1468
                        {
 
1469
                                TabDlg* tabSet = getManagingTabs(c);
 
1470
                                tabSet->selectTab(c);
 
1471
                        }
1285
1472
                }
1286
1473
                else
1287
1474
                        e->account()->openChat(e->from());
1365
1552
        if(d->s5bServer->isActive())
1366
1553
                d->s5bServer->stop();
1367
1554
 
1368
 
        if(option.dtPort==0) return; // file transfer disabled
1369
 
        if(!d->s5bServer->start(option.dtPort)) {
1370
 
                QMessageBox::information(0, tr("Error"), tr("Unable to bind to port %1 for Data Transfer").arg(option.dtPort));
 
1555
        if (option.dtPort) {
 
1556
                if(!d->s5bServer->start(option.dtPort)) {
 
1557
                        QMessageBox::information(0, tr("Error"), tr("Unable to bind to port %1 for Data Transfer").arg(option.dtPort));
 
1558
                }
1371
1559
        }
1372
1560
}
1373
1561
 
 
1562
void PsiCon::doSleep()
 
1563
{
 
1564
        setGlobalStatus(Status("",tr("Computer went to sleep"),0,false));
 
1565
}
 
1566
 
 
1567
void PsiCon::doWakeup()
 
1568
{
 
1569
        // TODO: Restore the status from before the log out. Make it an (hidden) option for people with a bad wireless connection.
 
1570
        //setGlobalStatus(Status());
 
1571
}
 
1572
 
 
1573
 
1374
1574
QPtrList<PsiToolBar> *PsiCon::toolbarList() const
1375
1575
{
1376
1576
        QPtrList<PsiToolBar> *list = new QPtrList<PsiToolBar>();