/
main.qml
129 lines (113 loc) · 3.1 KB
/
main.qml
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import QtQuick
import QtQuick.Controls
import QtWebView
import com.pipacs.o2
ApplicationWindow {
id: app
visible: true
title: "Sialis"
minimumWidth: 300
minimumHeight: 200
height: 700
O1Twitter {
id: o1Twitter
clientId: "The app's API Key from developer.twitter.com"
clientSecret: "The app's API Secret from developer.twitter.com "
localPort: 8888
onOpenBrowser: {
browser.url = url
browser.visible = true
}
onCloseBrowser: {
browser.visible = false
}
onLinkedChanged: {
loginButton.enabled = true
twitterApi.requestTweets()
}
}
TwitterApi {
id: twitterApi
authenticator: o1Twitter
}
footer: ToolBar {
Label {
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
text: o1Twitter.linked? ("Logged in as " + o1Twitter.extraTokens["screen_name"]): "Not logged in"
}
Button {
id: loginButton
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
text: o1Twitter.linked? "Logout": "Login"
onClicked: {
enabled = false
if (o1Twitter.linked) {
o1Twitter.unlink()
} else {
o1Twitter.link()
}
}
}
height: loginButton.height + 5
}
ListView {
id: listView
anchors.fill: parent
model: twitterApi.tweetModel
delegate: listDelegate
highlight: Rectangle {color: "#10000000"}
focus: true
Component {
id: listDelegate
Item {
width: parent.width
height: label.contentHeight + 10
Row {
anchors.fill: parent
Label {
id: label
anchors.centerIn: parent
width: parent.width
text: rawText
wrapMode: Text.Wrap
}
Rectangle {
width: parent.width
height: 1
color: "#10000000"
border.color: "transparent"
}
}
MouseArea {
anchors.fill: parent
onClicked: listView.currentIndex = index
}
}
}
}
ApplicationWindow {
id: browser
visible: false
minimumHeight: 800
minimumWidth: 500
title: "Login"
property url url: ""
WebView {
anchors.fill: parent
url: browser.url
}
onClosing: {
close.accepted = true
loginButton.enabled = true
}
}
Timer {
interval: 30000
repeat: true
running: true
triggeredOnStart: true
onTriggered: twitterApi.requestTweets()
}
}