Advertisement
Guest User

Untitled

a guest
Dec 21st, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.44 KB | None | 0 0
  1. Firstpage.qml
  2.  
  3. import QtQuick 2.0
  4. import Sailfish.Silica 1.0
  5. import "../pages/DBasestuff.js" as DBase
  6.  
  7. Page {
  8. id: page
  9.  
  10. property bool stopthisshit: false
  11.  
  12. Component.onCompleted: {
  13.  
  14. DBase.inDBase();
  15. //populateList()
  16.  
  17. }
  18. onStatusChanged: {
  19.  
  20. console.log("status changed")
  21. if (!stopthisshit) {
  22. populateList()
  23. }
  24.  
  25. }
  26.  
  27. SilicaListView {
  28. id:connectionsList
  29. anchors.fill: parent
  30. model:listModel
  31. section {
  32. property: 'section'
  33. delegate: SectionHeader {
  34. text: section
  35. }
  36. }
  37. VerticalScrollDecorator { flickable:connectionsList }
  38.  
  39. ViewPlaceholder {
  40. text: qsTr("Pull down to add a new connection.")
  41. enabled: connectionsList.count == 0
  42. }
  43.  
  44. PullDownMenu {
  45. MenuItem {
  46. text: qsTr("New SSH connection")
  47. onClicked: pageStack.push(Qt.resolvedUrl("CreateSSH.qml"))
  48. }
  49. MenuItem {
  50. text: qsTr("New Mosh connection")
  51. onClicked: pageStack.push(Qt.resolvedUrl("CreateMosh.qml"))
  52. }
  53. }
  54.  
  55. header: Image {
  56. source: "mossh_logo.png"
  57. anchors {
  58. horizontalCenter: parent.horizontalCenter
  59. }
  60. MouseArea {
  61. anchors.fill: parent
  62. onClicked: pageStack.push(Qt.resolvedUrl("About.qml"))
  63. }
  64. }
  65.  
  66. delegate: ListItem {
  67. id: listItem
  68. menu: contextMenuComponent
  69.  
  70. onClicked: {
  71.  
  72. }
  73. Grid{
  74. columns: 2
  75. spacing: 5
  76.  
  77. GlassItem {
  78. color : "green"
  79. }
  80. Grid {
  81. rows:2
  82.  
  83. Label {
  84. text: model.connection_name
  85. }
  86. Row {
  87. Label {
  88. text: model.type
  89. color: "yellow"
  90. font.pixelSize: Theme.fontSizeTiny
  91. }
  92. Label {
  93. text: " connection at " +model.username +"@"+ model.address
  94. color: "grey"
  95. font.pixelSize: Theme.fontSizeTiny
  96. }
  97. }
  98.  
  99. }
  100. Component {
  101. id: contextMenuComponent
  102. ContextMenu {
  103. MenuItem {
  104. text: qsTr("Disconnect")
  105. visible: false //fucntion or whatever to check if active
  106. onClicked: {
  107.  
  108. }
  109. }
  110. MenuItem {
  111. text: qsTr("Edit")
  112. onClicked: {
  113. console.log("going to edit", model.username)
  114. page.stopthisshit = true
  115. pageStack.push(Qt.resolvedUrl("EditCon.qml"), {"modelID": model})
  116. }
  117. }
  118. MenuItem {
  119. text: qsTr("Delete")
  120. onClicked: {
  121. console.log("Deleting:",model.connection_name, model.username, model.address, model.type, model.category, model.activate_on_start, model.connection_commands);
  122. DBase.removeConnection(model.id);
  123. listModel.remove(index);
  124. }
  125. }
  126. }
  127. }
  128. }
  129. }
  130. }
  131.  
  132. ListModel {
  133. id: listModel
  134.  
  135. }
  136. function populateList(){
  137.  
  138. listModel.clear()
  139.  
  140. var connection = DBase.getConnections()
  141.  
  142. for (var i = 0; i < connection.rows.length; i++){
  143.  
  144. var component = Qt.createComponent("Connection.qml")
  145.  
  146. console.log("creating list connection", i+1);
  147. console.log("--->>>", connection.rows.item(i).id,connection.rows.item(i).connection_name,connection.rows.item(i).username, connection.rows.item(i).address,connection.rows.item(i).type, connection.rows.item(i).category, connection.rows.item(i).act_on_start,connection.rows.item(i).connection_commands)
  148.  
  149. var mod = component.createObject(null, {
  150. section:"Connections",
  151. id:connection.rows.item(i).id,
  152. connection_name: connection.rows.item(i).connection_name,
  153. username: connection.rows.item(i).username,
  154. address: connection.rows.item(i).address,
  155. type: connection.rows.item(i).type,
  156. category: connection.rows.item(i).category,
  157. activate_on_start: connection.rows.item(i).act_on_start,
  158. connection_commands: connection.rows.item(i).connection_commands
  159. })
  160.  
  161. listModel.append(mod)
  162.  
  163. }
  164.  
  165. }
  166.  
  167. }
  168.  
  169. import QtQuick 2.0
  170. import Sailfish.Silica 1.0
  171. import "../pages/DBasestuff.js" as DBase
  172.  
  173.  
  174. EDITCON.qml
  175.  
  176. Dialog {
  177. id: editdialog
  178.  
  179. property var modelID
  180.  
  181. //FIX me Add commands Check.
  182. canAccept: connectionnameField.text != modelID.connection_name || usernameField.text != modelID.username || hostnameField.text != modelID.address || connectionCat.value != modelID.category || activateOnStart.checked != modelID.activate_on_start
  183.  
  184. acceptDestinationAction: PageStackAction.Pop
  185. acceptDestinationProperties: {"stopthisshit": false}
  186.  
  187. onAccepted:{
  188. DBase.updateConnection(modelID.id,connectionnameField.text,usernameField.text,hostnameField.text,connectionCat.value,activateOnStart.checked,"-4")
  189. console.log("edited connection")
  190. }
  191.  
  192. SilicaFlickable {
  193.  
  194. id: editconnection
  195. anchors.fill: parent
  196. contentHeight: editColumn.height + Theme.paddingLarge
  197. VerticalScrollDecorator { flickable:editconnection }
  198.  
  199. Column {
  200. id: editColumn
  201. width: parent.width
  202. spacing: Theme.paddingLarge
  203.  
  204. DialogHeader {
  205. id: dheader
  206. acceptText:qsTr("Confirm Edit")
  207. }
  208.  
  209. TextField {
  210.  
  211. id: connectionnameField
  212. focus: true
  213. width: parent.width
  214. text: modelID.connection_name
  215. label:qsTr( "Connection Name")
  216. labelVisible: true
  217. EnterKey.enabled: text.length > 0
  218. EnterKey.iconSource: "image://theme/icon-m-enter-next"
  219. EnterKey.onClicked: usernameField.focus = true
  220. }
  221.  
  222. TextField {
  223.  
  224. id:usernameField
  225. focus: true
  226. width: parent.width
  227. text: modelID.username
  228. label: qsTr("Username")
  229. labelVisible: true
  230. EnterKey.enabled: text.length > 0
  231. EnterKey.iconSource: "image://theme/icon-m-enter-next"
  232. EnterKey.onClicked: hostnameField.focus = true
  233. }
  234.  
  235. TextField {
  236.  
  237. id:hostnameField
  238. width: parent.width
  239. text: modelID.address
  240. label: qsTr("Host")
  241. labelVisible: true
  242. EnterKey.enabled: text.length > 0
  243. EnterKey.onClicked: focus = false
  244. }
  245.  
  246. ComboBox {
  247.  
  248. //FIX this to display properly the category
  249.  
  250. id: connectionCat
  251. width: parent.width
  252. label: qsTr("Connection Category")
  253. menu: ContextMenu {
  254. MenuItem { text: "Work" }
  255. MenuItem { text: "Test" }
  256. MenuItem { text: "Personal" }
  257. }
  258. }
  259.  
  260. TextSwitch {
  261.  
  262. id: activateOnStart
  263. checked: modelID.activate_on_start
  264. text: "Connect on Start"
  265. description: qsTr("Checking this switch will activate the conneciton when MoSSH starts.")
  266.  
  267. }
  268. SectionHeader {
  269.  
  270. text:qsTr("Advanced Options")
  271. }
  272. }
  273. }
  274. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement