~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: 2009-09-25 17:49:51 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090925174951-lvm7kdap82o8xhn3
Tags: 0.13-1
* Updated to upstream version 0.13
* Set Standards-Version to 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
#include "globalshortcutmanager.h"
90
90
#include "desktoputil.h"
91
91
#include "tabmanager.h"
92
 
 
 
92
#include "capsmanager.h"
 
93
#include "avcall/avcall.h"
 
94
#include "avcall/calldlg.h"
 
95
 
 
96
 
 
97
#include "AutoUpdater/AutoUpdater.h"
 
98
#ifdef HAVE_SPARKLE
 
99
#include "AutoUpdater/SparkleAutoUpdater.h"
 
100
#endif
93
101
 
94
102
#ifdef Q_WS_MAC
95
103
#include "mac_dock.h"
96
104
#endif
97
105
 
 
106
// from opt_avcall.cpp
 
107
extern void options_avcall_update();
 
108
 
98
109
//----------------------------------------------------------------------------
99
110
// PsiConObject
100
111
//----------------------------------------------------------------------------
148
159
                        QFileInfo info(d, *it);
149
160
                        if(info.isDir()) {
150
161
                                if(!folderRemove(QDir(info.filePath())))
151
 
                                        return FALSE;
 
162
                                        return false;
152
163
                        }
153
164
                        else {
154
165
                                //printf("deleting [%s]\n", info.filePath().latin1());
157
168
                }
158
169
                QString name = d.dirName();
159
170
                if(!d.cdUp())
160
 
                        return FALSE;
 
171
                        return false;
161
172
                //printf("removing folder [%s]\n", d.filePath(name).latin1());
162
173
                d.rmdir(name);
163
174
 
164
 
                return TRUE;
 
175
                return true;
165
176
        }
166
177
};
167
178
 
257
268
        QMenuBar* defaultMenuBar;
258
269
        CapsRegistry* capsRegistry;
259
270
        TabManager *tabManager;
 
271
        AutoUpdater *autoUpdater;
260
272
};
261
273
 
262
274
//----------------------------------------------------------------------------
280
292
        d->s5bServer = 0;
281
293
        d->proxy = 0;
282
294
        d->tuneController = 0;
 
295
        d->autoUpdater = 0;
283
296
 
284
297
        d->actionList = 0;
285
298
        d->defaultMenuBar = new QMenuBar(0);
294
307
        saveCapabilities();
295
308
        delete d->capsRegistry;
296
309
 
 
310
        delete d->autoUpdater;
297
311
        delete d->actionList;
298
312
        delete d->edb;
299
313
        delete d->defaultMenuBar;
324
338
        // to options.xml only.
325
339
        QString backupfile = optionsFile() + "-preOptionsMigration";
326
340
        if (QFile::exists(pathToProfileConfig(activeProfile))
327
 
                && QFile::exists(optionsFile())
 
341
                && PsiOptions::exists(optionsFile())
328
342
                && !QFile::exists(backupfile)) {
329
343
                QFile::copy(optionsFile(), backupfile);
330
344
        }
348
362
        d->tuneController = new CombinedTuneController();
349
363
#endif
350
364
 
 
365
        // Auto updater initialization
 
366
#ifdef HAVE_SPARKLE
 
367
        d->autoUpdater = new SparkleAutoUpdater(ApplicationInfo::getAppCastURL());
 
368
#endif
 
369
        if (d->autoUpdater && PsiOptions::instance()->getOption("options.auto-update.check-on-startup").toBool()) {
 
370
                d->autoUpdater->checkForUpdates();
 
371
        }
 
372
 
351
373
        // calculate the small font size
352
374
        const int minimumFontSize = 7;
353
375
        common_smallFontSize = qApp->font().pointSize();
357
379
        FancyLabel::setSmallFontSize( common_smallFontSize );
358
380
        
359
381
        
