2017-08-29 05:09:17 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-08-29 14:05:51 +00:00
|
|
|
"log"
|
2017-08-29 05:09:17 +00:00
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/therecipe/qt/core"
|
|
|
|
"github.com/therecipe/qt/gui"
|
|
|
|
"github.com/therecipe/qt/qml"
|
|
|
|
"github.com/therecipe/qt/quickcontrols2"
|
|
|
|
|
2019-05-01 15:15:56 +00:00
|
|
|
"github.com/muesli/chirp/accounts/mastodon"
|
2017-08-29 05:09:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// reply is used to post a new tweet
|
|
|
|
// if replyid is > 0, it's send as a reply
|
|
|
|
func reply(replyid string, message string) {
|
|
|
|
var err error
|
|
|
|
iid, _ := strconv.ParseInt(replyid, 10, 64)
|
|
|
|
if iid > 0 {
|
2017-08-29 14:05:51 +00:00
|
|
|
log.Println("Sending reply to:", iid, message)
|
2017-08-29 05:09:17 +00:00
|
|
|
err = tc.Reply(iid, message)
|
|
|
|
} else {
|
2017-08-29 14:05:51 +00:00
|
|
|
log.Println("Sending tweet:", message)
|
2019-05-01 16:43:14 +00:00
|
|
|
err = tc.Post(message)
|
2017-08-29 05:09:17 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
2019-05-01 15:15:56 +00:00
|
|
|
log.Println("Error posting to Account:", err)
|
2017-08-29 05:09:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// retweet a message
|
|
|
|
func retweet(id string) {
|
|
|
|
iid, _ := strconv.ParseInt(id, 10, 64)
|
2017-08-29 14:05:51 +00:00
|
|
|
log.Println("Retweeting:", iid)
|
2017-08-29 05:09:17 +00:00
|
|
|
err := tc.Retweet(iid)
|
2019-05-01 15:15:56 +00:00
|
|
|
log.Println("Error posting to Account:", err)
|
2017-08-29 05:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// like a message
|
|
|
|
func like(id string) {
|
|
|
|
iid, _ := strconv.ParseInt(id, 10, 64)
|
2017-08-29 14:05:51 +00:00
|
|
|
log.Println("Liking:", iid)
|
2017-08-29 05:09:17 +00:00
|
|
|
err := tc.Like(iid)
|
2019-05-01 15:15:56 +00:00
|
|
|
log.Println("Error posting to Account:", err)
|
2017-08-29 05:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// runApp loads and executes the QML UI
|
|
|
|
func runApp(config Config) {
|
|
|
|
quickcontrols2.QQuickStyle_SetStyle(config.Style)
|
|
|
|
|
|
|
|
app := qml.NewQQmlApplicationEngine(nil)
|
|
|
|
app.RootContext().SetContextProperty("uiBridge", uiBridge)
|
|
|
|
app.RootContext().SetContextProperty("accountBridge", accountBridge)
|
|
|
|
app.RootContext().SetContextProperty("settings", configBridge)
|
|
|
|
|
|
|
|
app.Load(core.NewQUrl3("qrc:/qml/chirp.qml", 0))
|
|
|
|
gui.QGuiApplication_Exec()
|
|
|
|
}
|
|
|
|
|
2019-05-01 15:15:56 +00:00
|
|
|
// setupMastodon starts a new Mastodon client and sets up event handling & models for it
|
|
|
|
func setupMastodon(config Account) {
|
|
|
|
tc = mastodon.NewAccount(config.Username, config.Password, config.Instance, config.ClientID, config.ClientSecret)
|
2017-08-29 05:09:17 +00:00
|
|
|
tweetModel := NewMessageModel(nil)
|
|
|
|
notificationModel := NewMessageModel(nil)
|
|
|
|
|
|
|
|
accountBridge.SetUsername("Logging in...")
|
|
|
|
accountBridge.SetMessages(tweetModel)
|
|
|
|
accountBridge.SetNotifications(notificationModel)
|
|
|
|
|
|
|
|
evchan := make(chan interface{})
|
|
|
|
go handleEvents(evchan, tweetModel, notificationModel)
|
|
|
|
go func() {
|
|
|
|
tc.Run(evchan)
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
core.QCoreApplication_SetApplicationName("Chirp")
|
2019-05-01 15:15:56 +00:00
|
|
|
core.QCoreApplication_SetOrganizationName("fribbledom.com")
|
2017-08-29 05:09:17 +00:00
|
|
|
core.QCoreApplication_SetAttribute(core.Qt__AA_EnableHighDpiScaling, true)
|
|
|
|
gui.NewQGuiApplication(len(os.Args), os.Args)
|
|
|
|
|
|
|
|
setupQmlBridges()
|
|
|
|
|
|
|
|
// load config
|
|
|
|
config := LoadConfig()
|
|
|
|
if config.Style == "" {
|
|
|
|
config.Style = "Material"
|
|
|
|
}
|
|
|
|
configBridge.SetStyle(config.Style)
|
|
|
|
|
2019-05-01 15:15:56 +00:00
|
|
|
setupMastodon(config.Account[0])
|
2017-08-29 05:09:17 +00:00
|
|
|
runApp(config)
|
|
|
|
|
|
|
|
// save config
|
|
|
|
config.Style = configBridge.Style()
|
|
|
|
SaveConfig(config)
|
|
|
|
}
|