Qt/QML App for Friendiqa
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Newsitem.qml 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. // This file is part of Friendiqa
  2. // https://git.friendi.ca/lubuwest/Friendiqa
  3. // Copyright (C) 2017 Marco R. <thomasschmidt45@gmx.net>
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // In addition, as a special exception, the copyright holders give
  11. // permission to link the code of portions of this program with the
  12. // OpenSSL library under certain conditions as described in each
  13. // individual source file, and distribute linked combinations including
  14. // the two.
  15. //
  16. // You must obey the GNU General Public License in all respects for all
  17. // of the code used other than OpenSSL. If you modify file(s) with this
  18. // exception, you may extend this exception to your version of the
  19. // file(s), but you are not obligated to do so. If you do not wish to do
  20. // so, delete this exception statement from your version. If you delete
  21. // this exception statement from all source files in the program, then
  22. // also delete it here.
  23. //
  24. // This program is distributed in the hope that it will be useful,
  25. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. // GNU General Public License for more details.
  28. //
  29. // You should have received a copy of the GNU General Public License
  30. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. import QtQuick 2.0
  32. import QtQuick.Controls 1.4
  33. import QtQuick.Controls.Styles 1.4
  34. import "qrc:/js/news.js" as Newsjs
  35. import "qrc:/js/helper.js" as Helperjs
  36. import "qrc:/qml/genericqml"
  37. Item {
  38. id: newsitem
  39. width: parent.width
  40. height:toprow.height+friendicaActivities.height+controlrow.height+1//Math.max((itemMessage.height+topFlow.height+friendicaActivities.height+4*mm),profileImage.height+user_name.height+mm)
  41. property int itemindex: index
  42. property string attending: ""
  43. onAttendingChanged: {attendLabel.visible=true;
  44. attendLabel.text= qsTr("attending: ")+ qsTr(attending)}
  45. signal replyto(string parent_id)
  46. function showActivityContacts(contacts){
  47. var component = Qt.createComponent("qrc:/qml/newsqml/FriendicaActivities.qml");
  48. var imagedialog = component.createObject(friendicaActivities,{"activitymembers": contacts});
  49. }
  50. function findTags(fulltext){
  51. return fulltext.match(/\s+[#]+[A-Za-z0-9-_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF]+/g)
  52. }
  53. Rectangle{width:newsitem.width; height: 1; anchors.bottom: newsitem.bottom; color:"light grey"}
  54. Rectangle{
  55. width:newsitem.width
  56. height:newsitem.height-1
  57. color: (newsitemobject.messagetype==1)?"#ffe6e6" : "white"
  58. Row{id:toprow
  59. Column {
  60. id: authorcolumn
  61. width: 8*mm
  62. Image {
  63. id:profileImage
  64. source: ((newsitemobject.user.profile_image!="") && (typeof(newsitemobject.user.profile_image)=="string"))? "file://"+newsitemobject.user.profile_image : newsitemobject.user.profile_image_url
  65. x:1
  66. width: 7*mm
  67. height: 7*mm
  68. MouseArea{
  69. anchors.fill: parent
  70. onClicked:{
  71. showContact(newsitemobject.user)}
  72. }
  73. onStatusChanged: if (profileImage.status == Image.Error) {source="qrc:/images/defaultcontact.jpg"}
  74. }
  75. Label {
  76. id:user_name
  77. color: "grey"
  78. width:parent.width
  79. font.pixelSize: 1.5*mm
  80. wrapMode: Text.WrapAtWordBoundaryOrAnywhere
  81. text: newsitemobject.user.name+forumname
  82. }
  83. }
  84. Column {
  85. id:newscolumn
  86. width: newsitem.width-8*mm
  87. Flow{
  88. id:topFlow
  89. spacing: mm
  90. width:parent.width
  91. Label {
  92. id:messageTypeLabel
  93. color: "grey"
  94. text: if (newsitemobject.messagetype==0){qsTr("Source: ")+newsitemobject.source
  95. } else if (newsitemobject.messagetype==1){ qsTr("Direct Message")} else {" Notification"}
  96. font.pixelSize: 1.5*mm
  97. }
  98. Label {
  99. id:createdAtLabel
  100. color: "grey"
  101. font.pixelSize: 1.5*mm
  102. horizontalAlignment: Label.AlignRight
  103. text: dateDiff
  104. }
  105. Label {
  106. id:replytoLabel
  107. color: "grey"
  108. font.pixelSize: 1.5*mm
  109. horizontalAlignment: Label.AlignRight
  110. text: try {qsTr("In reply to ")+newsitemobject.reply_user.screen_name
  111. }catch(e){" "}
  112. }
  113. Label {
  114. id:newscountLabel
  115. visible:((newstabstatus=="Conversations")&&(newsitemobject.newscount>1))?true:false
  116. color: "grey"
  117. height:3.5*mm
  118. font.pixelSize: 1.5*mm
  119. font.bold: true
  120. horizontalAlignment: Label.AlignRight
  121. text: try {(newsitemobject.newscount-1)+qsTr(" comments") }catch(e){" "}
  122. MouseArea{
  123. anchors.fill:parent
  124. onClicked: {
  125. newsStack.push("qrc:/qml/newsqml/Conversation.qml");
  126. showConversation(index,newsitemobject)
  127. }
  128. }
  129. }
  130. }
  131. Column{ id: messageColumn
  132. //anchors.top:topFlow.bottom
  133. width:parent.width
  134. spacing:mm
  135. clip:true
  136. height: Math.min(implicitHeight,3/4*root.height)
  137. MouseArea{
  138. width: newsitem.width-8*mm-2
  139. height: itemMessage.height
  140. onPressAndHold: {
  141. newsStack.push("qrc:/qml/newsqml/Conversation.qml");
  142. showConversation(index,newsitemobject)
  143. }
  144. Text {
  145. color: "#404040"
  146. linkColor: "light green"
  147. id: itemMessage
  148. textFormat: Text.RichText
  149. text: newsitemobject.statusnet_html//newsitemobject.attachmentList.length>0?newsitemobject.text : newsitemobject.statusnet_html
  150. width: newsitem.width-8*mm-2
  151. height: implicitHeight
  152. wrapMode: Text.Wrap
  153. clip:true
  154. //MouseArea{anchors.fill:parent;onClicked: print("Test")}
  155. onLinkActivated:{
  156. Qt.openUrlExternally(link)}
  157. Component.onCompleted:{
  158. if (newsitemobject.messagetype==0){
  159. var hashtags=[];
  160. hashtags=findTags(newsitemobject.text);
  161. var component = Qt.createComponent("qrc:/qml/newsqml/Hashtag.qml");
  162. for (var tags in hashtags){
  163. var hashtagQml = component.createObject(friendicaActivities,{"text":hashtags[tags].trim()});
  164. }}
  165. if (newsitemobject.attachmentList.length>0){
  166. for(var attachments in newsitemobject.attachmentList){// (newsitemobject.attachmentList[attachments].url);
  167. if(newsitemobject.attachmentList[attachments].mimetype.substring(0,5)=="image"){
  168. var component = Qt.createComponent("qrc:/qml/newsqml/NewsImage.qml");
  169. var imageQml = component.createObject(messageColumn,{"source":newsitemobject.attachmentList[attachments].url,"mimetype":newsitemobject.attachmentList[attachments].mimetype});
  170. }
  171. else if(newsitemobject.attachmentList[attachments].mimetype=="text/html"){
  172. var component = Qt.createComponent("qrc:/qml/newsqml/NewsLink.qml");
  173. var linkQml = component.createObject(messageColumn,{"url":newsitemobject.attachmentList[attachments].url});
  174. }
  175. else {//print(newsitemobject.attachmentList[attachments].url+" Type: "+newsitemobject.attachmentList[attachments].mimetype)
  176. var component = Qt.createComponent("qrc:/qml/newsqml/NewsVideo.qml");
  177. var videoQml = component.createObject(messageColumn,{"source":newsitemobject.attachmentList[attachments].url,"mimetype":newsitemobject.attachmentList[attachments].mimetype});
  178. }
  179. }
  180. }
  181. }
  182. }}
  183. }
  184. BlueButton{
  185. width: newsitem.width-8*mm-2
  186. height:5*mm
  187. //anchors.bottom: messageColumn.bottom//itemMessage.bottom
  188. visible: messageColumn.implicitHeight>3/4*root.height//itemMessage.implicitHeight>3/4*root.height
  189. text:"\uf078"
  190. fontColor:"grey"
  191. border.color: "transparent"
  192. color:"white"
  193. // gradient: Gradient {
  194. // GradientStop { position: 0.0; color: "transparent" }
  195. // GradientStop { position: 0.5; color: "white" }
  196. // }
  197. radius:0
  198. onClicked: {
  199. if (text=="\uf078"){
  200. messageColumn.height=messageColumn.implicitHeight+10*mm;text="\uf077"
  201. } else {
  202. messageColumn.height=Math.min(messageColumn.implicitHeight,3/4*root.height);
  203. text="\uf078";
  204. newsView.positionViewAtIndex(index,ListView.Beginning);
  205. }
  206. }
  207. }
  208. }
  209. }
  210. Flow{
  211. id:friendicaActivities
  212. anchors.top:toprow.bottom
  213. width:parent.width
  214. spacing:mm
  215. Label{color: "grey"
  216. height:3.5*mm
  217. font.pixelSize: 1.5*mm
  218. text: friendica_activities.likeText
  219. MouseArea{
  220. anchors.fill: parent
  221. onClicked: { showActivityContacts(newsitemobject.friendica_activities.like)}
  222. }
  223. }
  224. Label{color: "grey"
  225. height:3.5*mm
  226. font.pixelSize: 1.5*mm
  227. text: friendica_activities.dislikeText
  228. MouseArea{
  229. anchors.fill: parent
  230. onClicked: { showActivityContacts(newsitemobject.friendica_activities.dislike)}
  231. }
  232. }
  233. Label{color: "grey"
  234. height:3.5*mm
  235. font.pixelSize: 1.5*mm
  236. text: friendica_activities.attendyesText
  237. MouseArea{
  238. anchors.fill: parent
  239. onClicked: { showActivityContacts(newsitemobject.friendica_activities.attendyes)}
  240. }}
  241. Label{color: "grey"
  242. height:3.5*mm
  243. font.pixelSize: 1.5*mm
  244. text: friendica_activities.attendnoText
  245. MouseArea{
  246. anchors.fill: parent
  247. onClicked: { showActivityContacts(newsitemobject.friendica_activities.attendno)}
  248. }
  249. }
  250. Label{color: "grey"
  251. height:3.5*mm
  252. font.pixelSize: 1.5*mm
  253. text: friendica_activities.attendmaybeText
  254. MouseArea{
  255. anchors.fill: parent
  256. onClicked: { showActivityContacts(newsitemobject.friendica_activities.attendmaybe)}
  257. }
  258. }
  259. Label{
  260. id:attendLabel
  261. color: "grey"
  262. height:3.5*mm
  263. font.pixelSize: 1.5*mm
  264. horizontalAlignment: Label.AlignRight
  265. text: (friendica_activities.self.attending)?(qsTr("Attending: ")+ qsTr(friendica_activities.self.attending)):""
  266. }
  267. }
  268. Row{id:controlrow
  269. anchors.top:friendicaActivities.bottom
  270. CheckBox{
  271. id:likeCheckbox
  272. width:10*mm
  273. visible: (newsitemobject.messagetype==0)? true:false
  274. checked:(friendica_activities.self.liked==1)?true:false
  275. style: CheckBoxStyle {
  276. indicator: Rectangle{
  277. implicitWidth: 10*mm
  278. implicitHeight:3*mm
  279. Text{
  280. anchors.centerIn: parent
  281. font.pixelSize: 2.5*mm
  282. font.family:fontAwesome.name
  283. color:control.checked?"black": "grey"
  284. text:control.checked?"\uf118"+"!":"\uf118"
  285. }
  286. }
  287. }
  288. onClicked: {
  289. if(likeCheckbox.checked==true){Newsjs.like(root.login,root.db,1,"like",newsitemobject.id,root);dislikeCheckbox.checked=false; model.friendica_activities.self.liked=0 }
  290. else{Newsjs.like(root.login,root.db,0,"like",newsitemobject.id,root); model.friendica_activities.self.liked=1}}
  291. }
  292. CheckBox{
  293. id: dislikeCheckbox
  294. width:10*mm
  295. visible: (newsitemobject.messagetype==0)? true:false
  296. checked: (friendica_activities.self.disliked==1)?true:false
  297. style: CheckBoxStyle {
  298. indicator: Rectangle{
  299. implicitWidth: 10*mm
  300. implicitHeight:3*mm
  301. Text{
  302. anchors.centerIn: parent
  303. font.pixelSize: 2.5*mm
  304. font.family:fontAwesome.name
  305. color:control.checked?"black": "grey"
  306. text: control.checked?"\uf119"+"!":"\uf119"
  307. }
  308. }
  309. }
  310. onClicked: {
  311. if (dislikeCheckbox.checked==true){Newsjs.like(root.login,root.db,1,"dislike",newsitemobject.id,root);likeCheckbox.checked=false; model.friendica_activities.self.disliked=0}
  312. else {Newsjs.like(root.login,root.db,0,"dislike",newsitemobject.id,root); model.friendica_activities.self.disliked=1}}
  313. }
  314. CheckBox {
  315. id:favoritedCheckbox
  316. visible:(newsitemobject.messagetype==0)
  317. width: 10*mm
  318. style: CheckBoxStyle {
  319. indicator:Rectangle{
  320. x:4*mm
  321. width: 3*mm
  322. implicitHeight:4*mm
  323. Text{
  324. color: control.checked?"black":"grey"
  325. font.pixelSize: 2.5*mm
  326. text:"\uf005"
  327. }
  328. }
  329. }
  330. checked:(newsitemobject.favorited>0)
  331. onClicked:{
  332. if(favoritedCheckbox.checkedState==Qt.Checked){
  333. Newsjs.favorite(login,true,newsitemobject.id,root); model.newsitemobject.favorited=1}
  334. else if(favoritedCheckbox.checkedState==Qt.Unchecked){
  335. Newsjs.favorite(login,false,newsitemobject.id,root);model.newsitemobject.favorited=0}
  336. }
  337. }
  338. Rectangle{
  339. width: 10*mm
  340. height: 4*mm
  341. visible:(newsitemobject.messagetype!==2)
  342. color:"transparent"
  343. Text{
  344. id:newsmenusymbol
  345. color: "grey"
  346. anchors.centerIn: parent
  347. font.pixelSize: 2.5*mm
  348. font.family:fontAwesome.name
  349. text: "\uf142"
  350. }
  351. MouseArea{
  352. anchors.fill:parent
  353. onClicked: {newsmenu.popup()}}
  354. }
  355. Rectangle{
  356. width: 10*mm
  357. height: 4*mm
  358. visible:(newsitemobject.messagetype!==2)&&(newstab.newstabstatus!="Conversation")
  359. color:"transparent"
  360. Text{
  361. id:conversationsymbol
  362. color: "grey"
  363. anchors.centerIn: parent
  364. font.pixelSize: 2.5*mm
  365. font.family: fontAwesome.name
  366. text: "\uf086"
  367. }
  368. MouseArea{
  369. anchors.fill:parent
  370. onClicked:{
  371. //conversationsymbol.color="black";
  372. // var component = Qt.createComponent("qrc:/qml/newsqml/Conversation.qml");
  373. // var conversationItem = component.createObject(friendicaActivities);
  374. newsStack.push("qrc:/qml/newsqml/Conversation.qml")
  375. showConversation(index,newsitemobject)
  376. }
  377. }
  378. }
  379. }
  380. Menu {
  381. id:newsmenu
  382. MenuItem {
  383. text: qsTr("Reply")
  384. onTriggered: {
  385. var directmessage=0;
  386. if (newsitemobject.messagetype==1){ directmessage=1}
  387. newsStack.push("qrc:/qml/newsqml/MessageSend.qml",{"reply_to_user": newsitemobject.user.screen_name,"parentId":newsitemobject.id,"login":root.login,"directmessage":directmessage});
  388. }
  389. }
  390. MenuItem {
  391. text: qsTr("DM")
  392. onTriggered: {
  393. root.directmessageSignal(newsitemobject.user.screen_name);
  394. }
  395. }
  396. MenuItem {
  397. text: qsTr("Repost")
  398. onTriggered: {
  399. Newsjs.retweetNews(root.login,db,newsitemobject.id,root,function(reply){
  400. Helperjs.showMessage("Repost",qsTr("Success!"),root)
  401. })
  402. }
  403. }
  404. MenuItem {
  405. text: qsTr("Conversation")
  406. onTriggered: {
  407. conversationsymbol.color="black";
  408. var component = Qt.createComponent("qrc:/qml/newsqml/Conversation.qml");
  409. var conversationItem = component.createObject(friendicaActivities,{"news":newsitemobject.chatArray});
  410. showConversation(index,newsitemobject)
  411. }
  412. }
  413. Menu{
  414. title: qsTr("Attending")
  415. MenuItem{
  416. text:qsTr("yes")
  417. onTriggered: {Newsjs.attend(root.login,db,"yes",newsitemobject.id,root,function(){
  418. model.friendica_activities.self.attending="yes";attending="yes"})
  419. }
  420. }
  421. MenuItem{text:qsTr("maybe")
  422. onTriggered: {Newsjs.attend(root.login,db,"maybe",newsitemobject.id,root,function(){
  423. model.friendica_activities.self.attending="maybe";attending="maybe"})
  424. }
  425. }
  426. MenuItem{text:qsTr("no")
  427. onTriggered: {Newsjs.attend(root.login,db,"no",newsitemobject.id,root,function(){
  428. model.friendica_activities.self.attending="no";attending="no"})}
  429. }
  430. }
  431. MenuItem {
  432. text: qsTr("Delete")
  433. onTriggered: {
  434. Newsjs.deleteNews(root.login,root.db,newsitemobject.id,newsitemobject.messagetype,root,function(reply){
  435. var msg = {'deleteId': index, 'model': newsModel};
  436. newsWorker.sendMessage(msg);
  437. })
  438. }
  439. }
  440. //MenuItem{
  441. // text:qsTr("Show on website")
  442. // onTriggered:Qt.openUrlExternally(login.server+"/display/"+newsitemobject
  443. //}
  444. }
  445. }}