360
 
        if (!QFile::exists(optionsFile()) && !QFile::exists(pathToProfileConfig(activeProfile))) {
361
 
                if (!options->load(":/options/newprofile.xml")) {
 
382
        if (!PsiOptions::exists(optionsFile())) {
 
383
                if (!options->newProfile()) {
362
384
                        qWarning("ERROR: Failed to new profile default options");
363
385
                }
364
386
        }
523
545
                                                haveEnabled = it->opt_enabled;
524
546
                                                if (it->opt_enabled) {
525
547
                                                        if (!PsiOptions::instance()->getOption("options.account.domain").toString().isEmpty())
526
 
                                                                it->jid = JIDUtil::accountFromString(Jid(it->jid).user()).bare();
 
548
                                                                it->jid = JIDUtil::accountFromString(Jid(it->jid).node()).bare();
527
549
                                                }
528
550
                                        }
529
551
                                        else
532
554
                                else {
533
555
                                        // Overwirte locked properties
534
556
                                        if (!PsiOptions::instance()->getOption("options.account.domain").toString().isEmpty())
535
 
                                                it->jid = JIDUtil::accountFromString(Jid(it->jid).user()).bare();
 
557
                                                it->jid = JIDUtil::accountFromString(Jid(it->jid).node()).bare();
536
558
                                }
537
559
                        }
538
560
                }
558
580
#endif
559
581
 
560
582
        connect(ActiveProfiles::instance(), SIGNAL(raiseMainWindow()), SLOT(raiseMainwin()));
 
583
        connect(ActiveProfiles::instance(), SIGNAL(openUri(const QUrl &)), SLOT(doOpenUri(const QUrl &)));
 
584
 
 
585
        DesktopUtil::setUrlHandler("xmpp", this, "doOpenUri");
 
586
 
 
587
        if(AvCallManager::isSupported()) {
 
588
                options_avcall_update();
 
589
                AvCallManager::setAudioOutDevice(PsiOptions::instance()->getOption("options.media.devices.audio-output").toString());
 
590
                AvCallManager::setAudioInDevice(PsiOptions::instance()->getOption("options.media.devices.audio-input").toString());
 
591
                AvCallManager::setVideoInDevice(PsiOptions::instance()->getOption("options.media.devices.video-input").toString());
 
592
                AvCallManager::setBasePort(PsiOptions::instance()->getOption("options.p2p.bytestreams.listen-port").toInt());
 
593
                AvCallManager::setExternalAddress(PsiOptions::instance()->getOption("options.p2p.bytestreams.external-address").toString());
 
594
        }
561
595
 
562
596
        return true;
563
597
}
564
598
 
 
599
bool PsiCon::haveAutoUpdater() const
 
600
{
 
601
        return d->autoUpdater != 0;
 
602
}
 
603
 
565
604
void PsiCon::registerCaps(const QString& ext, const QStringList& features)
566
605
{
567
606
        DiscoItem::Identity identity = { "client", ApplicationInfo::name(), "pc" };
606
645
                d->saveProfile(acc);
607
646
 
608
647
        GlobalShortcutManager::clear();
 
648
 
 
649
        DesktopUtil::unsetUrlHandler("xmpp");
609
650
}
610
651
 
611
652
 
790
831
        return acb;
791
832
}
792
833
 
793
 
void PsiCon::createAccount(const QString &name, const Jid &j, const QString &pass, bool opt_host, const QString &host, int port, bool legacy_ssl_probe, UserAccount::SSLFlag ssl, QString proxy)
 
834
void PsiCon::createAccount(const QString &name, const Jid &j, const QString &pass, bool opt_host, const QString &host, int port, bool legacy_ssl_probe, UserAccount::SSLFlag ssl, QString proxy, const QString &tlsOverrideDomain, const QByteArray &tlsOverrideCert)
794
835
{
795
 
        d->contactList->createAccount(name, j, pass, opt_host, host, port, legacy_ssl_probe, ssl, proxy);
 
836
        d->contactList->createAccount(name, j, pass, opt_host, host, port, legacy_ssl_probe, ssl, proxy, tlsOverrideDomain, tlsOverrideCert);
796
837
}
797
838
 
798
839
PsiAccount *PsiCon::createAccount(const UserAccount& acc)
947
988
        }
948
989
}
949
990
 
950
 
void PsiCon::doOpenUri(const QUrl &uriToOpen)
 
