~ubuntu-branches/ubuntu/wily/psi/wily-proposed

« back to all changes in this revision

Viewing changes to src/whiteboarding/wbmanager.cpp

  • Committer: Package Import Robot
  • Author(s): Jan Niehusmann
  • Date: 2014-07-01 21:49:34 UTC
  • mfrom: (6.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20140701214934-gt4dkgm94byi4vnn
Tags: 0.15-1
* New upstream version
* set debhelper compat level to 9
* set Standards-Version to 3.9.5 (no further changes)
* add lintian override regarding license-problem-non-free-RFC
* use qconf to regenerate configure script
* implement hardening using buildflags instead of hardening-wrapper

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *
19
19
 * You should have received a copy of the GNU General Public License
20
20
 * along with this library; if not, write to the Free Software
21
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
22
 *
23
23
 */
24
24
 
36
36
 
37
37
WbManager::WbManager(XMPP::Client* client, PsiAccount* pa, SxeManager* sxemanager) {
38
38
        pa_ = pa;
39
 
    sxemanager_ = sxemanager;
40
 
 
41
 
    client->addExtension("whiteboard", Features(WBNS));
42
 
 
43
 
    connect(sxemanager_, SIGNAL(sessionNegotiated(SxeSession*)), SLOT(createWbDlg(SxeSession*)));
44
 
    sxemanager_->addInvitationCallback(WbManager::checkInvitation);
 
39
        sxemanager_ = sxemanager;
 
40
 
 
41
        client->addExtension("whiteboard", Features(WBNS));
 
42
 
 
43
        connect(sxemanager_, SIGNAL(sessionNegotiated(SxeSession*)), SLOT(createWbDlg(SxeSession*)));
 
44
        sxemanager_->addInvitationCallback(WbManager::checkInvitation);
 
45
}
 
46
 
 
47
WbManager::~WbManager()
 
48
{
 
49
        qDeleteAll(dialogs_);
45
50
}
46
51
 
47
52
void WbManager::openWhiteboard(const Jid &target, const Jid &ownJid, bool groupChat, bool promptInitialDoc) {
48
 
    
49
 
    // check that the target supports whiteboarding via SXE
50
 
    QList<QString> features;
51
 
    features += WBNS;
52
 
    if(!sxemanager_->checkSupport(target, features)) {
53
 
        QMessageBox::information(NULL, tr("Unsupported"), tr("The contact does not support whiteboarding."));
54
 
        return;
55
 
    }
56
 
    
57
 
    
 
53
 
 
54
        // check that the target supports whiteboarding via SXE
 
55
        QList<QString> features;
 
56
        features += WBNS;
 
57
        if(!sxemanager_->checkSupport(target, features)) {
 
58
                QMessageBox::information(NULL, tr("Unsupported"), tr("The contact does not support whiteboarding."));
 
59
                return;
 
60
        }
 
61
 
 
62
 
58
63
        // See if we have a session for the JID
59
64
        WbDlg* w = findWbDlg(target);
60
65
        if(!w) {
61
 
            // else negotiate a new session and return null
62
 
        
63
 
        QDomDocument doc;
64
 
 
65
 
        if(promptInitialDoc) {
66
 
            bool openExisting = (QMessageBox::Yes == QMessageBox::question(NULL,
67
 
                                                        tr("Open Existing SVG?"),
68
 
                                                        tr("Would you like to open an existing SVG document in the whitebaord?"),
69
 
                                                        QMessageBox::Yes | QMessageBox::No,
70
 
                                                        QMessageBox::No));
71
 
            
72
 
            if(openExisting) {
73
 
                // prompt for an existing file
74
 
                QString fileName = QFileDialog::getOpenFileName(NULL, tr("Initial SVG Document for the Whiteboard"),
75
 
                                                                 QDir::homePath(),
76
 
                                                                 tr("Scalable Vector Graphics (*.svg)"));
77
 
 
78
 
                QFile file(fileName);
79
 
                if(file.open(QIODevice::ReadOnly)) {
80
 
                    doc.setContent(file.readAll(), true);
81
 
                    file.close();
82
 
                }
83
 
            }
84
 
        }
85
 
 
86
 
        if(doc.documentElement().nodeName() != "svg") {
87
 
 
88
 
            // initialize with an empty whiteboarding document
89
 
            doc = QDomDocument();
90
 
            doc.setContent(QString(EMPTYWB), true);
91
 
 
92
 
        }
93
 
 
94
 
 
95
 
        // negotiate the session
 
66
                // else negotiate a new session and return null
 
67
 
 
68
                QDomDocument doc;
 
69
 
 
70
                if(promptInitialDoc) {
 
71
                        bool openExisting = (QMessageBox::Yes == QMessageBox::question(NULL,
 
72
                                                                                                                tr("Open Existing SVG?"),
 
73
                                                                                                                tr("Would you like to open an existing SVG document in the whitebaord?"),
 
74
                                                                                                                QMessageBox::Yes | QMessageBox::No,
 
75
                                                                                                                QMessageBox::No));
 
76
 
 
77
                        if(openExisting) {
 
78
                                // prompt for an existing file
 
79
                                QString fileName = QFileDialog::getOpenFileName(NULL, tr("Initial SVG Document for the Whiteboard"),
 
80
                                                                                                                                 QDir::homePath(),
 
81
                                                                                                                                 tr("Scalable Vector Graphics (*.svg)"));
 
82
 
 
83
                                QFile file(fileName);
 
84
                                if(file.open(QIODevice::ReadOnly)) {
 
85
                                        doc.setContent(file.readAll(), true);
 
86
                                        file.close();
 
87
                                }
 
88
                        }
 
89
                }
 
90
 
 
91
                if(doc.documentElement().nodeName() != "svg") {
 
92
 
 
93
                        // initialize with an empty whiteboarding document
 
94
                        doc = QDomDocument();
 
95
                        doc.setContent(QString(EMPTYWB), true);
 
96
 
 
97
                }
 
98
 
 
99
 
 
100
                // negotiate the session
96
101
                sxemanager_->startNewSession(target, ownJid, groupChat, doc, features);
97
102
        }
98
103
        else
101
106
 
102
107
void WbManager::removeDialog(WbDlg* dialog)
103
108
{
104
 
    dialogs_.takeAt(dialogs_.indexOf(dialog))->deleteLater();
 
109
        dialogs_.removeAt(dialogs_.indexOf(dialog));
 
110
        delete dialog;
105
111
}
106
112
 
107
113
WbDlg* WbManager::findWbDlg(const Jid &jid) {
116
122
}
117
123
 
118
124
void WbManager::createWbDlg(SxeSession* session) {
119
 
    // check if the session is a whiteboarding session
120
 
    bool whiteboarding = false;
121
 
    foreach(QString feature, session->features()) {
122
 
        if(feature == WBNS)
123
 
            whiteboarding = true;
124
 
    }
125
 
 
126
 
    if(whiteboarding) {
127
 
        // create the WbDlg
128
 
        WbDlg* w = new WbDlg(session, pa_);
129
 
 
130
 
        // connect the signals
131
 
        connect(w, SIGNAL(sessionEnded(WbDlg*)), SLOT(removeDialog(WbDlg*)));
132
 
        connect(session, SIGNAL(peerLeftSession(Jid)), w, SLOT(peerLeftSession(Jid)));
133
 
 
134
 
        dialogs_.append(w);
135
 
 
136
 
        bringToFront(w);
137
 
    }
 
125
        // check if the session is a whiteboarding session
 
126
        bool whiteboarding = false;
 
127
        foreach(QString feature, session->features()) {
 
128
                if(feature == WBNS)
 
129
                        whiteboarding = true;
 
130
        }
 
131
 
 
132
        if(whiteboarding) {
 
133
                // create the WbDlg
 
134
                WbDlg* w = new WbDlg(session, pa_);
 
135
 
 
136
                // connect the signals
 
137
                connect(w, SIGNAL(sessionEnded(WbDlg*)), SLOT(removeDialog(WbDlg*)));
 
138
                connect(session, SIGNAL(peerLeftSession(Jid)), w, SLOT(peerLeftSession(Jid)));
 
139
 
 
140
                dialogs_.append(w);
 
141
 
 
142
                bringToFront(w);
 
143
        }
138
144
}
139
145
 
140
146
bool WbManager::checkInvitation(const Jid &peer, const QList<QString> &features) {
141
 
    if(!features.contains(WBNS))
142
 
        return false;
 
147
        if(!features.contains(WBNS))
 
148
                return false;
143
149
 
144
 
    return (QMessageBox::Yes == QMessageBox::question(NULL,
145
 
                                    tr("Whiteboarding Invitation?"),
146
 
                                    tr("%1 has invited you to a whiteboarding session. Would you like to join?").arg(peer.full()),
147
 
                                    QMessageBox::Yes | QMessageBox::No,
148
 
                                    QMessageBox::No));
 
150
        return (QMessageBox::Yes == QMessageBox::question(NULL,
 
151
                                                                        tr("Whiteboarding Invitation?"),
 
152
                                                                        tr("%1 has invited you to a whiteboarding session. Would you like to join?").arg(peer.full()),
 
153
                                                                        QMessageBox::Yes | QMessageBox::No,
 
154
                                                                        QMessageBox::No));
149
155
}