~nik90/touch-irc/revamp-connect-page

1 by Joseph Mills
1st push ever
1
/*
2
 * Copyright (C) 2008-2014 The Communi Project
3
 *
4
 * This example is free, and not covered by the LGPL license. There is no
5
 * restriction applied to their modification, redistribution, using and so on.
6
 * You can study them, modify them, use them in your own program - either
7
 * completely or partially.
8
 */
9
10
import QtQuick 2.0
11
import Ubuntu.Components 0.1
12
import Communi 3.0
13
14
15
MainView{
16
    id: window
17
    objectName: "mainView"
18
    applicationName: "irc client"
19
    automaticOrientation: true
20
    anchorToKeyboard: true
21
    width: units.gu(40)
22
    height: units.gu(71)
23
    property bool isConnected: false
24
    PageStack{
25
        id: pageStack
26
        Component.onCompleted:  push(connectPage)
27
        Settings{
28
            id:settingsPage
29
            visible: false
30
        }
31
        ConnectPage {
32
            id: connectPage
33
            visible: false
34
35
            onAccepted: {
36
                chatPage.currentBuffer = serverBuffer
37
                connection.sendCommand(cmd.createJoin(channel))
38
                connection.open()
39
                pageStack.push(chatPage)
40
            }
41
            onRejected: Qt.quit()
42
        }
43
44
        ChatPage {
45
            id: chatPage
46
            visible: false
47
            title: isConnected ? currentBuffer.name : "Connecting"
48
49
            bufferModel: IrcBufferModel {
50
                id: bufferModel
51
52
                sortMethod: Irc.SortByTitle
53
                connection: IrcConnection {
54
                    id: connection
55
                    host: connectPage.host
56
                    port: connectPage.port
57
                    secure: connectPage.secure
58
                    saslMechanism: connectPage.sasl ? supportedSaslMechanisms[0] : ""
59
                    nickName: connectPage.nickName
60
                    realName: connectPage.realName
61
                    userName: connectPage.userName
62
                    password: connectPage.password
63
                }
64
                onMessageIgnored: serverBuffer.receiveMessage(message)
65
66
                function quit() {
67
                    bufferModel.clear()
68
                    connection.quit(qsTr("Irc Client"))
69
                    connection.close()
70
                    Qt.quit()
71
                }
72
            }
73
            serverBuffer: IrcBuffer {
74
                id: serverBuffer
75
                sticky: true
76
                persistent: true
77
                name: connection.displayName
78
                Component.onCompleted: bufferModel.add(serverBuffer)
79
            }
80
        }
81
82
    }//stack
83
    Irc { id: irc
84
85
    }
86
    IrcCommand { id: cmd }
87
88
    Component.onDestruction: bufferModel.quit()
89
}