991
void PsiCon::doOpenUri(const QUrl &uri)
951
992
{
952
 
        Q_UNUSED(uriToOpen);    
953
 
        
954
 
/*
955
 
        QUrl uri(uriToOpen);    // got to copy, because setQueryDelimiters() is not const
956
 
 
957
 
        qWarning("uri:  " + uri.toString());
 
993
        qDebug() << "uri:  " << uri.toString();
958
994
 
959
995
        // scheme
960
 
 
961
 
        if (uri.scheme() != "xmpp") {   // try handling legacy URIs
962
 
                QMessageBox::warning(0, tr("Warning"), QString("URI (link) type \"%1\" is unsupported.").arg(uri.scheme()));
 
996
        if (uri.scheme() != "xmpp") {
 
997
                QMessageBox::critical(0, tr("Unsupported URI type"), QString("URI (link) type \"%1\" is not supported.").arg(uri.scheme()));
 
998
                return;
963
999
        }
964
1000
 
965
1001
        // authority
966
 
 
967
1002
        PsiAccount *pa = 0;
968
 
        if (uri.authority().isEmpty()) {
 
1003
        //if (uri.authority().isEmpty()) {
969
1004
                pa = d->contactList->defaultAccount();
970
1005
                if (!pa) {
971
 
                        QMessageBox::warning(0, tr("Warning"), QString("You don't have any account enabled."));
972
 
                }
973
 
        }
974
 
        else {
975
 
                qWarning("uri auth: [" + uri.authority() + "]");
976
 
 
977
 
                Jid authJid = JIDUtil::fromString(uri.authority());
978
 
                foreach(PsiAccount* acc, d->contactList->enabledAccounts()) {
979
 
                        if (acc->jid().compare(authJid, false)) {
980
 
                                pa = acc;
981
 
                        }
982
 
                }
983
 
 
984
 
                if (!pa) {
985
 
                        foreach(PsiAccount* acc, d->contactList->accounts()) {
986
 
                                if (acc->jid().compare(authJid, false)) {
987
 
                                        QMessageBox::warning(0, tr("Warning"), QString("The account for %1 JID is disabled right now.").arg(authJid.bare()));
988
 
                                        return; // FIX-ME: Should suggest enabling it now
989
 
                                }
990
 
                        }
991
 
                }
992
 
                if (!pa) {
993
 
                        QMessageBox::warning(0, tr("Warning"), QString("You don't have an account for %1.").arg(authJid.bare()));
 
1006
                        QMessageBox::critical(0, tr("Error"), QString("You need to have an account configured and enabled to open URIs (links)."));
994
1007
                        return;
995
1008
                }
996
 
        }
997
 
 
998
 
        // entity
999
 
 
1000
 
        QString path = uri.path();
1001
 
        if (path.startsWith('/'))       // this happens when authority part is present
1002
 
                path = path.mid(1);
1003
 
        Jid entity = JIDUtil::fromString(path);
1004
 
 
1005
 
        // query
1006
 
 
1007
 
        uri.setQueryDelimiters('=', ';');
1008
 
 
1009
 
        QString querytype = uri.queryItems().value(0).first;    // defaults to empty string
1010
 
 
1011
 
        if (querytype == "message") {
1012
 
                if (uri.queryItemValue("type") == "chat")
1013
 
                        pa->actionOpenChat(entity);
1014
 
                else {
1015
 
                        pa->dj_newMessage(entity, uri.queryItemValue("body"), uri.queryItemValue("subject"), uri.queryItemValue("thread"));
1016
 
                }
1017
 
        }
1018
 
        else if (querytype == "roster") {
1019
 
                pa->openAddUserDlg(entity, uri.queryItemValue("name"), uri.queryItemValue("group"));
1020
 
        }
1021
 
        else if (querytype == "join") {
1022
 
                pa->actionJoin(entity, uri.queryItemValue("password"));
1023
 
        }
1024
 
        else if (querytype == "vcard") {
1025
 
                pa->actionInfo(entity);
1026
 
        }
1027
 
        else if (querytype == "disco") {
1028
 
                pa->actionDisco(entity, uri.queryItemValue("node"));
1029
 
        }
1030
 
        else {
1031
 
                pa->actionSendMessage(entity);
1032
 
        }
1033
 
*/}
 
1009
        //
 
1010
        // TODO: finish authority component handling
 
1011
        //
 
1012
        //} else {
 
1013
        //      qDebug() << "uri auth: [" << uri.authority() << "]");
 
1014
 
 
1015
        //      // is there such account ready to use?
 
1016
        //      Jid authJid = JIDUtil::fromString(uri.authority());
 
1017
        //      foreach (PsiAccount* acc, d->contactList->enabledAccounts()) {
 
1018
        //              if (acc->jid().compare(authJid, false)) {
 
1019
        //                      pa = acc;
 
1020
        //              }
 
1021
        //      }
 
1022
 
 
1023
        //      // or maybe it is configured but not enabled?
 
1024
        //      if (!pa) {
 
1025
        //              foreach (PsiAccount* acc, d->contactList->accounts()) {
 
1026
        //                      if (acc->jid().compare(authJid, false)) {
 
1027
        //                              QMessageBox::error(0, tr("Error"), QString("The account for %1 JID is disabled right now.").arg(authJid.bare()));
 
1028
        //                              return; // TODO: Should suggest enabling it now
 
1029
        //                      }
 
1030
        //              }
 
1031
        //      }
 
1032
 
 
1033
        //      // nope..
 
1034
        //      if (!pa) {
 
1035
        //              QMessageBox::error(0, tr("Error"), QString("You don't have an account for %1.").arg(authJid.bare()));
 
1036
        //              return;
 
1037
        //      }
 
1038
        //}
 
1039
 
 
1040
        pa->openUri(uri);
 
1041
 
 
1042
 
 
1043
}
1034
1044
 
1035
1045
void PsiCon::doToolbars()
1036
1046
{
1097
1107
 
1098
1108
        updateS5BServerAddresses();
1099
1109
 
 
1110
        if(AvCallManager::isSupported()) {
 
1111
                AvCallManager::setAudioOutDevice(PsiOptions::instance()->getOption("options.media.devices.audio-output").toString());
 
1112
                AvCallManager::setAudioInDevice(PsiOptions::instance()->getOption("options.media.devices.audio-input").toString());
 
1113
                AvCallManager::setVideoInDevice(PsiOptions::instance()->getOption("options.media.devices.video-input").toString());
 
1114
                AvCallManager::setBasePort(PsiOptions::instance()->getOption("options.p2p.bytestreams.listen-port").toInt());
 
1115
                AvCallManager::setExternalAddress(PsiOptions::instance()->getOption("options.p2p.bytestreams.external-address").toString());
 
1116
        }
 
1117
 
1100
1118
        // mainwin stuff
1101
1119
        d->mainwin->setWindowOpts(PsiOptions::instance()->getOption("options.ui.contactlist.always-on-top").toBool(), (PsiOptions::instance()->getOption("options.ui.systemtray.enable").toBool() && PsiOptions::instance()->getOption("options.contactlist.use-toolwindow").toBool()));
1102
1120
        d->mainwin->setUseDock(PsiOptions::instance()->getOption("options.ui.systemtray.enable").toBool());
1291
1309
                return;
1292
1310
        }
1293
1311
 
 
1312
        if(e->type() == PsiEvent::AvCallType) {
 
1313
                AvCallEvent *ae = (AvCallEvent *)e;
 
1314
                AvCall *sess = ae->takeAvCall();
 
1315
                e->account()->eventQueue()->dequeue(e);
 
1316
                e->account()->queueChanged();
 
1317
                e->account()->cpUpdate(*u);
 
1318
                if(sess) {
 
1319
                        if(!sess->jid().isEmpty()) {
 
1320
                                CallDlg *w = new CallDlg(e->account(), 0);
 
1321
                                w->setAttribute(Qt::WA_DeleteOnClose);
 
1322
                                w->setIncoming(sess);
 
1323
                                bringToFront(w);
 
1324
                        }
 
1325
                        else {
 
1326
                                QMessageBox::information(0, tr("Call ended"), tr("Other party canceled call."));
 
1327
                                delete sess;
 
1328
                        }
 
1329
                }
 
1330
                return;
 
1331
        }
 
1332
 
1294
1333
        bool isChat = false;
1295
1334
        bool sentToChatWindow = false;
1296
1335
        if ( e->type() == PsiEvent::Message ) {
1440
1479
                AccountRegDlg w(proxy());
1441
1480
                int n = w.exec();
1442
1481
                if (n == QDialog::Accepted) {
1443
 
                        contactList()->createAccount(w.jid().node(),w.jid(),w.pass(),w.useHost(),w.host(),w.port(),w.legacySSLProbe(),w.ssl(),w.proxy(),false);
 
1482
                        contactList()->createAccount(w.jid().node(),w.jid(),w.pass(),w.useHost(),w.host(),w.port(),w.legacySSLProbe(),w.ssl(),w.proxy(),w.tlsOverrideDomain(), w.tlsOverrideCert(), false);
1444
1483
                }
1445
1484
        }
1446
1485
}