summaryrefslogtreecommitdiffstats
blob: 920e94e2c14a2272d48f141671c9721fbc4580ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright (c) 2010-2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <Swift/QtUI/QtBookmarkDetailWindow.h>

#include <QMessageBox>

#include <Swift/QtUI/QtSwiftUtil.h>

namespace Swift {

QtBookmarkDetailWindow::QtBookmarkDetailWindow(QWidget* parent) : QDialog(parent) {
    setupUi(this);
    setAttribute(Qt::WA_DeleteOnClose, true);
    //connect(buttons_, SIGNAL(accepted()), SLOT(accept()));
    //connect(buttons_, SIGNAL(rejected()), SLOT(reject()));
    setFixedHeight(sizeHint().height());
}

void QtBookmarkDetailWindow::accept() {
    if (commit()) {
        QDialog::accept();
    }
}

boost::optional<MUCBookmark> QtBookmarkDetailWindow::createBookmarkFromForm() {
    //check room
    //check bookmarkName
    JID room(Q2PSTRING(room_->text()));
    if (!room.isValid() || room.getNode().empty() || !room.getResource().empty()) {
        QMessageBox::warning(this, tr("Bookmark not valid"), tr("You must specify a valid room address (e.g. someroom@rooms.example.com)."));
        return boost::optional<MUCBookmark>();
    }
    std::string name(Q2PSTRING(name_->text()));
    if (name.empty()) {
        name = room.toString();
    }

    MUCBookmark bookmark(room, name);
    std::string nick(Q2PSTRING(nick_->text()));
    std::string password(Q2PSTRING(password_->text()));
    bookmark.setAutojoin(autojoin_->isChecked());
    if (!nick.empty()) {
        bookmark.setNick(nick);
    }
    if (!password.empty()) {
        bookmark.setPassword(password);
    }
    return bookmark;
}

void QtBookmarkDetailWindow::createFormFromBookmark(const MUCBookmark& bookmark) {
    if (bookmark.getRoom().isValid()) {
        room_->setText(P2QSTRING(bookmark.getRoom().toString()));
    }

    if (!bookmark.getName().empty()) {
        name_->setText(P2QSTRING(bookmark.getName()));
    }

    if (bookmark.getNick()) {
        nick_->setText(P2QSTRING((*bookmark.getNick())));
    }

    if (bookmark.getPassword()) {
        password_->setText(P2QSTRING((*bookmark.getPassword())));
    }

    if (bookmark.getAutojoin()) {
        autojoin_->setCheckState(Qt::Checked);
    } else {
        autojoin_->setCheckState(Qt::Unchecked);
    }
}

}