~ubuntu-branches/ubuntu/wily/kid3/wily

« back to all changes in this revision

Viewing changes to src/qml/app/FrameEditDialog.qml

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2015-05-12 18:56:41 UTC
  • mfrom: (1.1.19) (2.3.3 sid)
  • Revision ID: package-import@ubuntu.com-20150512185641-hgeys2pingwq9mwn
Tags: 3.2.1-1
* New upstream release.
  - Add new build dependency qt4-dev-tools.
* Uploading to unstable.
* Switch to DEP5 debian/copyright format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * \file FrameEditDialog.qml
 
3
 * Dialog to edit frames.
 
4
 *
 
5
 * \b Project: Kid3
 
6
 * \author Urs Fleisch
 
7
 * \date 16 Feb 2015
 
8
 *
 
9
 * Copyright (C) 2015  Urs Fleisch
 
10
 *
 
11
 * This program is free software; you can redistribute it and/or modify
 
12
 * it under the terms of the GNU Lesser General Public License as published by
 
13
 * the Free Software Foundation; version 3.
 
14
 *
 
15
 * This program is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 * GNU Lesser General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU Lesser General Public License
 
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
22
 */
 
23
 
 
24
import QtQuick 2.2
 
25
import "../componentsqtquick" //@!Ubuntu
 
26
//import Ubuntu.Components 1.1 //@Ubuntu
 
27
//import Ubuntu.Components.Popups 1.0 //@Ubuntu
 
28
//import Ubuntu.Components.ListItems 1.0 //@Ubuntu
 
29
import Kid3 1.0
 
30
 
 
31
Dialog {
 
32
  id: page
 
33
 
 
34
  property QtObject frameObject
 
35
  signal frameEdited(variant frame)
 
36
 
 
37
  function open(frame) {
 
38
    page.title = frame.internalName
 
39
    fieldList.model = frame.fields
 
40
    frameObject = frame
 
41
    page.show()
 
42
    if (frame.type === Frame.FT_Picture) {
 
43
      app.setCoverArtImageData(frame.getBinaryData())
 
44
    }
 
45
  }
 
46
 
 
47
  Component {
 
48
    id: textLineEdit
 
49
    TextField {
 
50
      text: _modelData.value
 
51
      onAccepted: {
 
52
        focus = false
 
53
      }
 
54
      onActiveFocusChanged: {
 
55
        if (!activeFocus) {
 
56
          _modelData.value = text
 
57
        }
 
58
      }
 
59
    }
 
60
  }
 
61
 
 
62
  Component {
 
63
    id: textEdit
 
64
    TextArea {
 
65
      text: _modelData.value
 
66
      onActiveFocusChanged: {
 
67
        if (!activeFocus) {
 
68
          _modelData.value = text
 
69
        }
 
70
      }
 
71
    }
 
72
  }
 
73
 
 
74
  Component {
 
75
    id: comboBoxEdit
 
76
 
 
77
    ComboBox {
 
78
      dropDownParent: root
 
79
      model: if (_modelData.id === Frame.ID_TextEnc)
 
80
               script.getTextEncodingNames()
 
81
             else if (_modelData.id === Frame.ID_PictureType)
 
82
               script.getPictureTypeNames()
 
83
             else if (_modelData.id === Frame.ID_TimestampFormat)
 
84
               script.getTimestampFormatNames()
 
85
             else if (_modelData.id === Frame.ID_ContentType)
 
86
               script.getContentTypeNames()
 
87
      currentIndex: _modelData.value
 
88
      onCurrentIndexChanged: _modelData.value = currentIndex
 
89
    }
 
90
  }
 
91
 
 
92
  Component {
 
93
    id: exportFileSelectDialog
 
94
    FileSelectDialog {
 
95
      property variant field
 
96
      parent: root
 
97
      title: qsTr("Export")
 
98
      onFinished: {
 
99
        if (path) {
 
100
          script.writeFile(path, field.value)
 
101
        }
 
102
      }
 
103
    }
 
104
  }
 
105
 
 
106
  Component {
 
107
    id: importFileSelectDialog
 
108
    FileSelectDialog {
 
109
      property variant field
 
110
      parent: root
 
111
      title: qsTr("Import")
 
112
      onFinished: {
 
113
        if (path) {
 
114
          field.value = script.readFile(path)
 
115
        }
 
116
      }
 
117
    }
 
118
  }
 
119
 
 
120
  Component {
 
121
    id: imageView
 
122
 
 
123
    Column {
 
124
      width: parent.width
 
125
      spacing: constants.spacing
 
126
 
 
127
      Button {
 
128
        id: importButton
 
129
        width: parent.width
 
130
        text: qsTr("Import")
 
131
        onClicked: {
 
132
          constants.openPopup(importFileSelectDialog, importButton,
 
133
                        {"filePath": app.dirName + "/" +
 
134
                                     configs.fileConfig().defaultCoverFileName,
 
135
                          "field": _modelData})
 
136
        }
 
137
      }
 
138
 
 
139
      Button {
 
140
        id: exportButton
 
141
        width: parent.width
 
142
        text: qsTr("Export")
 
143
 
 
144
        onClicked: {
 
145
          constants.openPopup(exportFileSelectDialog, exportButton,
 
146
                        {"filePath": app.dirName + "/" +
 
147
                                     configs.fileConfig().defaultCoverFileName,
 
148
                          "field": _modelData})
 
149
        }
 
150
      }
 
151
 
 
152
      Item {
 
153
        id: imageItem
 
154
        width: parent.width
 
155
        height: 120
 
156
        Image {
 
157
          anchors.fill: parent
 
158
          fillMode: Image.PreserveAspectFit
 
159
          source: app.coverArtImageId
 
160
          cache: false
 
161
        }
 
162
      }
 
163
    }
 
164
  }
 
165
 
 
166
  ListView {
 
167
    id: fieldList
 
168
    height: constants.gu(30)
 
169
    clip: true
 
170
    delegate: Column {
 
171
      width: parent.width
 
172
      spacing: constants.spacing
 
173
      Label {
 
174
        id: nameLabel
 
175
        text: modelData.name
 
176
      }
 
177
 
 
178
      Loader {
 
179
        width: parent.width
 
180
        property QtObject _modelData: modelData
 
181
        sourceComponent:
 
182
            if (typeof modelData.value === "number")
 
183
              if (modelData.id === Frame.ID_TextEnc ||
 
184
                  modelData.id === Frame.ID_PictureType ||
 
185
                  modelData.id === Frame.ID_TimestampFormat ||
 
186
                  modelData.id === Frame.ID_ContentType)
 
187
                comboBoxEdit
 
188
              else
 
189
                textLineEdit
 
190
            else if (typeof modelData.value === "string")
 
191
              if (modelData.id === Frame.ID_Text)
 
192
                textEdit
 
193
              else
 
194
                textLineEdit
 
195
            else if (typeof modelData.value === "object")
 
196
              if (modelData.id === Frame.ID_Data &&
 
197
                  modelData.type === Frame.FT_Picture)
 
198
                imageView
 
199
      }
 
200
      ThinDivider {
 
201
        visible: index != fieldList.count - 1
 
202
      }
 
203
    }
 
204
  }
 
205
 
 
206
  Row {
 
207
    spacing: constants.spacing
 
208
    Button {
 
209
      width: (parent.width - parent.spacing) / 2
 
210
      text: qsTr("Cancel")
 
211
      onClicked: {
 
212
        page.hide()
 
213
        page.frameEdited(null)
 
214
        frameObject = null
 
215
      }
 
216
    }
 
217
    Button {
 
218
      width: (parent.width - parent.spacing) / 2
 
219
      text: qsTr("OK")
 
220
      onClicked: {
 
221
        fieldList.focus = false // to force editingFinished on delegate
 
222
        page.hide()
 
223
        page.frameEdited(frameObject)
 
224
        frameObject = null
 
225
      }
 
226
    }
 
227
  }
 
228
}